// JavaScript Document
function formCheck()
{
	// Make quick references to our fields
	var FirstName = document.getElementById('FirstName');
	var LastName = document.getElementById('LastName');
	var CompanyName = document.getElementById('CompanyName');
	var Phone = document.getElementById('Phone');
	var Email = document.getElementById('Email');
	
	
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(FirstName, "Please enter only letters for your firstname")){
		if(isAlphabet(LastName, "Please enter only letters for your lastname")){
			if(notEmpty(CompanyName, "Please enter your companyname")){
				if(isNumeric(Phone, "Please enter a valid phone number")){
					if(emailValidator(Email, "Please enter a valid email address")){
							return true;
						}
					}
				}
		}
	}
			
		return false;
	
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}


function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
document.formcheck.submit();

/*function formCheck()
{
	if(document.formcheck.FirstName.value=="")
	{
	alert("Please enter your Name");
	document.formcheck.FirstName.focus();
	return false;
	}

		
	if(document.formcheck.LastName.value=="")
	{
	alert("Please enter your Last Name");
	document.formcheck.LastName.focus();
	return false;
	}
	if(document.formcheck.CompanyName.value=="")
	{
	alert("Please enter your Company Name");
	document.formcheck.CompanyName.focus();
	return false;
	}
	if(document.formcheck.Phone.value=="")
	{
	alert("Please enter your Phone Number");
	document.formcheck.Phone.focus();
	return false;
	}

	if (isNaN(document.formcheck.Phone.value))
	{
	alert("Invalid Phone Number");
	document.formcheck.Phone.focus();
	document.formcheck.Phone.select();
	return false;
	}

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
var returnval=emailfilter.test(document.formcheck.Email.value)
	if (returnval==false){
	alert("Please enter a valid email address.")
	document.formcheck.Email.focus();
	document.formcheck.Email.select();
	return false;
	}

	
	document.formcheck.submit();

}*/


