//******************************************************************************* 
//  FORMS VALIDATION AND SUBMISSION
//
// 2009-03-15 - Roofsaver Forms
// 2009-03-18 - Add Business phone to residential forms
// 2009-03-23 - Add Business phone to Warranty and Ask form
// 2011-09-12 - Remove bcc.
//******************************************************************************* 	
	var thesite = "http://avenueroadroofing.com";
	var test = "/test";  //Set to blank for production.
  	test = "";

function doSurvey ( form ) {	
//******************************************************************************* 
//  SURVEY FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	
	if (spaceTrim(document.form0.SalesRep.value) == "") errormessage=errormessage + "Name of Sales Rep\n";

//* SURVEY QUESTIONS - RADIOS
	if (document.form0.Arrive_on_Time[0].checked ||	document.form0.Arrive_on_Time[1].checked) {  }
	 		else { errormessage = errormessage + "Arrive on time?\n" } 

	if (document.form0.Neat_and_Professional[0].checked || document.form0.Neat_and_Professional[1].checked) {  }
	 		else { errormessage = errormessage + "Neat and professional?\n" } 	 		
	 		
	if (document.form0.Informative_Answers[0].checked || document.form0.Informative_Answers[1].checked) {  }
	 		else { errormessage = errormessage + "Informative answers?\n" } 
	 		
	if (document.form0.Commitments_Fulfilled[0].checked || document.form0.Commitments_Fulfilled[1].checked) {  }
	 		else { errormessage = errormessage + "Commitments fulfilled?\n" } 

	if (document.form0.Gift_Certificate[0].checked || document.form0.Gift_Certificate[1].checked || document.form0.Gift_Certificate[2].checked) {  }
	 		else { errormessage = errormessage + "Choice of gift certificate\n" } 	 		
	 			 			
//* ROOF SAVER SERVICE REQUESTED - RADIOS
	if (document.form0.Performance_Rating[0].checked ||
		document.form0.Performance_Rating[1].checked ||
		document.form0.Performance_Rating[2].checked ||
		document.form0.Performance_Rating[3].checked ||
		document.form0.Performance_Rating[4].checked) {  }
	 		else { errormessage = errormessage + "Performance Rating\n" } 

	if (document.form0.Consider_ARR_Again[0].checked ||	document.form0.Consider_ARR_Again[1].checked) {  }
	 		else { errormessage = errormessage + "Consider Avenue Road Roofing again?\n" } 
	 			
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";	
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing
 
//	if (spaceTrim(document.form0.Comments.value) == "xx") {errormessage=""; testFlag = 1;} 

//* If comments start with xx, set testFlag on - for deleveoper testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
 
	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca";  
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "ARR - CUSTOMER SURVEY";
 	
		document.form0.good_url.value = thesite + test + "/en/why-survey-confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}
	
function doRoofsaverSloped ( form ) {	
//******************************************************************************* 
//  RESIDENTIAL ROOF SAVER FORM - SLOPED
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 

//* PAST CUSTOMER - RADIOS
	if (document.form0.Past_customer[0].checked ||
		document.form0.Past_customer[1].checked) {  }
	 		else { errormessage = errormessage + "Past customer?\n" } 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	sEmail = spaceTrim(document.form0.Email.value);
//* if email not blank, it must be valid.
	if (sEmail != "") {
		if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	}

    if (spaceTrim(document.form0.Intersection.value) == "") errormessage=errormessage + "Closest major intersection\n";

//* ROOF SAVER SERVICE REQUESTED - RADIOS
	if (document.form0.Service_Requested[0].checked ||
		document.form0.Service_Requested[1].checked ||
		document.form0.Service_Requested[2].checked ||
		document.form0.Service_Requested[3].checked) {  }
	 		else { errormessage = errormessage + "Service Requested\n" } 
    
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
		
// 		sEmailto =  "pc@twistedpixel.com";  //* FOR TESTING

 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
// 		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca"; 

		document.form0.email.value = document.form0.Email.value;
		//* Email field is blank so set from email (formmail "from" var) to default recipient
		if (spaceTrim(document.form0.Email.value) == "") {
			document.form0.email.value = sEmailto;
		} 
 	  		  	
 	  	sSubject = "ARR - ROOF SAVER - SLOPED ROOFS";
 
	  	document.form0.subject.value = sSubject;
 	
		document.form0.good_url.value = thesite + test + "/en/res-roof-roofsaver-confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}	

function doRoofsaverFlat ( form ) {	
//******************************************************************************* 
//  ROOF SAVER FORM - FLAT ROOFS
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 

//* PAST CUSTOMER - RADIOS
	if (document.form0.Past_customer[0].checked ||
		document.form0.Past_customer[1].checked) {  }
	 		else { errormessage = errormessage + "Past customer?\n" } 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	sEmail = spaceTrim(document.form0.Email.value);
//* if email not blank, it must be valid.
	if (sEmail != "") {
		if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	}

    if (spaceTrim(document.form0.Intersection.value) == "") errormessage=errormessage + "Closest major intersection\n";
    
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
 
	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		
// 		sEmailto =  "pc@twistedpixel.com";  //* FOR TESTING
 		
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
// 		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca"; 

		document.form0.email.value = document.form0.Email.value;
		//* Email field is blank so set from email (formmail "from" var) to default recipient
		if (spaceTrim(document.form0.Email.value) == "") {
			document.form0.email.value = sEmailto;
		} 
 	  		  	
 	  	sSubject = "ARR - ROOF SAVER - FLAT ROOFS";
 	  	
	  	document.form0.subject.value = sSubject;
 	
		document.form0.good_url.value = thesite + test + "/en/res-roof-roofsaver-confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}	

function doEstimateRes ( form ) {	
//******************************************************************************* 
//  ESTIMATE - RESIDENTIAL FORM  & REQUEST RESIDENTIAL REPAIR (only subject differs)
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 

//* PAST CUSTOMER - RADIOS
	if (document.form0.Past_customer[0].checked ||
		document.form0.Past_customer[1].checked) {  }
	 		else { errormessage = errormessage + "Past customer?\n" } 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	sEmail = spaceTrim(document.form0.Email.value);
//* if email not blank, it must be valid.
	if (sEmail != "") {
		if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	}

    if (spaceTrim(document.form0.Intersection.value) == "") errormessage=errormessage + "Closest major intersection\n";

//* TYPE_OF_HOME SELECTION LIST 
	var itemHome = document.form0.Type_of_Home.selectedIndex;	
  	if (itemHome == 0) errormessage=errormessage + "Type of Home\n";
    
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "xx") {errormessage=""; testFlag = 2;} 
	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca"; 

		document.form0.email.value = document.form0.Email.value;
		//* Email field is blank so set from email (formmail "from" var) to default recipient
		if (spaceTrim(document.form0.Email.value) == "") {
			document.form0.email.value = sEmailto;
		} 
 	  		  	
 	  	sSubject = "ARR - ESTIMATE - RESIDENTIAL";
		if (thefile.substring(0,"repairs-res-form".length) == "repairs-res-form")	{
			sSubject = "ARR - REPAIRS - RESIDENTIAL";
		}	
 	  	
	  	document.form0.subject.value = sSubject;
 	
		document.form0.good_url.value = thesite + test + "/en/confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}

function doEstimateCom ( form ) {	
//******************************************************************************* 
//  ESTIMATE - COMMERCIAL FORM & REQUEST COMMERCIAL REPAIR (only subject differs)
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 

//* PAST CUSTOMER - RADIOS
	if (document.form0.Past_customer[0].checked ||
		document.form0.Past_customer[1].checked) {  }
	 		else { errormessage = errormessage + "Past customer?\n" } 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Company.value) == "") errormessage=errormessage + "Company\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	sEmail	= spaceTrim(document.form0.Email.value);
//* if email not blank, it must be valid.
	if (sEmail != "") {
		if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
 	}
 	
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";
 	
//	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for deleveoper testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
 
	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		sEmailto = "webmaster@avenueroadroofing.com"; // Default recipient 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca";  
 	  	document.form0.email.value = document.form0.Email.value;
		
		//* Email field is blank so set from email (formmail "from" var) to default recipient
		if (spaceTrim(document.form0.Email.value) == "") {
			document.form0.email.value = sEmailto;
		} 
		
 	  	sSubject = "ARR - ESTIMATE - COMMERCIAL";
		if (thefile.substring(0,"repairs-com-form".length) == "repairs-com-form")	{
			sSubject = "ARR - REPAIRS - COMMERCIAL";
		}	 	  	 	  	
	  	document.form0.subject.value = sSubject;
 	
		document.form0.good_url.value = thesite + test + "/en/confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}

function doContactRes ( form ) {	
//******************************************************************************* 
//  CONTACT US - RESIDENTIAL FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";	
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing
 
//	if (spaceTrim(document.form0.Comments.value) == "xx") {errormessage=""; testFlag = 1;} 

//* If comments start with xx, set testFlag on - for deleveoper testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
 
	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca";  
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "ARR - CONTACT - RESIDENTIAL";
 	
		document.form0.good_url.value = thesite + test + "/en/confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
// 		document.form0.action = "http://www.avenueroadroofing.com/mailer/formmail.php";
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}

function doContactCom ( form ) {	
//******************************************************************************* 
//  CONTACT US - COMMERCIAL FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Company.value) == "") errormessage=errormessage + "Company\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";	
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for deleveoper testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 
	
	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca";  
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "ARR - CONTACT - COMMERCIAL";
 	
		document.form0.good_url.value = thesite + test + "/en/confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}
function doConcierge ( form ) {	
//******************************************************************************* 
//  CONTACT US - RESIDENTIAL CONCIERGE     contact-res-concierge-form.php
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	
//* REFER SELECTION LIST 
	var itemRefer = document.form0.Refer.selectedIndex;
// 	var sRefer 	= document.form0.Refer.options[itemRefer].value; 	
  	if (itemRefer == 0) errormessage=errormessage + "How did you hear about us?\n";	
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing
 
//	if (spaceTrim(document.form0.Comments.value) == "xx") {errormessage=""; testFlag = 1;} 

//* If comments start with xx, set testFlag on - for deleveoper testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
 
	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca";  
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "ARR - CONTACT - CONCIERGE SERVICE";
 	
		document.form0.good_url.value = thesite + test + "/en/confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
// 		document.form0.action = "http://www.avenueroadroofing.com/mailer/formmail.php";
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}
function doWarranty ( form ) {	
//******************************************************************************* 
//  WARRANTY INQUIRY FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	
// 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	if ((spaceTrim(document.form0.Telephone_Home.value) == "") &  (spaceTrim(document.form0.Telephone_Business.value) == ""))  errormessage=errormessage + "Telephone\n";
		
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
 
 
//* CHECKBOX 
    if (document.form0.Nature_of_Inquiry01.checked ||
    document.form0.Nature_of_Inquiry02.checked ||
    document.form0.Nature_of_Inquiry03.checked ||
    document.form0.Nature_of_Inquiry04.checked ||
    document.form0.Nature_of_Inquiry05.checked ||
    document.form0.Nature_of_Inquiry06.checked ||
    document.form0.Nature_of_Inquiry07.checked ||
    document.form0.Nature_of_Inquiry08.checked ||
    document.form0.Nature_of_Inquiry09.checked ||
    spaceTrim(document.form0.Nature_of_Inquiry_Other.value) != "") 	{ 

    //* NOP	
    }
	else { errormessage=errormessage+"Nature of Inquiry\n" }	
     	     	
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for deleveoper testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
 
	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
//			document.form0.recipients.value = document.form0.Email.value;
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca";  
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "ARR - WARRANTY INQUIRY";
 	
		document.form0.good_url.value = thesite + test + "/en/confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}

function doEmploy ( form ) {	
//******************************************************************************* 
//  EMPLOYMENT GET ON FILE FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	sEmail = spaceTrim(document.form0.Email.value);
//* if email not blank, it must be valid.
	if (sEmail != "") {
		if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
 	}

//* PAST CUSTOMER - RADIOS

	if (document.form0.Currently_Employed[0].checked ||
		document.form0.Currently_Employed[1].checked) {  }
	 		else { errormessage = errormessage + "Currently Employed\n" } 

	if (document.form0.Currently_Employed[0].checked) {
		if (document.form0.Current_Employment_Years[0].checked ||
			document.form0.Current_Employment_Years[1].checked ||
			document.form0.Current_Employment_Years[2].checked ||
			document.form0.Current_Employment_Years[3].checked ||
			document.form0.Current_Employment_Years[4].checked) {  }
	 		else { errormessage = errormessage + "Length of time employed\n" } 	
	} 	 		
 
//* TRADE SELECTION LIST 
	var itemTrade = document.form0.Trade_Profession.selectedIndex;
// 	var sTrade 	= document.form0.Trade_Profession.options[itemTrade].value; 	
// 	if (itemTrade == 0) errormessage=errormessage + "Trade/Profession\n";

 
//* CHECKBOX 
    if (document.form0.Installer_Flat_Roof.checked ||
	    document.form0.Installer_Steep_Slope_Roofer.checked ||
	    document.form0.Installer_Roof_Repair_Tech.checked ||
	    document.form0.Installer_Siding.checked ||
	    document.form0.Commercial_Sales_Professional.checked ||
	    document.form0.Residential_Sales_Professional.checked ||
	    document.form0.Office_Administration.checked ||
	    spaceTrim(document.form0.Trade_Profession_Other.value) != "" ||
	    itemTrade > 0)  	{ 

    //* NOP	
    }
	else { errormessage=errormessage+"Occupation\n" }	
     	
     	
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for deleveoper testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "zz") {errormessage=""; testFlag = 2;} 
 
	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca";  
 	  	document.form0.email.value = document.form0.Email.value;
		
		//* Email field is blank so set from email (formmail "from" var) to default recipient
		if (spaceTrim(document.form0.Email.value) == "") {
			document.form0.email.value = sEmailto;
		} 
 	  	 	  	
	  	document.form0.subject.value = "ARR - EMPLOYMENT - GET ON FILE";
 	
		document.form0.good_url.value = thesite + test + "/en/emp-confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}


function doAsk ( form ) {	
//******************************************************************************* 
//  ASK CRAIG FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
 	
// 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	if ((spaceTrim(document.form0.Telephone_Home.value) == "") &  (spaceTrim(document.form0.Telephone_Business.value) == ""))  errormessage=errormessage + "Telephone\n";
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
	
	if (spaceTrim(document.form0.Question.value) == "") errormessage=errormessage + "Question\n";	
 		
//  	errormessage ="";  // Uncomment to deactivate validation for Testing
 
//* If comments start with xx, set testFlag on - for developer testing 
	var sQuestion = spaceTrim(document.form0.Question.value);
	if (sQuestion.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sQuestion.substring(0,4) == "zz") {errormessage=""; testFlag = 2;}	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		sEmailto = "webmaster@avenueroadroofing.com"; // Default recipient 	
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}
  	 	
//		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
// 	 	document.form0.bcc.value = "pc@twistedpixel.com, wolfgang@wordsatwork.ca"; 
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "ARR - ASK CRAIG";
 
		document.form0.good_url.value = thesite + test + "/en/confirm.php";
 		document.form0.action = thesite + "/mailer/formmail.php";  
// 		document.form0.action = "http://www.avenueroadroofing.com/mailer/formmail.php";
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
} 

function spaceTrim(InString) {
//*******************************************************************************
// Trim leading and trailing spaces of form input fields
//*******************************************************************************
	var LoopCtrl=true;
	while (LoopCtrl) {
		if (InString.indexOf("  ") != -1) {
			Temp = InString.substring(0, InString.indexOf("  "))
			InString = Temp + InString.substring(InString.indexOf("  ")+1, 
				InString.length)
		} else
			LoopCtrl = false;
	}
	if (InString.substring(0, 1) == " ")
		InString = InString.substring(1, InString.length)
	if (InString.substring (InString.length-1) == " ")
		InString = InString.substring(0, InString.length-1)
	return (InString)
}

function doClear ( form ) {	
//*******************************************************************************
// Clear Form  -  
//*******************************************************************************	
//alert(pagelang);
    var msg_e = "Are you sure that you want to clear all the data you have entered on this form?";
    var msg_f = "Voulez-vous vraiment effacer toutes les données?";
    var clearmsg = msg_e;
 // if (pagelang == "f") clearmsg = msg_f;
    
	var confirmOK = confirm(clearmsg);
  	if (confirmOK) document.form0.reset();    
}
