/**************************************************************************************************
*                                                                        VARIABLE DECLARATIONS                                                                        *
**************************************************************************************************/

var sQueryResults, iTotalQueryResults = 0, iTotalFields, iMapWidthDown, iMapWidthUp, iMapHeightDown, 
	iMapHeightUp, bNewRefImage = true, LegRows = new Array(), mapxml, placesxml, 
	sModifiers = "none", iIdIndex, sOldImg = "", bCloseFooter = false, sLabelLayers = new Array(), 
	sLabelFields = new Array(), bCoordShow = false, sVMLSaved = new Array(), bAllowPan = true;

sVMLSaved[0] = "0px";
sVMLSaved[1] = "0px";
sVMLSaved[2] = "0px";
sVMLSaved[3] = "0px";
sVMLSaved[4] = "";
sVMLSaved[5] = "0px";
sVMLSaved[6] = "0px";
sVMLSaved[7] = "";
sVMLSaved[8] = "";
sVMLSaved[9] = "";
sVMLSaved[10] = "";
sVMLSaved[11] = 0;
sVMLSaved[12] = 0;

var theopener = window.opener;
if (theopener != null)
{
	mapxml_file = theopener.XMLFile;
	Imap = theopener.Imap;
	Imode = theopener.Imode;
	Iextent = theopener.Iextent;
	Ipoint = theopener.Ipoint;
	Iscale = theopener.Iscale;
	Iqstr = theopener.Iqstr;
	Iqlayer = theopener.Iqlayer;
	Iqfield = theopener.Iqfield;
}

window.name = "GISMaps";



/**************************************************************************************************
*                                                                      ONLOAD EVENT HANDLER                                                                            *
**************************************************************************************************/

function init()
{
	RegisterEvents();
	LoadMapservXML();
}



/**************************************************************************************************
*                                                            EVENT HANDLERS (ALPHABETIZED)                                                                    *
**************************************************************************************************/

function LoadInfo() { frames["infoframe"].location = "bin/html/info.html"; }

function MouseDown()
{
	if (self.innerWidth)
	{
		iMapWidthDown = top.frames['mapframe'].self.innerWidth;
		iMapHeightDown = top.frames['mapframe'].self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		iMapWidthDown = top.frames['mapframe'].document.documentElement.clientWidth;
		iMapHeightDown = top.frames['mapframe'].document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		iMapWidthDown = top.frames['mapframe'].document.body.clientWidth;
		iMapHeightDown = top.frames['mapframe'].document.body.clientHeight;
	}
}

function MouseUp()
{
	if (self.innerWidth)
	{
		iMapWidthUp = top.frames['mapframe'].self.innerWidth;
		iMapHeightUp = top.frames['mapframe'].self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		iMapWidthUp = top.frames['mapframe'].document.documentElement.clientWidth;
		iMapHeightUp = top.frames['mapframe'].document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		iMapWidthUp = top.frames['mapframe'].document.body.clientWidth;
		iMapHeightUp = top.frames['mapframe'].document.body.clientHeight;
	}
	
	if (iMapWidthUp != iMapWidthDown || iMapHeightUp != iMapHeightDown) top.frames["infoframe"].Submit_Refresh();
}



/**************************************************************************************************
*                                                       SUPPLEMENTAL FUNCTIONS (ALPHABETIZED)                                                     *
**************************************************************************************************/

function LoadMapservXML()
{
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest)
  {
    mapxml = new XMLHttpRequest();
    mapxml.onreadystatechange = function()
    {
      if (mapxml.readyState != 4) return;
      if (mapxml.status == 200) LoadPlacesXML();
      else alert("Could not load XML file: mapserv.xml");
    }
    mapxml.open("GET", "config/xml/mapserv.xml", true);
    mapxml.send(null);
  }
  // branch for IE/Windows ActiveX version
  else if (window.ActiveXObject)
  {
    mapxml = new ActiveXObject("Microsoft.XMLHTTP");
    mapxml.onreadystatechange = function()
    {
      if (mapxml.readyState != 4) return;
      if (mapxml.status == 200) LoadPlacesXML();
      else alert("Could not load XML file: mapserv.xml");
    }
    mapxml.open("GET", "config/xml/mapserv.xml", true);
    mapxml.send();
  }
  else alert("Problem with XML get.");
}

function LoadPlacesXML()
{
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest)
  {
    placesxml = new XMLHttpRequest();
    placesxml.onreadystatechange = function()
    {
      if (placesxml.readyState != 4) return;
      if (placesxml.status == 200) LoadInfo();
      else
      {
        placesxml = null;
        LoadInfo();
      }
    }
    placesxml.open("GET", "config/xml/places.xml", true);
    placesxml.send(null);
  }
  // branch for IE/Windows ActiveX version
  else if (window.ActiveXObject)
  {
    placesxml = new ActiveXObject("Microsoft.XMLHTTP");
    placesxml.onreadystatechange = function()
    {
      if (placesxml.readyState != 4) return;
      if (placesxml.status == 200) LoadInfo();
      else
      {
        placesxml = null;
        LoadInfo();
      }
    }
    placesxml.open("GET", "config/xml/places.xml", true);
    placesxml.send();
  }
  else
  {
    placesxml = null;
    LoadInfo();
  }
}

function RegisterEvents()
{
  var element = document.getElementById("topframeset");
  element.onmousedown = MouseDown;
  element.onmouseup = MouseUp;
}