function ValidEmail(email) {
  if (email.length < 5) return false;
  at_location = email.indexOf("@")
  dot_location = email.lastIndexOf(".")
  if (at_location == -1 || dot_location == -1 || at_location > dot_location )  return false;
  if (at_location == 0) return false;
  if (dot_location - at_location < 2 ) return false;
  if (email.length - dot_location < 2) return false;
  return true;
}
function valF(tel) {
  if (tel == "" ||!isNum(tel)) {
      return false;
  }
  return true;
}
function IsEmpty(str) {
  if((str == "") || (str == null)) return true;
  for (var counter = 0; counter < str.length; counter++) {
   if(str.charAt(counter) != " " && str.charAt(counter) != "0" && str.charAt(counter) != "1"
    && str.charAt(counter) != "2" && str.charAt(counter) != "3" && str.charAt(counter) != "4"
     && str.charAt(counter) != "5"  && str.charAt(counter) != "6"  && str.charAt(counter) != "7"
      && str.charAt(counter) != "8"  && str.charAt(counter) != "9"  && str.charAt(counter) != "="
       && str.charAt(counter) != "!"  && str.charAt(counter) != "~"  && str.charAt(counter) != "@"
        && str.charAt(counter) != "#"  && str.charAt(counter) != "$"  && str.charAt(counter) != "%"
         && str.charAt(counter) != "^"  && str.charAt(counter) != "&"  && str.charAt(counter) != "8"
          && str.charAt(counter) != "("  && str.charAt(counter) != ")"  && str.charAt(counter) != "."
           && str.charAt(counter) != ","  && str.charAt(counter) != ";"  && str.charAt(counter) != ":"
            && str.charAt(counter) != "["  && str.charAt(counter) != "]") return false;

   }
   return true;

}
function isNum(passedVal) {
  for (i=0; i<passedVal.length; i++) {
     if (passedVal.charAt(i) < "0" && passedVal.charAt(i) != '-') return false
     if (passedVal.charAt(i) > "9" && passedVal.charAt(i) != '-') return false
  }
  return true
}
function CheckEstForm() {
  if(IsEmpty(document.Estimate.estimate_first_name.value)) {
       alert('Please Enter your First Name!');
       document.Estimate.estimate_first_name.focus();
       return false;
  } 
  if(IsEmpty(document.Estimate.estimate_last_name.value)) {
       alert('Please Enter your Last Name!');
       document.Estimate.estimate_last_name.focus();
       return false;
  }
  if (document.Estimate.estimate_last_name.value == document.Estimate.estimate_first_name.value) {
       alert('Please Enter your Full Name!');
       document.Estimate.estimate_last_name.focus();
       return false;
  }
  if(!ValidEmail(document.Estimate.estimate_email.value)){
       alert('Please Enter a valid E-Mail!');
       document.Estimate.estimate_email.focus();
       return false;
  }
  if(!valF(document.Estimate.estimate_phone.value)){alert('Please Enter a valid Phone number!\n(847-546-0000)');document.Estimate.estimate_phone.focus();return false;};
  if(''==document.Estimate.estimate_city.value){alert('Please Enter your City!');document.Estimate.estimate_city.focus();return false;};
  if(''==document.Estimate.estimate_state.value) {alert('Please Select your State!');document.Estimate.estimate_state.focus();return false;}; 
  return true;
}