var submitted = false;

//############################## FORM VALIDATOR ##############################//

function FrontPage_Form1_Validator(theForm){
	var postalcode = theForm.Postal_Code1.value;
	var postalcode2 = theForm.Postal_Code2.value;

	if (theForm.Access_Code.selectedIndex == 0){
		alert("Please select your Program");
		theForm.Access_Code.focus();
		return (false);
	}

	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.value == "High School" || theForm.Highest_Degree_Earned.value == "Associates"){
		alert("Sorry, you must have at least a Bachelor\'s degree to qualify for this program.");
		theForm.Highest_Degree_Earned.focus();
		return false;
	}

	if (theForm.Country.value == "none"){
		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.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 (postalcode.search(/^[a-zA-Z]\d[a-zA-Z]$/) == -1 || postalcode2.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 Primay 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 Primay Phone Number.");
			theForm.us_Primary_Phone_1.focus();
			return (false);
		}
	}
	else{
		if (theForm.Int_Primary_Phone.value == ""){
			alert("Please enter your Primay 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("The Email address you entered is invalid.\nPlease 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.Secondary_Phone.value = theForm.Can_Secondary_Phone_1.value + theForm.Can_Secondary_Phone_2.value + theForm.Can_Secondary_Phone_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.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.State.value = " ";
	}

submitted = 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;
}


//############################## FLASH DETECTOR ##############################//

var detectableWithVB = false;
var pluginFound = false;

function goURL(daURL){
    window.location = daURL;
}
function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    if(redirectURL && ((pluginFound && redirectIfFound) || (!pluginFound && !redirectIfFound))){
		goURL(redirectURL);
		return pluginFound;
    }else{
		return pluginFound;
    }	
}
function canDetectPlugins(){
    if(detectableWithVB || (navigator.plugins && navigator.plugins.length > 0)){
		return true;
    }else{
		return false;
    }
}
function detectFlash(redirectURL, redirectIfFound){
    pluginFound = detectPlugin('Shockwave','Flash'); 
    if(!pluginFound && detectableWithVB){
		pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}
function detectPlugin() {
    var daPlugins = detectPlugin.arguments;
    var pluginFound = false;
    if (navigator.plugins && navigator.plugins.length > 0){
		var pluginsArrayLength = navigator.plugins.length;
			for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ){
	    		var numFound = 0;
	    		for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++){
					if((navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0)){
						numFound++;
					}   
	    		}
	    		if(numFound == daPlugins.length){
					pluginFound = true;
					break;
	    		}
			}
    }
    return pluginFound;
}

// VBSCRIPT FOR IE/WINDOWS

if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)){
    document.writeln('<script language="VBscript">');
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');
    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('</scr' + 'ipt>');
}


//############################## IE FOR MAC DETECTOR (DISABLES MENU) ##############################//
var isMac = false;
if(navigator.userAgent.indexOf('Mac') != -1){
	isMac = true;
}
		
	
//############################## COPYRIGHT DATE ##############################//

var newDate = new Date();
var daYear = newDate.getFullYear();
var daDate = ""+daYear+"";


//############################## IMAGE ROLLOVER ##############################//

function HoverImage(img){
	var oldSrc = new String(img.src);
	var newSrc = oldSrc.substring(0, oldSrc.length - 6);
	newSrc += "_1.gif";
	img.src = newSrc;
}
	
function unHoverImage(img){
	var oldSrc = new String(img.src);
	var newSrc = oldSrc.substring(0, oldSrc.length - 6);
	newSrc += "_0.gif";
	img.src = newSrc;
}

//############################## QUICK LINKS MENU ##############################//
function goQUICKLINKS(BU){
	if(BU.value.indexOf('') > -1){
		location = BU.value;
	}else{
		window.open(BU.value,'BU','width=750,height=550,status=yes,toolbar=yes,loctionbar=yes,resizable=yes');
	}
}

function writeQUICKLINKS(){
	document.write('<span class="fine_text"><b>Quick Links:</b></span>&nbsp;&nbsp;');
	document.write('<select name="QUICKLINKS" onChange="goQUICKLINKS(this);" size="1" class="field_text">');
	document.write('<option value="" selected>Select page to view:</option>');
	document.write('<option value="">&nbsp;</option>');
	document.write('<option value="/">Homepage</option>');
	document.write('<option value="/about/">About Vanderbilt</option>');
	document.write('<option value="/about/vanderbilt.asp">&nbsp;&nbsp;&raquo; About Vanderbilt University</option>');
	document.write('<option value="/about/deans_message.asp">&nbsp;&nbsp;&raquo; Message from the Dean</option>');
	document.write('<option value="/about/vision_purpose.asp">&nbsp;&nbsp;&raquo; Vision &amp; Purpose</option>');
	document.write('<option value="/about/faculty.asp">&nbsp;&nbsp;&raquo; Faculty</option>');
	document.write('<option value="/programs/">Online Programs</option>');
	document.write('<option value="/programs/hsm/">&nbsp;&nbsp;&raquo; Health Systems Management (HSM)</option>');
	document.write('<option value="/programs/hsm/program_overview.asp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo; Program Overview</option>');
	document.write('<option value="/programs/hsm/course_curriculum.asp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo; Course Curriculum</option>');
	document.write('<option value="/programs/hsm/course_descriptions.asp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo; Course Descriptions</option>');
	document.write('<option value="/programs/crm/">&nbsp;&nbsp;&raquo; Clinical Research Management (CRM)</option>');
	document.write('<option value="/programs/crm/program_overview.asp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo; Program Overview</option>');
	document.write('<option value="/programs/crm/course_curriculum.asp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo; Course Curriculum</option>');
	document.write('<option value="/programs/crm/course_descriptions.asp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo; Course Descriptions</option>');
	document.write('<option value="/elearning/">E-Learning</option>');
	document.write('<option value="/elearning/how_it_works.asp">&nbsp;&nbsp;&raquo; How It Works</option>');
	document.write('<option value="/elearning/support_network.asp">&nbsp;&nbsp;&raquo; Support Network</option>');
	document.write('<option value="/elearning/technical_requirements.asp">&nbsp;&nbsp;&raquo; Technical Requirements</option>');
	document.write('<option value="/admissions/">Admissions</option>');
	document.write('<option value="/admissions/requirements.asp">&nbsp;&nbsp;&raquo; Requirements</option>');
	document.write('<option value="/admissions/tuition_fees.asp">&nbsp;&nbsp;&raquo; Tuition Information</option>');
	document.write('<option value="/admissions/financial_aid.asp">&nbsp;&nbsp;&raquo; Financial Aid</option>');
	document.write('<option value="/faq.asp">Frequently Asked Questions</option>');
	document.write('<option value="/contact.asp">Contact Us</option>');
	document.write('<option value="/request_info/">Download Brochure</option>');
	document.write('</select>');
	document.write('<br>');
	document.write('<br>');
}

