// 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 Validdropdown(item) {
if(item=="%") return false;
return true;
}

function errordropdown(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.focus();
   errfound = 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");  
	  
	if (!Validdropdown(document.form1.spec.value)) 
	  errordropdown(document.form1.spec,"Invalid Speciality");
	  
	if (!Validdropdown(document.form1.providers.value)) 
	  errordropdown(document.form1.providers,"Invalid no. of Physicians");

	 if (!Validdropdown(document.form1.timeframe.value)) 
	  errordropdown(document.form1.timeframe,"Invalid Timeframe");
	  	 
	 if (!Validdropdown(document.form1.product.value)) 
	  errordropdown(document.form1.product,"Invalid Product/Service");
	  

	 
	 /* if (!ValidLength(document.form1.add1.value,5))
     error(document.form1.add1,"Invalid Address");  
	 
	 	 
	  if (!ValidLength(document.form1.city.value,3))
     error(document.form1.city,"Invalid City");  
	  
	  
	  if (!Validdropdown(document.form1.Region.value)) 
	  errordropdown(document.form1.Region,"Invalid State Name");
	  
	  
	  if (!ValidLength(document.form1.zip.value,5))
     error(document.form1.zip,"Invalid Zip");   
	 */

       return !errfound; // true if there are no errors 

}