var submitted = false;

//############################## FORM VALIDATOR ##############################//

function checkP1(theForm){
	if (theForm.First_Name.value == ""){
		alert("Please enter your First Name.");
		theForm.First_Name.focus();
		return (false);
	}
	if (theForm.Last_Name.value == ""){
		alert("Please enter your Last Name.");
		theForm.Last_Name.focus();
		return (false);
	}
	if (theForm.Primary_Phone_1.value == "" || theForm.Primary_Phone_2.value == "" || theForm.Primary_Phone_3.value == ""){
		alert("Please enter your Primary Phone Number.");
		theForm.Primary_Phone_1.focus();
		return (false);
	}else{
		theForm.Primary_Phone.value = theForm.Primary_Phone_1.value + theForm.Primary_Phone_2.value + theForm.Primary_Phone_3.value + ' x' + theForm.Primary_Ext.value;
	}
	if (theForm.Email.value == ""){
		alert("Please enter your Email Address.");
		theForm.Email.focus();
		return (false);
	}else{
  		var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
		var returnval = emailfilter.test(theForm.Email.value);
		if (returnval == false){
			alert("The Email Address you entered is invalid. Please enter a valid Email address.");
			theForm.Email.focus();
			return false;
		}
	}
	if (theForm.Highest_Degree_Earned.selectedIndex == 0){
		alert("Please select your Highest Degree Earned.");
		theForm.Highest_Degree_Earned.focus();
		return (false);
	}
	if (theForm.Highest_Degree_Earned.value == "High School" || theForm.Highest_Degree_Earned.value == "Associates"){
		alert("Sorry, a Bachelor's degree is required to qualify for this program.");
		theForm.Highest_Degree_Earned.focus();
		return (false);
	}

nextDiv()
//end
}

function FrontPage_Form1_Validator(theForm){
	theForm.Region.value = "United States";

	if (theForm.Address.value == ""){
		alert("Please enter your Address.");
		theForm.Address.focus();
		return (false);
	}
	if (theForm.City.value == ""){
		alert("Please enter your City.");
		theForm.City.focus();
		return (false);
	}
	if (theForm.State.selectedIndex == 0){
		alert("Please select your State.");
		theForm.State.focus();
		return (false);
	}
	if (theForm.Zip1.value == ""){
		alert("Please enetr your Zip Code.");
		theForm.Zip1.focus();
		return (false);
	}else{
		theForm.Zip.value = theForm.Zip1.value + theForm.Zip2.value;
	}

//end
}


//############################## PHONE NUMBER VALIDATION ##############################//

function numbersonly(myfield, e, dec){
	var key;
	var keychar;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
		keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
		return true;
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else if (dec && (keychar == ".")){
		myfield.form.elements[dec].focus();
		return false;
		}
	else
		return false;
}
	
		
//############################## PHONE AUTO TAB ##############################//

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(Primary_Phone,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(Primary_Phone.value.length >= len && !containsElement(filter,keyCode)) {
		Primary_Phone.value = Primary_Phone.value.slice(0, len);
		Primary_Phone.form[(getIndex(Primary_Phone)+1) % Primary_Phone.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;
	}
	function getIndex(Primary_Phone) {
		var index = -1, i = 0, found = false;
		while (i < Primary_Phone.form.length && index == -1)
		if (Primary_Phone.form[i] == Primary_Phone)index = i;
		else i++;
		return index;
	}
	return true;
}


