function solarCalculate() {
	frm = document.getElementById('solarcalc');
	monthlyKWHA = frm.generatedA.value-0;
	monthlyKWHB = frm.generatedB.value-0;
	solarPortionA = frm.needsA.value-0;
	solarPortionB = frm.needsB.value-0;
	generatedA = monthlyKWHA * solarPortionA;
	generatedB = monthlyKWHB * solarPortionB;

	sunA = frm.sunA.options[frm.sunA.selectedIndex].value-0;
	sunB = frm.sunB.options[frm.sunB.selectedIndex].value-0;
	sizeAv = Math.round(generatedA/sunA *10)/10;
	sizeBv = Math.round(generatedB/sunB *10)/10;
	insert(sizeAv,"sizeA");
	insert(sizeBv,"sizeB");

	installrateA = frm.installrateA.options[frm.installrateA.selectedIndex].value;
	installrateB = frm.installrateB.options[frm.installrateB.selectedIndex].value;
	installcostAv = Math.round(sizeAv * installrateA * 1000);
	installcostBv = Math.round(sizeBv * installrateB * 1000);
	insert(installcostAv,"installcostA");
	insert(installcostBv,"installcostB");

	wattrebateA = frm.wattrebateA.options[frm.wattrebateA.selectedIndex].value;
	wattrebateB = frm.wattrebateB.options[frm.wattrebateB.selectedIndex].value;
	rebateAv = Math.round(sizeAv * wattrebateA *1000);
	rebateBv = Math.round(sizeBv * wattrebateB *1000);
	insert(rebateAv,"rebateA");
	insert(rebateBv,"rebateB");

	taxcreditusedA = frm.taxcreditusedA.options[frm.taxcreditusedA.selectedIndex].value;
	taxcreditusedB = frm.taxcreditusedB.options[frm.taxcreditusedB.selectedIndex].value;
	taxcreditAv = Math.round( (installcostAv-rebateAv) * 0.30 * taxcreditusedA);
	taxcreditBv = Math.round( (installcostBv-rebateBv) * 0.30 * taxcreditusedB);
	insert(taxcreditAv,"taxcreditA");
	insert(taxcreditBv,"taxcreditB");

	netcostAv = installcostAv - rebateAv - taxcreditAv;
	netcostBv = installcostBv - rebateBv - taxcreditBv;
	insert(netcostAv,"netcostA");
	insert(netcostBv,"netcostB");

	gridRate = frm.gridrate.options[frm.gridrate.selectedIndex].value/100;
	yearlySavingsA = generatedA * gridRate * 12;
	yearlySavingsB = generatedB * gridRate * 12;
	insert( Math.round(netcostAv/yearlySavingsA*10)/10, "paybackA");
	insert( Math.round(netcostBv/yearlySavingsB*10)/10, "paybackB");
	
	intRate = frm.interestRate.options[frm.interestRate.selectedIndex].value/12;
	denominator = exp((1+intRate),240);
	monthlycostAv = Math.round(( netcostAv * intRate * exp(1+intRate,240) ) / (denominator-1));
	monthlycostBv = Math.round(( netcostBv * intRate * exp(1+intRate,240) ) / (denominator-1));
	insert(monthlycostAv,"monthlycostA");
	insert(monthlycostBv,"monthlycostB");

	 kwhpriceAv = Math.round(netcostAv / (generatedA * 12 * 20) * 100) /100;
	 kwhpriceBv = Math.round(netcostBv / (generatedB * 12 * 20) * 100) /100;
	 if (kwhpriceAv*10==Math.floor(kwhpriceAv*10)) { kwhpriceAv+="0";}
	 if (kwhpriceBv*10==Math.floor(kwhpriceBv*10)) { kwhpriceBv+="0";}
	 insert(kwhpriceAv,"kwhpriceA");
	 insert(kwhpriceBv,"kwhpriceB");
}

function exp(x,e) {
 if (e<0) { e=-e; inverted=1;} else {inverted=0;}
	runningValue=x;
	for (count=1; count<e; count++) {
		runningValue=runningValue*x;
	}
	if (inverted) {runningValue = 1/runningValue;}
	return runningValue;
}

function insert(theValue,theSpan) {
	if (theValue>=1000) {
	  theValue = theValue+"";
	  len = theValue.length;
	  theValue = theValue.substring(0,len-3)+','+theValue.substring(len-3,len)};
	document.getElementById(theSpan).innerHTML = theValue;
}

solarCalculate();