﻿function calcSolarBennies(formId,destination){
	frm = document.getElementById(formId);
	var sqFeet = frm.elements[0].value;
	var kilowatts = sqFeet / 100;
	var kwLifeTime = sqFeet * 25 * 1200 / 100;
	var poundsCarbonDioxide = kwLifeTime * 1.569;
	var pineTrees = kwLifeTime * .064;
	var carsOnRoad = kwLifeTime * .00013;
	var barrelsOil = kwLifeTime * .0017;
	var poundsSulfur = kwLifeTime * .00526;
	var poundsNitrogen = kwLifeTime * .00194;
	var homesElectric = kwLifeTime * .000094;

	var responseText = "";
	responseText = "Assuming your roof has no serious shading or other obstacles the size of your solar electric system would be approximately: ";
        responseText += addCommas(kilowatts.toFixed(0)) + " kilowatts<br><br>";
	responseText += "In its lifetime your solar electric system would produce: ";
        responseText += addCommas(kwLifeTime.toFixed(0)) + " kilowatt hours of green energy<br>";
	responseText += "And offset:<br>";
	responseText += "<ul>";
	responseText += "<li>" + addCommas(poundsCarbonDioxide.toFixed(0)) + " pounds Carbon Dioxide</li>";
	responseText += "<li>" + addCommas(pineTrees.toFixed(0)) + " pine trees cut down</li>";
	responseText += "<li>" + addCommas(carsOnRoad.toFixed(0)) + " cars on the road for one year</li>";
	responseText += "<li>" + addCommas(barrelsOil.toFixed(0)) + " barrels of oil</li>";
	responseText += "<li>" + addCommas(poundsSulfur.toFixed(0)) + " pounds of Sulphur Dioxide</li>";
	responseText += "<li>" + addCommas(poundsNitrogen.toFixed(0)) + " pounds of Nitrogen Dioxide</li>";
	responseText += "<li>" + addCommas(homesElectric.toFixed(0)) + " homes’ electricity use</li>";
	responseText += "</ul>";

	var display = document.getElementById(destination);
	display.innerHTML = responseText;

}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
