// JavaScript Document
// All coding by Alex Leeor for C LEVEL. All rights reserved. To use this code please seek permission first. 

function setUp() {
	document.footprint.floorspaceFt.style.background = '#eeeeee';
	document.footprint.floorspaceM.style.background = '#eeeeee';
	
	
}



function homecalc1(ap) 
	{
		
		if ( document.footprint.electricityTotal1.value == "") 
		{

		return false;
		}
		
		
	var elecTot = eval(document.footprint.electricityTotal1.value);
	var elecTot2 = Math.round(eval(elecTot) * eval(0.43)*100)/100;
	document.footprint.electricityCO2.value = elecTot2;
	document.footprint.floorspaceFt.style.background = '#eeeeee';
	document.footprint.floorspaceM.style.background = '#eeeeee';
	
    		    	document.footprint.hme_gas1.style.background = '#FFFFFF';
	document.footprint.electricityTotal1.style.background = '#FFFFFF';
	document.footprint.floorspaceFt.value = "";
	document.footprint.floorspaceM.value = "";
	document.footprint.gasTotEstCO.value = "0";
	calculateTot();
	return false;
	}

function homecalc2(ap) 
	{
	
		if ( document.footprint.floorspaceM.value == "") 
		{
		return false;
		}
		
	var elecTot = eval(document.footprint.floorspaceM.value);
	var elecTot2 = elecTot * eval(0.1572) * eval(1000)  ;
	document.footprint.gasTotEstCO.value = Math.round(eval(elecTot2)*100)/100;
	document.footprint.floorspaceFt.style.background = '#eeeeee';
	document.footprint.floorspaceM.style.background = '#FFFFFF';
    	document.footprint.electricityTotal1.style.background = '#eeeeee';
		    	document.footprint.hme_gas1.style.background = '#eeeeee';
				calculateTot();

		

document.footprint.floorspaceFt.value = "";
	document.footprint.electricityTotal1.value = "";
		document.footprint.hme_gas1.value = "";
				document.footprint.hme_gasTotCO2.value = "0";
		document.footprint.electricityCO2.value = "0";
		calculateTot();
	

	return false;
	 
	}
	
function homecalc3(ap) 
	{
	
	
		if ( document.footprint.floorspaceFt.value == "") 
		{
		return false;
		}
							
		
		
	var elecTot = eval(document.footprint.floorspaceFt.value);
	var elecTot2 = elecTot * eval(0.0146) * eval(1000);
	var elecTot3 = elecTot2; 
		document.footprint.gasTotEstCO.value = Math.round((elecTot3)*100)/100;
		document.footprint.floorspaceFt.style.background = '#FFFFFF';
		document.footprint.floorspaceM.style.background = '#eeeeee';
		document.footprint.hme_gas1.style.background = '#eeeeee';
    	document.footprint.electricityTotal1.style.background = '#eeeeee';
		document.footprint.electricityTotal1.value = "";
		document.footprint.electricityTotal1.value = "";
		document.footprint.hme_gas1.value = "";
		document.footprint.floorspaceM.value = "";
		document.footprint.hme_gasTotCO2.value = "0";
		document.footprint.electricityCO2.value = "0";
		calculateTot();
	return false;
	 
	}
	

function homecalc4(ap) 
	{
		if ( document.footprint.hme_gas1.value == "enter value") 
		{
		return false;
		}
	
	
	var gasTot = eval(document.footprint.hme_gas1.value);
	document.footprint.floorspaceFt.style.background = '#FFFFFF';
	document.footprint.floorspaceM.style.background = '#eeeeee';
			    document.footprint.hme_gas1.style.background = '#FFFFFF';
							    document.footprint.electricityTotal1.style.background = '#FFFFFF';
    	document.footprint.floorspaceFt.style.background = '#eeeeee';
		    	document.footprint.floorspaceM.style.background = '#eeeeee';
	document.footprint.floorspaceFt.value = "";
	document.footprint.floorspaceM.value = "";
		
							document.footprint.gasTotEstCO.value = "0";
   // 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) *10) /10	;
calculateTot();
						}
	

function homecalc9(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;
	calculateTot();
	}
	
	
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();
						document.footprint.hme_travelcardistanceM.style.background = '#FFFFFF';
				document.footprint.hme_travelcardistanceKm.style.background = '#eeeeee';
			calculateTot();
			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;
				document.footprint.hme_travelcardistanceM.style.background = '#FFFFFF';
				document.footprint.hme_travelcardistanceKm.style.background = '#eeeeee';
				calculateTot();
				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;
			document.footprint.hme_travelcardistanceM.style.background = '#FFFFFF';
				document.footprint.hme_travelcardistanceKm.style.background = '#eeeeee';
calculateTot();
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;
			document.footprint.hme_travelcardistanceM.style.background = '#FFFFFF';
				document.footprint.hme_travelcardistanceKm.style.background = '#eeeeee';
calculateTot();
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();
							document.footprint.hme_travelcardistanceM.style.background = '#eeeeee';
				document.footprint.hme_travelcardistanceKm.style.background = '#FFFFFF';
calculateTot();
			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;
							document.footprint.hme_travelcardistanceM.style.background = '#eeeeee';
				document.footprint.hme_travelcardistanceKm.style.background = '#FFFFFF';
				calculateTot();
return false;						
				}	

		if (document.footprint.hme_travelcarSize.selectedIndex == 2) 
				{
				
				document.footprint.hme_carTotCO2.value = Math.round(eval(document.footprint.hme_travelcardistanceKm.value) * eval(0.17) *1000)/1000;
											document.footprint.hme_travelcardistanceM.style.background = '#eeeeee';
				document.footprint.hme_travelcardistanceKm.style.background = '#FFFFFF';
				calculateTot();
				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;
										document.footprint.hme_travelcardistanceM.style.background = '#eeeeee';
				document.footprint.hme_travelcardistanceKm.style.background = '#FFFFFF';
				calculateTot();
			return false;						
				}

	
	}	
			

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);
	calculateTot();
	return false;
	
	}
	
	
function homecalc6(ap) 
	{
	document.footprint.waste_bagsCO2.value = Math.round(document.footprint.hmewaste_bags.value  * 0.00563 *1000 * 1000) /1000; 
	calculateTot();
	return false;
	}

	

function clearIt(ap)
	{
	if ( ap.value == "enter value") 
		{ 
		ap.value = "";
		}
		
		if ( ap.value == "0") 
		{ 
		ap.value = "";
		}
	}
	
	
/// final total calculation 

var checkFlag = "no";

function calculateTotA() {

checkFlag = "yes";
calculateTot()

}

function calculateTot(ap)  {
	
if (checkFlag == "no" ) {return false};


if (document.footprint.results1.value != "NaN" )
	{ 
	var resultsTotTemp5 = eval(document.footprint.electricityCO2.value) + eval(document.footprint.hme_gasTotCO2.value) + eval(document.footprint.gasTotEstCO.value);
	document.footprint.results1.value = Math.round(resultsTotTemp5 *10)/10;
	}
	
		
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" )
	{
	alert("Please complete the ENERGY and TRAVEL sections");	
	var resultsTemp2 = 0;
	var resultsTemp2 = eval(document.footprint.hme_carTotCO2.value);
	return false;
	}


var resultsTemp2 = eval(document.footprint.hme_carTotCO2.value);

	
		
if (resultsTemp2 != "NaN") 
	{	
	document.footprint.results2.value = Math.round(resultsTemp2 *1)/1;	
	}
	
	
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 *10)/10;
	}
	
	
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 *10)/10;
	}
//document.footprint.resultsFINALT.value = Math.round(eval(document.footprint.resultsFINAL.value) / eval(1000)*1000/1000);


var finalPrice = document.footprint.resultsFINALT.value
finalPrice = finalPrice * 9

var monthTot1 = document.footprint.Month.selectedIndex;
var yearTot1 = document.footprint.Year.selectedIndex;

if (monthTot1 == 0) { var monthTot10 = "Jan" };
if (monthTot1 == 1) { var monthTot10 = "Feb" };
if (monthTot1 == 2) { var monthTot10 = "Mar" };
if (monthTot1 == 3) { var monthTot10 = "Apr" };
if (monthTot1 == 4) { var monthTot10 = "May" };
if (monthTot1 == 5) { var monthTot10 = "Jun" };
if (monthTot1 == 6) { var monthTot10 = "Jul" };
if (monthTot1 == 7) { var monthTot10 = "Aug" };
if (monthTot1 == 8) { var monthTot10 = "Sep" };
if (monthTot1 == 9) { var monthTot10 = "Oct" };
if (monthTot1 == 10) { var monthTot10 = "Nov" };
if (monthTot1 == 11) { var monthTot10 = "Dec" };
//alert(monthTot10);
if (yearTot1 == 0) { var yearTot10 = "2004" };
if (yearTot1 == 1) { var yearTot10 = "2005" };
if (yearTot1 == 2) { var yearTot10 = "2006" };
if (yearTot1 == 3) { var yearTot10 = "2007" };
if (yearTot1 == 4) { var yearTot10 = "2008" };
if (yearTot1 == 5) { var yearTot10 = "2009" };
if (yearTot1 == 6) { var yearTot10 = "2010" };
//alert(yearTot10);



document.form_12.property_3.value = document.footprint.CompanyName.value+ " : Year Ending: " + monthTot10 + " " + yearTot10 + " : " +document.footprint.email.value+  " : Electicity(kg) " +document.footprint.electricityCO2.value+  " : Gas(kg)" +document.footprint.hme_gasTotCO2.value+  " : Power Combined Estimate(kg)" +document.footprint.gasTotEstCO.value+  " : Car(kg) " +document.footprint.hme_carTotCO2.value+  " : Waste " +document.footprint.waste_bagsCO2.value+  " : TOTAL CO2 " +document.footprint.resultsFINALT.value+  " Tonnes CO2";

document.form_12.price.value = Math.round(finalPrice *100)/100

return false;



}

function payGoogle() {
if (document.form_12.price.value == "" )
	{
	alert("Please complete the carbon footprint calculation");
	return false;
	}
	


}

function compensateLife()
{
	
	
	var amt = Math.round(eval(document.footprint.resultsFINALT.value) * eval(9)*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";	
}
	