// JavaScript Document
function formValidator(){
	var Name = document.getElementById('Name');
	var Email = document.getElementById('Email');
	var ReEmail = document.getElementById('ReEmail');
	var State = document.getElementById('State');
	var Phone = document.getElementById('Phone');

	// Check each input in the order that it appears in the form!
	if(notEmpty(Name, "Please enter your name!")){
		if(emailValidator(Email, "Please enter a valid email address!")){
			if(CheckEmail(ReEmail, "Please re-enter your email address for verification purposes! (They need to match!)")){
				if(madeSelection(State, "Please Choose a Location!")){
					if(isNumeric(Phone, "Please Enter Numbers Only for Phone!")){
							return true;
						}
					}
				}
		}
	}
	return false;
	
}

function notEmpty(Name, helperMsg){
	if(Name.value.length == 0){
		alert(helperMsg);
		Name.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function emailValidator(Email, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(Email.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		Email.focus();
		return false;
	}
}

function CheckEmail(ReEmail, helperMsg) {
var one = document.form1.Email.value;
var another = document.form1.ReEmail.value;
if(one == another) { return true;
	}else{
		alert(helperMsg);
		ReEmail.focus();
		return false;
	}
}

function madeSelection(State, helperMsg){
	if(State.value == "--"){
		alert(helperMsg);
		State.focus();
		return false;
	}else{
		return true;
	}
}

function isNumeric(Phone, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(Phone.value.match(numericExpression)){
		return true;
	}
	if(Phone.value.length == 0){
		return true;
	}
	else{
		alert(helperMsg);
		Phone.focus();
		return false;
	}
}


