/************************************
	Generic javascript functions 
*************************************/


/*  Remove any text in the dealer locator field when it is clicked  */
function clearSearchField()  {
	if (this.dealerLocator.searchZIP.value != '')  {
		this.dealerLocator.searchZIP.value = 'Enter Zip Code';
	}
	else {
		this.dealerLocator.searchZIP.value = '';
	}
}

function getsubtotal()  {
	
}


/* Check to see if there are empty form fields */
function isblank(s)  {
	for(var i = 0; i < s.length; i++)  {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
return true;
}


/* Verify that all required form fields are filled out */
function verify(f)  {
	var msg;
	var emptyFields = "";
	var errors = "";

	for (var i=0; i<f.length; i++)  {
		var e = f.elements[i];
		if (((e.type == "text") || (e.type == "textarea")) && !e.optional)  {
			if ((e.value == null) || (e.value == "") || isblank(e.value))  {
				emptyFields += "\n          " + e.alt;
				continue;
			}
			if (e.numeric || (e.min !=null) || e.max != null)  {
				var v = parseFloat(e.value);
				if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max)))  {
						errors += "- The field " + e.alt + " must be a number";
						if (e.min != null)
							errors += " that is greater than " + e.min;
						if (e.max != null && e.min != null)
							errors += " and less than " + e.max;
						else if (e.max !=null)
							errors += " that is less than " + e.max;
						errors += ".\n";
				}
			}
		}
	}

	if (!emptyFields && !errors) return true;

	msg = "---------------------------------------------------------------\n\n"
	msg += " The form was not submitted because of the following error(s).\n";
	msg += "Please Correct these error(s) and re-submit.\n";
	msg += " --------------------------------------------------------------\n\n"

	if (emptyFields)  {
		msg += "- The following required field(s) are empty:" + emptyFields + "\n";
		if (errors) msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}



function updateTotal()  {
	
	if (!this.document.custom)  {
		return;
	}
	else {
		var retailPrice = (this.document.custom.retailPrice.value * 1);
		var levelLength = (this.document.custom.levelLength.value);
		
		/* Scuff Plates */
		if (this.document.custom.sp[0].checked == true)  {	// Add the cost of the Scuff Plates //
			sp = 6.50;
			/*
			this.document.custom.fg[0].checked = false;
			this.document.custom.fg[1].checked = true;
			*/
		}  else {
			sp = 0.00;
		}
		/* Rubber Cushions */
		if (this.document.custom.rc[0].checked == true)  {  // Add the cost of the Rubber Cushions //
			rc = 5.50;  
		}  else {
			rc = 0.00;
		} 
		/*  Finger Grooves */
		if (this.document.custom.fl[0].checked == true)  {
			fl = 8.00;
		} else {
			fl = 0.00;
		}
		/* Magnets */
		if (this.document.custom.m[0].checked == true)  {
			if (levelLength <= 12)  {
				m = 4.00;
			}
			if (levelLength == 15 || levelLength == 18)  {
				m = 6.00;
			}
			if (levelLength > 18 && levelLength < 40)  {
				m = 8.00;
			}
			if (levelLength > 36 && levelLength < 60)  {
				m = 12.00;
			}
			if (levelLength > 50)  {
				m = 16.00;
			}
		} else {
			m = 0.00;
		}
		/* 45 degree angled vial */
		if (this.document.custom.av[0].checked == true)  {
			av = 5.00;
		} else {
			av = 0.00;	
		}
		/* Binding Engraving */
		if (this.document.custom.be[0].checked == true)  {
			be = 1.00;
		} else {
			be = 0.00;
		}
		/* Plate Engraving */
		if (this.document.custom.pe[0].checked == true)  {
			pe = 5.00;
		} else {
			pe = 0.00;
		}
		/* Finger Grooves */
		if (this.document.custom.fg[0].checked == true)  {
			fg = 0.00;
			if (this.document.custom.levelLength.value < 24)  {
				// The level is shorter than 24" and finger grooves are not available. //
				this.document.custom.fg[0].checked = false;
				this.document.custom.fg[1].checked = true;
			}
			this.document.custom.sp[0].checked = false;
			this.document.custom.sp[1].checked = true;
			sp = 0.00;
		} else {
			fg = 0.00;
		}
		/* Additional Windows */
		if (this.document.custom.aw[0].checked == true)  {
			aw = 16.00;
		} else {
			aw = 0.00;
		}
		
		/* Calculate the Wood Costs */	
		if (this.document.custom.wood_1[0].selected == true)  wood1 = 0.00;
		if (this.document.custom.wood_1[1].selected == true)  wood1 = 0.00;
		if (this.document.custom.wood_1[2].selected == true)  wood1 = 8.00;
		if (this.document.custom.wood_1[3].selected == true)  wood1 = 13.50;
		if (this.document.custom.wood_1[4].selected == true)  wood1 = 13.50;
		if (this.document.custom.wood_1[5].selected == true)  wood1 = 13.50;
		
		if (this.document.custom.wood_2[0].selected == true)  wood2= 0.00;	
		if (this.document.custom.wood_2[1].selected == true)  wood2 = 0.00;
		if (this.document.custom.wood_2[2].selected == true)  wood2 = 0.00;
		if (this.document.custom.wood_2[3].selected == true)  wood2 = 8.00;
		if (this.document.custom.wood_2[4].selected == true)  wood2 = 13.50;
		if (this.document.custom.wood_2[5].selected == true)  wood2 = 13.50;
		if (this.document.custom.wood_2[6].selected == true)  wood2 = 13.50;
			
		if (this.document.custom.wood_3[6])  {
			if (this.document.custom.wood_3[0].selected == true)  wood3 = 0.00;
			if (this.document.custom.wood_3[1].selected == true)  wood3 = 0.00;
			if (this.document.custom.wood_3[2].selected == true)  wood3 = 0.00;
			if (this.document.custom.wood_3[3].selected == true)  wood3 = 8.00;
			if (this.document.custom.wood_3[4].selected == true)  wood3 = 13.50;
			if (this.document.custom.wood_3[5].selected == true)  wood3 = 13.50;
			if (this.document.custom.wood_3[6].selected == true)  wood3 = 13.50;
		}
		else {
			if (this.document.custom.wood_3[0].selected == true)  wood3 = 0.00;
			if (this.document.custom.wood_3[1].selected == true)  wood3 = 0.00;
			if (this.document.custom.wood_3[2].selected == true)  wood3 = 8.00;
			if (this.document.custom.wood_3[3].selected == true)  wood3 = 13.50;
			if (this.document.custom.wood_3[4].selected == true)  wood3 = 13.50;
			if (this.document.custom.wood_3[5].selected == true)  wood3 = 13.50;
		}
		
		/* Exception for 5 Piece levels */
		
		if (!this.document.custom.wood_4)  {
			wood4 = 0.00;
			wood5 = 0.00;
		}
		else {
			if (this.document.custom.wood_4[0].selected == true)  wood4 = 0.00;	
			if (this.document.custom.wood_4[1].selected == true)  wood4 = 0.00;
			if (this.document.custom.wood_4[2].selected == true)  wood4 = 0.00;
			if (this.document.custom.wood_4[3].selected == true)  wood4 = 8.00;
			if (this.document.custom.wood_4[4].selected == true)  wood4 = 13.50;
			if (this.document.custom.wood_4[5].selected == true)  wood4 = 13.50;
			if (this.document.custom.wood_4[6].selected == true)  wood4 = 13.50;
				
			if (this.document.custom.wood_5[0].selected == true)  wood5 = 0.00;
			if (this.document.custom.wood_5[1].selected == true)  wood5 = 0.00;
			if (this.document.custom.wood_5[2].selected == true)  wood5 = 8.00;
			if (this.document.custom.wood_5[3].selected == true)  wood5 = 13.50;
			if (this.document.custom.wood_5[4].selected == true)  wood5 = 13.50;
			if (this.document.custom.wood_5[5].selected == true)  wood5 = 13.50;
		}
		
			
		
		subtotal = retailPrice + sp + rc + fl + m + av + be + pe + fg + aw + wood1 + wood2 + wood3 + wood4 + wood5; 
			
		subtotal = subtotal.toFixed(2);
	
		this.document.custom.subTotal.value = subtotal;
	}
	
return;
}