//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************

//var g_SchoolMenuVisible
var activeSchLayer;
activeSchLayer = 0;
var unself;

// Courtesy of SimplytheBest.net (http://simplythebest.net)
var loadcheck;
function preload() {
    menu = new Array()
	menu[01] = "images/arrow.gif";
	menu[02] = "images/transparent.gif";
	
    im = new Array()
    for (var i = 1; i < menu.length; i++){
           im[i] = new Image()
           im[i].src = menu[i]

    }

loadcheck = 1;
}

function swapimg(num,imgname){
	if (loadcheck == 1) {
		imgname.src = im[num].src
	}
}

function init_seop() {
	preload();
}

// do school search
function doSchoolSearch(id){
	var theForm
	if(isNav4){
		if (id=="P") theForm = document.PSchools.document.frmSchool_P;
		if (id=="E") theForm = document.ESchools.document.frmSchool_E;
		if (id=="M") theForm = document.MSchools.document.frmSchool_M;
		if (id=="S") theForm = document.SSchools.document.frmSchool_S;
		if (id=="O") theForm = document.OSchools.document.frmSchool_O;
		if (id=="C") theForm = document.CSchools.document.frmSchool_C;
		if (id=="U") theForm = document.USchools.document.frmSchool_U;
	} else {
		if (id=="P") theForm = document.frmSchool_P;
		if (id=="E") theForm = document.frmSchool_E;
		if (id=="M") theForm = document.frmSchool_M;
		if (id=="S") theForm = document.frmSchool_S;
		if (id=="O") theForm = document.frmSchool_O;
		if (id=="C") theForm = document.frmSchool_C;
		if (id=="U") theForm = document.frmSchool_U;
	}

	if (theForm.Schools.options.selectedIndex == -1) {
		alert("Please enter or select\na valid school's name.");
		//return;
	} else {
		hideLayer(id + "Schools");
		showLayer("loadLayer");
		var theString = theForm.Schools.options[theForm.Schools.selectedIndex].value;
		var sX_COORD = theString.substring(0,20);
		var sY_COORD = theString.substring(20,40);
		var sName = theString.substring(40,theString.length);
		var fX_COORD = parseFloat(sX_COORD, 10);
		var fY_COORD = parseFloat(sY_COORD, 10);

		document.frmNavigation.Cmd.value = 'SCHOOL';
		document.frmNavigation.LM.value = theString;
		document.frmNavigation.GeocodeLabel.value = sName;
		document.frmNavigation.GeocodePoint_X.value = sX_COORD;
		document.frmNavigation.GeocodePoint_Y.value = sY_COORD;
		document.frmNavigation.ShowWhat.value = "";
				
		document.frmNavigation.target="";
		document.frmNavigation.submit();
	}
}

// set search tool
function showmenu(newMenu) {
	hideMenuLayers();
	activeSchLayer = newMenu;
	var id;

	if (newMenu == 1) {
		id = "P";
	} else if (newMenu == 2) {
		id = "E";
	} else if (newMenu == 3) {
		id = "M";
	} else if (newMenu == 4) {
		id = "S";
	} else if (newMenu == 5) {
		id = "O";
	} else if (newMenu == 6) {
		id = "C";
	} else if (newMenu == 7) {
		id = "U";
	}

	if (id) {
		hideLayer("theTop");
		showLayer(id+"Schools");
		if(isIE) document["frmSchool_"+id].word.focus();
	}
	g_SchoolMenuVisible = true
}

//hide search layers
function hideMenuLayers(){

	if (activeSchLayer == 1) {
		hideLayer("PSchools");
	} else if (activeSchLayer == 2) {
		hideLayer("ESchools");
	} else if (activeSchLayer == 3) {
		hideLayer("MSchools");
	} else if (activeSchLayer == 4) {
		hideLayer("SSchools");
	} else if (activeSchLayer == 5) {
		hideLayer("OSchools");
	} else if (activeSchLayer == 6) {
		hideLayer("CSchools");
	} else if (activeSchLayer == 7) {
		hideLayer("USchools");
	}

	showLayer("theTop");
	activeSchLayer = 0;
	g_SchoolMenuVisible = false
}

function WriteSchoolForm(id, entries) {
	var schType
	if (id=="P") schType = "Private Schools";
	if (id=="E") schType = "Elementary Schools";
	if (id=="M") schType = "Middle Schools";
	if (id=="S") schType = "Senior Schools";
	if (id=="O") schType = "Other Schools";
	if (id=="C") schType = "College Schools";
	if (id=="U") schType = "University Schools";

	var content;
	content = "";
	content += "<form name='frmSchool" + "_" + id + "' onsubmit='doSchoolSearch(" + "\"" + id + "\""+ ");;return false;'>";

	content += "<table width='200' border='1' cellspacing='0' cellpadding='0' bgcolor='#FFF2D7' bordercolor='#666666'>";
	content += "<tr>";
	content += "<td>";

	content += "<P><table align='center' bgcolor='#FFF2D7' border='0' cellspacing='0' cellpadding='2'>";

	if(isIE){
		content += "<font class='LayerReport2'><b>&nbsp;<img name='m_arrow' src='images/arrow_open.gif' width='12' height='6' border='0'>&nbsp;&nbsp;" + schType + "</B></FONT><BR>"
		content += "<Font Style='Font-Family: Arial; Font-Size: 10px; Color: Black;'><b>&nbsp;<img name='m_arrow' src='images/transparent.gif' width='12' height='6' border='0'>&nbsp;&nbsp;(Enter or Select Name)</B></FONT><BR>"

		content += "<font class='SelectSchool'><INPUT class='SelectSchool' style='WIDTH: 100%' TYPE='text' AUTOCOMPLETE='off' VALUE='' NAME='word' ONKEYUP='autoComplete(this,this.form.Schools,true);' ONFOCUS='this.select();'></FONT><BR>"
		content += "<TR><TD><font class='SelectSchool'><p align='left'><SELECT size='10' class='SelectSchool' name='Schools' ONCHANGE='this.form.word.value = this.options[this.selectedIndex].text'>";
	} else if(isNav4){
		content += "<TR><TD><font class='SelectSchool'><p align='left'><SELECT size='10' class='SelectSchool' name='Schools'>";
	} else if (isNav){
		content += "<TR><TD><font class='SelectSchool'><p align='left'><SELECT size='1' class='SelectSchool' name='Schools'>";
	}

	content += entries;

	content += "</SELECT></P></font></TD></TR>";

	content += "<TR align='center'>";
	content += "<td align='center'>";
	content += "<a href='javascript:hideMenuLayers();'><img src='images/Buttons_New/close_button_02.gif' border='0' alt='Close'></a>";
	content += "&nbsp;&nbsp;";
	content += "<a href='javascript:doSchoolSearch(" + "\"" + id + "\""+ ");'><img src='images/locate_button.gif' border='0' alt='Locate School'></a>";
	content += "</td>";
	content += "</TR>";

	content += "</table></P>";

	content += "</td>";
	content += "</tr>";
	content += "</table>";

	content += "</form>";

	return content;
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
// ===================================================================

function autoComplete (field, select, forcematch) {
	var property = "text";
	var found = false;
	for (var i = 0; i < select.options.length; i++) {
	if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
		found=true; break;
		}
	}
	if (found) { select.selectedIndex = i; }
	else { select.selectedIndex = -1; }
	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1); 
			return;
			}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				}
			}
		}
	}

