var acro = "";
var progValue = "";

function getProgram(){
	acro = "";

	if(document.forms[0].Access_Code.value == ""){
		return false;
	}

	var acParts = document.forms[0].Access_Code.value.split("-");

	if(acParts[0] == "EK"){
		acro = acParts[2];
	}else{
		acro = acParts[1];
	}
	
	document.forms[0].emailsubject.value =  "ACU Online - " + acro + " Program";

if(acro.indexOf("MED") == -1){
	document.getElementById('specializations_med').style.display = "none";
}

if(acro.indexOf("MEDCI") > -1 && acro.indexOf("MEDHE") == -1){
	//document.getElementById('specializations_med').style.display = "inline";
	showSpec('med');
}

if(acro.indexOf("MEDLL") > -1){
	showSpec('med2');
}

if(acro.indexOf("MEDHE") > -1){
	showSpec('none');
}

if(acro.indexOf("GC") > -1){
	showSpec('med4');
}
//end getProgram
}

function showSpec(sspec){
if(sspec == "med"){
	document.getElementById('specializations_med').style.display = "inline";
}else{
	document.getElementById('specializations_med').style.display = "none";
}
					
if(sspec == "med2"){
	document.getElementById('specializations_med2').style.display = "inline";
}else{
	document.getElementById('specializations_med2').style.display = "none";
}
					
if(sspec == "med4"){
	document.getElementById('specializations_med4').style.display = "inline";
}else{
	document.getElementById('specializations_med4').style.display = "none";
}
//end sspec
}

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

var errList = new Array();
	
function FrontPage_Form1_Validator(theForm){
	if(theForm.Access_Code.value == ""){
		alert("Please select your Program.");
		theForm.Access_Code.focus();
		return (false);
	}else{
		getProgram();
		if(theForm.Access_Code.selectedIndex == 1){
			if(theForm.Specialization_MEDCI.selectedIndex == 0){
				alert("Please enter your Specialization.");
				theForm.Specialization_MEDCI.focus();
				return (false);
			}else{
				document.forms[0].program.value = "ACU_" + theForm.Specialization_MEDCI.value;
				theForm.Specialization.value = theForm.Specialization_MEDCI.value;
			}
		}
		if(theForm.Access_Code.selectedIndex == 2){
			if(theForm.Specialization_MEDLL.selectedIndex == 0){
				alert("Please enter your Specialization.");
				theForm.Specialization_MEDLL.focus();
				return (false);
			}else{
				document.forms[0].program.value = "ACU_" + theForm.Specialization_MEDLL.value;
				theForm.Specialization.value = theForm.Specialization_MEDLL.value;
			}
		}
		if(theForm.Access_Code.selectedIndex == 3){
			theForm.Specialization.value = "na";
			document.forms[0].program.value = "ACU_MEDHE";
		}
		if(theForm.Access_Code.selectedIndex == 4){
			if(theForm.Specialization_GC.selectedIndex == 0){
				alert("Please enter your Specialization.");
				theForm.Specialization_GC.focus();
				return (false);
			}else{
				document.forms[0].program.value = "ACU_" + theForm.Specialization_GC.value;
				theForm.Specialization.value = theForm.Specialization_GC.value;
			}
		}
	}
		
		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);
		}
		
		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;
		}
		
		//############################## 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.");
				theForm.Email.focus();
				return (false);
			}
		}
		//############################## END EMAIL VALIDATION ##############################//
		
		if (theForm.Country.selectedIndex == 0){
			alert("Please enter 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);
	  	}
		
		// UNITED STATES VALIDATION
		if (theForm.Country.value == "United States"){
			if (theForm.us_State.value == "none"){
				alert("Please select your State.");
				theForm.us_State.focus();
				return (false);
		}
		if (theForm.Zip1.value == ""){
			alert("Please enter your Zip Code.");
			theForm.Zip1.focus();
			return (false);
			}
		}

		// CANADA VALIDATION
		if (theForm.Country.value == "Canada"){
			if (theForm.Province.value == "none"){
				alert("Please select your Province.");
				theForm.Province.focus();
				return (false);
	  	}
		if (theForm.Postal_Code1.value == "" || theForm.Postal_Code2.value == ""){
			alert("Please enter your Postal Code.");
			theForm.Postal_Code1.focus();
			return (false);
	  	}
		if (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;
		}
	}

	// PRIMARY PHONE VALIDATION
	if (theForm.Country.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);
		}
	}
	else if (theForm.Country.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);
		}
	}
	else{
		if (theForm.Int_Primary_Phone.value == ""){
			alert("Please enter your Primary Phone Number.");
			theForm.Int_Primary_Phone.focus();
			return (false);
		}
	}
	
	if (theForm.agreement.checked == false){
		alert("Please agree to be contacted by an ACU admissions counselor.");
		theForm.agreement.focus();
		return (false);
	}

if(theForm.First_Name.value == "embtest"){
	alert(document.forms[0].Access_Code.value);
	return false;
}
	// SET VALUE OF HIDDEN FIELDS 
	if (theForm.Country.value == "Canada"){
		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.Secondary_Phone.value = theForm.Can_Secondary_Phone_1.value + theForm.Can_Secondary_Phone_2.value + theForm.Can_Secondary_Phone_3.value;
		theForm.Cell_Phone.value = theForm.can_cell_1.value + theForm.can_cell_2.value + theForm.can_cell_3.value;
		theForm.Zip.value = theForm.Postal_Code1.value + theForm.Postal_Code2.value;
		theForm.State.value = theForm.Province.value;
	}	
	else if (theForm.Country.value == "United States"){
		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.Secondary_Phone.value = theForm.us_Secondary_Phone_1.value + theForm.us_Secondary_Phone_2.value + theForm.us_Secondary_Phone_3.value;
		theForm.Cell_Phone.value = theForm.us_cell_1.value + theForm.us_cell_2.value + theForm.us_cell_3.value;
		theForm.Zip.value = theForm.Zip1.value + theForm.Zip2.value;
		theForm.State.value = theForm.us_State.value;
	}	
	else{
		theForm.Region.value = "International";		
		theForm.Primary_Phone.value = theForm.Int_Primary_Phone.value;
		theForm.Secondary_Phone.value = theForm.Int_Secondary_phone.value;
		theForm.Cell_Phone.value = theForm.Int_Cellular_phone.value;
		theForm.State.value = " ";
	}

//end FrontPage_Form1_Validator
}


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

//############################## CHECKBOX LINK CLICK ##############################//

function clickCheck(el){
	if(document.forms[0][el].type == "checkbox"){
		if(document.forms[0][el].checked == true){
			document.forms[0][el].checked = false;
		}else{
			document.forms[0][el].checked = true;
		}
	}
//end clickCheck
}