var submitted = false;

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

function FrontPage_Form1_Validator(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.Highest_Degree_Earned.selectedIndex == 0){
		alert("Please select your Highest Degree Earned.");
		theForm.Highest_Degree_Earned.focus();
		return (false);
	}
	if (theForm.Highest_Degree_Earned.selectedIndex < 2){
		alert("This program requires a minimum of a Bachelor's degree.");
		theForm.Highest_Degree_Earned.focus();
		return (false);
	}
	if (theForm.Country.selectedIndex == 0){
		alert("Please select your Country.");
		theForm.Country.focus();
		return (false);
	}
	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.Country.value == "United States"){
		if (theForm.State.value == "none"){
			alert("Please select your State.");
			theForm.State.focus();
			return (false);
		}
		if (theForm.Zip1.value == ""){
			alert("Please enter your Zip Code.");
			theForm.Zip1.focus();
			return (false);
		}
	}
	if (theForm.Country.value == "Canada"){
		if (theForm.State.value == "none"){
			alert("Please select your Province.");
			theForm.State.focus();
			return (false);
	  	}
		if (theForm.Zip1.value == "" || theForm.Zip2.value == ""){
			alert("Please enter your Postal Code.");
			theForm.Zip1.focus();
			return (false);
	  	}
		if (theForm.Zip1.value.search(/^[a-zA-Z]\d[a-zA-Z]$/) == -1 || theForm.Zip2.value.search(/^\d[a-zA-Z]\d$/) == -1){
			alert("We're sorry, but your Postal Code appears to be invalid. Please enter a valid Postal Code.");
			theForm.Zip1.focus();
			return false;
		}
	}
	if (theForm.Primary_Phone1.value == "" || theForm.Primary_Phone2.value == "" || theForm.Primary_Phone3.value == ""){
		alert("Please enter your Telephone Number.");
		theForm.Primary_Phone1.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("Email invalid. Please enter a valid Email address.");
			theForm.Email.focus();
			return false;
		}
	}

//############################## HIDDEN VALUES ##############################//

		theForm.Region.value = theForm.Country.value;
		theForm.Primary_Phone.value = theForm.Primary_Phone1.value + theForm.Primary_Phone2.value + theForm.Primary_Phone3.value + "Ext." + theForm.Primary_Ext.value;
		theForm.Zip.value = theForm.Zip1.value + theForm.Zip2.value;

//end FrontPage_Form1_Validator
}



//############################## PRIVACY POLICY MOUSEOVER ##############################//

function showPP(){
	if(document.getElementById('privacy-policy').style.visibility == "hidden"){
		document.getElementById('privacy-policy').style.visibility = "visible";
	}else{
		document.getElementById('privacy-policy').style.visibility = "hidden";
	}
//end
}

//############################## PHOTO AUTOTAB & CHECK ##############################//


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

//############################## Zip Autotab ##############################//

function autoTabZip(el,e){
	if(document.forms[0].Country.value == "Canada"){
		if(el.value.length == 3){
			document.forms[0][(getIndex(el)+1) % el.form.length].focus();
		}
		if(el.value.length > 3){
			el.value = el.value.substr(0,3);
		}
	}
	if(document.forms[0].Country.value == "United States"){
		if(el.value.length == 5){
			document.forms[0][(getIndex(el)+1) % el.form.length].focus();
		}
		if(el.name == "Zip1" && el.value.length > 5){
			el.value = el.value.substr(0,5);
		}
		if(el.name == "Zip2" && el.value.length > 4){
			el.value = el.value.substr(0,4);
		}
	}
	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;
//end autoTabZip
}

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

function doSP(c){
	if(c.value == "United States"){
		document.forms[0].State.selectedIndex = 1;
	}
	if(c.value == "Canada"){
		document.forms[0].State.selectedIndex = 54;
	}
	if(c.value == "none"){
		document.forms[0].State.selectedIndex = 0;
	}
//end doSP
}