
// Name Validator
function isFName()	{
	var name1 = document.frx1.pname.value;
	var regex_for_name	= /^[A-Za-z]+ [A-Za-z]+$/
	var alt_regex_for_name	= /^[A-Za-z]+$/
	if(   (name1.search(regex_for_name) != -1)  || (name1.search(alt_regex_for_name) != -1 ) ) {
			return true;
	} else {
		alert("Name is invalid");
		document.frx1.pname.focus();
		return	false;	
	}

}

// Company Name Validator
function isCName()	{
	var name2 = document.frx1.cname.value;
	if ((name2 == "") || (name2.length < 5))
	{
		alert("Company Name is invalid");
		document.frx1.cname.focus();
		return	false;	
	}

}

// Phone No. Validator
function isPhone()	{
	var str = document.frx1.phone.value;
	if ((str == "") || (str.length < 15))
	{
		alert("\nThe Phone no is either empty or less than 15 chars.\n\nPlease enter your Phone No.")
		document.frx1.phone.focus();
		return false;
	}
}


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")
		   return false
		}

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

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

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

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

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

 		 return true					
	}


function ValidateAltEmail() {

	var emailID=document.frx1.email;
	
	if(emailID.value == '' ) {
		alert("Invalid E-mail");
		emailID.focus()
		return false;	
	}
	
	if (echeck(emailID.value)==false) {
			emailID.focus()
			return false
	}
	
	return true;
 }


function validate()	{

	if ( isFName() == false )	{	 // Checks the Name
		return false;			
	} // End of check Name

	if ( isCName() == false )	{	 // Checks the Company Name
		return false;			
	} // End of check Company Name

	if ( ValidateAltEmail() == false )	{	 // Checks E-mail
		return false;			
	} 

	if ( isPhone() == false )	{	 // Checks Phone No.
		return false;			
	}
	


} // End of Function Validate
