//******************************************************************************* 
//  FORMS VALIDATION AND SUBMISSION
//
// 2009-09-23 - New Gutter Cleaning Form res-roof-gutter-form.php
//******************************************************************************* 	
	var thesite = "http://www.avenueroadroofing.com";
	var test = "/test";  //Set to blank for production.
  	test = "";
	

function doGutterForm ( form ) {	
//******************************************************************************* 
//   REQUEST GUTTER CLEANING
//******************************************************************************* 
	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.
//***  
 
//* 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 { 	
 		var sEmailto = "webmaster@avenueroadroofing.com";			// Default receipient 
 	  	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 - REQUEST GUTTER CLEANING";
 
	  	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); 	
   }  
}
 
