var submitted = false;

//############################## FORM VALIDATOR ##############################//

function FrontPage_Form1_Validator(theForm){
	var acChecked = false;
	var progList = new Array();

	var schtemp = theForm.Access_Code.value.split("-");

	if (theForm.MSAFA.type == "checkbox" && theForm.MSAFA.checked == true){
		theForm.Access_Code.value = "NEC-MSAFA-"+schtemp[2];
		theForm.program.value = "NEC_MSAFA";
		theForm.confirm.value = "http://online.nec.edu/accounting-master-degree/request_info/thank_you_MSAFA.asp";
	} else {
		theForm.Access_Code.value = "NEC-MSA-"+schtemp[2];
		theForm.program.value = "NEC_MSA";
		theForm.confirm.value = "http://online.nec.edu/accounting-master-degree/request_info/thank_you_MSA.asp";
	}
	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.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, you must have at least a Bachelor's degree to qualify for this program.");
		theForm.Highest_Degree_Earned.focus();
		return false;
	}
	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.\nPlease enter a valid Email address.")
			theForm.Email.focus();
			return (false);
		}
	}
	if (theForm.Region.value == "none"){
		alert("Please select your Country.");
		theForm.Region.focus();
		return (false);
	}

	// UNITED STATES VALIDATION

	if (theForm.Region.value == "United States"){
		if (theForm.Zip1.value == ""){
			alert("Please enter your Zip Code.");
			theForm.Zip1.focus();
			return (false);
		}
		if (theForm.Zip1.value.length != "5"){
			alert("Please ensure your Zip Code is valid.");
			theForm.Zip1.focus();
			return (false);
		}
	}

	// CANADA VALIDATION

	if (theForm.Region.value == "Canada"){
		if (theForm.Postal_Code1 && (theForm.Postal_Code1.value == "" || theForm.Postal_Code2.value == "")){
			alert("Please enter your Postal Code.");
			theForm.Postal_Code1.focus();
			return (false);
	  	}
		if (theForm.Postal_Code1 && (theForm.Postal_Code1.value.search(/^[a-zA-Z]\d[a-zA-Z]$/) == -1 || theForm.Postal_Code2.value.search(/^\d[a-zA-Z]\d$/) == -1)){
			alert("The Postal Code you entered is invalid.\nPlease enter a valid Postal Code.");
			theForm.Postal_Code1.focus();
			return false;
		}
	}

	// INTERNATIONAL VALIDATION

	if (theForm.Region.value == "International"){
		if (theForm.Country.value == "none"){
			alert("Please select your Country.");
			theForm.Country.focus();
			return (false);
	  	}
	}

	// PRIMARY PHONE VALIDATION

	if (theForm.Region.value == "Canada"){
		if (theForm.Can_Primary_Phone_1.value == "" || theForm.Can_Primary_Phone_2.value == "" || theForm.Can_Primary_Phone_3.value == ""){
			alert("Please enter your Primary Phone Number.");
			theForm.Can_Primary_Phone_1.focus();
			return (false);
		}
		if (theForm.Can_Primary_Phone_1.value.length != "3" || theForm.Can_Primary_Phone_2.value.length != "3" || theForm.Can_Primary_Phone_3.value.length != "4"){
			alert("Please ensure the Primary Phone Number you entered is valid.");
			theForm.Can_Primary_Phone_1.focus();
			return (false);
		}
	}
	else if (theForm.Region.value == "United States"){
		if (theForm.us_Primary_Phone_1.value == "" || theForm.us_Primary_Phone_2.value == "" || theForm.us_Primary_Phone_3.value == ""){
			alert("Please enter your Primary Phone Number.");
			theForm.us_Primary_Phone_1.focus();
			return (false);
		}
		if (theForm.us_Primary_Phone_1.value.length != "3" || theForm.us_Primary_Phone_2.value.length != "3" || theForm.us_Primary_Phone_3.value.length != "4"){
			alert("Please ensure the Primary Phone Number you entered is valid.");
			theForm.us_Primary_Phone_1.focus();
			return (false);
		}
	}
	else{
		if (theForm.Int_Primary_Phone.value == ""){
			alert("Please enter your Primary Phone Number.");
			theForm.Int_Primary_Phone.focus();
			return (false);
		}
	}

	/*if (theForm.First_Name.value == "embtest"){
			alert(theForm.Access_Code.value);
			return (false);
		}
	
	if (theForm.us_Primary_Phone_1.value == "123"){
			alert("State" + theForm.State.value);
			return (false);
		}*/

	// SET VALUE OF HIDDEN FIELDS 

	if (theForm.Region.value == "Canada"){
		theForm.Primary_Phone.value = theForm.Can_Primary_Phone_1.value + theForm.Can_Primary_Phone_2.value + theForm.Can_Primary_Phone_3.value + ' x' + theForm.Can_Primary_Ext.value;
		theForm.Zip.value = theForm.Postal_Code1.value + theForm.Postal_Code2.value;
		getProvince(theForm.Zip.value);
	}
	else if (theForm.Region.value == "United States"){
		theForm.Primary_Phone.value = theForm.us_Primary_Phone_1.value + theForm.us_Primary_Phone_2.value + theForm.us_Primary_Phone_3.value + ' x' + theForm.us_Primary_Ext.value;
		theForm.Zip.value = theForm.Zip1.value;
		getState(theForm.Zip.value);
	}
	else{
		theForm.Primary_Phone.value = theForm.Int_Primary_Phone.value;
		theForm.State.value = " ";
		theForm.Zip.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;
}

//############################## CATCH-ALL PROGRAM DETAILS SCRIPT ##############################//

function chgPgm(w){
	// SAMPLE Access Code: NEC-MSHA-01-HP
	if(document.forms[0].Access_Code.selectedIndex == 0){
		document.forms[0].confirm.value = "";
		return false;
	}
	var thePgm = "";
	var tempPgmCode = w.value.split("-");
	var thePgm = tempPgmCode[1].toLowerCase();

	document.forms[0].confirm.value = "http://online.nec.edu/request_info/thank_you.asp?pgm="+thePgm;

//end chgPgm
}


//############################## APPLY NOW HIDDEN DIV ##############################//

function show(daDiv){
	if(daDiv.value == "Request_Form" && daDiv.checked == true){
		document.getElementById('Request_Form').style.display = "inline";
		document.getElementById('Fast_Track').style.display = "none";
		/*document.getElementById('Intro').style.display = "none";*/
		/*document.payment_data.Submit.value = "Login >>";
		document.getElementById('submit_button').style.display = "inline";*/
	}
	if(daDiv.value == "Fast_Track" && daDiv.checked == true){
		document.getElementById('Request_Form').style.display = "none";
		document.getElementById('Fast_Track').style.display = "inline";
		/*document.getElementById('Intro').style.display = "none";*/
		/*document.payment_data.Submit.value = "Send >>";
		document.getElementById('submit_button').style.display = "none";*/
	}
//end show
}

//############################## PRIVACY POLICY MOUSEOVER ##############################//

function showInfo(w){
	if(document.getElementById('info_'+w).style.display == "inline"){
		document.getElementById('info_'+w).style.display = "none";
	}else{
		document.getElementById('info_'+w).style.display = "inline";
	}
//end
}

function hideInfo(w){
	if(document.getElementById('info_'+w).style.display == "none"){
		document.getElementById('info_'+w).style.display = "inline";
	}else{
		document.getElementById('info_'+w).style.display = "none";
	}
//end
}

//############################## COPYRIGHT DATE ##############################//

var newDate = new Date();
var daYear = newDate.getFullYear();
var daDate = ""+daYear+"";
