function calc() {
	if (isNaN(document.getElementById('miles').value) || isNaN(document.getElementById('price').value) || isNaN(document.getElementById('mpg').value) || isNaN(document.getElementById('parking').value) || isNaN(document.getElementById('publicT').value) ){
		alert("Please check your input data!");
	} else if (!document.getElementById('miles').value || !document.getElementById('price').value || !document.getElementById('mpg').value || !document.getElementById('parking').value || !document.getElementById('publicT').value) {
		alert("Please fill in all the fields");
	
	} else {

miles = document.getElementById('miles').value;
price = document.getElementById('price').value;
mpg = eval(document.getElementById('mpg').value);
parking = document.getElementById('parking').value;
publicT = document.getElementById('publicT').value;
wearCost = document.getElementById('wearCost').value;
var gasDaily = (price * (miles/mpg));
var totalGasDaily = (eval(gasDaily) + eval(parking));
var gasYear = (240 * totalGasDaily);
var wearDaily = (miles * wearCost);
var wearYearly = (240 * wearDaily);
var gasTotalRaw = (eval(wearYearly) + eval(gasYear));
var gasTotal = gasTotalRaw.toFixed(2);
var publicTotalRaw = (240 * (eval(publicT)));
var publicTotal = publicTotalRaw.toFixed(2);
var totalSaveRaw = (gasTotal - eval(publicTotal));
var totalSave = totalSaveRaw.toFixed(2);		
var total = "<br />Yearly Cost of commuting by Automobile: $" + gasTotal + ".<br />Yearly Cost of commuting by Public Transit: $" + publicTotal + ".<br />Total Savings: <b>$" + totalSave + ".</b>";
document.getElementById('answer').innerHTML=total;
		
	}
}


document.write('<form><table width="350px" cellspacing="1" cellpadding="1">');

document.write('<tr><td align="left" width="200px"><b>Daily Miles Ridden:</b></td>');
document.write('<td align="left" width="150px"><input type="text" id="miles" maxlength="3" value=""   /></td></tr>');
document.write('<tr><td align="left" ><b>Price of Gas Per Gallon ($):</b></td>');
document.write('<td align="left" ><input type="text" id="price" value="" maxlength="4" /></td></tr>');
document.write('<tr><td align="left" ><b>Your Car\'s MPG:</b></td>');
document.write('<td align="left" ><input type="text" id="mpg" value="" maxlength="2"  /></td></tr>');
document.write('<tr><td align="left"><b>Size of Your Car:</b></td>');
document.write('<td align="left" ><select name="wearCost" id="wearCost"><option value=".0453">Small Car</option><option selected="" value=".0552">Medium Car</option><option value=".0584">Large Car</option><option value=".0543">Mini-Van</option><option value=".0640">SUV</option></select></td></tr>');
document.write('<tr><td align="left" ><b>Daily Parking Cost ($):</b></td>');
document.write('<td align="left" ><input type="text" id="parking" value="" maxlength="2"   /></td></tr>');
document.write('<tr><td align="left" ><b>Daily RoundTrip Cost Using Public Transit ($):</b></td>');
document.write('<td align="left" ><input type="text" id="publicT" maxlength="4" value=""   /></td></tr>');
document.write('<tr>&#32;<td></td><td align="left"><input type="button" value="Calculate" id="gassubmit" name="gassubmit" onClick="calc()"  /></td></tr>');
document.write('<tr><td colspan="2" align="left" ><span id="answer" ></span></td></tr>');


document.write('</table></form>');