// JavaScript Document
// All coding by Alex Leeor for C LEVEL. All rights reserved. To use this code please seek permission first. 

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.17)) *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) 
{
	
	for (i = 0; i < document.footprint.consumption.length; i++)
	if (document.footprint.consumption[i].checked)
	var consumptionCheck = document.footprint.consumption[i].value;
	
	
  //for (i = 0; i < document.menuform.radius.length; i++)
  //      if (document.menuform.radius[i].checked)
  //var r = document.menuform.radius[i].value;


var flightTot = eval(document.footprint.hme_flight1.value) +  eval(document.footprint.hme_flight2.value) +  eval(document.footprint.hme_flight3.value)  * eval(1000);

document.footprint.results1.value = eval(document.footprint.hme_electricityTotCO2.value) + eval(document.footprint.hme_gasTotCO2.value) + eval(document.footprint.hme_oilTotCO2.value);
document.footprint.results2.value  = eval(document.footprint.hme_carTotCO2.value) + eval(document.footprint.hme_trainbusCO2.value) + eval(flightTot);
document.footprint.results3.value  = eval(document.footprint.waste_bagsCO2.value) + eval(consumptionCheck);


document.footprint.resultsFINAL.value = Math.round(eval(document.footprint.results1.value) + eval(document.footprint.results2.value) + eval(document.footprint.results3.value)*1000/1000);


document.footprint.resultsFINALT.value = Math.round(eval(document.footprint.resultsFINAL.value) / eval(1000)*1000/1000);

if (document.footprint.resultsFINALT.value == "NaN") 
	{
	alert("Please check the form for missing information");
	return false;
	}
	
var finalPrice = document.footprint.resultsFINALT.value;
finalPrice = finalPrice * 8;
document.footprint.price.value = Math.round(finalPrice *1)/1;
return false;
}


function payGoogle() {
if (document.footprint.price.value == "" )
	{
	alert("Please complete the carbon footprint calculation");
	return false;
	}
}