// JavaScript Document
// All coding by Alex Leeor for C LEVEL. All rights reserved. To use this code please seek permission first. 



function bus_lpg(ap) {
	
if (document.footprint.annual_petrol.value != 'enter value' && document.footprint.annual_diesel.value != 'enter value' && document.footprint.annual_lpg.value != 'enter value' ) 	
	{
		var vansTot = eval(document.footprint.annual_petrol.value) * 2.30;	
	var vansTot2 = vansTot + eval(document.footprint.annual_diesel.value) * 2.63;	
	var vansTot3 = vansTot2 + eval(document.footprint.annual_lpg.value) * 1.49;	
	document.footprint.bus_vanstruck.value = Math.round(eval(vansTot3)*100)/100;
};

}







function homecalc1(ap) 
	{
		
		
		if ( document.footprint.hme_electricity1.value == "enter value" || document.footprint.hme_electricity2.value == "enter value" || document.footprint.hme_electricity3.value == "enter value" || document.footprint.hme_electricity4.value == "enter value") 
		{
		return false;
		}
	
	
	var elecTot = eval(document.footprint.hme_electricity1.value) + eval(document.footprint.hme_electricity2.value) + eval(document.footprint.hme_electricity3.value) + eval(document.footprint.hme_electricity4.value);
    document.footprint.hme_electricityTot.value = Math.round(elecTot*1000) / eval(document.footprint.homeorpersonal.value)/1000	;
	document.footprint.hme_electricityTotCO2.value = Math.round(eval(elecTot) * eval(0.43) / eval(document.footprint.homeorpersonal.value) *1000)/1000;
	return false;
	}
	

function homecalc2(ap) 
	{
		if ( document.footprint.hme_gas1.value == "enter value" || document.footprint.hme_gas2.value == "enter value" || document.footprint.hme_gas3.value == "enter value" || document.footprint.hme_gas4.value == "enter value") 
		{
		return false;
		}
	
	
	var gasTot = eval(document.footprint.hme_gas1.value) + eval(document.footprint.hme_gas2.value) + eval(document.footprint.hme_gas3.value) + eval(document.footprint.hme_gas4.value);
    document.footprint.hme_gasTot.value = Math.round(eval(gasTot) / eval(document.footprint.homeorpersonal.value) *1000)/1000;
	document.footprint.hme_gasTotCO2.value = Math.round(eval(gasTot) * eval(0.19) / eval(document.footprint.homeorpersonal.value) *1000)/1000;
	}
	

function homecalc3(ap) 
	{
		if ( document.footprint.hme_oil.value == "enter value" ) 
		{
		return false;
		}
	document.footprint.hme_oilTotCO2.value = Math.round(eval(document.footprint.hme_oil.value) * eval(2.975) / eval(document.footprint.homeorpersonal.value)  *1000)/1000;
	}
	
	
function homecalc4a(ap) 
	{
		
		document.footprint.hme_travelcardistanceKm.value = Math.round(eval(document.footprint.hme_travelcardistanceM.value) * eval(1.609)*100)/100;
		
		if (document.footprint.hme_travelcarSize.selectedIndex == 0) 
			{
			//alert("Please select your vehicle size");
			//ap.focus();
			return false;
			}
		
		if (document.footprint.hme_travelcarSize.selectedIndex == 1) 
				{
				document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) * eval(0.125) *1000)/1000;
				return false;						
				}

		if (document.footprint.hme_travelcarSize.selectedIndex == 2) 
				{
				document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) * eval(0.175) *1000)/1000;
				return false;						
				}
				
		if (document.footprint.hme_travelcarSize.selectedIndex == 3) 
				{
				document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) * eval(0.22) *1000)/1000;
				return false;						
				}


	}
	
	function homecalc4b(ap) 
	{
		
		document.footprint.hme_travelcardistanceM.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) / eval(1.609)*100)/100;
		
		if (document.footprint.hme_travelcarSize.selectedIndex == 0) 
			{
			//alert("Please select your vehicle size");
			//ap.focus();
			return false;
			}
		
		if (document.footprint.hme_travelcarSize.selectedIndex == 1) 
				{
				document.footprint.hme_travelcarSize2.value = "";
				document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) * eval(0.125) *1000)/1000;
				return false;						
				}

		if (document.footprint.hme_travelcarSize.selectedIndex == 2) 
				{
				document.footprint.hme_travelcarSize2.value = "";
				document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) * eval(0.17) *1000)/1000;
				return false;						
				}
				
		if (document.footprint.hme_travelcarSize.selectedIndex == 3) 
				{
				document.footprint.hme_travelcarSize2.value = "";
				document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) * eval(0.22) *1000)/1000;
				return false;						
				}

	
	}


function homecalc4c()
{
			if (document.footprint.hme_travelcarSize2.value != "") 
			{ 
			document.footprint.hme_travelcarSize.selectedIndex = 0
 			document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcarSize2.value) * eval(document.footprint.hme_travelcardistanceKm.value) / eval(1000))*1000/1000;	
			}
	
	
}
			
			

function homecalc5(ap) 
	{
	document.footprint.hme_trainbusCO2.value = Math.round(eval((document.footprint.hme_train.value) * eval(1.609) * eval(0.04) ) + eval((document.footprint.hme_bus.value) * eval(1.609) * eval(0.09)) *1000/1000);
	return false;
	
	}
	
	
function homecalc6(ap) 
	{
		document.footprint.waste_bagsCO2.value = Math.round(document.footprint.hmewaste_bags.value  * 0.00563 *1000 * 1000) /1000;   

	return false;
	}

	

function clearIt(ap)
	{
	if ( ap.value == "enter value") 
		{ 
		ap.value = "";
		}
	}
	
	
/// final total calculation 

function calculateTot(ap) 
{
	
var flightTot = eval(document.footprint.hme_flight1.value) * 1000;

if (document.footprint.results1.value != "NaN" )
	{ 
	var resultsTotTemp5 = eval(document.footprint.hme_electricityTotCO2.value) + eval(document.footprint.hme_gasTotCO2.value) + eval(document.footprint.hme_oilTotCO2.value);
	document.footprint.results1.value = Math.round(resultsTotTemp5 *100)/100;
	}
	
		
if (document.footprint.results1.value == "NaN") 
	{ 
	alert("You have not entered all the data. Please check the ENERGY section and fill in any missing information");
	}


if (document.footprint.hme_carTotCO2.value == "enter value" || document.footprint.annual_petrol.value == "enter value" || document.footprint.annual_diesel.value == "enter value" || document.footprint.annual_lpg.value == "enter value")
	{
	alert("Please complete the ENERGY and TRAVEL sections");	
	var resultsTemp2 = 0;
	return false;
	}


var resultsTemp2 = eval(document.footprint.hme_carTotCO2.value) + eval(document.footprint.hme_trainbusCO2.value) + eval(flightTot) + eval(document.footprint.bus_vanstruck.value);

	
		
if (resultsTemp2 != "0") 
	{	
	document.footprint.results2.value = Math.round(resultsTemp2 *100)/100;	
	}
	
	
if (document.footprint.results2.value == "NaN") 
	{ 
	alert("You have not entered all the data. Please check the TRAVEL AND TRANSPORT section and fill in any missing information");
	}


if (document.footprint.hmewaste_bags.value != "enter value") 
	{
	document.footprint.results3.value  = Math.round(document.footprint.waste_bagsCO2.value *1000)/1000;
	}
	
	
if (document.footprint.hmewaste_bags.value == "enter value" || document.footprint.hmewaste_bags.value == "") 
	{
	alert("Please complete the OFFICE WASTE SECTION");
	//document.footprint.hmewaste_bags.value = "";
	//document.footprint.hmewaste_bags.focus();	
	return false;

	
	}
	
	
if (document.footprint.results3.value == "NaN") 
	{ 
	alert("You have not entered all the data. Please check the OFFICE WASTE section and fill in any missing information") 
	return false;
	}

var totalTemp3 = eval(document.footprint.results1.value) + eval(document.footprint.results2.value) + eval(document.footprint.results3.value);

document.footprint.resultsFINAL.value = Math.round(totalTemp3 *100)/100;


var totalTemp4 = document.footprint.resultsFINALT.value = eval(document.footprint.resultsFINAL.value) / 1000;
//alert(totalTemp4)
if ( totalTemp4 != "NaN")	
	{
	document.footprint.resultsFINALT.value = Math.round( eval(document.footprint.resultsFINAL.value) / 1000 *1000)/1000;
	}
//document.footprint.resultsFINALT.value = Math.round(eval(document.footprint.resultsFINAL.value) / eval(1000)*1000/1000);


var finalPrice = document.footprint.resultsFINALT.value
finalPrice = finalPrice * 8
document.footprint.price.value = Math.round(finalPrice *1)/1


return false;



}

function payGoogle() {
if (document.form_9.price.value == "" )
	{
	alert("Please complete the carbon footprint calculation");
	return false;
	}
	


}

function compensateLife()
{
	
	
	var amt = Math.round(eval(document.footprint.resultsFINALT.value) * eval(8)*100)/100;
	//alert(amt);

//document.location="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=info%40clevel%2eco%2euk&undefined_quantity=1&item_name=Carbon%20Balanced%20Business&amount=" + amt +"&no_shipping=1&return=http%3a%2f%2fwww%2eclevel%2eco%2euk%2fsuccess%2ehtm&cancel_return=http%3a%2f%2fwww%2eclevel%2eco%2ejuk%2fcancel%2ehtm&no_note=1&currency_code=GBP&lc=GB&bn=PP%2dBuyNowBF&charset=UTF%2d8";	
}
	