var submitted = false;

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

function FrontPage_Form1_Validator(theForm){

	/*if (theForm.Access_Code.selectedIndex == 0){
		alert("Please select a Program.");
		theForm.Access_Code.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 Applicant does not have Bachelor's Degree or higher, they are prompted to Undergraduate Program
	//if(theForm.Highest_Degree_Earned.value == "High School" || theForm.Highest_Degree_Earned.value == "Associates"){
//		alert("You must have a minimum Bachelors degree to apply.");
//    	theForm.Highest_Degree_Earned.focus();
//		return false;
//	}
	
	if (theForm.First_Name.value == ""){
		alert("Please enter your First Name.");
		theForm.First_Name.focus();
		return (false);
	}
	
	//error checking
		/*if(theForm.First_Name.value == "abc"){
			alert('program: ' + theForm.program.value);
			alert('Access Code: ' + theForm.Access_Code.value);
			return false;
		}*/
	
	if (theForm.Last_Name.value == ""){
		alert("Please enter your Last Name.");
		theForm.Last_Name.focus();
		return (false);
	}
	
	//############################## EMAIL VALIDATION ##############################//

	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.");
			//document.getElementById('email_error').style.display = "inline";
			theForm.Email.focus();
			//theForm.Email.className = "input_box_error";
			return (false);
		}
		//else{
			//document.getElementById('email_error').style.display = "none";
			//theForm.Email.className = "input_box";
		//}
	}
	
	//############################## END EMAIL VALIDATION ##############################//
	

		if (theForm.Zip1.value == ""){
			alert("Please enter your Zip Code.");
			theForm.Zip1.focus();
			return (false);
		}

	// PRIMARY PHONE VALIDATION
	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);
	}

	// SET VALUE OF HIDDEN FIELDS 
	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 + theForm.Zip2.value;

	getState(theForm.Zip.value);

//end validation
}

//############################## MICROFORM VALIDATOR ##############################//

function FrontPage_Form2_Validator(theForm){

	if (theForm.Access_Code.selectedIndex == 0){
		alert("Please select a Program.");
		theForm.Access_Code.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 Applicant does not have Bachelor's Degree or higher, they are prompted to Undergraduate Program
	//if(theForm.Highest_Degree_Earned.value == "High School" || theForm.Highest_Degree_Earned.value == "Associates"){
//		alert("You must have a minimum Bachelors degree to apply.");
//    	theForm.Highest_Degree_Earned.focus();
//		return false;
//	}
	
	if (theForm.First_Name.value == ""){
		alert("Please enter your First Name.");
		theForm.First_Name.focus();
		return (false);
	}
	
	//error checking
		if(theForm.First_Name.value == "abc"){
			alert('program: ' + theForm.program.value);
			alert('Access Code: ' + theForm.Access_Code.value);
			return false;
		}
	
	if (theForm.Last_Name.value == ""){
		alert("Please enter your Last Name.");
		theForm.Last_Name.focus();
		return (false);
	}
	
	//############################## EMAIL VALIDATION ##############################//

	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.");
			//document.getElementById('email_error').style.display = "inline";
			theForm.Email.focus();
			//theForm.Email.className = "input_box_error";
			return (false);
		}
		//else{
			//document.getElementById('email_error').style.display = "none";
			//theForm.Email.className = "input_box";
		//}
	}
	
	//############################## END EMAIL VALIDATION ##############################//
	

		if (theForm.Zip1.value == ""){
			alert("Please enter your Zip Code.");
			theForm.Zip1.focus();
			return (false);
		}

	// PRIMARY PHONE VALIDATION
	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);
	}

	// SET VALUE OF HIDDEN FIELDS 
	theForm.Primary_Phone.value = theForm.us_Primary_Phone_1.value + theForm.us_Primary_Phone_2.value + theForm.us_Primary_Phone_3.value;
	theForm.Zip.value = theForm.Zip1.value + theForm.Zip2.value;

	getState(theForm.Zip.value);
//end validation
}



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


//############################## COPYRIGHT DATE ##############################//

var newDate = new Date();
var daYear = newDate.getFullYear();
var daDate = ""+daYear+"";


//############################## 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
}


//############################## TOP NAV ##############################//

var timeout	= 2000;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

