
/* 
	code by greg doolittle 
	www.gregdoolittle.com
*/


function calculate(a,b,c,result) {
	var a = document.getElementById(a).value;
	var b = document.getElementById(b).value;
	var c = document.getElementById(c).value;	
	var result_placeholder = document.getElementById(result);

	if (a == 0 || b == 0 || c == 0) {
		// no good.
		result_placeholder.value = 0;
	} else {
		// carry on.
		var product = Math.round((a / b * c) * 10)/10;
		result_placeholder.value = product;
		grandTotal();
	}
}

function calculateHome() {
//	var zip = document.getElementById("zip_code").value;
	var zip = 0.002852;
	var thermRate = 0.073187;

	var electric = document.getElementById("electricity").value;
	var gas = document.getElementById("gas").value;	
	var result_placeholder = document.getElementById("result_home");
		
	if ((zip == 0 && electric == 0) || (zip == 0 && gas == 0)) {
		// no good.
		result_placeholder.value = 0;
	} else {
		// carry on.
		var product = Math.round((zip * electric + thermRate * gas) * 10)/10;
		result_placeholder.value = product;
		grandTotal();
	}	
	
}

function calculateAir() {
	var short = document.getElementById("short_trip_mileage").value;
	var long = document.getElementById("long_trip_mileage").value;	
	var balance = Math.round((short * 0.00024 + long * 0.00018) * 10)/10;
	var result_placeholder = document.getElementById("result_air");
	result_placeholder.value = balance;
	grandTotal();
}


/*
	this function adds the three subtotals to calculate the 
	grand total for the lifestyle category	
*/
function grandTotal() {
	var grandTotalHolder = document.getElementById('quantity');	
	var carTotal  = Math.round((0 + document.getElementById('result_car').value)*10)/10;
	var homeTotal = Math.round((0 + document.getElementById('result_home').value)*10)/10;	
	var airTotal  = Math.round((0 + document.getElementById('result_air').value)*10)/10;	
	var grandTotalValue = 0; 
	grandTotalValue += Math.round((carTotal + homeTotal + airTotal)*10)/10;
	//grandTotalValue = Math.round(grandTotalValue * 10)/10;
	grandTotalHolder.value = grandTotalValue;
}