function calculate()
{  


	var miles = document.getElementById("miles").value;
	if ( miles.length == 0 )
	{
		 alert("Please enter number of miles you drive each year");
		 return;
	}
	miles = fixNumber(miles);
	miles = parseFloat(miles);
	if ( isNaN(miles) )
	{
		 alert("Please enter number of miles you drive each year as a number");
		 return;
	}
	if ( miles <= 0 )
	{
		 alert("You aren't driving any miles, so you won't be spending anything on gas");
		 return;
	}

	var mpgold = document.getElementById("mpgold").value;
	if ( mpgold.length == 0 )
	{
		 alert("Please enter the MPG of your current vehicle.");
		 return;
	}
	mpgold = fixNumber(mpgold);
	mpgold = parseFloat(mpgold);
	if ( isNaN(mpgold) )
	{
		 alert("Please enter the MPG of your current vehicle as a number.");
		 return;
	}
	if ( mpgold <= 0 )
	{
		alert("Your current vehicle gets 0 mpg, so it can't be driven.")
		return;
	}

	var mpgnew = document.getElementById("mpgnew").value;
	if ( mpgnew.length == 0 )
	{
		 alert("Please enter the MPG of a new vehicle.");
		 return;
	}
	mpgnew = fixNumber(mpgnew);
	mpgnew = parseFloat(mpgnew);
	if ( isNaN(mpgnew) )
	{
		 alert("Please enter the MPG of a new vehicle as a number.");
		 return;
	}
	if ( mpgnew <= 0 )
	{
		alert("Your new vehicle gets 0 mpg, so it can't be driven.")
		return;
	}

	var cost = document.getElementById("cost").value;
	if ( cost.length == 0 )
	{
		 alert("Please enter the cost of a gallon of gas");
		 return;
	}
	cost = fixNumber(cost);
	cost = parseFloat(cost);
	if ( isNaN(cost) )
	{
		 alert("Please enter the cost of a gallon of gas as a number");
		 return;
	}
	if ( cost <= 0 )
	{
		 alert("If gas is free, you won't save anything by being more fuel-efficient.");
		 return;
	}
	

	var costold = ( miles / mpgold ) * cost;
	var costnew = ( miles / mpgnew ) * cost;

	var results = "Gas for your current vehicle costs " + formatDollars(costold) + " dollars a year.";
	results += "<p>Gas for the new vehicle will cost " + formatDollars(costnew) + " dollars a year.";

	var savings = costold - costnew;
	if ( savings >= 0 )
		results += "<p>You will save " + formatDollars(savings) + " a year on gas.";
	else
		results += "<p>You will pay " + formatDollars(-1*savings) + " extra a year on gas.";

	 
	var x = document.getElementById("results");


	x.innerHTML = results;
	x.style.display = "block";
}
