var map;

function doCalc(){
	var vfuelcost = window.document.savings.fuelcost.value;
      var vlpgcost = window.document.savings.lpgcost.value;
	var vefficiency = window.document.savings.efficiency.value;
	var vefficiencyunits = window.document.savings.efficiencyunits.value;
	var vdistance = window.document.savings.distance.value;
	var vdistanceunits = window.document.savings.distanceunits.value;
	var vconvcost = window.document.savings.convcost.value;

	var m2k = 1.609344;
	var mpg2lpk = 2.82481053;
	var mpl2lpk = 0.621371192;
	var kpg2lpk = 4.54609188;
	var kpl2lpk = 1;
	var gpm2lpk = 2.82481053;
	var lpm2lpk = 0.621371192;
	var gpk2lpk = 4.54609188;
	var Pet2LPG = 0.6;

	if (vdistanceunits=="m"){
	    vdistance=vdistance*m2k;	
	}
	var did = "nothing";
	switch(vefficiencyunits){
	case "MPG":
	   vefficiency = 1 / vefficiency * mpg2lpk
	   break 
	case "MPL":
	   vefficiency = 1 / vefficiency * mpl2lpk 
	   break 
	case "KPG":
	   vefficiency = 1 / vefficiency * kpg2lpk
	   break 
	case "KPL":
	   vefficiency = 1 / vefficiency * kpl2lpk
	   break 
	case "GPM":
	   vefficiency = gpm2lpk * vefficiency
	   break 
	case "LPM":
	   vefficiency = lpm2lpk * vefficiency
	   break 
	case "GPK":
	   vefficiency = gpk2lpk * vefficiency
	   break 
	case "LPK":
	   vefficiency = vefficiency
	}
	
	var pettot = vfuelcost*vdistance*vefficiency/100;
	var lpgtot = vlpgcost*vdistance*(vefficiency/.8)/100;
	var diffcost = pettot-lpgtot;

	var PetCO2 = 2.893*vdistance*vefficiency;
	var LPGCO2 = 1.863*vdistance*(vefficiency/0.8);
	var diffCO2 = PetCO2-LPGCO2;
	var time2rec = vconvcost*1.175/diffcost;
	var ye = Math.floor(time2rec);
	var mo = (time2rec-ye)*12;
	mo = Math.round(mo*10)/10;
	window.document.savings.outCO2.value=Math.round(diffCO2*100)/100;
	window.document.savings.outYearSavings.value=Math.round(diffcost*100)/100;
	window.document.savings.outTimetoRecovery.value= ye + " years, " + mo + " months";	
}


