var factors=[6.0221366516752E+026,5000,0.022046226218488,100000,100,564.38339119329,15432.358352941,1000,0.019684130552221,1,1000000000,1000000,9.80665,35.27396194958,643.01493137256,2.2046226218488,0.078736522208885,0.15747304441777,0.00098420652761106,0.0011023113109244,0.001,32.150746568628];
var gbrt=["atomic mass unit (amu)","carat (metric)","cental","centigram","dekagram","dram (dr)","grain (gr)","gram (g)","hundredweight (UK)","kilogram (kg)","microgram (µg)","milligram (mg)","newton (Earth)","ounce (oz)","pennyweight (dwt)","pound (lb)","quarter","stone","ton (UK, long)","ton (US, short)","tonne (t)","troy ounce"];
function fix(v){
if (!isFinite(v)) return "";
if (v==0) return "0";
st=""+v;
epos=st.indexOf('E');
if (epos==-1) epos=st.indexOf('e');
sdigi=Math.log(Math.abs(v)) / Math.LN10;
sdigif=Math.floor(sdigi);
if (epos==-1){
adjust=Math.pow(10, sdigif-12);
faqs=Math.round(v/adjust);
norst=""+faqs;
if (sdigif<12){
adjust2=Math.pow(10, 12-sdigif);
return (faqs / adjust2);}
else return (faqs*adjust);}
else {
zo=v*Math.pow(10, 12-sdigif);
szo=String(Math.round(zo));
inse=-1;
if (szo.charAt(0)=='-') inse=2;
else inse=1;
rest=szo.substring(inse,szo.length);
i=rest.length-1;
while (i>=0 && rest.charAt(i)=='0')
i--;
rest=rest.substring(0,i+1);
rou=szo.substring(0,inse);
if (rest.length>0) rou += "."+rest;
if (sdigif<0) sa=rou+"E";
else sa=rou+"E+";
snow=sa+sdigif;
vanow=Math.abs(parseFloat(snow));
faqsvab=Math.abs(v);
if (sdigif>=0){
if (vanow>5*faqsvab)
snow=sa+String(sdigif-1);
else if (vanow<faqsvab/5)
snow=sa+String(sdigif+1);}
else if (sdigif>=0){
if (vanow>5*faqsvab)
snow=sa+String(sdigif+1);
else if (vanow<faqsvab/5)
snow=sa+String(sdigif-1);}
vanow=parseFloat(snow);
if (vanow>1.1*v || vanow<0.9*v) return v;
else return snow;}}

function convert()
{
isNS4=(document.layers) ? true : false;
isIE4=(document.all && !document.getElementById) ? true : false;
isIE5=(document.all && document.getElementById) ? true : false;
isNS6=(!document.all && document.getElementById) ? true : false;
myform=document.forms['cform'];
w1=myform.D1.options[myform.D1.selectedIndex].value;
w2=myform.D2.options[myform.D2.selectedIndex].value;
faqsorg=factors[w2]/factors[w1];
resfaqs=myform.T1.value*faqsorg;
if (isIE5 || isNS6){
elm=document.getElementById("N1");
elm2=document.getElementById("N2");
elm.innerHTML=gbrt[w1];
elm2.innerHTML=gbrt[w2];}
if (isNaN(parseFloat(resfaqs)))
myform.T2.value="";
else
{myform.T2.value=fix(parseFloat(resfaqs))+" ";}}
