/* #####=====| Validation for Main Form |=====##### */
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.Baccalaureate_Accounting[0].checked == false && theForm.Baccalaureate_Accounting[1].checked == false){
    alert("Please indicate if you have a Baccalaureate in Accounting.");
    return (false);
  }
  if (theForm.Baccalaureate_Accounting[1].checked == true){
    alert("We're sorry, but you must have your Baccalaureate in Accounting to qualify for this program.");
    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);
  }
	// UNITED STATES VALIDATION
	if (theForm.Country.value == "United States"){
		if (theForm.us_State.selectedIndex == 0){
			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.selectedIndex == 0){
			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("Your Postal Code appears to be invalid. Please 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.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;
		}
	}

	// 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.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.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.State.value = " ";
	}

//end FrontPageForm1
}


/* #####=====| Validation for Microform |=====##### */
function FrontPage_Form2_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.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("Please enter a valid Email address.");
		theForm.Email.focus();
		return false;
	}
  }
  if (theForm.Primary_Phone1.value == ""){
	alert("Please enter your Area Code.");
	theForm.Primary_Phone1.focus();
	return false;
  }
  if (theForm.Primary_Phone2.value == ""){
	alert("Please enter the first part of your Phone Number.");
	theForm.Primary_Phone2.focus();
	return false;
  }
  if (theForm.Primary_Phone3.value == ""){
	alert("Please enter the second part of your Phone Number.");
	theForm.Primary_Phone3.focus();
	return false;
  }
  if (theForm.State.selectedIndex == 0){
    alert("Please select your State.");
    theForm.State.focus();
    return (false);
  }
	theForm.Primary_Phone.value = theForm.Primary_Phone1.value + theForm.Primary_Phone2.value + theForm.Primary_Phone3.value;
//end FrontPageForm2
}


//############################## NUMBERS ONLY ##############################//

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


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

function showInfo(w,s){
	if(s == "on"){
		document.getElementById('info_'+w).style.visibility = "visible";
	}
	if(s == "off"){
		document.getElementById('info_'+w).style.visibility = "hidden";
	}
//end
}
