// JavaScript Document
//global variable for error flag
var errfound = false;
//function to validate by length
function ValidLength(item, len) {
   return (item.length >= len);
}


function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.select();
   elem.focus();
   errfound = true;
}

//function to validate an email address
function ValidEmail(item) {
   if (!ValidLength(item, 5)) return false;
 if (item.indexOf ('@', 0) == -1) return false;
   return true;
}

function checkphone() {
document.form1.phone.value="";
}


function Validate() {
   errfound = false;
   if (!ValidLength(document.form1.fname.value,1))
      error(document.form1.fname,"Invalid First Name");
  if (!ValidLength(document.form1.lname.value,1))
     error(document.form1.lname,"Invalid Last Name");  
	 
	var objRegExp  = /(^\d{3}-\d{3}-\d{4}$)/;
   strValue = document.form1.phone.value;
   if(objRegExp.test(strValue) == false)
    {
	error(document.form1.phone,"Follow This Style: 999-999-9999");  
	} 
	 
	 if (!ValidEmail(document.form1.email.value))
      error(document.form1.email, "Invalid Email Address");  
	  
	 return !errfound; // true if there are no errors 

}