function validateFormOnSubmit(theForm) {
var reason = "";
theForm["good_url"].value = default_return_URL;
			
  reason += validateFirstname(		theForm["first_name"]);
  reason += validateLastname(		theForm["last_name"]);
  reason += validateBusinessname(	theForm["business_name"]);
  reason += validateEmail(		theForm["webtolead_email1"]);
  reason += validatePhone(		theForm["phone_home"]);
  reason += validateAvgccsales(		theForm["avg_monthly_gross_c"]);
  //reason += validateAcceptCC(		theForm["accept_cc"]);
  reason += validateRadioIsChecked(	theForm["accept_cc_c"], "Please state whether or not your BUSINESS ACCEPTS CREDIT CARDS.\n");
  

if (toggleRedirectPage1(theForm["avg_monthly_gross_c"])) {
	    theForm["good_url"].value = toggleRedirectPage1(theForm["avg_monthly_gross_c"]) ; 
  }
if (toggleRedirectPage2(theForm["accept_cc_c"])) {
	    theForm["good_url"].value = toggleRedirectPage2(theForm["accept_cc_c"]) ; 
  }
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

//			  alert("All fields are filled correctly");
//			  return false;
}
function validateFirstname(fld) {
	var error = "";
 
	if (fld.value.length == 0) {
		fld.style.background = 'Yellow'; 
		error = "Please enter your FIRST NAME.\n"
	} else {
		fld.style.background = 'White';
	}
	return error;  
}
function validateLastname(fld) {
	var error = "";
 
	if (fld.value.length == 0) {
		fld.style.background = 'Yellow'; 
		error = "Please enter your LAST NAME.\n"
	} else {
		fld.style.background = 'White';
	}
	return error;  
}
function validatePhone(fld) {
	myregexp = /[^0-9]/g;
	fld.value = fld.value.replace(myregexp, '');
	var error = "";
	var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
		error = "Please enter your PHONE NUMBER.\n";
		fld.style.background = 'Yellow';
	} else if (isNaN(parseInt(stripped))) {
		error = "The PHONE NUMBER contains illegal characters.\n";
		fld.style.background = 'Yellow';
	} else if (!(stripped.length == 10)) {
		error = "The PHONE NUMBER is the wrong length. Make sure you included an area code.\n";
		fld.style.background = 'Yellow';
	} else {
		fld.style.background = 'White';
	}
	return error;
}
function validateBusinessname(fld) {
	var error = "";
 
	if (fld.value.length == 0) {
		fld.style.background = 'Yellow'; 
		error = "Please enter your BUSINESS NAME.\n"
	} else {
		fld.style.background = 'White';
	}
	return error;  
}
function validateEmail(fld) {
	var error="";
	var tfld = fld.value.replace(" ", "");                        // value of field with whitespace trimmed off
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
	if (fld.value == "") {
		fld.style.background = 'Yellow';
		error = "Please enter your EMAIL ADDRESS.\n";
	} else if (!emailFilter.test(tfld)) {              //test email for illegal characters
		fld.style.background = 'Yellow';
		error = "Please enter a valid EMAIL ADDRESS.\n";
	} else if (fld.value.match(illegalChars)) {
		fld.style.background = 'Yellow';
		error = "The email address contains illegal characters.\n";
	} else {
		fld.style.background = 'White';
	}
	return error;
}
function validateAvgccsales(fld) {
	var error = "";
 
	if (fld.selectedIndex == 0) {
		fld.style.background = 'Yellow'; 
		error = "Please enter your ESTIMATED AVERAGE MONTHLY GROSS SALES.\n"
	} else {
		fld.style.background = 'White';
	}
	return error;  
}
function validateRadioIsChecked(fld, errMsg) {
	var error = errMsg;
	for(i=0; i<fld.length; i++){
		if(fld[i].checked == true){error = "";}else{};
	}
	return error;  
}
function toggleRedirectPage1(fld) {
	if(fld.selectedIndex == 1){
			return http_site_root + "form-submission/thankyou-unq/";
	} else { return false;}
}
function toggleRedirectPage2(fld) {
	if(fld[1].checked == 1){
			return http_site_root + "form-submission/thankyou-no-cc/";
	} else { return false;}
}

