var c;
function validateFormOnSubmit(theForm) {

var reason = "";

  reason += validateFirst(theForm.first);
  reason += validateLast(theForm.last);
  reason += validateCompany(theForm.company);
  reason += validateEmail(theForm.email);
  reason += validatePhone(theForm.phone);
  reason += validateAddress(theForm.street);
  reason += validateCity(theForm.city);
  reason += validateState(theForm.state);
  reason += validateZip(theForm.zip);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
  
  return true;
}
c="1";
function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFF66 '; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateFirst(fld) {
    if (!fld) return "";
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ 
 
    if (fld.value == "") {
        fld.style.background = '#FFFF66 '; 
        error = "You didn't enter a first name.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 150)) {
        fld.style.background = '#FFFF66 '; 
        error = "The first name is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FFFF66 '; 
        error = "The first name contains invalid characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateLast(fld) {
    if (!fld) return "";
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ 
 
    if (fld.value == "") {
        fld.style.background = '#FFFF66 '; 
        error = "You didn't enter a last name.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 150)) {
        fld.style.background = '#FFFF66 '; 
        error = "The last name is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FFFF66 '; 
        error = "The last name contains invalid characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateCompany(fld) {
    if (!fld) return "";
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ 
 
    if (fld.value == "") {
        fld.style.background = '#FFFF66 '; 
        error = "You didn't enter a company name.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 200)) {
        fld.style.background = '#FFFF66 '; 
        error = "The organization name is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FFFF66 '; 
        error = "The company name contains invalid characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateEmail(fld) {
    if (!fld) return "";
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#FFFF66 ';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFFF66 ';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFFF66 ';
        error = "The email address contains invalid characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    if (!fld) return "";
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = '#FFFF66 ';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains invalid characters.\n";
        fld.style.background = '#FFFF66 ';
    } else if (stripped.length < 10) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = '#FFFF66 ';
    }
    return error;
}
function validateAddress(fld) {
    if (!fld) return "";
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
 
    if (fld.value == "") {
        fld.style.background = '#FFFF66 '; 
        error = "You didn't enter an address.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 300)) {
        fld.style.background = '#FFFF66 '; 
        error = "The address is the wrong length.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateCity(fld) {
    if (!fld) return "";
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#FFFF66 '; 
        error = "You didn't enter a city.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 150)) {
        fld.style.background = '#FFFF66 '; 
        error = "The city is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FFFF66 '; 
        error = "The city contains invalid characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateState(fld) {
    if (!fld) return "";
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
 
    if (fld.value == "") {
        fld.style.background = '#FFFF66 '; 
        error = "You didn't enter a state.\n";
    } else if ((fld.value.length < 1) || (fld.value.length > 150)) {
        fld.style.background = '#FFFF66 '; 
        error = "The state is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FFFF66 '; 
        error = "The state contains invalid characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateZip(fld) {
    if (!fld) return "";
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a zip number.\n";
        fld.style.background = '#FFFF66 ';
    } else if (isNaN(parseInt(stripped))) {
        error = "The zip contains invalid characters.\n";
        fld.style.background = '#FFFF66 ';
    } else if (!(stripped.length == 5)) {
        error = "The zip is the wrong length. Make sure you included an area code.\n";
        fld.style.background = '#FFFF66 ';
    }
    return error;
}
function getVisitorInfo () {
	document.getElementById('00N80000004ffaj').value = document.referrer;
	document.getElementById('00N80000004fgPl').value = c;
}
