// JavaScript Document
function validate(){
  document.form.fname.style.backgroundColor='white';
  document.form.lname.style.backgroundColor='white';
  document.form.phone.style.backgroundColor='white';
  document.form.email.style.backgroundColor='white';

  var valid=true;
  var returnString='';
  var filteredChars = "`qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM-=~!@#$%^&*)(_+|}{:?><,./;'][ ";
  if(document.form.fname.value == ""){
    alert('Please enter your first name.');
    document.form.fname.style.backgroundColor='yellow';
    document.form.fname.focus();
    valid=false;
  }
  if(document.form.lname.value == ""){
    alert('Please enter your last name.');
    document.form.lname.style.backgroundColor='yellow';
    document.form.lname.focus();
    valid=false;
  }
  var emailStr = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|mobi|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
  if (!emailStr.test(document.form.email.value)){
      alert('Please enter a valid email.');
      document.form.email.style.backgroundColor='yellow';
      document.form.email.focus();
      valid=false;
  }
  var p=document.form.phone.value;
  for (i = 0; i < p.length; i++) {  
      var c = p.charAt(i);
      if (filteredChars.indexOf(c) == -1)
        returnString += c;
  }
  document.form.phone.value = returnString;
  
  if (returnString.length != 10) {
    alert("please enter a 10 digit Phone Number");
    document.form.phone.style.backgroundColor='yellow';
    document.form.phone.focus();
    valid=false;
  }
  return valid;
}