function validLength(item,len) {
  return(item.length>=len);
}

function validEmail(item) {
  var emailRegEx = /^[0-9A-Za-z][_\.0-9A-Za-z-]*[0-9A-Za-z]@([0-9A-Za-z][0-9A-Za-z-]*[0-9A-Za-z]\.)*[A-Za-z]{2,6}$/;
  return emailRegEx.test(item);
}

function validDomain(item) {
  var domainRegEx = /^([0-9A-Za-z][0-9A-Za-z-]+[0-9A-Za-z]\.)*[A-Za-z]{2,6}$/;
  return domainRegEx.test(item);
}

function Validate() {
  document.getElementById('submit_form').disabled=true;
  var errortext = "";
  var errorfound = false;
  var errcolor = "#FE8A19";
  var normalcolor = "#FFFFFF";
  if(!validLength(document.regform.fname.value, 2)) {
    errortext = errortext + "Please enter your first name.\n";
    errorfound = true;
    document.regform.fname.style.background = errcolor;
    document.regform.fname.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(!validLength(document.regform.lname.value, 2)) {
    errortext = errortext + "Please enter your last name.\n";
    errorfound = true;
    document.regform.lname.style.background = errcolor;
    document.regform.lname.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(!validLength(document.regform.city.value, 3)) {
    errortext = errortext + "Please enter your city.\n";
    errorfound = true;
    document.regform.city.style.background = errcolor;
    document.regform.city.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(!validLength(document.regform.state.value, 2)) {
    errortext = errortext + "Please enter your state or province.\n";
    errorfound = true;
    document.regform.state.style.background = errcolor;
    document.regform.state.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(!validEmail(document.regform.email.value)) {
    errortext = errortext + "Please enter a valid email address.\n";
    errorfound = true;
    document.regform.email.style.background = errcolor;
    document.regform.email.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(!validLength(document.regform.office_phone.value, 7)) {
    errortext = errortext + "Please enter your phone number.\n";
    errorfound = true;
    document.regform.office_phone.style.background = errcolor;
    document.regform.office_phone.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(!validDomain(document.regform.domain_name.value)) {
    errortext = errortext + "Please enter a valid domain.\n";
    errorfound = true;
    document.regform.domain_name.style.background = errcolor;
    document.regform.domain_name.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(!validLength(document.regform.referred_by_fname.value, 3)) {
    errortext = errortext + "Please enter a valid Agent First Name.\n";
    errorfound = true;
    document.regform.referred_by_fname.style.background = errcolor;
    document.regform.referred_by_fname.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
    if(!validLength(document.regform.referred_by_lname.value, 2)) {
    errortext = errortext + "Please enter a valid Agent Last Name.\n";
    errorfound = true;
    document.regform.referred_by_lname.style.background = errcolor;
    document.regform.referred_by_lname.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
  if(document.regform.interested_in.selectedIndex==0) {
    errortext = errortext + "Please select a service.\n";
    errorfound = true;
    document.regform.interested_in.style.background = errcolor;
    document.regform.interested_in.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
/*************** Comment Out Captcha Validation ******************** 
  if(!validLength(document.regform.captchatext.value, 6)) {
    errortext = errortext + "Please enter the security code.\n";
    document.regform.captchatext.style.background = errcolor;
    document.regform.captchatext.onclick = function() {this.style.background = normalcolor; this.onclick="";}
  }
*******************************************************************/
  if(errorfound == true) {
    document.getElementById('submit_form').disabled=false;
    document.getElementById('required_field_indicator').style.color = errcolor;
    alert(errortext);
    return false;
  } else {
    return true;
  }
  return false;
}


