// ============= validate.js file =========================

function check_request_form(theForm) {
    var why = "";
    why += checkFirstName(theForm.first_name.value);
    why += checkLastName(theForm.last_name.value);
    why += checkCompany(theForm.company.value);
    why += checkTitle(theForm.title.value);
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkState(theForm.state.value);
    why += checkCountry(theForm.country.value);

    if (why != "") {
       alert(why);
       return false;
    } else {
      return true;
    }
}

/* function check_request_form2(theForm) {
    var why = "";
    why += checkFirstName(theForm.first_name.value);
    why += checkLastName(theForm.last_name.value);
    why += checkEmail(theForm.email.value);
    why += checkFirstName(theForm.first_name1.value);
    why += checkLastName(theForm.last_name1.value);
    why += checkEmail(theForm.email1.value);
    

    if (why != "") {
       alert(why);
       return false;
    } else {
      return true;
    }
}*/

function check_request_form2(theForm) {
    var why = "";
 /*    why += checkFirstName(theForm.00N40000001vgG6.value);
    why += checkLastName(theForm.00N40000001vgGB.value);
    why += checkEmail(theForm.00N40000001vgGC.value);*/
     why += checkFirstName(theForm.first_name.value);
    why += checkLastName(theForm.last_name.value);
    why += checkEmail(theForm.email.value);
   
   
    

    if (why != "") {
       alert(why);
       return false;
    } else {
      return true;
    }
}









function check_Email(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    if (why != "") {
       alert(why);
       return false;
    }
  return true;
}

function checkMessage(theForm) {
    var why = "";
    why += checkUsername(theForm.name.value);
    why += checkEmail(theForm.email.value);
 //   why += checkPhone(theForm.phone.value);
    why += isEmptySubject(theForm.subject.value);
    why += isEmptyBody(theForm.body.value);
    if (why != "") {
       alert(why);
       return false;
    }
  return true;
}


// ==================================
function checkFirstName (strng) {
var error = "";
if (strng == "") {
   error = "Please enter First Name.\n";
} else {
var illegalChars = /[^A-Za-z\.\- ]/; // allow letters, numbers, and underscores
  if (strng.length < 2) {
     error = "First Name is too short.\n";
  }
  else if (illegalChars.test(strng)) {
     error = "First Name field contains illegal characters.\n";
  }
 }
return error;
}

// ==================================
function checkLastName (strng) {
var error = "";
if (strng == "") {
   error = "Please enter Last Name.\n";
} else {
var illegalChars = /[^A-Za-z\.\- ]/; // allow letters, numbers, and underscores
  if (strng.length < 2) {
     error = "Last Name is too short.\n";
  }
  else if (illegalChars.test(strng)) {
     error = "Last Name field contains illegal characters.\n";
  }
 }
return error;
}
// ==================================
function checkCompany (strng) {
var error = "";
if (strng == "") {
   error = "Please enter Company name.\n";
} else {
var illegalChars = /[^0-9A-Za-z\.\- ]/; // allow letters, numbers, period and underscores
  if (strng.length < 2) {
     error = "Company name is too short.\n";
  }
  else if (illegalChars.test(strng)) {
     error = "Company name field contains illegal characters.\n";
  }
 }
return error;
}
// ==================================
function checkTitle (strng) {
var error = "";
if (strng == "") {
   error = "Please enter Title.\n";
} else {
var illegalChars = /[^A-Za-z\.\- ]/; // allow letters, numbers, and underscores
  if (strng.length < 2) {
     error = "Title is too short.\n";
  }
  else if (illegalChars.test(strng)) {
     error = "Title field contains illegal characters.\n";
  }
 }
return error;
}

//==================================
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter Email.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
       error = "Please enter a valid Email.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "Email has invalid format.\n";
       }
    }
return error;
}
//==================================
// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng != "") {
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if ( stripped.replace(/[^\d]/g,'') != stripped ) {
       error = "The Phone field contains illegal characters.\n";
    } else {
      if (stripped.length < 5) {
	error = "The Phone field is too short. Make sure area code is included.\n";
      }
    }
  } else {
    error = "Please enter Phone Number.\n";
  }
  return error;
}
// ==================================
function checkState (strng) {
var error = "";
  if ((strng == "") || (strng == "NONE")) {
    error = "Please select the State.\n";
  }
return error;
}
// ==================================
function checkCountry (strng) {
var error = "";
  if ((strng == "") || (strng == "NONE")) {
    error = "Please select the Country.\n";
  }
return error;
}
// ==================================
function checkIndustry (strng) {
var error = "";
  if ((strng == "") || (strng == "NONE")) {
    error = "Please select the Industry.\n";
  }
return error;
}