// JavaScript Document
var savings = 35;
function computeIt()
{
	document.getElementById('miles').disabled=false;
	document.getElementById('mpg').disabled=false;
	document.getElementById('cost').disabled=false;
	var miles = parseFloat(document.getElementById('miles').value);
	var mpg = parseFloat(document.getElementById('mpg').value);
	var cost = parseFloat(document.getElementById('cost').value);
	if (!isNaN(miles) && !isNaN(mpg) && miles!=0 && miles!=null && mpg!=0 && mpg!=null)
	{
		var res="<br><table border='0'><tr><td class='p2' width='40%'>You burn:</td><td class='p2' width='60%'>"+Math.round(miles/mpg)+" gallons/mo.</td></tr>"
			+"<tr><td class='p2'>You spend:</td><td class='p2'>$"+Math.round((miles/mpg)*4*12) + "/year</td></tr>"
			+"<tr><td class='p2'><strong>You can save:</strong><br><span class='p1'>(at least 35%)</span></td><td class='p2' valign='top'>$"+Math.round((savings/100)*((miles/mpg)*4*12))+"/year</td></tr>"
			+"<tr><td class='p2'>For 2 cars:</td><td class='p2' valign='top'>$"+Math.round((savings/100)*((miles/mpg)*4*12)*2)+"/year</td></tr>"
			+"<tr><td class='p2' ><strong>You can save: </strong></td><td class='p2' valign='top'>$"+Math.round((savings/100)*((miles/mpg)*4*12)*12)+" in 12 years</td></tr></table><br>";
/*		var res="<div class='p_head'>How Much Are you Throwing Away?</div>"
			+"<p class='p2'><br>You consume: "+Math.round(miles/mpg)+" gallons/mo.</p>"
			+"<p class='p3'>You spend: $"+Math.round((miles/mpg)*4*12) + "/year</p>"
			+"<p class='p4'><strong>You can save: </strong>$"+Math.round((savings/100)*((miles/mpg)*4*12))+"/year<br>"
			+"<span class='p1'>(at least 35% savings)</span></p>"
			+"<p class='p5'><strong>You can save: </strong>$"+Math.round((savings/100)*((miles/mpg)*4*12)*12)+" in 12 years</p>"
			+"<p class='p3'>All you need to do is to install a very cheap device. <a href='http://www.halfwaterhalfgas.com'>Click here for more info</a></p>";*/
			document.getElementById('result').innerHTML=res;
			document.getElementById('result').style.display='block';
	}
	else if (cost!=0 && cost!=null && !isNaN(cost))
	{
		var res="<table border='0'><tr><td class='p2' width='40%'>You burn:</td><td class='p2' width='60%'>"+Math.round(cost/4)+" gallons/mo.</td></tr>"
			+"<tr><td class='p2'>You spend:</td><td class='p2'>$"+Math.round((cost/4)*12) + "/year</td></tr>"
			+"<tr><td class='p2'><strong>You can save:</strong><br><span class='p1'>(at least 35%)</span></td><td class='p2' valign='top'>$"+Math.round((savings/100)*(cost*12))+"/year</td></tr>"
			+"<tr><td class='p2'>For 2 cars:</td><td class='p2' valign='top'>$"+Math.round((savings/100)*(cost*12)*2)+"/year</td></tr>"
			+"<tr><td class='p2' ><strong>You can save: </strong></td><td class='p2' valign='top'>$"+Math.round((savings/100)*(cost*12)*12)+" in 12 years</td></tr></table><br>";
			//alert(res);
			document.getElementById('result').innerHTML=res;
			document.getElementById('result').style.display='block';
	}
	else
	{
		document.getElementById('result').innerHTML="<p class='p_head' style='color:red;'>Invalid number format</p>";
	}
	return false;
}
function enableDisable(which)
{
	if (which==1)
	{
		if (document.getElementById('miles').value.length>0 || document.getElementById('mpg').value.length>0)
		{
			document.getElementById('cost').disabled=true;
			document.getElementById('cost').value='';
		}
		else
			document.getElementById('cost').disabled=false;
	}
	else if (which==2)
	{
		if (document.getElementById('cost').value.length>0)
		{
			document.getElementById('miles').disabled=true;
			document.getElementById('mpg').disabled=true;
			document.getElementById('miles').value='';
			document.getElementById('mpg').value='';
		}
		else
		{
			document.getElementById('miles').disabled=false;
			document.getElementById('mpg').disabled=false;
		}
	}
}