var submitted = false;
//############################## FORM VALIDATOR ##############################//

function checkP1(theForm){
	if(theForm.iwant_otd && theForm.iwant_ot){
		if (theForm.iwant_otd.checked == false && theForm.iwant_ot.checked == false){
			alert("Please select at least one program.");
			return false;
		}
		if (theForm.iwant_otd.checked == true && theForm.iwant_ot.checked == false){
			theForm.program.value = "BU_OTD";
			theForm.Access_code.value = theForm.Access_code.value.replace(/BU-OT-/, 'BU-OTD-');
		}else{
			theForm.program.value = "OT";
			theForm.Access_code.value = theForm.Access_code.value.replace(/BU-OTD-/, 'BU-OT-');
		}
	}
	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);
	}
	if (theForm.NBCOT.value == ""){
    	alert("Please indicate if you are certified by the NBCOT.");
	    theForm.NBCOT.focus();
    	return (false);
	}
/*	if (theForm.NBCOT.value == "No"){
	    alert("Sorry, you must be NBCOT certified to qualify for this program.");
    	theForm.NBCOT.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 enter your Zip Code.");
		theForm.Zip1.focus();
		return (false);
	}else{
		theForm.Zip.value = theForm.Zip1.value + theForm.Zip2.value;
	}
	if(theForm.iwant_ot.checked == true && theForm.iwant_otd.checked == true){
		var secondString = '';
		secondString = '<html>\n<body>\n<form method="POST" action="http://ekgleads.embanet.com/leadsForms/Confirm.aspx">\n';

		for(x=0; x<theForm.length; x++){
			if(theForm[x].name == "program" && theForm[x].value == "OT"){
				secondString=secondString + '<input type="hidden" name="' + theForm[x].name + '" value="BU_OTD">\n';
			}
			else if(theForm[x].name == "program" && theForm[x].value == 'BU_OTD'){
				secondString=secondString + '<input type="hidden" name="' + theForm[x].name + '" value="OT">\n';
			}else{
				secondString=secondString + '<input type="hidden" name="' + theForm[x].name + '" value="' + theForm[x].value + '">\n';
			}
		}

		secondString = secondString + '</form>\n<scr' + 'ipt>\ndocument.forms[0].submit();\n</scr' + 'ipt>\n</body>\n</html>\n';
		window.frames['seconds'].document.open();
		window.frames['seconds'].document.write(secondString);
		window.frames['seconds'].document.close();
	}
//end
}


//############################## CANT UNCHECK THE MAIN PROGRAM ##############################//

//set this to the main program checkbox name so that it always remains checked
var mainProg = "iwant_xx";

function checkCheck(c){
	if(c.name == mainProg){
		c.checked = true;
	}
//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;
}

