/*****************************************
(C) http://www.calculator.net all right reserved.  
*****************************************/
function popMenu(A){htmlVal="";if(A=="metric"){htmlVal=htmlVal+'<li><a href="#" onclick="popMenu(\'standard\');">US units</a></li> <li id=\'menuon\'><a href="#" onclick="popMenu(\'metric\');">metric units</a></li> <li><a href="#" onclick="popMenu(\'other\');">other units</a></li>';gObj("ctype").value="metric";gObj("standard").style.display="none";gObj("metric").style.display="block";htmlVal="<ul>"+htmlVal+"</ul>";gObj("ucframe").innerHTML=""}else{if(A=="standard"){htmlVal=htmlVal+'<li id=\'menuon\'><a href="#" onclick="popMenu(\'standard\');">US units</a></li> <li><a href="#" onclick="popMenu(\'metric\');">metric units</a></li> <li><a href="#" onclick="popMenu(\'other\');">other units</a></li>';gObj("ctype").value="standard";gObj("standard").style.display="block";gObj("metric").style.display="none";htmlVal="<ul>"+htmlVal+"</ul>";gObj("ucframe").innerHTML=""}else{htmlVal=gObj("topmenu").innerHTML;gObj("ucframe").innerHTML='<iframe src="/converter/converter.php" width=520 height=235 frameborder="NO" scrolling="NO" allowTransparency="true" ></IFRAME>'}}gObj("topmenu").innerHTML=htmlVal}function calc(){showquickmsg("calculating...",true);uscodreading=gObj("uscodreading").value;uspodreading=gObj("uspodreading").value;usgasputin=gObj("usgasputin").value;usgasprice=gObj("usgasprice").value;mucodreading=gObj("mucodreading").value;mupodreading=gObj("mupodreading").value;mugasputin=gObj("mugasputin").value;mugasprice=gObj("mugasprice").value;isUSunit=(gObj("ctype").value=="standard")?true:false;hasGasPrice=false;outPutStr="";if(isUSunit){if(!isNumber(uscodreading)||(uscodreading<0)){showquickmsg("current odometer reading needs to be a positive number",true);return }else{if(!isNumber(uspodreading)||(uspodreading<0)){showquickmsg("previous odometer reading needs to be a positive number",true);return }else{if(!isNumber(usgasputin)||(usgasputin<0)){showquickmsg("gas put in the tank needs to be a positive number",true);return }}}if(usgasprice.length>0){if(!isNumber(usgasprice)||(usgasprice<0)){showquickmsg("gas price needs to be a positive number",true);return }else{usgasprice=parseFloat(usgasprice);hasGasPrice=true}}uscodreading=parseFloat(uscodreading);uspodreading=parseFloat(uspodreading);usgasputin=parseFloat(usgasputin);mPG=(uscodreading-uspodreading)/usgasputin;mPGStandard=mPG*1.60935/3.7854;outPutStr+="gas mileage is: <font color=green><b>"+mPG.toFixed(2)+" miles per gallon</b></font> or "+mPGStandard.toFixed(2)+" kilometers per liter. <br>";outPutStr+="mileage traveled since last time is: "+(uscodreading-uspodreading)+" miles.<br>";if(hasGasPrice){outPutStr+="your fill expense this time is: "+formatAsMoney(usgasputin*usgasprice)+".<br>";outPutStr+="your unit cost is: "+formatAsMoney(usgasprice/mPG)+" per mile or "+(mPG/usgasprice).toFixed(2)+" miles per $.<br>"}}else{if(!isNumber(mucodreading)||(mucodreading<0)){showquickmsg("current odometer reading needs to be a positive number",true);return }else{if(!isNumber(mupodreading)||(mupodreading<0)){showquickmsg("previous odometer reading needs to be a positive number",true);return }else{if(!isNumber(mugasputin)||(mugasputin<0)){showquickmsg("gas put in the tank needs to be a positive number",true);return }}}if(mugasprice.length>0){if(!isNumber(mugasprice)||(mugasprice<1)){showquickmsg("gas price needs to be a positive number",true);return }else{mugasprice=parseFloat(mugasprice);hasGasPrice=true}}mucodreading=parseFloat(mucodreading);mupodreading=parseFloat(mupodreading);mugasputin=parseFloat(mugasputin);mPGStandard=(mucodreading-mupodreading)/mugasputin;mPG=mPGStandard*3.7854/1.60935;outPutStr+="gas mileage is: <font color=green><b>"+mPGStandard.toFixed(2)+" kilometers per liter</b></font> or "+mPG.toFixed(2)+" miles per gallon. <br>";outPutStr+="distance traveled since last time is: "+(mucodreading-mupodreading)+" kilometers.<br>";if(hasGasPrice){outPutStr+="your fill expense this time is: "+formatAsMoney(mugasputin*mugasprice)+".<br>";outPutStr+="your unit cost is: "+formatAsMoney(mugasprice/mPGStandard)+" per kilometer or "+(mPGStandard/mugasprice).toFixed(2)+" kilometers per $.<br>"}}showquickmsg(outPutStr,false)};
