
// form validation functions
// Note, if the locator is on the same page as one of these forms,
// this form will become document.forms[1] instead of document.forms[0]

function fn_val_local_office_quote_form() {

	oFrm = document.forms[0];
	oEle = oFrm.elements;

	if (
		myValEmail(oEle['email'], "E-mail address", 0, 1) &&
		myValPhone(oEle['dayPhone'], "Day Phone", 1) &&
		myValPhone(oEle['eveningPhone'], "Evening Phone", 1) &&
		myValSelOptByIndex(oEle["contactPref"], "Contact Me via", 0) &&
		myValString(oEle['street'], "Street", 5, 200, 1) &&
		myValString(oEle["city"], "City", 2, 30, 1) &&
		myValSelOptByIndex(oEle["state_province"], "Province", 0) &&
		myValString(oEle["zip_postal_code"],"Postal Code",3,15,1) &&
		myValRadio(oEle["service_pref"], "Cleaning Service Request", 1) &&
		myValSelOptByIndex(oEle["howReferred"], "How did you hear about us", 0) &&
		myValNumber(oEle["square_footage"],"Square Footage",100,20000,1) &&
		myValRadio(oEle["residence"], "Residence", 1) &&
		myValRadio(oEle["stories"], "How many stories does your home have", 1) &&
		myValRadio(oEle["adults"], "Adults", 1) &&
		myValRadio(oEle["children"], "Children", 1) &&
		myValRadio(oEle["dogsCats"], "Dogs/Cats", 1)
		)
	{

		// check radio - require additional info box if necessary
		if (oEle["service_pref"][2].checked == false) {
			// Additional info not needed
			return true;
		}
		else if ( (oEle["service_pref"][2].checked == true) && (myValString(oEle['service_pref_other_desc'], "Cleaning Request - Other Description", 4, 75, 1)) ) {
			// Require additional info box
			return true;
		}
		else {
			return false;
		}
		
	}
	else {
		return false;
	}
}

function fn_val_careers() {

	oFrm = document.forms[0];
	oEle = oFrm.elements;

	if (
		myValString(oEle['name_field'], "Name", 3, 50, 1) &&
		myValEmail(oEle['email_field'], "E-mail address", 0, 0) &&
		myValPhone(oEle['phone_field'], "Phone", 1) &&
		myValString(oEle['besttime_field'], "Best time to call", 5, 500, 1) &&
		myValRadio(oEle["over_18_radio"], "Over 18", 1)
		)
	{
		return true;
	}
	else {
		return false;
	}
}


function fn_val_contact_us() {

	oFrm = document.forms[1];
	oEle = oFrm.elements;

	if (
		myValString(oEle['ZipPostalCode'], "ZipPostalCode", 3, 10, 1) &&
		myValEmail(oEle['EmailAddress'], "E-mail address", 0, 1) &&
		myValEmail(oEle['ConfirmEmailAddress'], "Confirm E-mail address", 0, 1) &&
		myValString(oEle['Comments'], "Comments", 5, 500, 1)
		)
	{
		return true;
	}
	else {
		return false;
	}
}

function fn_val_fran_info_req_form() {

	oFrm = document.forms[1];
	oEle = oFrm.elements;

	if (
		myValString(oEle['lastname'], "Last Name", 2, 25, 1) &&
		myValString(oEle['firstname'], "First Name", 2, 25, 1) &&
		myValEmail(oEle['reqemail'], "Email address", 0, 1)
		)
	{
		return true;
	}
	else {
		return false;
	}
}


  function fn_val_stayinformed() {

	oFrm = document.forms[1];
	oEle = oFrm.elements;

	if (
		myValString(oEle['FirstName'], "First Name", 2, 25, 1) &&
		myValString(oEle['ZipPostalCode'], "Zip/PostalCode", 3, 10, 1) &&
		myValEmail(oEle['EmailAddress'], "Email address", 0, 1)
		)
	{
		return true;
	}
	else {
		return false;
	}
}

function fn_val_ask_expert() {

	oFrm = document.forms[1];
	oEle = oFrm.elements;

	if (
		myValString(oEle['Name'], "Name", 3, 100, 1) &&
		myValEmail(oEle['EmailAddress'], "E-mail address", 0, 1) &&
		myValEmail(oEle['ConfirmEmailAddress'], "Confirm E-mail address", 0, 1) &&
		myValString(oEle['Question'], "Question", 10, 350, 1)
		)
	{
		return true;
	}
	else {
		return false;
	}
}

function fn_val_contact_this_office() {

	oFrm = document.forms[0];
	oEle = oFrm.elements;

	if (
		myValString(oEle['Name'], "Name", 3, 10, 1) &&
		myValEmail(oEle['EmailAddress'], "E-mail address", 0, 1) &&
		myValEmail(oEle['ConfirmEmailAddress'], "Confirm E-mail address", 0, 1) &&
		myValString(oEle['Comments'], "Comments", 10, 200, 1)
		)
	{
		return true;
	}
	else {
		return false;
	}
}

function fn_val_postal(oZipField) {

	// do a simple check on zipcode
	// temporary - should add a new zip/postal function in inc_myfunctions.js

	var usa_regex = /^(\d{5})$/;
	var can_regex = /^([a-zA-Z0-9]{3})$/;

	if ( (usa_regex.test(oZipField.value) != 1) && (can_regex.test(oZipField.value) != 1) ) {
		alert("Please type your 5-digit US zip code or the first 3 characters of your Canadian postal code.");
		return false;
	}

	else {
		return true;
	}
}

function fn_val_locality() {

	oFrm = document.forms[0];
	oEle = oFrm.elements;

	if (myValSelOptByIndex(oEle['state_selopt'], "USA State and Locality", 0)) {
		return true;
	}
	else {
		return false;
	}
	
}


function fn_val_request_cleaning() {

	oFrm = document.forms[0];
	oEle = oFrm.elements;
	//alert('test');
	
	if (
		myValString(oEle['firstname_field'], "First Name", 2, 25, 1) &&
		myValString(oEle['lastname_field'], "Last Name", 2, 25, 1) &&
		myValString(oEle['addr1_field'], "Address_1", 5, 100, 1) &&
		myValString(oEle['addr2_field'], "Address_2", 0, 100, 0) &&
		myValString(oEle['city_field'], "City", 2, 25, 1) &&
		myValSelOptByIndex(oEle["state_field"], "State", 0) &&
		myValString(oEle['zippostal_field'], "Zip/Postal", 3, 10, 1) &&
		myValString(oEle['ph_hm_area_field'], "Home Phone Number Area Code", 3, 3, 1) &&
		myValString(oEle['ph_hm_prefix_field'], "Home Phone Number Prefix", 3, 3, 1) &&
		myValString(oEle['ph_hm_suffix_field'], "Home Phone Number Suffix", 4, 4, 1) &&
		myValString(oEle['ph_wk_area_field'], "Daytime Phone Number Area Code", 3, 3, 1) &&
		myValString(oEle['ph_wk_prefix_field'], "Daytime Phone Number Prefix", 3, 3, 1) &&
		myValString(oEle['ph_wk_suffix_field'], "Daytime Phone Number Suffix", 4, 4, 1) &&
		myValEmail(oEle['email_field'], "Email address", 0, 1)
		)
	{
		return true;
	}
	else {
		return false;
	}
}


