//
//	Validate screen form fields
//

<!--
function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function validate ( form )
{
	 form.fname.value 		= trim(form.fname.value);
	 form.lname.value 		= trim(form.lname.value);
	 //form.addr1.value 		= trim(form.addr1.value);
	 //form.addr2.value 		= trim(form.addr2.value);
	 //form.city.value 		= trim(form.city.value);
	 //form.state.value 		= trim(form.state.value);
	 //form.zip.value 		= trim(form.zip.value);
	 //form.country.value 	= trim(form.country.value);
	 form.email.value 		= trim(form.email.value);
	 form.phone.value 		= trim(form.phone.value);
	 form.age.value 		= trim(form.age.value);
	 


 	if (form.fname.value == "" || form.fname.length == 0) 
	 {
		 alert( "Please enter your First name." );
		 form.fname.focus();
		 return false ;
	 }
	 
	
	  if (form.lname.value == "" || form.lname.length == 0) 
	  {
		 alert( "Please enter your Last Name." );
		 form.lname.focus();
		 return false ;
	  }
	
	
	  if (form.phone.value == "" || form.phone.length == 0) 
	  {
		 alert( "Please enter your phone number." );
		 form.phone.focus();
		 return false ;
	  }
	  
	  
	  if (form.age.value == "" || form.age.length == 0) 
	  {
		 alert( "Please enter your age." );
		 form.age.focus();
		 return false ;
	  }
	  
	  

	 
	 
	  
	  if (form.email.value == "" || form.email.length == 0) 
	  {
	 	 alert( "Please enter your Email address." );
	 	 form.email.focus();
	 	 return false ;
	  }
	  
	  
	  if (echeck(form.email.value)==false)
	  {
		 form.email.focus();
		 return false ;
	  }
	  // good to go baby . . 
	  return true ;
}



	
function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
	
//-->
