function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode;
     else
          key = e.which;
     return (key != 13);
}

function dorescalc() {
	var utilRate;
	value = document.rescalc.resInput.value;
	if (isNaN(value) || value == "") {
		document.getElementById('result_blank').innerHTML = "You must enter a number to get a result.";
		document.rescalc.resInput.focus();
	} else {
		result = Math.round(value/140*0.8);
		//document.rescalc.resResult.value = result;
		document.getElementById('result_blank').innerHTML = "Recommended system size: " + result + " kilowatt DC";
		new Effect.Highlight('result_blank');
		utilRate = utilityrate;
		monthly = document.rescalc.resInput.value;
		if (isNaN(monthly)) {
			document.getElementById('result_blank').innerHTML = "You must enter a number for the monthly consumption to get a result.";
			document.rescalc.resInput.focus();
		} else if ((utilRate > 0) && (monthly > 0)) {
			systemSize = Math.round(monthly/140*0.8);
			new Effect.Highlight('result_blank');
			if (systemSize != 0) {
				calcs = document.getElementById('calculations');
				calcs.style.display = "block";
				new Effect.Highlight('calculations');
				var cost = (estimatedcost * systemSize);
				var rebate = (1000 * systemSize * rebateRate);
				var fedtax = (cost - rebate) * .3;
				var statetax = cost * .1;
				if (statetax > 1000) statetax = 1000;
				var finalcost = cost - rebate - fedtax - statetax;
				var financing = " <br />Monthly payment if financed is $" + (finalcost * .01) + " or less.";
				var annsav = Math.round(systemSize * 140 * utilRate * 12);
				var roi = Math.round((annsav / finalcost) * 100);
				document.getElementById('cost').innerHTML = "$" + cost;
				document.getElementById('rebate').innerHTML = "$" + rebate;
				document.getElementById('fedtax').innerHTML = "$" + fedtax;
				document.getElementById('statetax').innerHTML = "$" + statetax;
				document.getElementById('finalcost').innerHTML = "$" + finalcost + financing;
				document.getElementById('utilRate').innerHTML = "$" + utilRate;
				document.getElementById('annsav').innerHTML = "$" + annsav;
				document.getElementById('roi').innerHTML = roi + "%";
				doCommonCalc(systemSize);

			}
		}
	}
}

function doCommonCalc(systemSize) {
	var commoncalcs;
	commoncalcs = document.getElementById('commoncalcs');
	commoncalcs.style.display = "block";
	new Effect.Highlight('commoncalcs');
	var monthlyProd = Math.round(systemSize * 140);
	var co2offset = Math.round(monthlyProd * 2.227);
	var noxoffset = Math.round(monthlyProd * 0.003794);
	var so2offset = Math.round(monthlyProd * 0.006301);
	var h20offset = Math.round(monthlyProd * .5);
	var coaloffset = Math.round(monthlyProd);
	document.getElementById('monthlyProd').innerHTML = monthlyProd + " Kwh/month";
	document.getElementById('co2offset').innerHTML = co2offset + " lbs.";
	document.getElementById('noxoffset').innerHTML = noxoffset + " lbs.";
	document.getElementById('so2offset').innerHTML = so2offset + " lbs.";
	document.getElementById('h20offset').innerHTML = h20offset + " lbs.";
	document.getElementById('coaloffset').innerHTML = coaloffset + " lbs."; 
}

function getValueByName(name) {
	var temp;
	eval("temp = document.watercalc." + name + ".value");
	if (isNaN(temp)) {
		temp = 0;
		eval("document.watercalc." + name + ".value = '0'");
	}
	return temp;
}

function dowatercalc() {
	var roofspace = getValueByName("roofspace");
	var roofspace = getValueByName("roofspace");
	var numpeople = getValueByName("numpeople");
	var topload = getValueByName("topload");
	var frontload = getValueByName("frontload");
	var showers = getValueByName("showers");
	var baths = getValueByName("baths");
	var faucet = getValueByName("faucet");
	var ac = getValueByName("ac");
	var swamp = getValueByName("swamp");
	var citrus = getValueByName("citrus");
	var dwarf = getValueByName("dwarf");
	var velvet = getValueByName("velvet");
	var screwbean = getValueByName("screwbean");
	var acacia = getValueByName("acacia");
	var oleander = getValueByName("oleander");
	var deciduous = getValueByName("deciduous");
	var evergreen = getValueByName("evergreen");
	var pomegranate = getValueByName("pomegranate");
	var mission = getValueByName("mission");
	var additionalqty = getValueByName("additionalqty");
	var additionalgalpermonth = getValueByName("additionalgalpermonth");
	var garden = getValueByName("garden");
	var grass = getValueByName("grass");

	if (isNaN(roofspace)) {
		alert("You must enter a value for roof space.");
		document.watercalc.roofspace.focus();
	}
	var totalharvest = Math.round(roofspace *(1/12)*0.9*7.48,0);
	document.getElementById('totalharvest').innerHTML = totalharvest + " gallons of rainwater per inch of rain";
	
	var min = totalharvest * 2;
	var max = totalharvest * 4;
	document.getElementById('sizerange').innerHTML = "between " + min + " and  " + max + " gallons.";

	var resources = Math.round((totalharvest)+(4*35*topload)+(4*10*frontload)+(4*numpeople*showers*20)+(30*numpeople*10*baths)+(faucet*numpeople*30)+(ac*10*30)+(swamp*15*30),0);
	document.getElementById('totalavailable').innerHTML = resources + " gallons per month.";
	
	var totalneeds = Math.round((citrus*8000/12)+(dwarf*5000/12)+(velvet*3000/12)+(screwbean*4000/12)+(acacia*3000/12)+(oleander*1000/12)+(deciduous*350/12)+(evergreen*450/12)+(pomegranate*3300/12)+(mission*3000/12)+(garden*(3180/50/12))+(grass*25/12)+(additionalqty*additionalgalpermonth),0);
	document.getElementById('totalneeds').innerHTML = totalneeds + " gallons per month.";
	
	var netbudget = resources - totalneeds;
	document.getElementById('netbudget').innerHTML = netbudget + " gallons per month.";
	
	calcs = document.getElementById('calculations');
	calcs.style.display = "block";
	new Effect.Highlight('calculations');
}

function dobuscalc() {
	var utilRate = document.buscalc.utilRate.value;
	var monthly = document.buscalc.monthly.value;
	if (isNaN(utilRate)) {
		document.getElementById('result_blank').innerHTML = "You must enter a number for the utility rate to get a result.";
		document.buscalc.utilRate.focus();
	} else if (isNaN(monthly)) {
		document.getElementById('result_blank').innerHTML = "You must enter a number for the monthly consumption to get a result.";
		document.buscalc.monthly.focus();
	} else if ((utilRate > 0) && (monthly > 0)) {
		systemSize = Math.round(monthly/140*0.8);
		document.getElementById('result_blank').innerHTML = "Recommended system size: " + systemSize + " kilowatt DC";
		new Effect.Highlight('result_blank');
		if (systemSize != 0) {
			var calcs = document.getElementById('calculations');
			calcs.style.display = "block";
			new Effect.Highlight('calculations');
			var cost = (estimatedcost * systemSize);
			var rebate = (1000 * systemSize * rebateRate);
			var fedtax = cost * .3;
			// if (fedtax > 2000) fedtax = 2000;
			var statetax = cost * .1;
			if (statetax > 25000) statetax = 25000;
			var deprec = Math.round((cost - rebate - (fedtax + statetax)/2) * .34);
			var finalcost = Math.round(cost - rebate - fedtax - statetax - deprec);
			var annsav = Math.round(100 * systemSize * 140 * utilRate * 12) / 100;
			var roi = Math.round((annsav / finalcost) * 100);
			document.getElementById('cost').innerHTML = "$" + cost;
			document.getElementById('rebate').innerHTML = "$" + rebate;
			document.getElementById('fedtax').innerHTML = "$" + fedtax;
			document.getElementById('statetax').innerHTML = "$" + statetax;
			document.getElementById('deprec').innerHTML = "$" + deprec;
			document.getElementById('finalcost').innerHTML = "$" + finalcost;
			document.getElementById('annsav').innerHTML = "$" + annsav;
			document.getElementById('roi').innerHTML = roi + "%";
			doCommonCalc(systemSize);
		}
	}
	
	
}
