var LastCategoryShown;
var currentForm = "";
var MaxVisibleLayers = 10;

var refreshMap = false;			// MAIRIM: refresh map next time a category is shown, if refresh buttom was not pressed.
var GeoMethod = "";

var IsLayerOnMap = false;
var HoverFlag = false;

function validate(value) {
	var valid = "0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<value.length; i++) {
		temp = "" + value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Only numbers are accepted!");
		return true;
	} else {
		return false;
	}
}

// set new form
function hideallLayer() {
	hideLayer("MainMenuForm");
	hideLayer("GenericForm");
	hideLayer("ToolMenuForm");
}

// set new form
function setForm(newForm) {
	doRefreshMap();
	var content
	if (newForm == "FIND") {
		hideallLayer();
		content = writeFindForm();
		replaceLayerContent("ToolMenuForm", content);
		showLayer("ToolMenuForm");
	} else if (newForm == "SETUNITS") {
		hideallLayer();
		content = writeSetUnitsForm();
		replaceLayerContent("ToolMenuForm", content);
		showLayer("ToolMenuForm");
	} else if (newForm == "BUFFER") {
		hideallLayer();
		content = writeBufferForm2();
		replaceLayerContent("ToolMenuForm", content);
		showLayer("ToolMenuForm");
	} else if (newForm == "MAINMENU") {
		hideallLayer();
		content = WriteMainMenuForm();
		replaceLayerContent("MainMenuForm", content);
		showLayer("MainMenuForm");
		
		//MAIRIM
		// toolMode == 9    FIND
		// toolMode == 20   MEASURE
		// toolMode == 25   BUFFER
		if (toolMode == 9 || toolMode == 20 || toolMode == 25) {
			clickFunction('zoomin');
			setToolPic('Zoom In');		
		}

				
	} else {
		content = "";
		replaceLayerContent("GenericForm", content);
		showLayer("GenericForm");
	}
	currentForm = newForm;
}

//MAIRIM
////////////////////////////////////////GREEN TABLE GENERATOR CODE //////////////////////////

function DoRoundTable_Green(theTWidth, theTHeight, theTitle, InTBody) {
	var content
	content = ""

	content += "<table WIDTH='" + theTWidth + "' border='0' cellpadding='0' cellspacing='0'>"

	content += "<tr>"
	content += "<td bgcolor='#eeeeeb' background='images/Portal_img/header_green_left.gif' width='11px' nowrap align='left' valign='middle' height='25px'><img src='images/Portal_img/space.gif' width='1' height='1' border='0' alt='spacer' valign='top'></td>"
	content += "<td bgcolor='#69bd51' width='100%' nowrap align='left' valign='middle' height='25px'>"
	content += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
	content += "<tr>"
	content += "<td width='100%' class='portletheader' nowrap align='left' valign='middle'>"
	content += theTitle	
	content += "</td>"
//	content += "<td nowrap align='right' valign='middle'> &nbsp;</td>"
	content += "</tr>"
	content += "</table>"
	content += "</td>"
	content += "<td bgcolor='#eeeeeb' background='images/Portal_img/header_green_right.gif' width='11px' nowrap align='right' valign='middle' height='25px'><img src='images/Portal_img/space.gif' width='1' height='1' border='0' alt='spacer' valign='top'></td>"
	content += "</tr>"

	content += "<tr>"
	content += "<td colspan='3'>"
	content += "<table width='100%' cellspacing='0' cellpadding='0' align='left' border='0'>"
	content += "<tr>"
	content += "<td bgcolor='#69bd51'><img src='images/Portal_img/space.gif' width='2' height='1' border='0' alt='spacer'></td>"
	content += "<td bgcolor='#ffffff'><img src='images/Portal_img/space.gif' width='8' height='1' border='0' alt='spacer'></td>"
	content += "<td bgcolor='#ffffff' width='100%'>"

	content += "<br>"
	content += "<TABLE WIDTH='" + theTWidth + "' HEIGHT='" + theTHeight + "' CELLSPACING='0' CELLPADDING='0' BORDER='0'>"

	content += "<tr><td>"
	content += InTBody
	content += "</TD></TR>"

	content += "</TABLE>"
	content += "</td>"

	content += "<td bgcolor='#FFFFFF'><img src='images/Portal_img/space.gif' width='8' height='1' border='0' alt='spacer'></td>"
	content += "<td bgcolor='#69bd51'><img src='images/Portal_img/space.gif' width='2' height='1' border='0' alt='spacer'></td>"
	content += "</tr>"
	content += "</table>"
	content += "</td>"
	content += "</tr>"

	content += '<tr>'
	content += '<td colspan="3">'
	content += '<table border="0" cellpadding="0" cellspacing="0">'
	content += '<tr>'
	content += '<td bgcolor="#69bd51"><img src="images/Portal_img/left_corner_green.gif" width="10" height="11" border="0" alt="left corner green image"></td>'
	content += '<td width="100%" background="images/Portal_img/bg_green_white.gif"><img src="images/Portal_img/space.gif" width="1" height="1" border="0" alt="spacer"></td>'
	content += '<td bgcolor="#69bd51"><img src="images/Portal_img/right_corner_green.gif" width="10" height="11" border="0" alt="right color green image"></td>'
	content += '</tr>'
	content += '</table>'
	content += '</td>'
	content += '</tr>'

	content += "</table>"

	return content;
}

////////////////////////////////////////    BLUE TABLE CODE        ///////////////////////////////////
function DoRoundTable_Blue(theTWidth, theTHeight, theTitle, InTBody) {

	var content
	content = ''

	content += '<table WIDTH="' + theTWidth + '" border="0" cellpadding="0" cellspacing="0">'

	content += '<tr>'
	content += '<td bgcolor="#eeeeeb" background="images/Portal_img/header_blue_left.gif" width="11px" nowrap align="left" valign="middle" height="25px"><img src="images/Portal_img/space.gif" width="1" height="1" border="0" alt="spacer" valign="top"></td>'
	content += '<td bgcolor="#0099cc" width="100%" nowrap align="left" valign="middle">'
	content += '<table width="100%" border="0" cellpadding="0" cellspacing="0">'
	content += '<tr>'
	content += '<td width="100%" class="portletheader" nowrap align="left" valign="middle">'
	content += theTitle
	content += '</td>'
	content += '<td nowrap align="right" valign="middle"> &nbsp;</td>'
	content += '</tr>'
	content += '</table>'
	content += '</td>'
	content += '<td bgcolor="#eeeeeb" background="images/Portal_img/header_blue_right.gif" width="11px" nowrap align="left" valign="middle" height="25px"><img src="images/Portal_img/space.gif" width="1" height="1" border="0" alt="spacer" valign="top"></td>'
	content += '</tr>'

	content += '<tr>'
	content += '<td colspan="3">'
	content += '<table width="100%" cellspacing="0" cellpadding="0" align="left" BORDER="0">'
	content += '<tr>'
	content += '<td bgcolor="#0099cc"><img src="images/Portal_img/space.gif" width="2" height="1" border="0" alt="spacer"></td>'
	//content += '<td bgcolor="#ffffff"><img src="images/Portal_img/space.gif" width="1" height="1" border="0" alt="spacer"></td>'
	content += '<td bgcolor="#ffffff" width="100%">'

	//content += '<br>'
	////content += '<TABLE WIDTH="' + theTWidth + '" HEIGHT="' + theTHeight + '" CELLSPACING="0" CELLPADDING="0" BORDER="0" align="center">'
	content += '<TABLE WIDTH="' + '100%' + '" HEIGHT="' + theTHeight + '" CELLSPACING="0" CELLPADDING="0" BORDER="0" align="center">'
	content += '<tr><td align="center">'
	content += InTBody
	content += '</TD></TR>'
	content += '</TABLE>'
	content += '</td>'

	//content += '<td bgcolor="#FFFFFF"><img src="images/Portal_img/space.gif" width="1" height="1" border="0" alt="spacer"></td>'
	content += '<td bgcolor="#0099CC"><img src="images/Portal_img/space.gif" width="2" height="1" border="0" alt="spacer"></td>'
	content += '</tr>'
	content += '</table>'
	content += '</td>'
	content += '</tr>'

	content += '<tr>'
	content += '<td colspan="3">'
	content += '<table border="0" cellpadding="0" cellspacing="0">'
	content += '<tr>'
	content += '<td bgcolor="#0099cc"><img src="images/Portal_img/left_corner_blue.gif" width="10" height="11" border="0" alt="left corner blue image"></td>'
	content += '<td width="100%" background="images/Portal_img/bg_blue_white.gif"><img src="images/Portal_img/space.gif" width="1" height="1" border="0" alt="spacer"></td>'
	content += '<td bgcolor="#0099cc"><img src="images/Portal_img/right_corner_blue.gif" width="10" height="11" border="0" alt="right color blue image"></td>'
	content += '</tr>'
	content += '</table>'
	content += '</td>'
	content += '</tr>'
	content += '</table>'

	return content;
}


////////////////////////////////////////	LANDMARK SEARCH CODE	/////////////////////////////////////////////////////

// do landmark search
function doLandSearch(){
	var theForm = document.getElementById('frmLand');

	if (theForm.LandMark.options.selectedIndex == -1) {
		alert("Please select a landmark");
		//return;
	} else {
		//showLayer("loadLayer");
		var theString = theForm.LandMark.options[theForm.LandMark.selectedIndex].value;
		var sX_COORD = theString.substring(0,13);
		var sY_COORD = theString.substring(13,26);
		var sName = theString.substring(26,theString.length);
		var fX_COORD = parseFloat(sX_COORD, 10);
		var fY_COORD = parseFloat(sY_COORD, 10);
		zoomToPoint(fX_COORD, fY_COORD, true,sName);
	}
}

function writeLandmarkForm(theRowID,theImg) {
	HoverFlag=true;
	prevRowID = theRowID;
	prevImgID = theImg;

	var content
	content = "";
	content = content + '<FORM ACTION="" ID="frmLand" name="frmLand" onMouseover="onMouseoverMenu(&quot;' + theRowID + '&quot;,&quot;' + theImg + '&quot;);">';
	content = content + landmarks
	content = content + '</FORM>';
	return content;
}

////////////////////////////////////////	SCHOOL SEARCH FORM	/////////////////////////////////////////////////////

function getLayerIndex(theLayer) {
	var FoundFlag = false;
	for (var i=0; i < LayerName.length; i++)
	   {
	   if (LayerName[i] == theLayer)
	      {
			//alert(LayerName[i]);
			FoundFlag = true;
			return i
	      }
	   }
	if (!FoundFlag) alert("Layer was not found..");
	return -1
}

function doSchoolSearch() {
	var theForm = document.getElementById('theSchoolForm');

	var type = theForm.SchoolType.options[theForm.SchoolType.options.selectedIndex].value;
	if (type == "") {
		alert("Please, select an option.");
		return
	}
	
	clickFunction ("query");

	var theString
	var tempIndex
	if (type == 'E' || type == 'M' || type == 'S' || type == 'O') {
		tempIndex = getLayerIndex('Public Schools');
		//alert(tempIndex);
		setActiveLayer(tempIndex,false);

		LayerVisible[tempIndex] = 1;

		theString = 'MDC.SchoolSite.TYPE = "' + type + '"';
		//if (theSchoolSearch != "ALL") theString = theString + ' AND MDC.SchoolSite.SCH_NAME LIKE "%' + theSchoolSearch + '%"' 
		sendQueryString(theString);
		//sendQueryString('MDC.SchoolSite.TYPE = "E"');
	} else if (type == 'C' || type == 'U') {
		tempIndex = getLayerIndex('Colleges and Universities');
		LayerVisible[tempIndex] = 1;

		//alert(tempIndex);
		setActiveLayer(tempIndex,false);
		theString = 'MDC.college.TYPE = "' + type + '"';
		//if (theSchoolSearch != "ALL") theString = theString + ' AND MDC.college.NAME LIKE "%' + theSchoolSearch + '%"' 
		sendQueryString(theString);
	} else if (type == 'P') {
		tempIndex = getLayerIndex('Private Schools');
		LayerVisible[tempIndex] = 1;

		//alert(tempIndex);
		setActiveLayer(tempIndex,false);
		theString = '';
		//if (theSchoolSearch != "ALL") theString = 'MDC.PrivateSchool.NAME LIKE "%' + theSchoolSearch + '%"' 
		sendQueryString(theString);
	}
	//Mairim 
	SchoolQueryType = type;	
}

function writeSchoolForm(theRowID,theImg) {
	HoverFlag=true;
	prevRowID = theRowID;
	prevImgID = theImg;

	setToolPic("ClearOut");

	var content
	content = "";

	content = content + '<FORM ACTION="" name="theSchoolForm" onMouseover="onMouseoverMenu(&quot;' + theRowID + '&quot;,&quot;' + theImg + '&quot;);">';
//	content = content + '<FONT FACE="Arial"><B>School Search:</B></FONT>';
	content = content + '<TABLE BORDER=1 CELLSPACING="0" NOWRAP BGCOLOR="#FFFFFF" bordercolor="#0099cc" WIDTH=100%>';
	content = content + '	<TR><td>';
	content = content + '<TABLE bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="4" NOWRAP WIDTH=100%>';

	content = content + '<TR><td COLSPAN="3">';
	content = content + '<TABLE BORDER="0" bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="0" NOWRAP WIDTH=100%>';
	content = content + '<TR>';
	content = content + '<TD NOWRAP ALIGN="LEFT">';
	content = content + '<img src="images/arrow_open.gif" border="0">&nbsp;';
	content = content + '<FONT class=SearchForm3><B>School Search</B></FONT>'
	content = content + '</TD>';

	content = content + '<td align="right" valign="top">';
	content = content + '<a href="javascript:doClosePopoutLayers()"><img src="images/winclose.gif" border="0" alt="Close form"></a>';
	content = content + '</td>';

	content = content + '</TR>';
	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '</TR>';

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top">'
	content += '		<font class="select"><select class="select" name="SchoolType" size="1">'
	content += '		<option value="" selected>Select an item</option>'
	content += '		<option value="P">Private Schools</option>'
	content += '		<option value="E">Elementary Schools</option>'
	content += '		<option value="M">Middle Schools</option>'
	content += '		<option value="S">Senior High Schools</option>'
	content += '		<option value="C">Colleges</option>'
	content += '		<option value="U">Universities</option>'
	content += '		<option value="O">Other Public Schools</option>'
	content += '		</select></font>'
	content += '      </td>'
	content += '    </tr>'

	content = content + '<TR>';
	content = content + '<TD colspan=2 ALIGN="CENTER">';
//	content = content + '<INPUT TYPE="Button" NAME="setDU" VALUE="Search" onclick="doSchoolSearch()">  <BR>';
	content = content + '<a href="javascript:doClosePopoutLayers();doSchoolSearch()"><img src="images/locate_button.gif" border="0" alt="Find School"></a>'
	
	content = content + '</TD>';
	content = content + '</TR>';

	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '	</TR>';
	content = content + '</TABLE>';
	content = content + '</FORM>';

	return content;
}

////////////////////////////////////////	BUFFER FORM /////////////////////////////////////////////////////

function doBuffer() {
//Mairim	
//this is the set units part
	var theForm = document.getElementById('theBufferForm');
	var TempScaleBarUnits = ScaleBarUnits;
	var i = theForm.newDUnits.selectedIndex;
	var k =  theForm.newDUnits.options[i].value;
		
	var m = "FEET";
	ScaleBarUnits = k;
	if (setMapUnits) {
		i = theForm.newMUnits.selectedIndex;
		m =  theForm.newMUnits.options[i].value;
		m = theUnits;
		MapUnits = m;
	}
	//theForm.cDisplayUnits.value = k;
			
	if (toolMode == 20) {
		//resetClick();
		var tDist = convertUnits_setDUnits(totalMeasure,TempScaleBarUnits,k);
		totalMeasure = tDist;
		//alert(totalMeasure);
		tDist = convertUnits_setDUnits(currentMeasure,TempScaleBarUnits,k);
		currentMeasure = tDist;
		updateMeasureBox();
		//if (drawScaleBar) sendMapXML();
	} else {
		//writeOptionForm();
		//if (drawScaleBar) sendMapXML();
	}

//Original code of the doBuffer function
	var theForm = document.getElementById('theBufferForm');

	bufferDistance = theForm.theDistance.value;
	theIndex = theForm.theTarget.selectedIndex;
	if (theIndex>0) {
		bufferTargetLayer = theForm.theTarget.options[theIndex].text;
		bufferTargetLayerIndex = parseInt(theForm.theTarget.options[theIndex].value);
		getBufferedData = theForm.getData.checked;
		drawTargetLayer=true;
	} else {
		drawTargetLayer=false;
		getBufferedData = false;
	}
	if (parseFloat(theForm.theDistance.value)>=0) {
		bufferIt();
	} else {
		alert("' + msgList[81] + '");
	}
}

//Mairim
function writeSetUnitsCombo() {
	var content
	content = "";
	content = content + '<select style="FONT-FAMILY: Arial; FONT-SIZE: 11px; WIDTH: 68px" name="newDUnits" >';
								
	content = content + '<option value="FEET"';
	if (ScaleBarUnits=="FEET") content = content + ' selected';
	content = content + '>' + unitList[1];
								
	content = content + '<option value="MILES"';
	if (ScaleBarUnits=="MILES") content = content + ' selected';
	content = content + '>' + unitList[2];
								
	content = content + '<option value="METERS"';
	if (ScaleBarUnits=="METERS") content = content + ' selected';
	content = content + '>' + unitList[3];
								
	content = content + '<option value="KILOMETERS"';
	if (ScaleBarUnits=="KILOMETERS") content = content + ' selected';
	content = content + '>' + unitList[4];
								
	content = content + '</select>';
return content;
}


function writeBufferForm2() {
	var content
	content = "";
	var content1
	content1 = "";

	content1 = content1 + '<TABLE BORDER=0 CELLSPACING="0" NOWRAP BGCOLOR="#EEEEEE" bordercolor="#666666" WIDTH="100%">';
	content1 = content1 + '<TR><TD align=left><img src="images/post2.gif" border="0" alt="Back to main menu.">&nbsp;&nbsp;<a href="javascript:setForm(&quot;MAINMENU&quot;);">Go back to main menu</a></TD></TR>';
	content1 = content1 + '</TABLE>';

	content = content + '<form ID="theBufferForm"  NAME="theBufferForm" onsubmit="doBuffer(); return false;">';
	content = content + '<TABLE BORDER=0 CELLSPACING="0" NOWRAP BGCOLOR="#FFFFFF" bordercolor="#666666" WIDTH="100%">';

	content = content + '<TR><td>';
	content = content + '<table cellspacing="0" cellpadding="1" bgcolor="#FFFFFF" width="100%">';
	//content = content + '<tr><td align="LEFT"><FONT class=SearchForm3><STRONG>Buffer</STRONG></FONT></td></tr>';
	content += '<tr bgcolor="#FFFFFF"><td>&nbsp;</td></tr>'

	content = content + '<tr><td align="LEFT"><SELECT class="select" name="theTarget">';
	content = content + '<option value=-1>' + msgList[87] + '</option>';
	for (var i=0;i<layerCount;i++) {
		if (LayerType[i]!="image") {
			content = content + '<option value=' + i + '>' + LayerName[i] + '</option>';
		}
	}
	content = content + '</SELECT>';
	content += '</td></tr>';

	content += '<tr>'
	content += '<td><FONT class=SearchForm2>'
	content += msgList[83] + '<FONT class="input1"><input style="FONT-FAMILY: Arial; FONT-SIZE: 11px; WIDTH: 46px" type="Text" name="theDistance" value="0" ></FONT> ';
	var j = 1;
	for (var i=0;i<sUnitList.length;i++) {
		if (ScaleBarUnits==sUnitList[i]) j=i;
	}
	//Mairim
	content += writeSetUnitsCombo();
	
	//content += sUnitList[j];
	content += msgList[84];
	content += LayerName[ActiveLayerIndex];
	content += '</FONT></td>'
	content += '</tr>'

	content += '<tr bgcolor="#FFFFFF"><td>&nbsp;</td></tr>'
	
	content = content + '<tr><td align="CENTER">';
	content = content + '<a href="javascript:doBuffer()"><img src="images/Create_Buffer.gif" border="0" alt="Perform Buffer Analysis"></a>';   
	content = content + '	<a href="javascript:cancelClick();setForm(&quot;MAINMENU&quot;);"><img src="images/cancel_button.gif" border="0" alt="Cancel Set Units"></a>';   
	content= content + '</td>';
	content = content + '</tr>'

	content = content + '<tr><td align="LEFT">';
	content = content + '<INPUT TYPE="checkbox" NAME="getData" VALUE="' + buttonList[10] + '"';
	if (getBufferedData) {
		content = content + ' CHECKED';
	}
	content = content + '><font class=SearchForm1>' + msgList[85] + '</font>';
	content = content + '</td></tr>';

	content = content + '</table>';
	content = content + '</TD>';
	content = content + '</TR>';	
	content = content + '</TABLE>';
	content = content + '</form>';
	
	content = DoRoundTable_Blue(200, 10, "Buffer", content);
	content = content1 + content;
	
	return content;
}

////////////////////////////////////////	FOLIO FORM	/////////////////////////////////////////////////////

function doFolioSearch() {
	var theForm = document.getElementById('theFolioForm');
	var theValue = theForm.theStyle.value;

	if (theValue == "") {
		alert("Please enter a folio number");
		return;	
	}

	if (validate(theValue)) {
		return;
	}

	if (theValue.length != 13) {
		//alert(theFolio.length);
		alert("Invalid Folio Number!\n\n\re.g. 0101000000022");
		return;
	}

	doClosePopoutLayers();
	var tempIndex
	tempIndex = getLayerIndex('Properties (Parcels)');
	//alert(tempIndex);
	setActiveLayer(tempIndex,false);
	LayerVisible[tempIndex] = 1;
	var qString = "";
	qString = "MDC.PROP_PTX.FOLIO = " + dQuote + theValue + dQuote;
	sendQueryString(qString);
}

function writeFolioForm(theRowID,theImg) {
	HoverFlag=true;
	prevRowID = theRowID;
	prevImgID = theImg;

	var content
	content = "";

	content = content + '<FORM ACTION="" ID="theFolioForm" name="theFolioForm" onsubmit="doFolioSearch(); return false;" onMouseover="onMouseoverMenu(&quot;' + theRowID + '&quot;,&quot;' + theImg + '&quot;);">';
	content = content + '<TABLE BORDER=1 CELLSPACING="0" NOWRAP BGCOLOR="#FFFFFF" bordercolor="#0099cc" WIDTH=100%>';

	content = content + '<TR><td>';
	content = content + '<TABLE BORDER=0 CELLSPACING="4" CELLPADDING="1" NOWRAP BGCOLOR="#FFFFFF" WIDTH=100%>';

	content = content + '<TR bgcolor="#FFFFFF"><td>';
	content = content + '<TABLE BORDER="0" bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="0" NOWRAP WIDTH=100%>';
	content = content + '<TR>';
	content = content + '<TD NOWRAP ALIGN="LEFT">';
	content = content + '<img src="images/arrow_open.gif" border="0">&nbsp;';
	content = content + '<FONT class=SearchForm3><B>Find Folio:</B></FONT>'
	content = content + '</TD>';
	content = content + '<td align="right" valign="top">';
	content = content + '<a href="javascript:doClosePopoutLayers()"><img src="images/winclose.gif" border="0" alt="Close form"></a>';
	content = content + '</td>';
	content = content + '</TR>';
	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '</TR>';

	content = content + '<TR>';
	content = content + '<TD>';
	content = content + '<FONT class=SearchForm1>Enter a folio Number<BR>Example: 3059320004260';
	content = content + ': <INPUT TYPE=TEXT NAME="theStyle" VALUE="">';
	content = content + '</FONT>';
	content = content + '</TD>';
					
	content = content + '</TR>';

	//content += '    <tr bgcolor="#FFF2D7"><td>&nbsp;</td></tr>'

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="center" valign="top">'
	content += '	  <a href="javascript:doFolioSearch()"><img src="images/locate_button.gif" border="0" alt="Find folio."></a>  <BR>'
	content += '      </td>'
	content += '    </tr>'

	content = content + '</TR>';

	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '	</TR>';
	content = content + '</TABLE>';
	content = content + '</FORM>';

	return content;
}

////////////////////////////////////////	SECTION FORM	/////////////////////////////////////////////////////

function doSectionSearch() {
	var theForm = document.getElementById('theTRSForm');
	var theValue = theForm.theStyle.value;

	if (theValue == "") {
		alert("Please enter a section number");
		return;	
	}
	if (validate(theValue)) {
		return;
	}
	if (theValue.length != 6) {
		//alert(theFolio.length);
		alert("Invalid Section Number!\n\n\re.g. 524023");
		return;
	}

	doClosePopoutLayers();
	var tempIndex
	tempIndex = getLayerIndex('Sections');
	//alert(tempIndex);
	setActiveLayer(tempIndex,false);
	LayerVisible[tempIndex] = 1;

	var qString = "";
	qString = "TTRRSS = " + dQuote + theValue + dQuote;
	sendQueryString(qString);
}

function writeSectionForm(theRowID,theImg) {
	HoverFlag=true;
	prevRowID = theRowID;
	prevImgID = theImg;

	var content
	content = "";

	content = content + '<FORM ACTION="" ID="theTRSForm" name="theTRSForm" onsubmit="doSectionSearch(); return false;" onMouseover="onMouseoverMenu(&quot;' + theRowID + '&quot;,&quot;' + theImg + '&quot;);">';
	content = content + '<TABLE BORDER=1 CELLSPACING="0" NOWRAP BGCOLOR="#FFFFFF" bordercolor="#0099cc" WIDTH=100%>';

	content = content + '<TR><td>';
	content = content + '<TABLE BORDER=0 CELLSPACING="4" CELLPADDING="1" NOWRAP BGCOLOR="#FFFFFF" WIDTH=100%>';

	content = content + '<TR bgcolor="#FFFFFF"><td>';
	content = content + '<TABLE BORDER="0" bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="0" NOWRAP WIDTH=100%>';
	content = content + '<TR>';
	content = content + '<TD NOWRAP ALIGN="LEFT">';
	content = content + '<img src="images/arrow_open.gif" border="0">&nbsp;';
	content = content + '<FONT class=SearchForm3><B>Find Section:</B></FONT>'
	content = content + '</TD>';
	content = content + '<td align="right" valign="top">';
	content = content + '<a href="javascript:doClosePopoutLayers()"><img src="images/winclose.gif" border="0" alt="Close form"></a>';
	content = content + '</td>';
	content = content + '</TR>';
	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '</TR>';

	content = content + '<TR>';
	content = content + '<TD>';
	content = content + '<FONT class=SearchForm1>Enter a section Number<BR>Example: 524023';
	content = content + ': <INPUT TYPE=TEXT NAME="theStyle" VALUE="">';
	content = content + '</FONT>';
	content = content + '</TD>';
					
	content = content + '</TR>';

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="center" valign="top">'
	content += '	  <a href="javascript:doSectionSearch()"><img src="images/locate_button.gif" border="0" alt="Find section."></a>  <BR>'
	content += '      </td>'
	content += '    </tr>'

	content = content + '</TR>';

	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '	</TR>';
	content = content + '</TABLE>';
	content = content + '</FORM>';

	return content;
}

////////////////////////////////////////	FIND FORM	/////////////////////////////////////////////////////

function setStyle() {
	var theForm = document.getElementById('theFindForm');
	var theValue = theForm.theStyle.value;
	if (theValue!="") {
		getFind(theValue);
	} else {
		alert(msgList[99]);
	}
}

function writeFindForm(theGroup) {
	var content
	content = "";
	var content1
	content1 = "";

	content = content + '<TABLE BORDER=0 CELLSPACING="0" NOWRAP BGCOLOR="#EEEEEE" bordercolor="#666666" WIDTH=100%>';

	content = content + '<TR><TD align=left><img src="images/post2.gif" border="0" alt="Back to main menu.">&nbsp;&nbsp;<a href="javascript:setForm(&quot;MAINMENU&quot;);">Go back to main menu</a></TD></TR>';

	content = content + '</TABLE>' 
	
	
	content1 = content1 + '<form action="" ID="theFindForm" NAME="theFindForm" onsubmit="setStyle(); return false;">';
	content1 = content1 + '<TABLE BORDER=0 CELLSPACING="0" NOWRAP BGCOLOR="#FFFFFF" bordercolor="#666666" WIDTH="100%">';
	content1 = content1 + '<TR><td>';
	content1 = content1 + '<TABLE BORDER="0" CELLSPACING="4" CELLPADDING="1" NOWRAP BGCOLOR="#FFFFFF" WIDTH="100%">';
	content1 = content1 + '<TR>';
	content1 = content1 + '<TH ALIGN="LEFT">';
	content1 = content1 + '<FONT class="SearchForm3"><B>' + modeList[17] + '</B></FONT>';
	content1 = content1 + '</TH>';
	content1 = content1 + '</TR>';


	var theValue = LayerName[ActiveLayerIndex];
	content1 += '<tr><td><FONT class=SearchForm2>'
	content1 += msgList[90] + theValue;
	content1 += '</FONT>'
	content1 += '<FONT class="input1"><input class="input1" type="Text" name="theStyle" value="" size="18"></FONT> ';
	content1 += '</td></tr>'

	content1 += '<tr bgcolor="#FFFFFF">'
	content1 += '<td align="center" valign="top">'
	content1 += '<a href="javascript:setStyle()"><img src="images/Find_String.gif" border="0" alt="Find string."></a> '
	content1 += '<a href="javascript:cancelClick();setForm(&quot;MAINMENU&quot;);"><img src="images/cancel_button.gif" border="0" alt="Cancel Set Units"></a>';   
	content1 += ' <BR></td>'
	
	content1 += '</tr>'

	content1 += '<TR bgcolor="#FFFFFF">'
	content1 += '<TH ALIGN="LEFT">';
	content1 += '<img src="images/Tip.gif" border="0" alt="Tip.">&nbsp;';
	content1 += '<FONT class=SearchForm2><B>' + msgList[79] + '</B></FONT>';
	content1 += '</TH>';
	content1 += '</TR>';

	content1 += '</TABLE>';
	content1 += '</TD>';
	content1 += '</TR>';
	content1 += '</TABLE>';
	content1 += '</FORM>';

	content1 = DoRoundTable_Blue(210, 10, "Find", content1);
	
	content = content + content1;
	return content;
}

////////////////////////////////////////	LAYER CATEGORY FORM		/////////////////////////////////////////////////////

// Show Generic Window
function ShowWin(sURL,sTitle,iHeight,iWidth,ynstatus,yntoolbar,ynmenubar,ynScroll,ynResize,ynleft,yntop) {
	var objWin;
	objWin = window.open(sURL, sTitle, "height="+iHeight+",width="+iWidth+",status="+ynstatus+",toolbar="+yntoolbar+",menubar="+ynmenubar+",scrollbars="+ynScroll+",resizable="+ynResize+",left="+ynleft+",top="+yntop+"");
	objWin.focus();
}

var theRow

function ShowCategory(theGroup,theRowID,theImg) {
	IsLayerOnMap = true;
	var hPosition = 194;
	var theHeight
	var startpos = 160;
	IsLayerOnMap = true;

	if (theGroup == "ORTHO") {
		theHeight = startpos + 200;
		hideallLayer();
		showLayer("MainMenuForm");
		deselectRow(prevImgID,prevRowID);
		selectRow('row14','arrow_14');
		ShowCategory('14','row14','arrow_14');
//		HoverFlag=true;
		return
	} else if (theGroup == "FOLIO") {
		theHeight = startpos + 300;
		content = writeFolioForm(theRowID,theImg);
		moveLayer("GenericForm", hPosition, theHeight);
		replaceLayerContent("GenericForm", content);
		showLayer("GenericForm");
		return
	} else if (theGroup == "SECTION") {
		theHeight = startpos + 320;
		content = writeSectionForm(theRowID,theImg);
		moveLayer("GenericForm", hPosition, theHeight);
		replaceLayerContent("GenericForm", content);
		showLayer("GenericForm");
		return
	} else if (theGroup == "LANDMARK") {
		theHeight = startpos + 340;
		content = writeLandmarkForm(theRowID,theImg);
		moveLayer("GenericForm", hPosition, theHeight);
		replaceLayerContent("GenericForm", content);
		showLayer("GenericForm");
		return
	} else if (theGroup == "SCHOOLS") {
		theHeight = startpos + 310;
		content = writeSchoolForm(theRowID,theImg);
		moveLayer("GenericForm", hPosition, theHeight);
		replaceLayerContent("GenericForm", content);
		showLayer("GenericForm");
		return
	} else if ((theGroup == "ADDRESS") || (theGroup == "INTERSECTION")) {
		GeoMethod = theGroup;
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		// geocode mode - requires aimsGeocode.js
		hideLayer("measureBox");
		modeBlurb = modeList[14];

		//setupGeocode();
		// Hard coded intead of calling setupGeocode()
		GCidCount = 3;
		GCid[0] = "STREET";
		GCid[1] = "ZONE";
		GCid[2] = "CROSSSTREET";
		//parent.TextFrame.document.location= appDir + "addmatch.htm";

		content = "";
		if (GeoMethod == "ADDRESS") {
			theHeight = startpos + 150;
			content = writeAddressForm(theRowID,theImg);
			moveLayer("GenericForm", hPosition, theHeight);
		}

		if (GeoMethod == "INTERSECTION") {
			theHeight = startpos + 80;
			content = writeIntersectionForm(theRowID,theImg);
			moveLayer("GenericForm", hPosition, theHeight);
		}
		replaceLayerContent("GenericForm", content);
		showLayer("GenericForm");
		return
	}

	if (theGroup == 1) theHeight = startpos - 20;
	if (theGroup == 2) theHeight = startpos - 10;
	if (theGroup == 3) theHeight = startpos + 10;
	if (theGroup == 4) theHeight = startpos + 30;
	if (theGroup == 5) theHeight = startpos + 50;
	if (theGroup == 6) theHeight = startpos + 70;	//C.Sibori (02/08) - changed back to 70
//	if (theGroup == 6) theHeight = startpos - 140;  //c. sibori (09/07) - was 70, changed to accommodate additional HealthStatistic layers
	if (theGroup == 7) theHeight = startpos - 50;  //C.Sibori (02/08) - was 90,  changed to accommodate height of Health Statistics theme
	if (theGroup == 8) theHeight = startpos + 110;
	if (theGroup == 9) theHeight = startpos + 130;
	if (theGroup == 10) theHeight = startpos + 150;
	if (theGroup == 11) theHeight = startpos + 170;
	if (theGroup == 12) theHeight = startpos + 150;
	if (theGroup == 13) theHeight = startpos + 170;
	if (theGroup == 14) theHeight = startpos + 190;
	if (theGroup == 15) theHeight = startpos + 210;	//C.Sibori (02/08) - new, needed because of new Heatlh Statistics theme

	//doRefreshMap();
	content = writeCategoryForm(theGroup,theRowID,theImg);
	replaceLayerContent("GenericForm", content);
	moveLayer("GenericForm", hPosition, theHeight);
	showLayer("GenericForm");
	isCategoryLayerOn = true;
	currentForm = "CATEGORY";
}	

function setVisibleLayer(theObj) {
	refreshMap = true;
	var j = 0;
	j = theObj.value;

	UpdatetheIFrameVL()
	// MAIRIM: Refresh the Iframe containing the visible layers
	var theIFrameVL = document.getElementById('myiframeVL');
	if (theIFrameVL!=null) theIFrameVL.src = "visibleLayersTool.htm";

	var theForm = document.getElementById('frmCategory');
	// If true, then assume aerial category is displayed.
	if (!LayerIsFeature[j]) {
		var temp;
		if (theObj.checked) temp=true; else temp=false;
	
		// Unchecked all entries.
		if (theForm.LayerVisible[theObj.name]) {
			for (var i=0; i < theForm.LayerVisible.length; i++) {
				//alert(theForm.LayerVisible[theObj.name][i].checked);
				theForm.LayerVisible[theObj.name][i].checked = false;
				LayerVisible[theForm.LayerVisible[theObj.name][i].value] = 0;
			}
		}

		// Checked only one.
		if (temp) {
			LayerVisible[j] = 1;
			theObj.checked = true;
		} else {
			LayerVisible[j] = 0;
			theObj.checked = false;
		}
	return
	}

	if (theObj.checked) {
	   	//MISHRAM - Updated to log Health and Human Services layers
		//C.Sibori (07/2008) - increased upper limit to 94 from 92 for new layers added 
		if ( j >= 64 && j <= 94 ) {
		 	WritetoLogFile(LayerName[j]);
		}

		var TotalLayersVisible = GetVisibleLayersCount();
		//alert("TotalLayersVisible: " + TotalLayersVisible);

		if (TotalLayersVisible < MaxVisibleLayers) {
			LayerVisible[j] = 1;
		} else {
			var theDiff = (TotalLayersVisible - MaxVisibleLayers) + 1;
			LayerVisible[j] = 0;
			theObj.checked = false;

			var msg = "";
			msg = msg + "The maximun number of layers that can be visible at one time has been exceeded.\n\nPlease, click OK in order to proceed to the visible layers window and uncheck at least ";
			msg = msg + theDiff + " layer(s).";
			alert(msg);
			
			// sURL,sTitle,iHeight,iWidth,ynstatus,yntoolbar,ynmenubar,ynScroll,ynResize,ynleft,yntop
			ShowWin("visibleLayers.htm", "VisibleLayers", "450", "300",0,0,0,1,1,500,300);
			return false
		}
	} else {
		LayerVisible[j] = 0;
	}
}


function UpdatetheIFrameVL()
{
	// MAIRIM: Refresh the Iframe containing the visible layers
	var theIFrameVL = document.getElementById('myiframeVL');
	if (theIFrameVL!=null) {
		theIFrameVL.src = "blank.htm";
		theIFrameVL.src = "visibleLayersTool.htm";
	}
}

function YESNOBox(msg)
{
  return confirm(msg);
}

function CategoryToInt(theStrGroup)
{
  return parseInt(theStrGroup, 10);
}

function CategoryToStr(theIntGroup)
{
	if (theIntGroup < 10)
		return "0" + theIntGroup;
	else
		return theIntGroup;
}

function GetCategoryName(theGroup)
{
  return CategoryList[CategoryToInt(theGroup)];
}

function GetVisibleLayersCount() {
	var theTotal = 0;
	var theCount = layerCount;
	//alert(theCount);
	
	for (var i=0;i<theCount;i++) {
		if ((!hideLayersFromList) || ((hideLayersFromList) && (!noListLayer[i]))) {
		if ((listAllLayers) || ((mapScaleFactor>=LayerMinScale[i]) && (mapScaleFactor<=LayerMaxScale[i]))) {

			if (LayerVisible[i] == 1 && LayerGroup[i] != "99") {	// MAIRIM: Exclude base layers.
				if (LayerIsFeature[i]) {
					theTotal = theTotal + 1;
				}
			}
		}
		}
	}
	return theTotal
}

function doRefreshMap()
{
	// Refresh if the refresh button was not pressed.
	if (refreshMap) {
		//alert("Map will be refresh to \nupdate layer visibility.");
		refreshMap = false;
		//sendMapXML();
	}
}

function doUpdateLayers()
{
	doClosePopoutLayers();
	IsLayerOnMap = false;
	refreshMap = false;
	sendMapXML();
}

function doClosePopoutLayers()
{
	deselectRow(prevImgID,prevRowID);
	hideLayer("GenericForm");
	HoverFlag = false;
	IsLayerOnMap = false;
//	doRefreshMap();
}

function writeCategoryForm(theGroup,theRowID,theImg) {

	HoverFlag=true;
	prevRowID = theRowID;
	prevImgID = theImg;

	var ShowAsterisk=false;
	LastCategoryShown = theGroup;

	//C.Sibori (02/08) - modified
	var ShowHealthDisclaimer1=false;
    	if (GetCategoryName(theGroup) == "Health and Human Services") {
		ShowHealthDisclaimer1 = true;
    	}
	var ShowHealthDisclaimer2=false;
    	if (GetCategoryName(theGroup) == "Health Statistics") {
		ShowHealthDisclaimer2 = true;
    	}

	var content
	content = "";

	content = content + '<FORM name="frmCategory" onMouseover="onMouseoverMenu(&quot;' + theRowID + '&quot;,&quot;' + theImg + '&quot;);">';
	content = content + '<TABLE BORDER=1 CELLSPACING="0" NOWRAP BGCOLOR="#FFFFFF" bordercolor="#0099cc" WIDTH=100%>';
	content = content + '	<TR><td>';
	content = content + '<TABLE BORDER="0" bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="1" NOWRAP WIDTH=100%>';

	content = content + '<TR><td COLSPAN="3">';
	content = content + '<TABLE BORDER="0" bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="0" NOWRAP WIDTH=100%>';
	content = content + '<TR>';
	content = content + '<TD NOWRAP ALIGN="LEFT">';
	content = content + '<img src="images/arrow_open.gif" border="0">&nbsp;';
	content = content + '<FONT class=SearchForm3><B>Theme Category:</B></FONT><BR>'
	content = content + '<FONT class=SearchForm2><B>' + GetCategoryName(theGroup) + '</B></FONT>';
	content = content + '</TD>';

	content = content + '<td align="right" valign="top">';
	content = content + '<a href="javascript:doClosePopoutLayers()"><img src="images/winclose.gif" border="0" alt="Close form"></a>';
	content = content + '</td>';

	content = content + '</TR>';
	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '</TR>';

	content += '<tr bgcolor="#FFFFFF"><td COLSPAN="3">&nbsp;</td></tr>'

	content = content + '<TR>';
	content = content + '<TD ALIGN="CENTER"><FONT class=SearchForm2>' + titleList[14] + '</FONT></TD>';
	content = content + '<TD ALIGN="CENTER"><FONT class=SearchForm2>' + titleList[15] + '</FONT></TD>';
	content = content + '<TD width="140"><FONT FACE="Arial Narrow" SIZE="-3">&nbsp;</FONT></TD>';
	content = content + '</TR>';

		var theCount = layerCount;
		//alert(theCount);
		for (var i=0;i<theCount;i++) {
			//alert(theGroup);
			//alert(LayerGroup[i]);
			if ((LayerGroup[i] == CategoryToStr(theGroup))) {
			if ((!hideLayersFromList) || ((hideLayersFromList) && (!noListLayer[i]))) {
				if ((listAllLayers) || ((mapScaleFactor>=LayerMinScale[i]) && (mapScaleFactor<=LayerMaxScale[i]))) {
					content = content + '<tr><td align="center">';
					content = content + '<input type="Checkbox" name="LayerVisible" onclick="setVisibleLayer(this)" value="' + i + '"';
					//content = content + '<input type="Checkbox" name="LayerVisible" value="' + i + '"';
					if (LayerVisible[i] == 1) content = content + ' checked';
					content = content + ' ></td>';
					content = content + '<td align="center">';
									
					if (LayerIsFeature[i]) {
						content = content + '<input type="Radio" onclick="setActiveLayer(' + i + ',true)" name="Active"';
						if (ActiveLayerIndex==i) content = content + ' checked';
						content = content + '>';
					} else {
						content = content + '&nbsp;';
					}
					content = content + '</td>';
					if ((i == 67) || (i == 70) || (i == 71)) {
						content = content + '<td><font class=SearchForm2>' + LayerName[i] + '</font><font class=Superscript><sup>(1)</sup></font></td>';
					} else if (i == 69) {
						content = content + '<td><font class=SearchForm2>' + LayerName[i] + '</font><font class=Superscript><sup>(2)</sup></font></td>';
					} else if (i >= 72 && i <= 77) {	
						content = content + '<td><font class=SearchForm2>' + LayerName[i] + '</font><font class=Superscript><sup>(1)</sup></font></td>';
					} else if (i == 78) {
						content = content + '<td><font class=SearchForm2>' + LayerName[i] + '</font><font class=Superscript><sup>(2)</sup></font></td>';
					} else if (i >= 79 && i <= 93) {	
						content = content + '<td><font class=SearchForm2>' + LayerName[i] + '</font><font class=Superscript><sup>(3)</sup></font></td>';
					} else {				
					content = content + '<td><font class=SearchForm2>' + LayerName[i] + '</font></td>';
					}
					if (displayLayerInfoButton) {
						content = content + '<td><INPUT TYPE="Button" NAME="InfoButton" VALUE="' + buttonList[43] + '" onclick="showLayerInfo(' + i + ')"></td>';
					}
					content = content + '</tr>';

				} else {
					ShowAsterisk=true;
					content = content + '<tr>';
					content = content + '<td align="center"><INPUT type=checkbox disabled></td>';
					content = content + '<td align="center"><INPUT type=radio disabled></td>';

					//content = content + '<td align="center"><img border="0" src="' + URLtoImages + 'checkbox_dim.gif" width="13" height="13"></td>';
					//content = content + '<td align="center"><img border="0" src="' + URLtoImages + 'radio_dim.gif" width="13" height="13"></td>';
					content = content + '<td><font class=SearchForm2>' + LayerName[i] + '</font><font class=Asterisk>*</font></td>';
					content = content + '</tr>';
				}
			}
			}
		}

		content += '    <tr bgcolor="#FFFFFF"><td COLSPAN="3">&nbsp;</td></tr>'

		if (ShowAsterisk) {
			content += '<tr bgcolor="#FFFFFF">'
			content += '<td COLSPAN="3" align="left" valign="top">'
			content += '</font><font class=Asterisk>&nbsp;&nbsp;*</font></font>&nbsp;<font class=SearchForm2>Scale too large to show. Use </font><img src="images/zoomin_Icon.gif" border="0" alt="Close form"><font class=SearchForm2> to view.</font>'
			content += '</td>'
			content += '</tr>'
			
		}

		if (ShowHealthDisclaimer1) {
			content += '<tr bgcolor="#FFFFFF">'
			content += '<td COLSPAN="3" align="left" valign="top">'
			content += '</font><font class=Superscript>&nbsp;&nbsp;<sup>(1)</sup></font>&nbsp;<font class=SearchForm2>Source:Health Council of South Florida</font>'
			content += '</td>'
			content += '</tr>'
			content += '<tr bgcolor="#FFFFFF">'
			content += '<td COLSPAN="3" align="left" valign="top">'
			content += '</font><font class=Superscript>&nbsp;&nbsp;<sup>(2)</sup></font>&nbsp;<font class=SearchForm2>Source:Miami-Dade County Health Department, 2007</font>'
			content += '</td>'
			content += '</tr>'
		}
		
		if (ShowHealthDisclaimer2) {	
			content += '<tr bgcolor="#FFFFFF">'
			content += '<td COLSPAN="3" align="left" valign="top">'
			content += '</font><font class=Superscript>&nbsp;&nbsp;<sup>(1)</sup></font>&nbsp;<font class=SearchForm2>Source:Florida Agency for Healthcare Administration</font>'
			content += '</td>'
			content += '</tr>'
			content += '<tr bgcolor="#FFFFFF">'
			content += '<td COLSPAN="3" align="left" valign="top">'
			content += '</font><font class=Superscript>&nbsp;&nbsp;<sup>(2)</sup></font>&nbsp;<font class=SearchForm2>Source:Florida Health Insurance Study, 2004</font>'
			content += '</td>'
			content += '</tr>'
			content += '<tr bgcolor="#FFFFFF">'
			content += '<td COLSPAN="3" align="left" valign="top">'
			content += '</font><font class=Superscript>&nbsp;&nbsp;<sup>(3)</sup></font>&nbsp;<font class=SearchForm2>Source:Florida Department of Health, Vital Statistics, 2006</font>'
			content += '</td>'
			content += '</tr>'
		}

		content = content + '</TABLE>';
		content = content + '</TD>';
		content = content + '	</TR>';
		content = content + '</TABLE>';
		content = content + '</FORM>';

		return content;

}

////////////////////////////////////////	SET UNITS FORM	/////////////////////////////////////////////////////

//var ScaleBarUnits = "FEET";
//var MapUnits = "METERS";

function cancelClick() {
	if (toolMode == 20) {
		updateMeasureBox();
	} 
	hideLayer("GenericForm")
}

function setDUnits() {
	var theForm = document.getElementById('frmMeasure');
	var TempScaleBarUnits = ScaleBarUnits;
	var i = theForm.newDUnits.selectedIndex;
	var k =  theForm.newDUnits.options[i].value;
	var m = "FEET";
	ScaleBarUnits = k;
	if (setMapUnits) {
		i = theForm.newMUnits.selectedIndex;
		m =  theForm.newMUnits.options[i].value;
		MapUnits = m;
	}
	//theForm.cDisplayUnits.value = k;
			
	if (toolMode == 20) {
		//resetClick();
		var tDist = convertUnits_setDUnits(totalMeasure,TempScaleBarUnits,k);
		totalMeasure = tDist;
		//alert(totalMeasure);
		tDist = convertUnits_setDUnits(currentMeasure,TempScaleBarUnits,k);
		currentMeasure = tDist;
		updateMeasureBox();
		if (drawScaleBar) sendMapXML();
	} else {
		//writeOptionForm();
		if (drawScaleBar) sendMapXML();
	}
}

function convertUnits_setDUnits(oldTotal,oldUnits,newUnits) {
	// no decimal numbers hardcoded so that this can be used
	// by locales that use comma instead of point

	var newTotal=0;
	if (oldUnits=="FEET") {
		//FEET
		if (newUnits=="MILES") {
			newTotal = oldTotal / 5280;
		} else if (newUnits=="METERS") {
			newTotal = oldTotal * (3048/10000);
		} else if (newUnits=="KILOMETERS") {
			newTotal = oldTotal * (3048/10000000);
		}
				
	} else if (oldUnits=="MILES") {
		//MILES
		if (newUnits=="FEET") {
			newTotal = oldTotal * 5280;
		} else if (newUnits=="METERS") {
			newTotal = oldTotal * (1609344/1000);
		} else if (newUnits=="KILOMETERS") {
			newTotal = oldTotal * (1609344/1000000);
		}
				
	} else if (oldUnits=="METERS") {
		//METERS
		if (newUnits=="FEET") {
			newTotal = oldTotal * (3280839895/1000000000);
		} else if (newUnits=="MILES") {
			newTotal = oldTotal * (6213711922/10000000000000);
		} else if (newUnits=="KILOMETERS") {
			newTotal = oldTotal / 1000;
		}
				
	} else {
		//KILOMETERS
		if (newUnits=="FEET") {
			newTotal = oldTotal * (3280839885/1000000);
		} else if (newUnits=="METERS") {
			newTotal = oldTotal * 1000;
		} else if (newUnits=="MILES") {
			newTotal = oldTotal * (6213711922/10000000000);
		}
				
				
	}
	var u = Math.pow(10,numDecimals);
	//if (u>0) 
		newTotal = parseInt(newTotal*u+(5/10))/u;

	return newTotal;
}

function writeSetUnitsForm() {
		var content
		content = '';
		var content1
		content1 = '';
		
		var f = document.Measure;
		
		content1 = content1 + '<TABLE BORDER=0 CELLSPACING="0" NOWRAP BGCOLOR="#EEEEEE" bordercolor="#666666" WIDTH=100%>';

		content1 = content1 + '<TR><TD align=left><img src="images/post2.gif" border="0" alt="Back to main menu.">&nbsp;&nbsp;<a href="javascript:setForm(&quot;MAINMENU&quot;);">Go back to main menu</a></TD></TR>';
		content1 = content1 + '</TABLE>';

		content = content + '<FORM ACTION="" ID="frmMeasure" NAME="frmMeasure">';
		content = content + '<TABLE BORDER=0 CELLSPACING="0" NOWRAP BGCOLOR="#FFFFFF" bordercolor="#666666" WIDTH=100%>';


		content = content + '<TR><TD>';
		content = content + '<TABLE BORDER=0 CELLSPACING="4" CELLPADDING="1" NOWRAP BGCOLOR="#FFFFFF" WIDTH=100%>';

		//content = content + '<TR>';
		//content = content + '<TH COLSPAN="2" ALIGN="LEFT">';
		//content = content + '<FONT class=SearchForm3><B>' + buttonList[32] + '</B></FONT>';
		//content = content + '</TH>';
		//content = content + '</TR>';

		content = content + '<TR>';
		content = content + '<TD>';
		content = content + '<FONT class=SearchForm1>' + titleList[16] + '</FONT>';
		content = content + '</TD>';

		content = content + '<TD>';
						
		var f = document.Measure;
		//document.writeln(parent.MapFrame.ScaleBarUnits);
		content = content + '<select class=select name="newDUnits">';
							
		content = content + '<option value="FEET"';
		if (ScaleBarUnits=="FEET") content = content + ' selected';
		content = content + '>' + unitList[1];
							
		content = content + '<option value="MILES"';
		if (ScaleBarUnits=="MILES") content = content + ' selected';
		content = content + '>' + unitList[2];
							
		content = content + '<option value="METERS"';
		if (ScaleBarUnits=="METERS") content = content + ' selected';
		content = content + '>' + unitList[3];
							
		content = content + '<option value="KILOMETERS"';
		if (ScaleBarUnits=="KILOMETERS") content = content + ' selected';
		content = content + '>' + unitList[4];
							
		content = content + '</select>';
						
		content = content + '</TD>';
		content = content + '	</TR>';

		content = content + '	<TR align=center>';
		content = content + '<TD>';
		content = content + '	<a href="javascript:setDUnits()"><img src="images/setunits_button.gif" border="0" alt="Set Units"></a>';   
		content = content + '</TD>';
		content = content + '<TD>';
		content = content + '	&nbsp;&nbsp;';
		content = content + '	<a href="javascript:cancelClick();setForm(&quot;MAINMENU&quot;);"><img src="images/cancel_button.gif" border="0" alt="Cancel Set Units"></a>';   
		content = content + '	&nbsp;&nbsp;';
		content = content + '</TD>';
		content = content + '	</TR>';
		content = content + '</TABLE>';
		content = content + '</TD>';
		content = content + '	</TR>';
		
		content = content + '</TABLE>';
		content = content + '</FORM>';
		
		content = DoRoundTable_Blue(210, 10, "Set Units", content);
		
		content = content1 + content;
		return content;
}

////////////////////////////////////////	GEOCODING AUXILIARY FORM	/////////////////////////////////////////////////////

function GetStrDir() {
	var content = '';
	content += '		<option value="" selected> &lt;none&gt;</option>'
	content += '		<option value="E">E</option>'
	content += '		<option value="N">N</option>'
	content += '		<option value="NE">NE</option>'
	content += '		<option value="NW">NW</option>'
	content += '		<option value="S">S</option>'
	content += '		<option value="SE">SE</option>'
	content += '		<option value="SW">SW</option>'
	content += '		<option value="W">W</option>'
	return content;
}	

function GetStrType() {
	var content = '';
	content += '		<option value="" selected> &lt;none&gt;</option>'
	content += '		<option value="AVE">AVE</option>'
	content += '		<option value="AVE CIR">AVE CIR</option>'
	content += '		<option value="AVE CT">AVE CT</option>'
	content += '		<option value="AVE DR">AVE DR</option>'
	content += '		<option value="AVE PL">AVE PL</option>'
	content += '		<option value="AVE RD">AVE RD</option>'
	content += '		<option value="BLVD">BLVD</option>'
	content += '		<option value="BES">BES</option>'
	content += '		<option value="CT">CT</option>'
	content += '		<option value="CIR">CIR</option>'
	content += '		<option value="CIR CT">CIR CT</option>'
	content += '		<option value="CIR DR">CIR DR</option>'
	content += '		<option value="CIR LN">CIR LN</option>'
	content += '		<option value="CIR PL">CIR PL</option>'
	content += '		<option value="CIR TER">CIR TER</option>'
	content += '		<option value="CONC">CONC</option>'
	content += '		<option value="CSWY">CSWY</option>'
	content += '		<option value="CT BLVD">CT BLVD</option>'
	content += '		<option value="CT CIR">CT CIR</option>'
	content += '		<option value="CT DR">CT DR</option>'
	content += '		<option value="DR">DR</option>'
	content += '		<option value="DR CIR">DR CIR</option>'
	content += '		<option value="HWY">HWY</option>'
	content += '		<option value="IS">IS</option>'
	content += '		<option value="IS RD">IS RD</option>'
	content += '		<option value="LN">LN</option>'
	content += '		<option value="LN CIR">LN CIR</option>'
	content += '		<option value="LN DR">LN DR</option>'
	content += '		<option value="LN RD">LN RD</option>'
	content += '		<option value="MILE">MILE</option>'
	content += '		<option value="PATH">PATH</option>'
	content += '		<option value="PKY">PKY</option>'
	content += '		<option value="PL">PL</option>'
	content += '		<option value="PL CIR">PL CIR</option>'
	content += '		<option value="PL RD">PL RD</option>'
	content += '		<option value="PL WAY">PL WAY</option>'
	content += '		<option value="PLZ">PLZ</option>'
	content += '		<option value="PSGE">PSGE</option>'
	content += '		<option value="PT">PT</option>'
	content += '		<option value="PT DR">PT DR</option>'
	content += '		<option value="RD">RD</option>'
	content += '		<option value="RD DR">RD DR</option>'
	content += '		<option value="RD PL">RD PL</option>'
	content += '		<option value="ST">ST</option>'
	content += '		<option value="ST CIR">ST CIR</option>'
	content += '		<option value="ST CSWY">ST CSWY</option>'
	content += '		<option value="ST CT">ST CT</option>'
	content += '		<option value="ST DR">ST DR</option>'
	content += '		<option value="ST PL">ST PL</option>'
	content += '		<option value="ST RD">ST RD</option>'
	content += '		<option value="SQ">SQ</option>'
	content += '		<option value="TER">TER</option>'
	content += '		<option value="TER CIR">TER CIR</option>'
	content += '		<option value="TER DR">TER DR</option>'
	content += '		<option value="TER RD">TER RD</option>'
	content += '		<option value="TER WAY">TER WAY</option>'
	content += '		<option value="TRL">TRL</option>'
	content += '		<option value="WAY">WAY</option>'
	return content;
}	

////////////////////////////////////////	ADDRESS FORM	/////////////////////////////////////////////////////

function sendQuery() {
	var theForm = document.getElementById('frmAddr');

	var HN = theForm.sHN1.value;
	var Dir = theForm.sDir1.options[theForm.sDir1.options.selectedIndex].value;
	var StN = theForm.sStN1.value;
	var StT = theForm.sStT1.options[theForm.sStT1.options.selectedIndex].value;
	var ZC = theForm.sZC1.value;
	
	var add1 = HN + " " + Dir + " " + StN + " " + StT;
	var Zone = ZC;

	if((HN == "")||(StN == "")){
		alert("Please enter a street number and name.");
	} else {
		hideLayer("GenericForm");
		showRetrieveData();		

		GCvalue[0] = add1;
		GCvalue[1] = Zone;
		GCvalue[2] = "";
		var theText = writeGeocodeXML();
		sendToServer(imsGeocodeURL,theText,27);
	}
}

function writeAddressForm(theRowID,theImg) {
	HoverFlag=true;
	prevRowID = theRowID;
	prevImgID = theImg;

	var content = '';

	content += '<FORM ACTION="javascript:doAddrSearch()" ID="frmAddr" name="frmAddr" onsubmit="javascript:doAddrSearch()" onMouseover="onMouseoverMenu(&quot;' + theRowID + '&quot;,&quot;' + theImg + '&quot;);">';
	content += '<table width="200" border="1" cellspacing="0" cellpadding="0" bordercolor="#0099cc">';
	content += '<tr>';
	content += '<td>';

	content += '  <table width="200" border="0" cellspacing="0" cellpadding="0">'

	content = content + '<TR bgcolor="#FFFFFF"><td COLSPAN="3">';
	content = content + '<TABLE BORDER="0" bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="0" NOWRAP WIDTH=100%>';
	content = content + '<TR>';
	content = content + '<TD NOWRAP ALIGN="LEFT">';
	content = content + '<img src="images/arrow_open.gif" border="0">&nbsp;';
	content = content + '<FONT class=SearchForm3><B>Address Search:</B></FONT>'
	content = content + '</TD>';

	content = content + '<td align="right" valign="top">';
	content = content + '<a href="javascript:doClosePopoutLayers()"><img src="images/winclose.gif" border="0" alt="Close form"></a>';
	content = content + '</td>';

	content = content + '</TR>';
	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '</TR>';

	content += '<tr bgcolor="#FFFFFF">'
	content += '<td align="left" valign="top" width="5">&nbsp;</td>'
	content += '<td colspan="2" align="left" valign="top">'
	content += '<font class="SearchForm2">Enter the address and click Locate. Use the Tab key to switch between fields or click using the mouse.</font>'
	content += '</td>'
	content += '</tr>'

	content += '    <tr bgcolor="#FFFFFF"><td colspan="3">&nbsp;</td></tr>'

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">House Number:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '	  <font class="input1"><input class="input1" name="sHN1" size="12"></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Direction:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '		<font class="select"><select class="select" name="sDir1" size="1">'
	content +=	GetStrDir();
	content += '		</select></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Street Name:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '	  <font class="input1"><input class="input1" name="sStN1" size="12"></font>'
	content += '      </td>'
	content += '    </tr>'

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Street Type:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '			<font class="select"><select class="select" name="sStT1" size="1">'
	content +=	GetStrType()
	content += '			</select></font>'
	content += '      </td>'
	content += '    </tr>'

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Zip Code (opt):</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '	  <font class="input1"><input class="input1" name="sZC1" size="5" maxlength="5"></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td colspan="3" align="center" valign="top">'
//	content += '	  <a href="javascript:doAddrSearch()" onmouseover="swap(document.LocateAddr.name,\'locate_2\');" onmouseout="swap(document.LocateAddr.name,\'locate_1\')"><img src="images/locate_1.gif" border="0" name="LocateAddr"></a>'
	content += '	  <a href="javascript:doClosePopoutLayers();sendQuery()"><img src="images/locate_button.gif" border="0" alt="Locate Address"></a>'
	content += '      </td>'
	content += '    </tr>'
	content += '  </table>'
	
	content += '</td>'
	content += '</tr>'
	content += '  </table>'

	content += '</form>'
	return content;
}

// do intersection search
function doInterSearch(){
	var theForm = document.getElementById('frmInter');

	var Dir1 = theForm.STDIR1.options[theForm.STDIR1.options.selectedIndex].value;
	var StN1 = theForm.STNAME1.value;
	var StT1 = theForm.STTYPE1.options[theForm.STTYPE1.options.selectedIndex].value;

	var Dir2 = theForm.STDIR2.options[theForm.STDIR2.options.selectedIndex].value;
	var StN2 = theForm.STNAME2.value;
	var StT2 = theForm.STTYPE2.options[theForm.STTYPE2.options.selectedIndex].value;

	if((StN1 == "")||(StN2 == "")){
		alert("Please enter a street name.");
	} else {
		hideLayer("GenericForm");
		showRetrieveData();		

		GCvalue[0] = Dir1 + " " + StN1 + " " + StT1;
		GCvalue[1] = "";
		GCvalue[2] = Dir2 + " " + StN2 + " " + StT2;
		var theText = writeGeocodeXML();
		sendToServer(imsGeocodeURL,theText,27);
	}
}

// write intersection form content
function writeIntersectionForm(theRowID,theImg) {
	HoverFlag=true;
	prevRowID = theRowID;
	prevImgID = theImg;

	var content = '';

	content += '<FORM ACTION="javascript:doInterSearch()" ID="frmInter" name="frmInter" onsubmit="javascript:doInterSearch()" onMouseover="onMouseoverMenu(&quot;' + theRowID + '&quot;,&quot;' + theImg + '&quot;);">';
	content += '<table width="200" border="1" cellspacing="0" cellpadding="0" bordercolor="#0099cc">'
	content += '<tr>'
	content += '<td>'

	content += '  <table width="200" border="0" cellspacing="0" cellpadding="2">'

	content = content + '<TR bgcolor="#FFFFFF"><td COLSPAN="3">';
	content = content + '<TABLE BORDER="0" bgcolor="#FFFFFF" CELLSPACING="0" CELLPADDING="0" NOWRAP WIDTH=100%>';
	content = content + '<TR>';
	content = content + '<TD NOWRAP ALIGN="LEFT">';
	content = content + '<img src="images/arrow_open.gif" border="0">&nbsp;';
	content = content + '<FONT class=SearchForm3><B>Intersection Search:</B></FONT>'
	content = content + '</TD>';
	content = content + '<td align="right" valign="top">';
	content = content + '<a href="javascript:doClosePopoutLayers()"><img src="images/winclose.gif" border="0" alt="Close form"></a>';
	content = content + '</td>';
	content = content + '</TR>';
	content = content + '</TABLE>';
	content = content + '</TD>';
	content = content + '</TR>';

	content += '<tr bgcolor="#FFFFFF">'
	content += '<td align="left" valign="top" width="5">&nbsp;</td>'
	content += '<td colspan="2" align="left" valign="top">'
	content += '<font class="SearchForm2">Enter the intersection and click Locate. Use the Tab key to switch between fields or click using the mouse.</font>'
	content += '</td>'
	content += '</tr>'

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td colspan="2" align="left" valign="top">'
	content += '	  <font class="SearchForm2"><b>Street 1</b></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Direction:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '		<font class="select"><select class="select" name="STDIR1" size="1">'
	content +=	GetStrDir();
	content += '		</select></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Street Name:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '	  <font class="input1"><input class="input1" name="STNAME1" size="12"></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Street Type:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '			<font class="select"><select class="select" name="STTYPE1" size="1">'
	content +=	GetStrType()
	content += '			</select></font>'
	content += '      </td>'
	content += '    </tr>'

// ******* Type 2 ********

	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td colspan="2" align="left" valign="top">'
	content += '	  <font class="SearchForm2"><b>Street 2</b></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Direction:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '		<font class="select"><select class="select" name="STDIR2" size="1">'
	content +=	GetStrDir();
	content += '		</select></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Street Name:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '	  <font class="input1"><input class="input1" name="STNAME2" size="12"></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td align="left" valign="top" width="5">&nbsp;</td>'
	content += '      <td align="left" valign="top" NOWRAP>'
	content += '	  <font class="SearchForm0">Street Type:</font>'
	content += '      </td>'
	content += '      <td align="left" valign="top">'
	content += '			<font class="select"><select class="select" name="STTYPE2" size="1">'
	content +=	GetStrType()
	content += '			</select></font>'
	content += '      </td>'
	content += '    </tr>'
	
	content += '    <tr bgcolor="#FFFFFF">'
	content += '      <td colspan="3" align="center" valign="top">'
	content += '	  <a href="javascript:doClosePopoutLayers();doInterSearch()"><img src="images/locate_button.gif" border="0" alt="Locate Intersection"></a>'
	content += '      </td>'
	content += '    </tr>'
	content += '  </table>'
	
	content += '</td>'
	content += '</tr>'
	content += '  </table>'
	
	content += '</form>'
	return content;
}

var unself
function timer(offon,theLayer,theRowID,theImg)  {
	if (offon == 0)	{
		unself = setTimeout('ShowCategory("' + theLayer + '","' + theRowID + '","' + theImg + '")', 400);
	}
	if (offon ==1)	{
		clearTimeout(unself);
	}
}

function selected(oRow){ oRow.style.backgroundColor= '#D3D3D3'; } 


function deselected(oRow){ 
var rowId
var acolor

rowId = oRow.id
rowId = rowId.substring(3)

if (rowId % 2 == 0 ) {
	acolor= '#E5FFFF'
} else {
	acolor= '#FFFFFF'
}
oRow.style.backgroundColor= acolor;
} 


function myOnClick(theImg,theLayer,theoRow)  {
//	HoverFlag=true;
	swapimg(1,theImg);
	selected(theoRow);
//	ShowCategory(theLayer);
	timer(1,'dummy','dummy','dummy');
	timer(0,theLayer,theoRow.id,theImg.name)
}

function myOnMouseOver(theImg,theLayer,theoRow)  {
	deselectRow(prevImgID,prevRowID);
	deselectRow(curImgID,curRowID);
	curRowID = theoRow.id;
	curImgID = theImg.id;

	swapimg(1,theImg);
	selected(theoRow);
//	ShowCategory(theLayer);
	timer(1,'dummy','dummy','dummy');
	timer(0,theLayer,theoRow.id,theImg.name)
}

function myOnMouseOut(theImg,theoRow)  {
	return
	deselected(theoRow);
	swapimg(2,theImg);
}

function deselectRow(prevImgID,prevRowID)  {
	if (prevRowID) {
		theTable=document.getElementById('MainMenu');
		thePrevRow=eval("document.getElementById('"+prevRowID+"')");
		thePrevImg=eval("document.getElementById('"+prevImgID+"')");

		swapimg(2,thePrevImg);
		deselected(thePrevRow);
	}
}

function selectRow(theRowID,theImgID) {
	if (theRowID || theImgID) {
		theTable=document.getElementById('MainMenu');
		theRow=eval("document.getElementById('"+theRowID+"')");
		theImg=eval("document.getElementById('"+theImgID+"')");

		swapimg(1,theImg);
		selected(theRow)
	}
}

var prevRowID;
var prevImgID;

var curRowID;
var curImgID;

function onMouseoutMMenu()  {
	selectRow(prevRowID,prevImgID);
}

function onMouseoverMenu(theRowID,theImgID)  {
	timer(1,'dummy','dummy','dummy');

	deselectRow(curImgID,curRowID);
	curRowID = theRowID;
	curImgID = theImgID;

	selectRow(theRowID,theImgID);
}


// write MainMenu
function WriteMainMenuForm() {
	var colHeight = 18;
	var theWidth = 200;

	var content = ''
	var content1 = ''
//	content += '<form name="frmMainMenu" onMouseOut="javascript:if (HoverFlag) {clearTimeout(unself);selectRow(prevRowID, prevImgID);}"><div class="TableFt1">'
//	content += '<form name="frmMainMenu" onMouseOut="javascript:if (HoverFlag) {clearTimeout(unself);hideLayer(&quot;GenericForm&quot;);deselectRow(prevImgID,prevRowID);HoverFlag=false;}"><div class="TableFt1">'
	content += '<form name="frmMainMenu">'
	
	content += '<div class="TableFt1">'
	content += '<table class="TableFt1" width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" bordercolor="#666666">'
	
	//content += '<form name="frmMainMenu">'
	content += '<tr>'
	content += '<td><div class="TableFt1">'

	content += '<table ID="MainMenu" class="TableFt1" width="100%" align="left" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0">'

	//content += '<tr>'
	//content += '<td nowrap=true height=20 colspan="2" align="left" valign="top">&nbsp;&nbsp;<img src="images/mapicon.gif" width="16" height="16" border="0"><font class="LayerReport2"><b>&nbsp;&nbsp;GIS Layers</b></font></td>'
	//content += '</tr>'

	for (var i=1;i<CategoryList.length;i++) {
		if (i % 2 == 0 ) {
			acolor= '#E5FFFF'
		} else {
			acolor= '#FFFFFF'
		}
		//C.Sibori (07/2008) - if linking from OCHP portal page, show only heatlh themes 
		if (showHealth == 1){
			if (CategoryList[i] == 'Health and Human Services' || CategoryList[i] == 'Health Statistics'){
				content += '<tr bgcolor="' + acolor + '" ID="row' + i + '" onClick="myOnClick(' + 'arrow_' + i + ',' + i + ',this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(' + 'arrow_' + i + ',' + i + ',this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(' + 'arrow_' + i + ',this);}">'
				content += '<td width="170" height=18 nowrap=true align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">' + CategoryList[i] + '</font></a></td>'
				content += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="' + 'arrow_' + i + '" name="' + 'arrow_' + i + '" src="images/transparent.gif" width="6" height="12" border="0"></td>'
				content += '</TR>'
			}
		}else{
			content += '<tr bgcolor="' + acolor + '" ID="row' + i + '" onClick="myOnClick(' + 'arrow_' + i + ',' + i + ',this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(' + 'arrow_' + i + ',' + i + ',this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(' + 'arrow_' + i + ',this);}">'
			//content += '<tr ID="row' + i + '" onClick="myOnClick(' + 'arrow_' + i + ',' + i + ',this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(' + 'arrow_' + i + ',' + i + ',this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(' + 'arrow_' + i + ',this);}">'
			content += '<td width="170" height=18 nowrap=true align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">' + CategoryList[i] + '</font></a></td>'
			content += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="' + 'arrow_' + i + '" name="' + 'arrow_' + i + '" src="images/transparent.gif" width="6" height="12" border="0"></td>'
			content += '</TR>'
		}
	}

	content += '<tr bgcolor="#FFFFFF">'
	content += '<td COLSPAN="2" align="center" valign="top">'
	content += '<table class="TableFt1" width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" bordercolor="#666666">'

//	content += '<tr onMouseover="javascript:if (HoverFlag) {clearTimeout(unself);hideLayer(&quot;GenericForm&quot;);deselectRow(prevImgID,prevRowID);}" bgcolor="#FFF2D7">'
	content += '<tr bgcolor="#FFFFFF">'
	content += '<td align="center" valign="top">'
	
	//MAIRIM: Removing refresh button from main form
	//content += '<A href="javascript:doUpdateLayers();"><img style="BORDER-COLOR: #FFFFFF" src="images/button-refreshmap.gif" border="1"></a>';
	content += '</td>'
	content += '</tr>'
	content += '</table>'
	content += '</td>'
	content += '</tr>'
	
	//test this code does not belong here
	
	content += '</table>'

	content += '</div></td>'
	content += '</tr>'
	
	//content += '</form>'
	content += '</table>'
	content += '</div>'
	content += '</form>'
	
	
	content = DoRoundTable_Blue(theWidth, 10, "Themes", content)
	
	content1 += '<form name="frmMainMenu">'
	content1 = '<div class="TableFt1">'
//	content1 += '<table class="TableFt1" width="' + theWidth + '" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" bordercolor="#666666">'
	content1 += '<table class="TableFt1" width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" bordercolor="#666666">'
	//content1 += '<form name="frmMainMenu">'
		
	content1 += '<tr>'
	content1 += '<td><div class="TableFt1">'

	content1 += '<table ID="MainMenu" class="TableFt1" width="100%" align="left" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0">'




	// FIND LOCATION

	//content1 += '<tr>'
	//content1 += '<td nowrap=true height=20 colspan="2" align="left" valign="top">&nbsp;<img src="images/geocode.gif" width="16" height="16" border="0"><font class="LayerReport2"><b>&nbsp;&nbsp;Find Location</b></font></td>'
	//content1 += '</tr>'

	content1 += '<tr bgcolor="#FFFFFF" ID="row91" onClick="myOnClick(arrow_add,&quot;ADDRESS&quot;,this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(arrow_add,&quot;ADDRESS&quot;,this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(arrow_add,this);}">'
	content1 += '<td width="170" nowrap=true height="' + colHeight + '" align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">Address</font></a></td>'
	content1 += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="arrow_add" name="arrow_add" src="images/transparent.gif" width="6" height="12" border="0"></td>'
	content1 += '</TR>'

	content1 += '<tr bgcolor="#E5FFFF" ID="row92" onClick="myOnClick(arrow_int,&quot;INTERSECTION&quot;,this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(arrow_int,&quot;INTERSECTION&quot;,this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(arrow_int,this);}">'
	content1 += '<td width="170" nowrap=true height="' + colHeight + '" align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">Intersection</font></a></td>'
	content1 += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="arrow_int" name="arrow_int" src="images/transparent.gif" width="6" height="12" border="0"></td>'
	content1 += '</TR>'

	content1 += '<tr bgcolor="#FFFFFF" ID="row93" onClick="myOnClick(arrow_sch,&quot;SCHOOLS&quot;,this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(arrow_sch,&quot;SCHOOLS&quot;,this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(arrow_sch,this);}">'
	content1 += '<td width="170" nowrap=true height="' + colHeight + '" align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">School</font></a></td>'
	content1 += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="arrow_sch" name="arrow_sch" src="images/transparent.gif" width="6" height="12" border="0"></td>'
	content1 += '</TR>'

	content1 += '<tr bgcolor="#E5FFFF" ID="row94" onClick="myOnClick(arrow_lan,&quot;LANDMARK&quot;,this);;" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(arrow_lan,&quot;LANDMARK&quot;,this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(arrow_lan,this);}">'
	content1 += '<td width="170" nowrap=true height="' + colHeight + '" align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">Landmark</font></a></td>'
	content1 += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="arrow_lan" name="arrow_lan" src="images/transparent.gif" width="6" height="12" border="0"></td>'
	content1 += '</TR>'

	content1 += '<tr bgcolor="#FFFFFF" ID="row95" onClick="myOnClick(arrow_fol,&quot;FOLIO&quot;,this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(arrow_fol,&quot;FOLIO&quot;,this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(arrow_fol,this);}">'
	content1 += '<td width="170" nowrap=true height="' + colHeight + '" align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">Folio</font></a></td>'
	content1 += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="arrow_fol" name="arrow_fol" src="images/transparent.gif" width="6" height="12" border="0"></td>'
	content1 += '</TR>'

	content1 += '<tr bgcolor="#E5FFFF" ID="row96" onClick="myOnClick(arrow_sec,&quot;SECTION&quot;,this);" onMouseover="javascript:if (HoverFlag) {myOnMouseOver(arrow_sec,&quot;SECTION&quot;,this);}" onMouseOut="javascript:if (HoverFlag) {myOnMouseOut(arrow_sec,this);}">'
	content1 += '<td width="170" nowrap=true height="' + colHeight + '" align="left" valign="middle">&nbsp;&nbsp;&nbsp;<a href="#" onClick="return false"><font class="MenuLinks">Section</font></a></td>'
	content1 += '<td width="30" height="' + colHeight + '" align="left" valign="bottom">&nbsp;<img ID="arrow_sec" name="arrow_sec" src="images/transparent.gif" width="6" height="12" border="0"></td>'
	content1 += '</TR>'

	content1 += '</table>'

	content1 += '</div></td>'
	content1 += '</tr>'
	//content1 += '</form>'
	content1 += '</table>'
	content1 += '</div>'
	content1 += '</form>'
	
    	content1 = DoRoundTable_Blue(theWidth, 10, "Find", content1)

	content = content + "<BR>" + content1


	return content;
}

// 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_images() {
	preload();
}

//MISHRAM - Updated for Health and Human Services - logging the layer names from this theme only
function WritetoLogFile(layname) {
	if (layname != "")
		{
			var url;
			url = "WriteLog.asp?LayerName=" + layname;
				
			var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
            request.open("POST", url, true);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.onreadystatechange = function(){
	        if(request.readyState==4)
                 {      	            
                 }
                      };
                request.send(null);
       }
}

// Decide browser version
//var ie4 = document.all && !document.getElementById;
//var ie5 = document.all && document.getElementById;
//var ns6 = !document.all && document.getElementById;
//var ns4 = document.layers;

