<!--

function validateFormOnSubmit(theForm) {
var reason = "";
errbackcolor='#FFFF99';
fixbackcolor='#FFFFFF';
//set the error and fixed backcolors for the form fields

  reason += validateFname(theForm.Fname);
  reason += validateLname(theForm.Lname);
  reason += validateAdd1(theForm.Add1);
  reason += validateCity(theForm.City);
  reason += validateState(theForm.State);
  reason += validateZip(theForm.Zip);
  reason += validateEmail(theForm.Email);
  reason += validateAreac(theForm.Areacode);
  reason += validatePrefix(theForm.Prefix);
  reason += validateTelroot(theForm.Telroot);
 



  if (reason != "") {
    alert("The required information is incomplete or contains errors:\n\n" + reason);
    return false;
  }

  return true;
}

function validateFname(fld) {
    var error = "";
    var stripped = fld.value.replace(/^\s*|\s*$/g,'');
    //strip out whitespace
	
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your First name.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 30)){
        fld.style.background = errbackcolor; 
        error = "The First name is incomplete.\n";
    } else if (illegalChars.test(stripped.value)) {
        fld.style.background = errbackcolor; 
        error = "The First name contains illegal characters.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}

function validateLname(fld) {
    var error = "";
    var stripped = fld.value.replace(/^\s*|\s*$/g,'');
    //strip out whitespace
	
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your Last name.\n";
    } else if ((fld.value.length < 2)  || (fld.value.length > 30)){
        fld.style.background = errbackcolor; 
        error = "The Last name is incomplete.\n";
    } else if (illegalChars.test(stripped.value)) {
        fld.style.background = errbackcolor; 
        error = "The Last name contains illegal characters.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}
function validateAdd1(fld) {
    var error = ""; 

   var stripped = fld.value.replace(/^\s*|\s*$/g,'');
    //strip out whitespace
	
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 

    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your Address.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 50)){
        fld.style.background = errbackcolor; 
        error = "The Address is incomplete.\n";
    } else if (illegalChars.test(stripped.value)) {
        fld.style.background = errbackcolor; 
        error = "The Address contains illegal characters.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}


function validateCity(fld) {
    var error = ""; 

   var stripped = fld.value.replace(/^\s*|\s*$/g,'');
   //strip out whitespace
	
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 

    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your City.\n";
    } else if ((fld.value.length < 3) || (fld.value.length > 30)) {
        fld.style.background = errbackcolor; 
        error = "The City is incomplete.\n";
    } else if (illegalChars.test(stripped.value)) {
        fld.style.background = errbackcolor; 
        error = "The City contains illegal characters.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}
function validateState(fld) {
    var error = "";
    var illegalChars = /\d/; // do not allow numbers
 
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your State.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 2)) {
        fld.style.background = errbackcolor; 
        error = "The State is invalid.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = errbackcolor; 
        error = "The State contains illegal characters.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}

 
function validateZip(fld) {
    var error = "";
    var illegalChars = /\D/; // allow numbers only
 
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your Zip.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 5)) {
        fld.style.background = errbackcolor; 
        error = "The Zip is incomplete.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = errbackcolor; 
        error = "The Zip is not valid.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}

function validateEmail(fld) {
    var error = "";
    var emailpattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
        
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your Email.\n";
    } else if(!emailpattern.test(fld.value)){  
	fld.style.background = errbackcolor; 
        error = "Please enter a valid Email.\n";
    } else if ((fld.value.length < 3) || (fld.value.length > 65)) {
        fld.style.background = errbackcolor; 
        error = "Please enter a valid Email.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}

function validateAreac(fld) {
    var error = "";
    var illegalChars = /\D/; // allow numbers
 
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter your Area code.\n";
    } else if ((fld.value.length < 3) || (fld.value.length > 3)) {
        fld.style.background = errbackcolor; 
        error = "The Area Code is incomplete.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '111' || fld.value == '222' || fld.value == '333' || fld.value == '444'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '555' || fld.value == '666' || fld.value == '777' || fld.value == '999'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '800' || fld.value == '888' || fld.value == '866' || fld.value == '877'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '211' || fld.value == '242' || fld.value == '246' || fld.value == '264'){
 	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '268' || fld.value == '284' || fld.value == '340' || fld.value == '876'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '851' || fld.value == '787' || fld.value == '000' || fld.value == '900'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '207' || fld.value == '201' || fld.value == '208' || fld.value == '609'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";	
    } else if(fld.value == '973' || fld.value == '732' || fld.value == '907' || fld.value == '848'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else if(fld.value == '551' || fld.value == '856' || fld.value == '862' || fld.value == '908'){
	fld.style.background = errbackcolor; 
        error = "The Area code is not valid.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}

function validatePrefix(fld) {
    var error = "";
    var illegalChars = /\D/; // allow numbers only
 
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter the middle 3 digits of your Phone number.\n";
    } else if ((fld.value.length < 3) || (fld.value.length > 3)) {
        fld.style.background = errbackcolor; 
        error = "The middle 3 digits of your Phone number are incomplete.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = errbackcolor; 
        error = "The middle 3 digits of your Phone number are invalid.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}
function validateTelroot(fld) {
    var error = "";
    var illegalChars = /\D/; // allow numbers only
 
    if (fld.value == "") {
        fld.style.background = errbackcolor; 
        error = "Please enter the last 4 digits of your Phone number.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 4)) {
        fld.style.background = errbackcolor; 
        error = "The last 4 digits of your Phone number are incomplete.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = errbackcolor; 
        error = "The last 4 digits of your Phone number are invalid.\n";
    } else {
        fld.style.background = fixbackcolor;
    } 
    return error;
}


//-->


