// JavaScript Document

var numberWindowPanes;
var numberWindowFrench;
var sqFootOfHouse;

var action;
var bNewConstruction;
var bWindowBothSides;
var strFrequency;
var debug = false;
var debugString = "";
var debugNewLine = "\n";
var totalCost = 0;

function myOnLoad(){
document.all['commercial_residential'].style.display = "none"; 
document.all['commercial_multi'].style.display = "none"; 
document.all['pressure'].style.display = "none"; 
document.all['other'].style.display = "none"; 
}


function changeDisplay(dropDown){

	action = dropDown.options[dropDown.selectedIndex].value;
	
	document.all['commercial_multi'].style.display = "none"; 
	document.all['commercial_residential'].style.display = "none"; 
	document.all['pressure'].style.display = "none"; 
	document.all['costTR'].style.display = ""; 
	document.all['resMessage'].style.display = "none";
	document.all['comMessage'].style.display = "none";
	document.all['resHeader'].style.display = "none";
	document.all['comHeader'].style.display = "none";
	document.all['other'].style.display = "none"; 

	if (action == "Commercial Multi Story") {
		debugString += "show call us" + debugNewLine;
		document.all['commercial_multi'].style.display = ""; 
		document.all['costTR'].style.display = "none"; 
	}
	else if (action == "Commercial Window Washing Single Story"){
		debugString += "comm single" + debugNewLine;
		document.all['commercial_residential'].style.display = ""; 
		document.all['comMessage'].style.display = "";
		document.all['comHeader'].style.display = "";
	}
	else if (action == "Residential Window Washing"){
		debugString += "res" + debugNewLine;
		document.all['commercial_residential'].style.display = ""; 
		document.all['resMessage'].style.display = "";
		document.all['resHeader'].style.display = "";
	}
	else if (action == "Commercial Pressure Washing" || action == "Residential Pressure Washing"){
		document.all['pressure'].style.display = ""; 
		debugString += "pressure" + debugNewLine;
	}
	else if (action == "Other - Steam Cleaning, Caulking, Water Spot Removal"){
		document.all['other'].style.display = ""; 
		debugString += "Other - Steam Cleaning, Caulking, Water Spot Removal" + debugNewLine;
		document.all['costTR'].style.display = "none"; 
	}
}
function getCost(){
	
	var cost = 0;
	var window_pane, french_pane;
	
	debugString = "action is " + action 
		  + "\nstrFrequency = " + strFrequency 
		  + "\nbWindowBothSides = " + bWindowBothSides 
		  + "\nnumberWindowPanes = " + numberWindowPanes
		  + "\nnumberWindowFrench = " + numberWindowFrench
		  + "\nsqFootOfHouse = " + sqFootOfHouse
		  + "\nbNewConstruction = " + bNewConstruction
		  ;
	

	//Commercial Costing
	if (action == "Commercial Window Washing Single Story"){
		if (strFrequency == "Quarterly or One Time"){
			if (bWindowBothSides == true){
				window_pane = 6; //it is $3 a pane and you double it
				french_pane = 8; //it is $8 a french window two sides
			}
			else{ //it is only one side of window
				window_pane = 3;  //it is $3 for one side
				french_pane = 5; //it is $5 a french window
			}
		}
		else if (strFrequency == "Monthly Or Less"){
		//the frequency is monthly, bi-weekly, or weekly	
		if (bWindowBothSides == true){
				window_pane = 2; //it is $1 a pane and you double it
				french_pane = 8; //it is $8 a french window two sides
			}
			else{ //it is only one side of window
				window_pane = 1;  //it is $1 for a pane
				french_pane = 5; //it is $5 a french window
			}
		}
		//calculate costs
		debugString += "\n------------- COSTS -----------\n";
		debugString += "\nfrench_pane:" + french_pane;
		debugString += "\nwindow_pane:" + window_pane;
		
		cost = (window_pane * numberWindowPanes) + (french_pane * numberWindowFrench);
		if (bNewConstruction == true){
			//if it is new construction, double the cost
			cost = cost * 2;
		}
		

}
	//end commercial costing
	
	//Residential Costing
	else if (action == "Residential Window Washing"){
		if (bWindowBothSides == true){
			window_pane = 10; //it is $5 a pane and you double it
			french_pane = 16; //it is $8 a french window two sides
		}
		else{ //it is only one side of window
			window_pane = 5;  //it is $5 for one side
			french_pane = 8; //it is $8 a french window
		}
		//calculate costs
		debugString += "\n------------- COSTS -----------\n";
		debugString += "\nfrench_pane:" + french_pane;
		debugString += "\nwindow_pane:" + window_pane;
		
		cost = (window_pane * numberWindowPanes) + (french_pane * numberWindowFrench);
		if (bNewConstruction == true){
			//if it is new construction, double the cost
			cost = cost * 2;
		}

	}
	//end Residential costing	

	//Pressure Washing Costing
	else if (action == "Commercial Pressure Washing" || action == "Residential Pressure Washing"){
		//pressure washign is $10 per sq/foot
		cost = .10 * sqFootOfHouse;
	}
	//end pressure washing costing	

	debugString += "\nCost:" + cost;
	return cost;
	

}
function calculateCost(){
	
	form = document.all['myForm'];

	if (action == "Commercial Pressure Washing" || action == "Residential Pressure Washing"){ //just pressure washing
		sqFootOfHouse = form.Sq_Footage_of_Unit.value;	
	}
	else{ //it is for window washing

		bNewConstruction = false;
		bWindowBothSides = false;
		strFrequency = false;
	
		//residential job
		numberWindowPanes = form.Windows.options[form.Windows.selectedIndex].text;
		numberWindowFrench = form.French_Windows.options[form.French_Windows.selectedIndex].text;

		//for commercial there are weekly, bi-weekly, monthly, quarterly, or one time
		//quarterly and one time are more
		frequency = form.Frequency_of_Cleaning.options[form.Frequency_of_Cleaning.selectedIndex].value;
		if( frequency == "Quarterly" || frequency == "One Time") 
			strFrequency = "Quarterly or One Time";
		else //"Monthly Or Less"
			strFrequency = "Monthly Or Less";
		//find out if we need to double the cost due to new construction 
		if(form.First_Cleaning_Or_Construction_Within_3_Months.options[form.First_Cleaning_Or_Construction_Within_3_Months.selectedIndex].value 
			== "Yes") 
			bNewConstruction = true;
			
		//find out if we are cleaning one or both sides of window
		if(form.Windows_Clean.options[form.Windows_Clean.selectedIndex].value == "Inside and Outside") 
			bWindowBothSides = true;
		

	} //end window washing

	totalCost = getCost();
	form.Cost_Estimate.value = totalCost;
	document.all['totalCost'].innerHTML = "$" + totalCost; 
	
	if (debug) alert(debugString);

}
