function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('firstname');
	var lastname = document.getElementById('lastname');
	var email = document.getElementById('email');
	var phone = document.getElementById('phone');
	var selection = document.getElementById('selection');
	var custom_message = document.getElementById('custom_message');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(firstname, "Please enter your first name")){
		if(isAlphabet(lastname, "Please enter your last name")){
			if(emailValidator(email, "Please enter a valid email address")){
				//if(isNumeric(phone, "Please enter your telephone number")){
				if(validatePhone(phone, "Phone number must be in the form xxx-xxx-xxxx")){
					if(madeSelection(selection, "Please select a topic")){
						if(notEmpty(custom_message, "Please enter a comment")){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 lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

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;
	}
}

function validatePhone(elem, helperMsg){
	var ph = elem.value;
	ph = ph.replace(/[^0-9]\-/,"");  // strip non-numeric characters except hyphen
	if(ph == "" || ph.length < 12){
		alert(helperMsg);
		return false;
	}else{
		return true;
	}
}