var isOpera = navigator.userAgent.indexOf("Opera") > -1;
var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera;
var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera;

var postalList = new Array();

postalList["A"] = "NL";
postalList["B"] = "NS";
postalList["C"] = "PE";
postalList["E"] = "NB";
postalList["G"] = "PQ";
postalList["H"] = "PQ";
postalList["J"] = "PQ";
postalList["K"] = "ON";
postalList["L"] = "ON";
postalList["M"] = "ON";
postalList["N"] = "ON";
postalList["P"] = "ON";
postalList["R"] = "MB";
postalList["S"] = "SK";
postalList["T"] = "AB";
postalList["V"] = "BC";
postalList["X"] = "NT";
postalList["Y"] = "YT";

function inqSubmit(which) { document.aiPrimaryForm.submit(); }
function chkSubmit() { document.chkEmail.submit(); }
function checkreset() { document.aiPrimaryForm.RESET.value = "Yes"; document.aiPrimaryForm.submit(); }
function setCursorEnd(x) {
	if (isIE) {
		var txtRange = x.createTextRange();
		txtRange.moveStart( "character", x.value.length );
		txtRange.moveEnd( "character", 0 );
		txtRange.select();
	} else if (isMoz) {
		x.setSelectionRange(x.value.length, x.value.length);
	}
}

var reControlChars = /[\x00\x08\x09\x0D\x10\x11\x12\x14\x1B\x21\x22\x23\x24\x25\x26\x27\x28\x2E]/;

function trap3Code(objEvent, nextObj) {
	 var iKeyCode, objInput, iSelRngLth;

	 if (isIE) {
		iKeyCode = objEvent.keyCode;
		objInput = objEvent.srcElement;
		var oSel = document.selection.createRange();
		iSelRngLth = oSel.text.length;
	 } else {
		iKeyCode = objEvent.which;
		objInput = objEvent.target;
		iSelRngLth = objInput.selectionEnd - objInput.selectionStart;
	 }

	 var strKey = String.fromCharCode(iKeyCode);

	 if (reControlChars.test(strKey)) { return true; }
	 if (iKeyCode < 48 || iKeyCode > 57) { return false; }
	 if (iSelRngLth) { return true; }
	 if (objInput.value.length > 2) { nextObj.focus(); }
	 return true;
}

function trapKeyDown(objEvent, prevObj) {
	 var iKeyCode, objInput, iSelRngLth;

	 if (isIE) {
		iKeyCode = objEvent.keyCode;
		objInput = objEvent.srcElement;
		var oSel = document.selection.createRange();
		iSelRngLth = oSel.text.length;
	 } else {
		iKeyCode = objEvent.which;
		objInput = objEvent.target;
		iSelRngLth = objInput.selectionEnd - objInput.selectionStart;
	 }

	 if (iKeyCode == 8 && objInput.value.length < 1 && iSelRngLth == 0) { setCursorEnd(prevObj); return false;}
	 return true;
}

function trapOnlyNums(objEvent) {
	 var iKeyCode, objInput;

	 if (isIE) {
		iKeyCode = objEvent.keyCode;
		objInput = objEvent.srcElement;
	 } else {
		iKeyCode = objEvent.which;
		objInput = objEvent.target;
	 }

	 var strKey = String.fromCharCode(iKeyCode);

	 if (reControlChars.test(strKey)) { return true; }
	 if (iKeyCode < 48 || iKeyCode > 57) { return false;}
	 return true;
}

function trapOnlyNumsPlus(objEvent) {
	 var iKeyCode, objInput;

	 if (isIE) {
		 iKeyCode = objEvent.keyCode;
		 objInput = objEvent.srcElement;
	 } else {
		iKeyCode = objEvent.which;
		 objInput = objEvent.target;
	 }

	 var strKey = String.fromCharCode(iKeyCode);

	 if (reControlChars.test(strKey)) { return true; }
	 if ((iKeyCode < 48 || iKeyCode > 57) && iKeyCode != 43 && iKeyCode != 45 && iKeyCode != 32)
		{return false;}
	 return true;
}

function initeventhndlrs () {
// Register form input handlers with anonymous functions to clean up inline Javascript (Only works with non-parameter functions)
	if (isMoz) {
	  if( document.captureEvents ) {
		document.captureEvents(Event.KEYPRESS);
		document.captureEvents(Event.KEYDOWN);
		document.captureEvents(Event.KEYUP);
		document.captureEvents(Event.CHANGE);
	  }
	}

	if (document.aiPrimaryForm) {
	  if (document.aiPrimaryForm.Citizenship) {
		document.aiPrimaryForm.Citizenship.onchange = function () { if (document.aiPrimaryForm.Citizenship.selectedIndex > 1) {showit('visa'); showit('extraquestions');} else {hideit('extraquestions');document.aiPrimaryForm.radio_visa[0].checked=0; document.aiPrimaryForm.radio_visa[1].checked=false; hideit('visa');} }
	  }
	  if (document.aiPrimaryForm.Country) {
		document.aiPrimaryForm.Country.onchange = function () { if (document.aiPrimaryForm.Country.selectedIndex == 2){showStatesCA();} }
	  }
	  if (document.aiPrimaryForm.program_code) {
	   if (document.aiPrimaryForm.school_code_v3.value == 'AIV' ||
	       document.aiPrimaryForm.school_code_v3.value == 'AIVB') { // vancouver only
	       showVancouverCampuses();
	   }
	   
	  }
	  if (document.aiPrimaryForm.Zip) {
		document.aiPrimaryForm.Zip.onchange = function () {if (document.aiPrimaryForm.Country.selectedIndex == 2) {showStatesCA();}}
	  }
	}
}

function checkShortForm() {
   var errorGlobal=doGlobalCheck();
   if (errorGlobal) {
      alert(errorGlobal);
      return false;
   }

// Used for form that does not have second email field for confirmation
	if ( document.aiPrimaryForm.UserEmail1st ) {
		document.aiPrimaryForm.UserEmail2nd.value = document.aiPrimaryForm.UserEmail1st.value;
	}
	
	if ( document.aiPrimaryForm.program_code ) {
		if ( document.aiPrimaryForm.program_code.selectedIndex ) {
			document.aiPrimaryForm.program_name.value = document.aiPrimaryForm.program_code[document.aiPrimaryForm.program_code.selectedIndex].text;
		} else {
			document.aiPrimaryForm.program_name.value = document.aiPrimaryForm.program_code.value;
		}
	}
	return checkForm();
}

function checkForm() {
// Check all input fields for required fields and valid data values and ranges
 var strProgramCode = "You must choose a program that interests you.\nYou may have many program interests but just select one in the top section and if you like, add the rest in the comment box.";
 var strFirstName = "Your First Name is required... 	\nPlease enter your first name.";
 var strLastName = "Your Last Name (or Surname) is required...  \nPlease enter your last name.";
 var strName = "Your combined name cannot exceed 32 characters. \nThis is a limitation of the database. Just use your an initial for your first name if necessary. \nPlease re-enter your name.";
 var strStreet = "Your Street Address is required...  \nPlease enter your street address.";
 var strStreetLength = "A Valid Street Address is required...  \nPlease enter your street address.";
 var strEmailAddress = "Please enter your email, must be xxx@yyy.com format";
 var strCity = "Your City is required...  \nPlease enter your city.";
 var strState = "Your State is required...  \nPlease enter your state.\n(Use 'Other' if not in US or Canada). ";
 var strCountry = "Your Country is required...  \nPlease enter your country.";
 var strCitizenVisa = "If you are not a citizen of the US, \nwe would like to know if you need a student Visa. \nPlease select yes or no.";
 var strHomephone_area_code = "An area code is required with your home phone number if you reside in the United States or Canada.";
 var strHomePhone = "A home phone number (including area code) is required if you reside in the United States or Canada.";
 var strInterPhone = "An international phone number is required if you reside in a country other than the United States or Canada.";
 var strZip = "The Zip/Postal code is required... 	 \nPlease enter your zip or postal code, or \"99999\" if not applicable.";
 var strEmail1st = "Your E-mails don't match! 	\nPlease re-enter them.";
 var strTooMany = "The Comments field has a 424 character limit. Your comments have been truncated. Please review your comments and make any necessary corrections.";
 var strHSGraduation = "Please enter the year you graduated (or expect to graduate) High School (or GED).";
 var strAssociate = "If you are interested in the Culinary Management\n program, we would like to know if you have already\n earned an associate's degree in culinary arts.  \nPlease check the appropriate box.";
 var strCAZip = "A valid Zip/Postal code is required... 	 \nPlease enter your zip or postal code for Canada.";

if ( document.aiPrimaryForm.program_code.value == "no" ) { alert(strProgramCode); document.aiPrimaryForm.program_code.focus(); return false; }
if ( document.aiPrimaryForm.Firstname.value == "" ) { alert(strFirstName); document.aiPrimaryForm.Firstname.focus(); return false; }
if ( document.aiPrimaryForm.Lastname.value == "" ) { alert(strLastName); document.aiPrimaryForm.Lastname.focus(); return false; }
if ( document.aiPrimaryForm.Firstname.value.length + document.aiPrimaryForm.Lastname.value.length > 32 ) { alert(strName); document.aiPrimaryForm.Firstname.focus(); return false; }

 if (document.aiPrimaryForm.UserEmail1st.value != "")
	{ regExpr = new RegExp("^\\w+[a-zA-Z0-9\\.\\&\\+\\-\\%]*[a-zA-Z0-9]+\\&*\\+*\\@{1}[a-zA-Z0-9\\-\\_]+[\\.]+[a-zA-Z0-9\\.\\-\\_]*[a-zA-Z0-9]+$");
		returnTest = regExpr.test(document.aiPrimaryForm.UserEmail1st.value);
		if (!(returnTest)){ alert("Your email address is not valid. Please use your full email address."); document.aiPrimaryForm.UserEmail1st.focus(); return false; }
		if ( document.aiPrimaryForm.UserEmail1st.value != document.aiPrimaryForm.UserEmail2nd.value) { alert(strEmail1st); document.aiPrimaryForm.UserEmail2nd.focus(); return false; }
	}
	else
	{
		alert(strEmailAddress); document.aiPrimaryForm.UserEmail1st.focus(); return false;
	}

if ( document.aiPrimaryForm.Street.value == "" ) { alert(strStreet); document.aiPrimaryForm.Street.focus(); return false; }
if ( document.aiPrimaryForm.Street.value.length < 5 ) { alert(strStreetLength); document.aiPrimaryForm.Street.focus(); return false; }
if ( document.aiPrimaryForm.City.value == "" ) { alert(strCity); document.aiPrimaryForm.City.focus(); return false; }
if ( document.aiPrimaryForm.Zip.value == "" ) { alert(strZip); document.aiPrimaryForm.Zip.focus(); return false; }
else if (document.aiPrimaryForm.Country.selectedIndex == 2 && postalList[document.aiPrimaryForm.Zip.value.charAt(0).toUpperCase()] == undefined){alert(strCAZip);document.aiPrimaryForm.Zip.focus(); return false; }
if ( document.aiPrimaryForm.Country.value == "" ) { alert(strCountry); document.aiPrimaryForm.Country.focus(); return false; }
if ( document.aiPrimaryForm.Country.selectedIndex == "1" )
	{ if ( document.aiPrimaryForm.Homephone_area_code.value == "" ) { alert(strHomephone_area_code); document.aiPrimaryForm.Homephone_area_code.focus(); return false; }
		if (document.aiPrimaryForm.Homephone_area_code.value.length < 3) { alert("Home phone area code must be three digits. \nPlease re-enter."); document.aiPrimaryForm.Homephone_area_code.focus(); return false; }
	}

if ( document.aiPrimaryForm.Country.selectedIndex == "1" ||  document.aiPrimaryForm.Country.selectedIndex == 2)
	{
		if ( document.aiPrimaryForm.Homephone_prefix.value == "" ) { alert(strHomePhone); document.aiPrimaryForm.Homephone_prefix.focus(); return false; }
		if (document.aiPrimaryForm.Homephone_prefix.value.length < 3) { alert("Home phone must be seven digits. \nPlease re-enter."); document.aiPrimaryForm.Homephone_prefix.focus(); return false; }
		if ( document.aiPrimaryForm.Homephone_suffix.value == "" ) { alert(strHomePhone); document.aiPrimaryForm.Homephone_suffix.focus(); return false; }
		if (document.aiPrimaryForm.Homephone_suffix.value.length < 4) { alert("Home phone must be seven digits. \nPlease re-enter."); document.aiPrimaryForm.Homephone_suffix.focus(); return false; }
		if ( document.aiPrimaryForm.state.selectedIndex == "0" ) { alert(strState); document.aiPrimaryForm.state.focus(); return false; }
	}

else
	{
		if ( document.getElementById("International_phone") ) {
			if ( document.aiPrimaryForm.International_phone.value == "" ) {
				alert(strInterPhone); document.aiPrimaryForm.International_phone.focus(); return false;
			}
		}
	}

if ( document.getElementById("International_phone") ) {

	var strNumbs = "0123456789";
	var goodinterphone = true;
	for (i=0; i<document.aiPrimaryForm.International_phone.value.length; i++)
		{ strChar = document.aiPrimaryForm.International_phone.value.charAt(i)
			if (strNumbs.indexOf(strChar) == -1)  { goodinterphone = false; }
		}

	if (!goodinterphone) {
		alert("Please use only digits for your International phone.");
		document.aiPrimaryForm.International_phone.focus();
		flag = false;
		return false;
	}
}

var strNumbs = "0123456789";
var goodhomephone = true;
for (i=0; i<document.aiPrimaryForm.Homephone_prefix.value.length; i++)
	{ strChar = document.aiPrimaryForm.Homephone_prefix.value.charAt(i);
		if (strNumbs.indexOf(strChar) == -1) { goodhomephone = false; }
	}
for (i=0; i<document.aiPrimaryForm.Homephone_suffix.value.length; i++)
	{ strChar = document.aiPrimaryForm.Homephone_suffix.value.charAt(i);
		if (strNumbs.indexOf(strChar) == -1) { goodhomephone = false; }
	}

if (!goodhomephone)
	{ alert("Home phone may be digits only. \nPlease re-enter.");    document.aiPrimaryForm.Homephone_prefix.focus(); flag = false; return false; }

regexstring = /([0-1][0-9][0-9]|[0-9]11|[2-9]22|[2-9]33|[2-9]44|[2-9]55|[2-9]66|[2-9]77|[2-9]88|[2-9]99|[2-9]00|37[0-9]|96[0-9])/;
if ( document.aiPrimaryForm.Homephone_area_code.value.match(regexstring) ) 	{ alert("This Home Phone area code is not valid for residential or commercial use in the US.  \nPlease re-enter this area code.");    document.aiPrimaryForm.Homephone_prefix.focus(); flag = false; return false; }

regexstring = /^(555|0[0-9][0-9])/;
if ( document.aiPrimaryForm.Homephone_prefix.value.match(regexstring) ) 	{ alert ("The exchange (2nd three numbers) of the Home Phone number is not valid for residential or commercial use in the US.  \nPlease re-enter your phone number.");
document.aiPrimaryForm.Homephone_prefix.focus(); flag = false; return false; }



if (document.aiPrimaryForm.Workphone_area_code.value || document.aiPrimaryForm.Workphone_prefix.value || document.aiPrimaryForm.Workphone_suffix.value)
{

	if (document.aiPrimaryForm.Workphone_area_code.value.length < 3) { alert("Other phone area code must be three digits. \nPlease re-enter or leave Other phone blank (optional).");
	document.aiPrimaryForm.Workphone_area_code.focus(); return false; }

	if (document.aiPrimaryForm.Workphone_prefix.value.length < 3) { alert("Other phone must be seven digits. \nPlease re-enter or leave Other phone blank (optional)."); document.aiPrimaryForm.Workphone_prefix.focus(); return false; }
	if (document.aiPrimaryForm.Workphone_suffix.value.length < 4) { alert("Other phone must be seven digits. \nPlease re-enter or leave Other phone blank (optional)."); document.aiPrimaryForm.Workphone_suffix.focus(); return false; }


	regexstring = /([0-1][0-9][0-9]|[0-9]11|[2-9]22|[2-9]33|[2-9]44|[2-9]55|[2-9]66|[2-9]77|[2-9]88|[2-9]99|[2-9]00|37[0-9]|96[0-9])/;
	if ( document.aiPrimaryForm.Workphone_area_code.value.match(regexstring) ) 	{ alert("This Other Phone area code is not valid for residential or commercial use in the US.  \nPlease re-enter this area code or leave Other phone blank (optional).");    document.aiPrimaryForm.Workphone_prefix.focus(); flag = false; return false; }

	regexstring = /^(555|0[0-9][0-9])/;
	if ( document.aiPrimaryForm.Workphone_prefix.value.match(regexstring) ) 	{ alert ("The exchange (2nd three numbers) of the Other Phone number is not valid for residential or commercial use in the US.  \nPlease re-enter your other phone number or leave Other phone blank (optional).");
	document.aiPrimaryForm.Workphone_prefix.focus(); flag = false; return false; }
}

if (document.getElementById("Comments") ) {
	maxLen = 424; // max number of characters allowed

	if (document.aiPrimaryForm.Comments.value.length > maxLen) { // if too long.... trim it!
		document.aiPrimaryForm.Comments.value = document.aiPrimaryForm.Comments.value.substring(0, maxLen);
		alert(strTooMany); document.aiPrimaryForm.Comments.focus();
		return false;
	}
}



if ( document.aiPrimaryForm.UserEmail1st.value != document.aiPrimaryForm.UserEmail2nd.value) { alert(strEmail1st); document.aiPrimaryForm.UserEmail2nd.focus(); return false; }
if ( document.aiPrimaryForm.graduation.selectedIndex < 1 ) { alert(strHSGraduation); document.aiPrimaryForm.graduation.focus(); return false; }

if ( document.aiPrimaryForm.Citizenship.selectedIndex > 1 ) {
	if ( !document.aiPrimaryForm.radio_visa[0].checked && !document.aiPrimaryForm.radio_visa[1].checked ) {
		alert(strCitizenVisa); document.aiPrimaryForm.radio_visa[0].focus(); return false;
	}
}

//document.aiPrimaryForm.submit();
return true;
}

var beenalertedonce=false;

function _inquireclick(prog) {
	var i = 0;
	var numofoptions = document.aiPrimaryForm.program_code.length;
	var inspectingselect = document.aiPrimaryForm.program_code;
	while ((i <= numofoptions) && (inspectingselect[i].id != prog)) {
		i++;
	}
	if (i < numofoptions) {
		inspectingselect[i].selected = true;
		inspectingselect.focus();
	}
	document.aiPrimaryForm.Firstname.select();
	document.aiPrimaryForm.Firstname.focus();
	if (!beenalertedonce)
	 {alert ( "Fill out the form to the right to request information \non your field of interest at this school!" );
		beenalertedonce=true;
	 }
	if (isIE) { event.returnValue = true;}
}

function _inquireclick_no_alert(prog) {
        var i = 0;
        var numofoptions = document.aiPrimaryForm.program_code.length;
        var inspectingselect = document.aiPrimaryForm.program_code;
        while ((i <= numofoptions) && (inspectingselect[i].id != prog)) {
                i++;
        }
        if (i < numofoptions) {
                inspectingselect[i].selected = true;
                inspectingselect.focus();
        }
        document.aiPrimaryForm.Firstname.select();
        document.aiPrimaryForm.Firstname.focus();
        beenalertedonce=true;
        if (isIE) { event.returnValue = true;}
}

var clflag=false;
function prevent_dblclick() {
	if (clflag)  return false;
	else clflag=true;  document.aiPrimaryForm.submit.disabled = true;  return true;
 }
function showit(it) {
 if (document.getElementById) {document.getElementById(it).style.visibility='visible'; }
 else if (document.all) {document.all(it).style.visibility='visible';}
}
function hideit(it) {
 if (document.getElementById) {document.getElementById(it).style.visibility='hidden'; }
 else if (document.all) {document.all(it).style.visibility='hidden';}
}

 function showStatesUS()
 {
 //		hideit('requireintl');
//		document.aiPrimaryForm.State.disabled = false;
		document.aiPrimaryForm.State.options.length=0;
		document.aiPrimaryForm.State.options[0]=new Option("", "", false, false);
		document.aiPrimaryForm.State.options[1]=new Option("AL", "AL", false, false);
		document.aiPrimaryForm.State.options[2]=new Option("AK", "AK", false, false);
		document.aiPrimaryForm.State.options[3]=new Option("AS", "AS", false, false);
		document.aiPrimaryForm.State.options[4]=new Option("AZ", "AZ", false, false);
		document.aiPrimaryForm.State.options[5]=new Option("AR", "AR", false, false);
		document.aiPrimaryForm.State.options[6]=new Option("CA", "CA", false, false);
		document.aiPrimaryForm.State.options[7]=new Option("CO", "CO", false, false);
		document.aiPrimaryForm.State.options[8]=new Option("CT", "CT", false, false);
		document.aiPrimaryForm.State.options[9]=new Option("DE", "DE", false, false);
		document.aiPrimaryForm.State.options[10]=new Option("DC", "DC", false, false);
		document.aiPrimaryForm.State.options[11]=new Option("FM", "FM", false, false);
		document.aiPrimaryForm.State.options[12]=new Option("FL", "FL", false, false);
		document.aiPrimaryForm.State.options[13]=new Option("GA", "GA", false, false);
		document.aiPrimaryForm.State.options[14]=new Option("GU", "GU", false, false);
		document.aiPrimaryForm.State.options[15]=new Option("HI", "HI", false, false);
		document.aiPrimaryForm.State.options[16]=new Option("ID", "ID", false, false);
		document.aiPrimaryForm.State.options[17]=new Option("IL", "IL", false, false);
		document.aiPrimaryForm.State.options[18]=new Option("IN", "IN", false, false);
		document.aiPrimaryForm.State.options[19]=new Option("IA", "IA", false, false);
		document.aiPrimaryForm.State.options[20]=new Option("KS", "KS", false, false);
		document.aiPrimaryForm.State.options[21]=new Option("KY", "KY", false, false);
		document.aiPrimaryForm.State.options[22]=new Option("LA", "LA", false, false);
		document.aiPrimaryForm.State.options[23]=new Option("ME", "ME", false, false);
		document.aiPrimaryForm.State.options[24]=new Option("MB", "MB", false, false);
		document.aiPrimaryForm.State.options[25]=new Option("MH", "MH", false, false);
		document.aiPrimaryForm.State.options[26]=new Option("MD", "MD", false, false);
		document.aiPrimaryForm.State.options[27]=new Option("MA", "MA", false, false);
		document.aiPrimaryForm.State.options[28]=new Option("MI", "MI", false, false);
		document.aiPrimaryForm.State.options[29]=new Option("MN", "MN", false, false);
		document.aiPrimaryForm.State.options[30]=new Option("MS", "MS", false, false);
		document.aiPrimaryForm.State.options[31]=new Option("MO", "MO", false, false);
		document.aiPrimaryForm.State.options[32]=new Option("MT", "MT", false, false);
		document.aiPrimaryForm.State.options[33]=new Option("NE", "NE", false, false);
		document.aiPrimaryForm.State.options[34]=new Option("NV", "NV", false, false);
		document.aiPrimaryForm.State.options[35]=new Option("NH", "NH", false, false);
		document.aiPrimaryForm.State.options[36]=new Option("NJ", "NJ", false, false);
		document.aiPrimaryForm.State.options[37]=new Option("NM", "NM", false, false);
		document.aiPrimaryForm.State.options[38]=new Option("NY", "NY", false, false);
		document.aiPrimaryForm.State.options[39]=new Option("NC", "NC", false, false);
		document.aiPrimaryForm.State.options[40]=new Option("ND", "ND", false, false);
		document.aiPrimaryForm.State.options[41]=new Option("CM", "CM", false, false);
		document.aiPrimaryForm.State.options[42]=new Option("OH", "OH", false, false);
		document.aiPrimaryForm.State.options[43]=new Option("OK", "OK", false, false);
		document.aiPrimaryForm.State.options[44]=new Option("OR", "OR", false, false);
		document.aiPrimaryForm.State.options[45]=new Option("PW", "PW", false, false);
		document.aiPrimaryForm.State.options[46]=new Option("PA", "PA", false, false);
		document.aiPrimaryForm.State.options[47]=new Option("PR", "PR", false, false);
		document.aiPrimaryForm.State.options[48]=new Option("RI", "RI", false, false);
		document.aiPrimaryForm.State.options[49]=new Option("SC", "SC", false, false);
		document.aiPrimaryForm.State.options[50]=new Option("SD", "SD", false, false);
		document.aiPrimaryForm.State.options[51]=new Option("TN", "TN", false, false);
		document.aiPrimaryForm.State.options[52]=new Option("TX", "TX", false, false);
		document.aiPrimaryForm.State.options[53]=new Option("UT", "UT", false, false);
		document.aiPrimaryForm.State.options[54]=new Option("VT", "VT", false, false);
		document.aiPrimaryForm.State.options[55]=new Option("VI", "VI", false, false);
		document.aiPrimaryForm.State.options[56]=new Option("VA", "VA", false, false);
		document.aiPrimaryForm.State.options[57]=new Option("WA", "WA", false, false);
		document.aiPrimaryForm.State.options[58]=new Option("WV", "WV", false, false);
		document.aiPrimaryForm.State.options[59]=new Option("WI", "WI", false, false);
		document.aiPrimaryForm.State.options[60]=new Option("WY", "WY", false, false);
 }

 function showStatesCA()
 {
 //		hideit('requireintl');
//		document.aiPrimaryForm.State.disabled = false;
		document.aiPrimaryForm.State.options.length=0;
		var province = document.aiPrimaryForm.Zip.value.charAt(0).toUpperCase();
		var postalList = new Array();

		postalList["A"] = "NL";
		postalList["B"] = "NS";
		postalList["C"] = "PE";
		postalList["E"] = "NB";
		postalList["G"] = "PQ";
		postalList["H"] = "PQ";
		postalList["J"] = "PQ";
		postalList["K"] = "ON";
		postalList["L"] = "ON";
		postalList["M"] = "ON";
		postalList["N"] = "ON";
		postalList["P"] = "ON";
		postalList["R"] = "MB";
		postalList["S"] = "SK";
		postalList["T"] = "AB";
		postalList["V"] = "BC";
		postalList["X"] = "NT";
		postalList["Y"] = "YT";
		postalList["all"] = ["AB", "BC", "MB", "NB", "NL", "NT", "NS", "NU", "ON", "PE", "PQ", "SK", "YT"];

		var code = postalList[province];
		if (province == "")
		{
			document.aiPrimaryForm.State.options[0]=new Option("", "", false, false);
			document.aiPrimaryForm.State.options[1]=new Option("AB", "AB", false, false);
			document.aiPrimaryForm.State.options[2]=new Option("BC", "BC", false, false);
			document.aiPrimaryForm.State.options[3]=new Option("MB", "MB", false, false);
			document.aiPrimaryForm.State.options[4]=new Option("NB", "NB", false, false);
			document.aiPrimaryForm.State.options[5]=new Option("NL", "NL", false, false);
			document.aiPrimaryForm.State.options[6]=new Option("NT", "NT", false, false);
			document.aiPrimaryForm.State.options[7]=new Option("NS", "NS", false, false);
			document.aiPrimaryForm.State.options[8]=new Option("NU", "NU", false, false);
			document.aiPrimaryForm.State.options[9]=new Option("ON", "ON", false, false);
			document.aiPrimaryForm.State.options[10]=new Option("PE", "PE", false, false);
			document.aiPrimaryForm.State.options[11]=new Option("PQ", "PQ", false, false);
			document.aiPrimaryForm.State.options[12]=new Option("SK", "SK", false, false);
			document.aiPrimaryForm.State.options[13]=new Option("YT", "YT", false, false);
		}
		else if (code==undefined || code=="")
		{
			var strCAZip = "A valid Zip/Postal code is required... 	 \nPlease enter your zip or postal code for Canda.";
			alert(strCAZip);
			document.aiPrimaryForm.Zip.focus();
			document.aiPrimaryForm.State.options[0]=new Option("", "", false, false);
			document.aiPrimaryForm.State.options[1]=new Option("AB", "AB", false, false);
			document.aiPrimaryForm.State.options[2]=new Option("BC", "BC", false, false);
			document.aiPrimaryForm.State.options[3]=new Option("MB", "MB", false, false);
			document.aiPrimaryForm.State.options[4]=new Option("NB", "NB", false, false);
			document.aiPrimaryForm.State.options[5]=new Option("NL", "NL", false, false);
			document.aiPrimaryForm.State.options[6]=new Option("NT", "NT", false, false);
			document.aiPrimaryForm.State.options[7]=new Option("NS", "NS", false, false);
			document.aiPrimaryForm.State.options[8]=new Option("NU", "NU", false, false);
			document.aiPrimaryForm.State.options[9]=new Option("ON", "ON", false, false);
			document.aiPrimaryForm.State.options[10]=new Option("PE", "PE", false, false);
			document.aiPrimaryForm.State.options[11]=new Option("PQ", "PQ", false, false);
			document.aiPrimaryForm.State.options[12]=new Option("SK", "SK", false, false);
			document.aiPrimaryForm.State.options[13]=new Option("YT", "YT", false, false);
		}
		else
		{
			document.aiPrimaryForm.State.options[0]=new Option("", "", false, false);
			for (var i = 0; i < postalList["all"].length; i++)
			{
				if (code == postalList["all"][i])
				{
					document.aiPrimaryForm.State.options[i+1] = new Option(postalList["all"][i], postalList["all"][i], true, true);
				}
				else
				{
					document.aiPrimaryForm.State.options[i+1] = new Option(postalList["all"][i], postalList["all"][i], false, false);
				}
			}
		}


 }

function doGlobalCheck() {
    var first, last, address1, address2, city, zip;
    var homephone, workphone, email, yearindex;

    if(document.aiPrimaryForm.Firstname) {
        first=document.aiPrimaryForm.Firstname.value;
    } else {
        first=null;
    }
    if(document.aiPrimaryForm.Lastname) {
        last=document.aiPrimaryForm.Lastname.value;
    } else {
        last=null;
    }
    if(document.aiPrimaryForm.Street) {
        address1=document.aiPrimaryForm.Street.value;
    } else {
        address1=null;
    }
    if(document.aiPrimaryForm.Street2 && document.aiPrimaryForm.Street2.value) {
        address2=document.aiPrimaryForm.Street2.value;
    } else {
        address2=null;
    }
    if(document.aiPrimaryForm.City) {
        city=document.aiPrimaryForm.City.value;
    } else {
        city=null;
    }
    if(document.aiPrimaryForm.Zip) {
        zip=document.aiPrimaryForm.Zip.value;
    } else {
        zip=null;
    }
    if(document.aiPrimaryForm.Homephone_area_code) {
        homephone=document.aiPrimaryForm.Homephone_area_code.value+document.aiPrimaryForm.Homephone_prefix.value+document.aiPrimaryForm.Homephone_suffix.value;
    } else {
        homephone=null;
    }
    if(document.aiPrimaryForm.Workphone_area_code) {
        workphone=document.aiPrimaryForm.Workphone_area_code.value+document.aiPrimaryForm.Workphone_prefix.value+document.aiPrimaryForm.Workphone_suffix.value;
    } else {
        workphone=null;
    }

    if(document.aiPrimaryForm.UserEmail1st) {
        email=document.aiPrimaryForm.UserEmail1st.value;
    } else {
        email=null;
    }
    if(document.aiPrimaryForm.State) {
        stateindex=document.aiPrimaryForm.State.selectedIndex;
    } else {
        stateindex=null;
    }
    if(document.aiPrimaryForm.graduation) {
        yearindex=document.aiPrimaryForm.graduation.selectedIndex;
    } else {
        yearindex=null;
    }
    if(document.aiPrimaryForm.program_code) {
        progindex=document.aiPrimaryForm.program_code.selectedIndex;
    } else {
        progindex=null;
    }

    var testtwochar = new RegExp(/[A-Z][A-Z]/i);
    var testtwoalpha = new RegExp(/\w\w/);
    var testphone = new RegExp(/\d{3}[\ \-]*\d{3}[\ \-]*\d{4}$/);
    var testmail = new RegExp(/^(\S+\.?)+\S+\@([\w\-]{2,}\.)+[\w\-]{2,3}$/i);
    var testzip = new RegExp(/^(\d\d\d\d\d)|(\w\w\w\s*\w\w\w)$/);
    var testsamethree = new RegExp(/^(.)\1\1/);
    var testsamefour = new RegExp(/^(.)\1\1\1/);
    var testsequence = new RegExp(/123456789/);

    var fullphone;
    var err = "";
    var cons = "";
    if(!testtwochar.test(first)) {
        err = err + "Firstname: At least 2 alpha characters, no numbers\n";
    }
    if(!testtwochar.test(last)) {
        err = err + "Lastname: At least 2 alpha characters, no numbers\n";
    }
    if(!testmail.test(email)) {
        err = err + "E-mail: Provide your contact email you would like additional information sent.\n";
    }
    if(!testphone.test(homephone)) {
        err = err + "Phone: Provide your home phone number.\n";
    }
    if(testsequence.test(homephone)) {
        err = err + "Phone: Home phone number shouldn't contain sequence\n"
    }

    if(address1 && !testtwoalpha.test(address1)) {
        err = err + "Address 1: At least 2 characters\n";
    }
    if(address2 && !testtwoalpha.test(address2)) {
        err = err + "Address 2: At least 2 characters\n";
    }
    if(!testtwochar.test(city)) {
        err = err + "City: At least 2 alpha characters, no numbers\n";
    }
    if(zip != null && !testzip.test(zip)) {
        err = err + "ZIP: Provide your 5 digit (or 6 digit if CA) zip code\n";
    }
    if(err) {
        err = "Please correct the following information:\n\n"+err;
    }
    return err;
}


 function showStatesOther()
 {
		document.aiPrimaryForm.State.options.length=0;
		document.aiPrimaryForm.State.options[0]=new Option("--", "--", true, true);

 }
 
 
// Reloads the window if Netscape Nav4 is resized
function MM_reloadPage(init) {
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

