// JavaScript Document

//############################## IMAGE ROLLOVER ##############################//

var blah;

function rollOver(name,state,sch){
		if(sch){
			blah=name+"_"+sch;
		}else{
			blah=name;
		}
    document.images[blah].src="/healtheducation/webtemplate_images/" + name + "_" + state + ".gif";
//end
}


//############################## SEARCH CHECKS ##############################//

var refCodeIn = "";

function searchCheck(theForm){
	if(location.href.indexOf(".cgi") > -1){
		refCodeIn = document.forms[0].refCode.value;
	}
	else if(location.href.indexOf("#") > -1){
		refCodeIn = location.href.substring(location.href.indexOf("?")+1,location.href.indexOf("#"));
	}else{
		refCodeIn = location.href.substr(location.href.indexOf("?")+1);
	}
	theForm.refCode.value = refCodeIn

	if(theForm.searchType.value == "quicksearch"){
		if(theForm.Keywords.value == ""){
			alert("You have not entered a search term.");
			theForm.Keywords.focus();
			return false;
		}
		if(theForm.Keywords.value.length < 2){
			alert("We're sorry, but you cannot search for one letter/number.  Please try again.");
			theForm.Keywords.focus();
			return false;
		}
	}
	if(theForm.searchType.value == "schoolsearch" || theForm.searchType.value == "3steps"){
		if(theForm.Degree.selectedIndex == 0){
			alert("Please select the Degree you're interested in.");
			theForm.Degree.focus();
			return false;
		}
		if(theForm.Program.selectedIndex == 0){
			alert("Please select the Program you're interested in.");
			theForm.Program.focus();
			return false;
		}
	}
	if(theForm.searchType.value == "browseindex"){
		if(theForm.Browseby[0].checked == false && theForm.Browseby[1].checked == false && theForm.Browseby[2].checked == false){
			alert("Please select how you would like to browse.");
			return false;
		}
	}
//end searchCheck
}

//############################## SEARCH BOX EXPAND/CONTRACT ##############################//

var expBrowse;
var step = 10; //the amount it opens per interval
var delay = 1; //the delay between intervals


function oC(nm){
	if(parseInt(document.getElementById('search_' + nm).style.height) > 35){
		expBrowse = setInterval("expandBox('"+nm+"',32,'c')",delay);
		//document.getElementById('search_' + nm).style.height = 32 + "px";
	}else{
		if(nm == "browse_index"){
			expBrowse = setInterval("expandBox('"+nm+"',150,'o')",delay);
			//document.getElementById('search_' + nm).style.height = 150 + "px";
		}
		if(nm == "find_school"){
			expBrowse = setInterval("expandBox('"+nm+"',170,'o')",delay);
			//document.getElementById('search_' + nm).style.height = 170 + "px";
		}
	}
//end
}

function expandBox(nm,h,oc){
	if(oc == "o"){
   		document.images[nm].src="http://www.exploreeducation.com/images/" + nm + "_header_1.gif";
		if(parseInt(document.getElementById('search_' + nm).style.height) >= h){
			clearInterval(expBrowse);
		}else{
			document.getElementById('search_' + nm).style.height = (parseInt(document.getElementById('search_' + nm).style.height) + step) + "px";
		}
	}
	if(oc == "c"){
   		document.images[nm].src="http://www.exploreeducation.com/images/" + nm + "_header_0.gif";
		if(parseInt(document.getElementById('search_' + nm).style.height) <= h){
			clearInterval(expBrowse);
			document.getElementById('search_' + nm).style.height = 32 + "px";
		}else{
			document.getElementById('search_' + nm).style.height = (parseInt(document.getElementById('search_' + nm).style.height) - step) + "px";
		}
	}
//end expandBox
}

//############################## MULTIPLE PROGRAMS ##############################//

var showTimer;

function showPgms(sch,wpgms){

var pgmList=wpgms.split(",");
var pgms = "";
var listDiv;
var isIE = false;

if(navigator.userAgent.indexOf("MSIE") > -1){
	isIE = true;
}

	if(isIE){
		listDiv = eval(document.all[sch+'PgmList']);
	}else{
		listDiv = eval(document.getElementById(sch+'PgmList'));
	}

for(a=0; a<pgmList.length; a++){
	if(isIE){
		pgms = pgms + "<tr><td>" + document.all[sch+'PgmList_'+pgmList[a]].innerHTML + "</td></tr>";
	}else{
		pgms = pgms + "<tr><td>" + document.getElementById(sch+'PgmList_'+pgmList[a]).innerHTML + "</td></tr>";
	}
}

listDiv.innerHTML = "<table border=0 width=186><tr><td align=center>Please select which program you are interested in:</td></tr></table><table>"+pgms+"</table>";

if(listDiv.style.visibility == "visible"){
	listDiv.style.visibility = "hidden";
	clearTimeout(showTimer);
}else{
	listDiv.style.visibility = "visible";
	showTimer = setTimeout('showPgms(\''+sch+'\',\''+wpgms+'\')',5000);
}

//end
}


//############################## COPYRIGHT DATE ##############################//

var newDate = new Date();
var daYear = newDate.getYear();

if(navigator.userAgent.indexOf("Gecko") > -1){
	daYear = daYear + 1900;
}

var daDate = ""+daYear+"";


//############################## TEST FORM ##############################//

function testForm(theForm){

	for(f=0; f<theForm.length; f++){
	//alert(theForm[f].type);
		if(theForm[f].type == "text"){
			if(theForm[f].name.indexOf("Phone") > -1 || theForm[f].name.indexOf("Ext") > -1){
				theForm[f].value = f;
			}
			else if(theForm[f].name.indexOf("Email") > -1){
				theForm[f].value = "TEST@TEST.COM";
			}
			else{
				theForm[f].value = "TEST";
			}
		}
		if(theForm[f].type == "select-one"){
			theForm[f].selectedIndex = 2;
			init();
		}
		if(theForm[f].type == "radio"){
			theForm[theForm[f].name][0].checked = true;
		}
		if(theForm[f].type == "checkbox"){
			theForm[f].checked = true;
		}
		if(theForm[f].type == "textarea"){
			theForm[f].value = "TEST";
		}
	}

//end
}

//############################## ADVERTISING FORM ##############################//
var errList = new Array();

function checkForm(theForm){

	for(f=0; f<theForm.length; f++){
		if(document.getElementById('req_' + theForm[f].name)){
			document.getElementById('req_' + theForm[f].name).innerHTML = "*";
		}
	}
	errList.length = 0;

	if(theForm.First_Name.value == ""){
		errList[errList.length] = "First_Name";
	}
	if(theForm.Last_Name.value == ""){
		errList[errList.length] = "Last_Name";
	}
	if(theForm.Country.value == ""){
		errList[errList.length] = "Country";
	}
	if(theForm.City.value == ""){
		errList[errList.length] = "City";
	}
	if(theForm.State.value == ""){
		errList[errList.length] = "State";
	}
	if(theForm.Country.value == "United States"){
		if(theForm.State.selectedIndex > 53){
			alert(theForm.State.options[theForm.State.selectedIndex].text + " is not a US State or Territory.  Please select again.");
			errList[errList.length] = "State";
		}
	}
	if(theForm.Country.value == "Canada"){
		if(theForm.State.selectedIndex < 53){
			alert(theForm.State.options[theForm.State.selectedIndex].text + " is not a Canadian Province or Territory.  Please select again.");
			errList[errList.length] = "State";
		}
	}
	if(theForm.Phone_Number.value == ""){
		errList[errList.length] = "Phone_Number";
	}
	if(theForm.Email.value == ""){
		errList[errList.length] = "Email";
	}else{
		var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
		var returnval = emailfilter.test(theForm.Email.value);

		if(returnval == false){
			errList[errList.length] = "Email";
		}
	}
	if(theForm.Institution && theForm.Institution.value == ""){
		errList[errList.length] = "Institution";
	}
	
	if(errList.length > 0){
		alert("You must complete all required fields.  All fields that require your attention have been highlighted in red for your convenience.");
		for(e=0; e<errList.length; e++){
			document.getElementById('req_' + errList[e]).innerHTML = "<font color=red>*</font>";
		}
		return false;
	}

//end
}
//############################## PAGE FUNCTIONS ##############################//

var tc = "na";
var cfrm = "confirm.asp";
var tcAll = "";

if(location.href.indexOf("?") > -1){
	var tcAll = location.href.substr(location.href.indexOf("?")+1);
	if(tcAll == "undefined"){
		tcAll = "";
	}
	if(tcAll == ""){
		tcAll = tc;
	}
	if(tcAll.indexOf("&") == -1){
		tc = tcAll;
	}else{
		tcandc = tcAll.split("&");
		tc = tcandc[0];
			if(tcandc[1] != ""){
				cfrm = "confirm_"+tcandc[1]+".asp";
			}
	}
}

function getPg(dir,pg){
	if(location.href.indexOf(".cgi") > -1){
		tcAll = document.forms[0].refCode.value;
	}
	else if(location.href.indexOf("#") > -1){
		tcAll = location.href.substring(location.href.indexOf("?")+1,location.href.indexOf("#"));
	}
	else if(location.href.indexOf("?") == -1){
		tcAll = "";
	}else{
		tcAll = location.href.substr(location.href.indexOf("?")+1);
	}
	if(pg == ""){
		pg = "default.asp";
	}
	if(dir == ""){
		location = "http://www.exploreeducation.com/" + pg + "?" + tcAll;
	}else if(dir.indexOf("exploreeducation") == -1 && dir.indexOf("http://") > -1){
		winLoc = dir + "/" + pg + "?" + tcAll;
		var newWin = window.open(winLoc,'ExploreEducation','width=800,height=800,top=10,left=0,resizable=yes,scrollbars=yes,location=yes,personalbar=yes,toolbar=yes,menubar=yes,status=yes');
	}else{
		location = "http://www.exploreeducation.com/" + dir + "/" + pg + "?" + tcAll;
	}

/* THIS IS THE SETUP FOR THE LINKS
<script>document.write('<a href="link" onClick="getPg(\'path\',\'pagename.ext\'); return false;">Home</a>');</script><noscript><a href="link">Home</a></noscript>
*/

//end getPg
}


function setACCP(){

	while(tc.indexOf("%96") > -1){
		tc = tc.replace("%96","-");
		if (tc.indexOf("%96") == -1){
			break;
		}
	}
	while(cfrm.indexOf("%96") > -1){
		cfrm = cfrm.replace("%96","_");
		if (cfrm.indexOf("%96") == -1){
			break;
		}
	}
// SAMPLE: BU–MSOT–na–01–WDHC–A
// SAMPLE: GW–HCMBA–na–01-WDHC-A

	if(document.forms[0].Access_code){
		acVer = document.forms[0].Access_code;
	}
	if(document.forms[0].Access_Code){
		acVer = document.forms[0].Access_Code;
	}
	if(document.forms[0].access_code){
		acVer = document.forms[0].access_code;
	}
	//alert(tc);
	if(tc != "na"){
		var inAC = tc.split("-");
		var tempAC = acVer.value.split("–");
		tempAC[2] = inAC[2];
		tc = tempAC.join("–");

		acVer.value = tc;
		document.forms[0].confirm.value = document.forms[0].confirm.value.replace("confirm.asp",cfrm);
	}
		//alert(acVer.value);
		//alert(document.forms[0].confirm.value);
//end setACCP
}


//############################## ADD TO FAVORITES ##############################//

function addFavorite() {
	if (window.sidebar){ // if using Mozilla
		window.sidebar.addPanel('ExploreEducation.com--Prestigious online degree programs', //Page title
		'http://www.exploreeducation.com', //link target
		""); // empty parameter
	}
	else if( document.all ) {//else if using IE
		window.external.AddFavorite(
		'http://www.exploreeducation.com', //target link
		'ExploreEducation.com--Prestigious online degree programs'); //title that you want displayed on the list
	}
	else { //if some other browser
		return;
	}	
// end addFavorite
}

