/*
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

	CALCULATOR
	
-----------------------------------------------------------------------------------------------------------------------------

	DEPENDENCIES: 
	MooTools - version 1.20              
	copyright 2007 | Valerio Proietti | http://mootools.net/
	MIT-style license | http://www.opensource.org/licenses/mit-license.php
	
	Clientside CNET Libraries for MooTools
	For descriptions and documentation: http://clientside.cnet.com/wiki/cnet-libraries
	
-----------------------------------------------------------------------------------------------------------------------------

	:: squarehead design studio   -  845.331.1953 | www.squarehead.com | sbliss@squarehead.com
	
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

//-----------------------------------------------------
// for calculator form
//-----------------------------------------------------

function initCalculatorForm() {
	
	// reset the form if someone uses the back button
	document.estimatorForm.reset();
	
	document.estimatorForm.usage.value = "consumption";
	changeUsage();
	
	// hide commercial select controls
	$('commercial_bill').setStyle('display', 'none');
	$('commercial_consumption').setStyle('display', 'none');
	
	// show residential select controls - default
	$('residential_bill').setStyle('display', 'block');
	$('residential_consumption').setStyle('display', 'block');
}

function changeUsage(){
	// bill or consumption? - from usage select control
	// if cost $/year
	if ( document.estimatorForm.usage.value == "bill" ) {
		$('annualKWH').setStyle('display', 'none');
		$('annualBill').setStyle('display', 'block');
	// kWh per year
	} else if ( document.estimatorForm.usage.value == "consumption" ) {		
		$('annualKWH').setStyle('display', 'block');
		$('annualBill').setStyle('display', 'none');
	}
}

function setType() {
	if ( document.estimatorForm.versionName.value == "residential" ) {
		$('commercial_bill').setStyle('display', 'none');
		$('residential_bill').setStyle('display', 'block');
		$('commercial_consumption').setStyle('display', 'none');
		$('residential_consumption').setStyle('display', 'block');
	} else if ( document.estimatorForm.versionName.value == "commercial" ) {
		$('commercial_bill').setStyle('display', 'block');
		$('residential_bill').setStyle('display', 'none');
		$('commercial_consumption').setStyle('display', 'block');
		$('residential_consumption').setStyle('display', 'none');
	}
}

// sets the variables required by the calculator app by setting hidden input fields

// set variable for $ cost per year
function setBill(fieldname){
	// get the value from field residential or commercial
	getvalue = eval('document.estimatorForm.'+fieldname+'.value');
	// set reportedUtilityBill to the value
	document.estimatorForm.reportedUtilityBill.value = getvalue;
	// clear annualConsumption in case it was set earlier
	document.estimatorForm.annualConsumption.value = '';
}

// set variable for usage in kWh
function setUsage(fieldname){
	// get the value from field residential or commercial
	getvalue = eval('document.estimatorForm.'+fieldname+'.value');
	// set annualConsumption to the value
	document.estimatorForm.annualConsumption.value = getvalue;
	// clear reportedUtilityBill in case it was set earlier
	document.estimatorForm.reportedUtilityBill.value = '';
}
