/**************************************************************************************************
*                                                                        VARIABLE DECLARATIONS                                                                        *
**************************************************************************************************/

var SLFieldNames = new Array(), SLFieldDisplays = new Array(), LLFieldNames = new Array(), 
	LLFieldDisplays = new Array(), LinkFields = new Array(), LinkPrefixs = new Array(), 
	LinkSuffixs = new Array(), LinkTexts = new Array(), LinkImages = new Array(), sModSequence = new 
	Array(), iRowSequence = new Array(), Query_SelUID = new Array(), iSelectedRows = new Array(), timer, 
	header = top.headerframe, info = top.infoframe, mapframe = top.mapframe, QueryExtent, QueryRecs, 
	Query_SelMid, Query_SelExtent, LastSetTop, sTLAssrNum = new Array(), sTLMap = new Array(), sTLMapTwnshp = new 
	Array(), sTLMapRange = new Array(), sTLMapRDir = new Array(), sTLMapSect = new Array(), sTLMapQSect = new 
	Array(), sTLMapSSect = new Array(), bCloseFooter = false;

if (window.ActiveXObject) var sClass = "className"; else var sClass = "class";
	
var RXML_Row = -1;  // the selected row of resultsxml
var RXML_Recs = 0;   // number of records in resultsxml
var RXML_Highlight = -1; // the last highlighted row of the resultsxml
var RTab_Row = -1;  // the selected row of the XSL Table
var RTab_Highlight = -1;  // the last highlighted row of the XSL Table
var MapToggle = "none";  // the current toggle state

var MapSel_Image = new Image();         MapSel_Image.src = "../images/high.png";
var MapSel_SelImage = new Image();      MapSel_SelImage.src = "../images/highSel.png";
var PanSel_Image = new Image();         PanSel_Image.src = "../images/highPan.png";
var PanSel_SelImage = new Image();      PanSel_SelImage.src = "../images/highPanSel.png";
var ZoomSel_Image = new Image();        ZoomSel_Image.src = "../images/highZoom.png";
var ZoomSel_SelImage = new Image();     ZoomSel_SelImage.src = "../images/highZoomSel.png";
var CloseFoot_Image = new Image();      CloseFoot_Image.src = "../images/closeBut.png";
var CloseFoot_SelImage = new Image();   CloseFoot_SelImage.src = "../images/closeButSel.png";
var ClearSel_Image = new Image();       ClearSel_Image.src = "../images/clear.png";
var ClearSel_SelImage = new Image();    ClearSel_SelImage.src = "../images/clearSel.png";
var MapAll_Image = new Image();         MapAll_Image.src = "../images/zoomFull.png";
var MapAll_SelImage = new Image();      MapAll_SelImage.src = "../images/zoomFullSel.png";
var GoFirst_Image = new Image();        GoFirst_Image.src = "../images/goToFirst.png";
var GoFirst_SelImage = new Image();     GoFirst_SelImage.src = "../images/goToFirstSel.png";
var GoPrevious_Image = new Image();     GoPrevious_Image.src = "../images/goToPrevious.png";
var GoPrevious_SelImage = new Image();  GoPrevious_SelImage.src = "../images/goToPreviousSel.png";
var GoNext_Image = new Image();         GoNext_Image.src = "../images/goToNext.png";
var GoNext_SelImage = new Image();      GoNext_SelImage.src = "../images/goToNextSel.png";
var GoLast_Image = new Image();         GoLast_Image.src = "../images/goToLast.png";
var GoLast_SelImage = new Image();      GoLast_SelImage.src = "../images/goToLastSel.png";



/**************************************************************************************************
*                                                                      ONLOAD EVENT HANDLER                                                                            *
**************************************************************************************************/

function OnLoad()
{
	RegisterEvents();
	ScrollTop();
}



/**************************************************************************************************
*                                                            EVENT HANDLERS (ALPHABETIZED)                                                                    *
**************************************************************************************************/

function ClearSel_Button_MOUSEDOWN() { document.getElementById('ClearSel_Button').setAttribute('src', ClearSel_SelImage.src); }

function ClearSel_Button_MOUSEOUT() { document.getElementById('ClearSel_Button').setAttribute('src', ClearSel_Image.src); }

function ClearSel_Button_MOUSEUP()
{
	document.getElementById('ClearSel_Button').setAttribute('src', ClearSel_Image.src);
	MapIt_Submit("none");
}

function CloseFoot_Button_MOUSEDOWN() { document.getElementById('CloseFoot_Button').setAttribute('src', CloseFoot_SelImage.src); }

function CloseFoot_Button_MOUSEOUT() { document.getElementById('CloseFoot_Button').setAttribute('src', CloseFoot_Image.src); }

function CloseFoot_Button_MOUSEUP()
{
	document.getElementById('CloseFoot_Button').setAttribute('src', CloseFoot_Image.src);
	RTable_Close();
}

function Footer_CLICK(e)
{
	if (!e) var e = window.event;
	
	var oTarget = (e.target) ? e.target : e.srcElement;
	theid = oTarget.id;
	
	if (theid.substring(0,4) == "tRow")
	{
		theRowIndex = theid.substring(4);
		RTable_Click(e,theRowIndex);
	}
}

function Footer_MOUSEOUT(e)
{
	if (!e) var e = window.event;
	var oTarget = (e.target) ? e.target : e.srcElement;
	
	if (oTarget.id != "")
	{
		theSrcE = document.getElementById(oTarget.id);
		theSrc = theSrcE.id;
		thePos = theSrc.indexOf("_");
		
		if (thePos != -1)
		{
			theBase = theSrc.substr(0,thePos);
			HeadE = document.getElementById(theBase + "_Header");
			if (HeadE != null) HeadE.style.textDecoration = 'none';
			theType = theSrc.substr((thePos + 1),(theSrc.length));
			if (theType == "Button") theSrcE.style.borderColor = "rgb(234,244,234)";
		}
	}
}

function Footer_MOUSEOVER(e)
{
	if (!e) var e = window.event;
	var oTarget = (e.target) ? e.target : e.srcElement;
	
	if (oTarget.id != "")
	{
		theSrcE = document.getElementById(oTarget.id);
		theSrc = theSrcE.id;
		thePos = theSrc.indexOf('_');
		
		if (thePos == -1) HelpHTML = "";
		else
		{
			theBase = theSrc.substr(0,thePos);
			HelpE = document.getElementById(theBase + "_HelpText");
			if (HelpE != null)
			{
				HelpHTML = HelpE.innerHTML
				HeadE = document.getElementById(theBase + "_Header");
				if (HeadE != null) HeadE.style.textDecoration = 'underline';
				theType = theSrc.substr((thePos + 1),(theSrc.length));
				if (theType == "Button") theSrcE.style.borderColor = "rgb(0,0,0)";
			}
			else HelpHTML = "";
		}
	}
	
	if (header != null) header.document.getElementById("HelpText").innerHTML = HelpHTML;
}

function GoFirst_Button_MOUSEDOWN() { document.getElementById('GoFirst_Button').setAttribute('src', GoFirst_SelImage.src); }

function GoFirst_Button_MOUSEOUT() { document.getElementById('GoFirst_Button').setAttribute('src', GoFirst_Image.src); }

function GoFirst_Button_MOUSEUP()
{
	document.getElementById('GoFirst_Button').setAttribute('src', GoFirst_Image.src);
	RTable_movefirst();
}

function GoLast_Button_MOUSEDOWN() { document.getElementById('GoLast_Button').setAttribute('src', GoLast_SelImage.src); }

function GoLast_Button_MOUSEOUT() { document.getElementById('GoLast_Button').setAttribute('src', GoLast_Image.src); }

function GoLast_Button_MOUSEUP()
{
	document.getElementById('GoLast_Button').setAttribute('src', GoLast_Image.src);
	RTable_movelast();
}

function GoNext_Button_MOUSEDOWN() { document.getElementById('GoNext_Button').setAttribute('src', GoNext_SelImage.src); }

function GoNext_Button_MOUSEOUT() { document.getElementById('GoNext_Button').setAttribute('src', GoNext_Image.src); }

function GoNext_Button_MOUSEUP()
{
	document.getElementById('GoNext_Button').setAttribute('src', GoNext_Image.src);
	RTable_movenext();
}

function GoPrevious_Button_MOUSEDOWN() { document.getElementById('GoPrevious_Button').setAttribute('src', GoPrevious_SelImage.src); }

function GoPrevious_Button_MOUSEOUT() { document.getElementById('GoPrevious_Button').setAttribute('src', GoPrevious_Image.src); }

function GoPrevious_Button_MOUSEUP()
{
	document.getElementById('GoPrevious_Button').setAttribute('src', GoPrevious_Image.src);
	RTable_moveprevious();
}

function MapAll_Button_MOUSEDOWN() { document.getElementById('MapAll_Button').setAttribute('src', MapAll_SelImage.src); }

function MapAll_Button_MOUSEOUT() { document.getElementById('MapAll_Button').setAttribute('src', MapAll_Image.src); }

function MapAll_Button_MOUSEUP()
{
	document.getElementById('MapAll_Button').setAttribute('src', MapAll_Image.src);
	MapIt_Submit("all");
}

function MapIt_Toggle(e)
{
	if (!e) var e = window.event;
	
	var thisButton = (e.target) ? e.target : e.srcElement;
	var thisToggle = thisButton.id;
	
	var IsShifted = false;
	if (e.shiftKey) IsShifted = e.shiftKey;
	else if (e.modifiers) if (e.modifiers == 4) IsShifted = true;
	
	if (RXML_Row == -1) MapToggle = thisToggle;
	
	if (MapToggle != "none") curButton = document.body.all.item(MapToggle);
	else curButton = null;
	
	if (IsShifted == true)
	{
		if (MapToggle == thisToggle)
		{
			MapToggle = "none";
			NonSelBut = thisButton;
		}
		else
		{
			MapToggle = thisToggle;
			NonSelBut = curButton;
			MapIt_Submit("sel");
		}
	}
	else
	{
		if (MapToggle == thisToggle)
		{
			MapToggle = "none";
			NonSelBut = thisButton;
		}
		else
		{
			curMapToggle = MapToggle;
			MapToggle = thisToggle;
			MapIt_Submit("sel");
			MapToggle = curMapToggle;
			NonSelBut = thisButton;
		}
	}
	
	if (NonSelBut != null)
	{
		switch (NonSelBut.id)
		{
			case "ZoomSel_Button":
				document.getElementById('ZoomSel_Button').setAttribute('src', ZoomSel_Image.src);
				break;
				
			case "PanSel_Button":
				document.getElementById('PanSel_Button').setAttribute('src', PanSel_Image.src);
				break;
				
			case "MapSel_Button":
				document.getElementById('MapSel_Button').setAttribute('src', MapSel_Image.src);
				break;
		}
	}
}

function MapSel_Button_MOUSEDOWN() { document.getElementById('MapSel_Button').setAttribute('src', MapSel_SelImage.src); }

function MapSel_Button_MOUSEOUT()
{
	if (MapToggle != "MapSel_Button") document.getElementById('MapSel_Button').setAttribute('src', MapSel_Image.src);
}

function PanSel_Button_MOUSEDOWN() { document.getElementById('PanSel_Button').setAttribute('src', PanSel_SelImage.src); }

function PanSel_Button_MOUSEOUT()
{
	if (MapToggle != "PanSel_Button") document.getElementById('PanSel_Button').setAttribute('src', PanSel_Image.src);
}

function ZoomSel_Button_MOUSEDOWN() { document.getElementById('ZoomSel_Button').setAttribute('src', ZoomSel_SelImage.src); }

function ZoomSel_Button_MOUSEOUT()
{
	if (MapToggle != "ZoomSel_Button") document.getElementById('ZoomSel_Button').setAttribute('src', ZoomSel_Image.src);
}



/**************************************************************************************************
*                                                       SUPPLEMENTAL FUNCTIONS (ALPHABETIZED)                                                     *
**************************************************************************************************/

function HTable_Resize()
{
	top.frames['infoframe'].document.getElementById('DebugTextArea').value += 
	"FOOT: Header_Resize() START\n";
	
	if (!document.all && !document.getElementById)
	{
		alert('The script on this page does\'t work in your browser');
		return;
	}
	
	var extra = 0;
	extra += 4; // +2 per point of cellpadding
	Htab = document.getElementById("HTable");
	Rtab = document.getElementById("RTable");
	Hcells = Htab.rows[0].cells;
	Rcells = Rtab.rows[0].cells;
	
	for (i = 0; i < Hcells.length; i++)
	{
		Hc = Hcells[i]
		Rc = Rcells[i]
		Rwidth = Rc.offsetWidth;
		Hwidth = Hc.offsetWidth;
		
		var dDecimal = 0;
		if (Rwidth > Hwidth)
		{
			thedif = Rwidth - Hwidth + extra;
			theleft = parseInt(thedif/2);
			theright = thedif - theleft;
			Hc.style.paddingLeft = theleft;
			Hc.style.paddingRight = theright;
			
			/*thedif = parseFloat((Rwidth - Hwidth) / 2);alert(thedif);
			dDecimal = 0;
			if (thedif.toString().indexOf(".5") != -1) dDecimal = 0.5;alert(dDecimal);
			Hc.style.paddingLeft = thedif - dDecimal;alert(Hc.style.paddingLeft);
			Hc.style.paddingRight = thedif + eval(dDecimal);alert(Hc.style.paddingRight);*/
		}
		else
		{
			thedif = Hwidth - Rwidth + extra;
			theleft = parseInt(thedif/2);
			theright = thedif - theleft;
			Rc.style.paddingLeft = theleft;
			Rc.style.paddingRight = theright;
			
			/*thedif = parseFloat((Hwidth - Rwidth) / 2);alert(thedif);
			dDecimal = 0;
			if (thedif.toString().indexOf(".5") != -1) dDecimal = 0.5;alert(dDecimal);
			Rc.style.paddingLeft = thedif - dDecimal;alert(Rc.style.paddingLeft);
			Rc.style.paddingRight = thedif + eval(dDecimal);alert(Rc.style.paddingRight);*/
		}
	}
}

function IRTable_Make()
{
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT: IRTable_Make() START\n";
	theIRTable = info.document.getElementById("IRTable");
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT:IRTable_Make: DELETE EXISTING ROWS\n";
	
	if (theIRTable.rows.length != 0)
	{
		numrows = theIRTable.rows.length;
		for (r = 0; r < numrows; r++) theIRTable.deleteRow(0);
	}
	
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT: IRTable_Make():  RXML_Row: " + RXML_Row + " \n";
	
	theStyle = "BCtopline";
	
	for (f = 0; f < LLFieldDisplays.length; f++)
	{
		thisValue = "";
		for (var i = 0; i < top.iTotalFields; i++)
		{
			if (top.sQueryResults[0][i] == LLFieldNames[f]) 
			{
				thisValue = top.sQueryResults[eval(RXML_Row) + 1][i];
				i = top.iTotalFields;
			}
		}
		
		// IE
		if (window.ActiveXObject) NewRow = theIRTable.insertRow();
		// non-IE browsers
		else NewRow = theIRTable.insertRow(theIRTable.rows.length);
		
		
		NewRow.noWrap = true;
		top.frames['infoframe'].document.getElementById('DebugTextArea').value += 
		"FOOT: IRTable_Make():  row " + f + " of " + 
		(LLFieldDisplays.length - 1) + "\n";
		ncl = NewRow.insertCell(0);
		ncl.setAttribute(sClass, theStyle);
		ncl.innerHTML = '<SPAN class="SubHeading2" style="font-weight:bold">' + LLFieldDisplays[f] + 
		'</SPAN>';
		ncr = NewRow.insertCell(1);
		ncr.setAttribute(sClass, theStyle);
		islink = false;
		
		for (lf = 0; lf < LinkFields.length; lf++)
		{
			if (LinkFields[lf] == LLFieldNames[f])
			{
				islink = true;
				thisPre = LinkPrefixs[lf];
				thisSuf = LinkSuffixs[lf];
				thisText = LinkTexts[lf];
				thisImage = LinkImages[lf];
			}
		}
		
		if (islink == true)
		{
			if (thisPre == null) thisPre = "";
			if (thisSuf == null) thisSuf = "";
			if (thisText != null && thisText != "") VisHTML = thisText;
			else if (thisImage != null && thisImage != "") VisHTML = '<IMG src="' + thisImage + '">';
			else VisHTML = thisValue;
			
			ncr.innerHTML = '<SPAN class="blueSubHeading"  onclick="Link_GoTo(' + "'" + thisPre + 
			thisValue + thisSuf + "'" + ')">' + VisHTML + '</SPAN>';
		}
		else ncr.innerHTML = '<SPAN class="SubHeading2">' + thisValue + '</SPAN>';
		
		theStyle = "BC2";
	}
	
	top.frames['infoframe'].document.getElementById('DebugTextArea').value += 
	"FOOT: IRTable_Make() END\n";
}

function MapIt_SetVariables()
{
	for (var i = 0; i < top.iTotalFields; i++)
	{
		if (top.sQueryResults[0][i] == "shpext")
		{
			Query_SelExtent = top.sQueryResults[eval(RXML_Row) + 1][i];
			i = top.iTotalFields;
		}
	}
	
	for (var i = 0; i < top.iTotalFields; i++)
	{
		if (top.sQueryResults[0][i] == "shpmid")
		{
			Query_SelMid = top.sQueryResults[eval(RXML_Row) + 1][i];
			i = top.iTotalFields;
		}
	}
	
	Query_SelUID.length = 0;
	for (var i = 0; i < top.iTotalFields; i++)
	{
		if (top.sQueryResults[0][i] == info.OldQueryUID)
		{
			for (var i01 = 0; i01 < iSelectedRows.length; i01++) Query_SelUID[i01] = 
			top.sQueryResults[eval(iSelectedRows[i01]) + 1][i];
			
			//Query_SelUID = top.sQueryResults[eval(RXML_Row) + 1][i];
			//i = top.iTotalFields;
		}
	}
	
	var RTab_Row_bak = RTab_Row;
	for (var i = 0; i < iSelectedRows.length; i++)
	{
		RTab_Row = iSelectedRows[i];
		RTable_SetHighlight(iSelectedRows[i]);
	}
	RTab_Row = RTab_Row_bak;
	//RTable_SetHighlight(RTab_Row);
}

function MapIt_Submit(who)
{
	switch (who)
	{
		case "all":
			if (RXML_Row == -1 && !bMaxRecs) return;
			if (info.bMultiQueryMode) info.bShpExt = true;
			if (info.OldQueryType != "point" || document.getElementById("RTable").rows.length != 1) info.Submit_Extent(info.QueryExtent);
			info.bShpExt = false;
			break;
			
		case "none":
			if (RXML_Row == -1 && !bMaxRecs) return;
			RTable_SetHighlight(-1);
			info.Submit_Refresh();
			break;
			
		case "sel":
			if (MapToggle == "none") return;
			MapIt_SetVariables();
			switch (MapToggle)
			{
				case "MapSel_Button":
					info.Submit_Refresh();
					break;
					
				case "PanSel_Button":
					info.Submit_Point(Query_SelMid, info.Map_scale, "panSel");
					break;
					
				case "ZoomSel_Button":
					if (info.OldQueryType.toLowerCase() == "point") info.Submit_Point(Query_SelMid, 2400, true);
					else info.Submit_Extent(Query_SelExtent);
					break;
					
				case "none":
					mapit = false;
					break;
			}
			break;
	}
}

function RegisterEvents()
{
	// event registration for HTML elements; alphabetically ordered by the element's id
	
	var oElement; // this object is reused for each element's event registration
	
	oElement = document.body;
	oElement.onmouseover = Footer_MOUSEOVER;
	oElement.onclick = Footer_CLICK;
	oElement.onmouseout = Footer_MOUSEOUT;
	
	oElement = document.getElementById("CloseFoot_Button");
	oElement.onmousedown = CloseFoot_Button_MOUSEDOWN;
	oElement.onmouseup = CloseFoot_Button_MOUSEUP;
	oElement.onmouseout = CloseFoot_Button_MOUSEOUT;
	
	oElement = document.getElementById("ClearSel_Button");
	oElement.onmousedown = ClearSel_Button_MOUSEDOWN;
	oElement.onmouseup = ClearSel_Button_MOUSEUP;
	oElement.onmouseout = ClearSel_Button_MOUSEOUT;

	oElement = document.getElementById("GoFirst_Button");
	oElement.onmousedown = GoFirst_Button_MOUSEDOWN;
	oElement.onmouseup = GoFirst_Button_MOUSEUP;
	oElement.onmouseout = GoFirst_Button_MOUSEOUT;
	
	oElement = document.getElementById("GoLast_Button");
	oElement.onmousedown = GoLast_Button_MOUSEDOWN;
	oElement.onmouseup = GoLast_Button_MOUSEUP;
	oElement.onmouseout = GoLast_Button_MOUSEOUT;
	
	oElement = document.getElementById("GoNext_Button");
	oElement.onmousedown = GoNext_Button_MOUSEDOWN;
	oElement.onmouseup = GoNext_Button_MOUSEUP;
	oElement.onmouseout = GoNext_Button_MOUSEOUT;
	
	oElement = document.getElementById("GoPrevious_Button");
	oElement.onmousedown = GoPrevious_Button_MOUSEDOWN;
	oElement.onmouseup = GoPrevious_Button_MOUSEUP;
	oElement.onmouseout = GoPrevious_Button_MOUSEOUT;
	
	oElement = document.getElementById("MapAll_Button");
	oElement.onmousedown = MapAll_Button_MOUSEDOWN;
	oElement.onmouseup = MapAll_Button_MOUSEUP;
	oElement.onmouseout = MapAll_Button_MOUSEOUT;
	
	oElement = document.getElementById("MapSel_Button");
	oElement.onmousedown = MapSel_Button_MOUSEDOWN;
	oElement.onmouseup = MapIt_Toggle;
	oElement.onmouseout = MapSel_Button_MOUSEOUT;
	
	oElement = document.getElementById("PanSel_Button");
	oElement.onmousedown = PanSel_Button_MOUSEDOWN;
	oElement.onmouseup = MapIt_Toggle;
	oElement.onmouseout = PanSel_Button_MOUSEOUT;
	
	oElement = document.getElementById("ZoomSel_Button");
	oElement.onmousedown = ZoomSel_Button_MOUSEDOWN;
	oElement.onmouseup = MapIt_Toggle;
	oElement.onmouseout = ZoomSel_Button_MOUSEOUT;
}

function reportRuntimeError(exception)
{
	return "<FONT face=Verdana size=2><FONT size=4>XSL Runtime Error</FONT><P><B>" + 
	exception.description + 
	"</B></P><P>Sorry, this is probably due to the fact that I built this thing for IE6.0</P></FONT>";
}

function RTable_ClearHighlight()
{
	if (RTab_Highlight != -1)
	{
		var oRTable = document.getElementById('RTable');
		if (RTab_Highlight == RTab_Row) oRTable.rows[RTab_Highlight].setAttribute(sClass, 'info');
		else oRTable.rows[RTab_Highlight].setAttribute(sClass, 'unselected');
	}
}

function RTable_ClearRow()
{
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"RTable_ClearRow(): Start clearing : " + RTab_Row + " \n";
	
	var oRTable = document.getElementById('RTable');
	if (RTab_Row != -1)
	{
		if (RTab_Highlight == RTab_Row) oRTable.rows[RTab_Row].setAttribute(sClass, "map");
		else oRTable.rows[RTab_Row].setAttribute(sClass, "unselected");
	}
	
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += "RTable_ClearRow(): End \n";
}

function RTable_ClearRows()
{
	theHTable = document.getElementById("HTable");
	
	if (theHTable.rows.length != 0)
	{
		numrows = theHTable.rows.length;
		for (r = 0; r < numrows; r++) theHTable.deleteRow(0);
	}
	
	theRTable = document.getElementById("RTable");
	
	if (theRTable.rows.length != 0)
	{
		numrows = theRTable.rows.length;
		for (r = 0; r < numrows; r++) theRTable.deleteRow(0);
	}
}

function RTable_Click(e,therow)
{
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += "RTable_Click: Start ; row: " + 
	therow + " \n";
	
	/*
	var sModifiers = "none";
	if (e.shiftKey && e.ctrlKey) sModifiers = "both";
	else if (e.shiftKey) sModifiers = "shift";
	else if (e.ctrlKey) sModifiers = "control";
	
	if (sModifiers == "none")
	{
		sModSequence.length = 0;
		sModSequence[0] = "none";
		iRowSequence.length = 0;
		iRowSequence[0] = therow;
		
		// for simple temp algorithm
		iSelectedRows.length = 0;
		iSelectedRows[0] = therow;
	}
	else
	{
		sModSequence[sModSequence.length] = sModifiers;
		iRowSequence[iRowSequence.length] = therow;
	}
	
	// for complex algorithm
	//iSelectedRows.length = 0;
	
	// simple temporary algorithm to allow selection of multiple records via the CTRL key
	if (sModifiers == "control") iSelectedRows[iSelectedRows.length] = therow;
	
	// TODO:  algorithm for selection of records
	*/
	
	iSelectedRows.length = 0;
	iSelectedRows[0] = therow;
	
	RTable_SetRow(iSelectedRows);
	MapIt_Submit("sel");
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += "RTable_Click: END \n";
}

function RTable_Close()
{
    bCloseFooter = true;
    if (top.bCoordShow)
    {
      var s = top.document.getElementById("rightframeset").rows;
      iRTableHeight = parseInt(s.substring(eval(s.indexOf(",", s.indexOf(",") + 1)) + 1));
    }
	
	info.bMultiQueryMode = false;
	top.iTotalQueryResults = 0;
	top.sQueryResults.length = 0;
	top.sModifiers = "none";
	
	info.g_sLastQueryType = "none";
	info.g_bQueryMode = false;
	info.bEmptyQuery = false;
	
	top.document.getElementById("rightframeset").rows = "27,*,0";
	info.QuerySaved = "false";
	info.Div_Toggle("Info_Div","hide",null);
	RTable_ClearRows();
	
	IRTable = top.frames["infoframe"].document.getElementById("IRTable");
	var iTotalIRRows = IRTable.rows.length;
	
	if (iTotalIRRows != 0)
	{
		for (ri = 0; ri < iTotalIRRows; ri++) IRTable.deleteRow(0);
	}
	
	var oHTable = document.getElementById('HTable');
	if (oHTable.tHead != null) oHTable.deleteTHead();
	document.getElementById("selnumtd").innerHTML = "0";
	document.getElementById("totalnumtd").innerHTML = "of  0";
	RXML_Row = -1;
	top.bNewRefImage = false;
	info.Submit_Refresh();
}

function RTable_Make()
{
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT:RTable_Make: START\n";
	RTable_ClearRows();
	theHTable = document.getElementById("HTable");
	
	// IE
	if (window.ActiveXObject) NewHead = theHTable.insertRow();
	// non-IE browsers
	else NewHead = theHTable.insertRow(theHTable.rows.length);
	
	NewHead.setAttribute(sClass, "head");
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT:RTable_Make: BUILD TABLE HEADER CELLS\n";
	
	// IE
	if (window.ActiveXObject)
	{
		for (c = 0; c < SLFieldDisplays.length; c++)
		{
			HeadCell = NewHead.insertCell();
			HeadCell.id = SLFieldNames[c];
			HeadCell.innerHTML = SLFieldDisplays[c];
			HeadCell.noWrap = true;
			HeadCell.setAttribute(sClass, "faketd");
		}
	}
	// non-IE browsers
	else
	{
		for (c = SLFieldDisplays.length - 1; c >= 0; c--)
		{
			HeadCell = NewHead.insertCell(0);
			HeadCell.id = SLFieldNames[c];
			HeadCell.innerHTML = SLFieldDisplays[c];
			HeadCell.noWrap = true;
			HeadCell.setAttribute(sClass, "faketd");
		}
	}
	
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT:RTable_Make: GO THROUGH THE RXML AND BUILD THE ROWS\n";
	
	var theRTable = document.getElementById("RTable");				
	
	for (r = 0; r < top.iTotalQueryResults; r++)
	{
		if (window.ActiveXObject) NewRow = theRTable.insertRow();
		else NewRow = theRTable.insertRow(theRTable.rows.length);						
		NewRow.setAttribute(sClass, "unselected");
		NewRow.disabled = false;
		NewRow.id = r.toString();
		NewRow.name = r.toString();
		
		for (c = 0; c < SLFieldDisplays.length; c++)
		{
			thisValue = "";
			for (var i = 0; i < top.iTotalFields; i++)
			{
				if (top.sQueryResults[0][i] == SLFieldNames[c])
				{
					thisValue = top.sQueryResults[eval(r) + 1][i];
					i = top.iTotalFields;
				}
			}
			
			islink = false;
			
			for (lf = 0; lf < LinkFields.length; lf++)
			{
				if (LinkFields[lf] == SLFieldNames[c])
				{
					islink = true;
					thisPre = LinkPrefixs[lf];
					thisSuf = LinkSuffixs[lf];
					thisText = LinkTexts[lf];
					thisImage = LinkImages[lf];
				}
			}
			
			if (window.ActiveXOject) NewCell = NewRow.insertCell(c);
			else NewCell = NewRow.insertCell(c);
			NewCell.setAttribute(sClass, "BC2");
			NewCell.noWrap = true;
			
			if (islink == true)
			{
				if (thisPre == null) thisPre = "";
				if (thisSuf == null) thisSuf = "";
				if (thisText != null && thisText != "") VisHTML = thisText;
				else if (thisImage != null && thisImage != "") VisHTML = '<IMG src="" + thisImage + "">';
				else VisHTML = thisValue;
				NewCell.innerHTML = '<A target="_blank" href="' + thisPre + thisValue + thisSuf + 
				'"><SPAN id="tRow' + r + '">' + VisHTML + "</SPAN>";
				document.getElementById("tRow" + r).onclick = Footer_CLICK;
			}
			else
			{
				if (thisValue != "") NewCell.innerHTML = thisValue;
				else NewCell.innerHTML = "";
			}
			
			NewCell.id = "tRow" + r;
		}
	}				
	
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT:RTable_Make: Rows: " + theRTable.rows.length + " \n";
	//theRTable.refresh();
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += 
	"FOOT: RTable_Make: SET VARIABLES AND SELECTIONS\n";
	RTab_Row = 0;
	RXML_Row = 0;
	iSelectedRows.length = 0;
	iSelectedRows[0] = 0;
	RTable_SetRow(iSelectedRows);
	//RTable_SetRow(RTab_Row);
	window.scrollTo(0,0);
	HTable_Resize();
}

function RTable_movefirst()
{
	if (RXML_Row == -1) return;
	
	if (RTab_Row > 0)
	{
		iSelectedRows.length = 0;
		iSelectedRows[0] = 0;
		RTable_SetRow(iSelectedRows);
		//RTable_SetRow(0);
		MapIt_Submit("sel");
	}
}

function RTable_movelast()
{
	if (RXML_Row == -1) return;
	
	if (RTab_Row < (document.getElementById('RTable').rows.length - 1))
	{
		iSelectedRows.length = 0;
		iSelectedRows[0] = document.getElementById('RTable').rows.length - 1;
		RTable_SetRow(iSelectedRows);
		//RTable_SetRow(RTable.rows.length - 1);
		MapIt_Submit("sel");
	}
}

function RTable_movenext()
{
	if (RXML_Row == -1) return;
	
	if (RTab_Row < (document.getElementById('RTable').rows.length - 1))
	{
		iSelectedRows.length = 0;
		iSelectedRows[0] = eval(RTab_Row) + 1;
		RTable_SetRow(iSelectedRows);
		//RTable_SetRow(eval(RTab_Row) + 1);
		MapIt_Submit("sel");
	}
}

function RTable_moveprevious()
{
	if (RXML_Row == -1) return;
	
	if (RTab_Row > 0)
	{
		iSelectedRows.length = 0;
		iSelectedRows[0] = RTab_Row - 1;
		RTable_SetRow(iSelectedRows);
		//RTable_SetRow(RTab_Row - 1);
		MapIt_Submit("sel");
	}
}

function RTable_SetHighlight(thisrow)
{
	RTable_ClearHighlight();
	RTab_Highlight = thisrow;
	
	var oRTable = document.getElementById('RTable');
	
	if (thisrow == -1) RXML_Highlight = -1;
	else RXML_Highlight = oRTable.rows[thisrow].id;
	
	if (thisrow != -1)
	{
		if (RTab_Highlight == RTab_Row) oRTable.rows[thisrow].setAttribute(sClass, 'mapNinfo');
		else oRTable.rows[thisrow].setAttribute(sClass, 'map');
	}
}

function RTable_SetRow(iSelectedRows)
{
	top.frames["infoframe"].document.getElementById("DebugTextArea").value += "RTable_SetRow: Start ; set: " + 
	iSelectedRows[0] + " \n";
	
	for (var i = 0; i < iSelectedRows.length; i++)
	{
		RTable_ClearRow();
		RTab_Row = parseInt(iSelectedRows[i]);
		RXML_Row = document.getElementById("RTable").rows[RTab_Row].id;
		
		if (i == 0) IRTable_Make();
		
		var oRTable = document.getElementById("RTable");
		if (RTab_Highlight == RTab_Row) oRTable.rows[iSelectedRows[i]].setAttribute(sClass, "mapNinfo");
		else oRTable.rows[iSelectedRows[i]].setAttribute(sClass, "info");
	}
	
	document.getElementById("selnumtd").innerHTML = eval(iSelectedRows[0]) + 1;
}

function ScrollTop()
{
	tldv = document.getElementById("ToolDiv");
	hddv = document.getElementById("HeaderDiv");
	
	if (window.innerHeight) curTop = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) curTop = 
	document.documentElement.scrollTop;
	else if (document.body) curTop = document.body.scrollTop;
	
	if (curTop == LastSetTop)
	{
		tldv.style.visibility = "visible";
		hddv.style.visibility = "visible";
		tldv.style.top = curTop;
		tldv.style.left = document.body.scrollLeft;
		tldv.style.width = document.body.offsetWidth - 16;
		hddv.style.top = (curTop + tldv.clientHeight + 2);
	}
	else
	{
		tldv.style.visibility = "hidden";
		hddv.style.visibility = "hidden";
	}
	
	LastSetTop = curTop;
	timer = setTimeout("ScrollTop();",200);
}
