var warning='';

function formValidator(){
	warning='';
	
	// Make quick references to our fields
	var firstname = document.getElementById('firstname');
	var lastname = document.getElementById('lastname');
	var email = document.getElementById('email');
	var message = document.getElementById('message');
	var warningbox = document.getElementById('warningbox');
	var valid = true;
	warningbox.style.display = 'none';


	
	// Check each input in the order that it appears in the form!
	if (!notEmpty(firstname, "If we could be on a first name basis...that would be cool. <br />"))
	{
		valid=false;
	}
	
	if (!notEmpty(lastname, "Last name too...if you don't mind.. <br />"))
	{
		valid=false;
	
	}
	if (!emailValidator(email, "We'll need an e-mail address, preferably valid, preferably yours. <br />"))
	{
		valid=false;
	}
	
	if (!notEmpty(message, "At least say hi!  (or put whatever other message you want in there) <br />"))
	{
		valid=false;
	
	}

	if (!valid)
	{
		warningbox.innerHTML = warning;
		warningbox.style.display = 'block';
		return false;
	}
	return true;
	
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		warning += helperMsg;
	}
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(!elem.value.match(numericExpression)){
		warning += helperMsg;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(!elem.value.match(alphaExp)){
		warning += helperMsg;
	}
}

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

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length < min && uInput.length > max){
		warning += helperMsg;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		warning += helperMsg;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(!elem.value.match(emailExp)){
		warning += helperMsg;
	}
}