//==========================
// Declare global variables.
//==========================
// Postback variables.
var PostBackForm;
var PostBack = new Object(); // Hidden fields for server/client interface
var IsPostBack = false;   //True means a postback from server is present
var PostBackDone = false; //True means website is ready
var PostBackBeg = false; //True means start of postback
var AnimateMap = false;

// Map layers variables
var LayersWindow = false;     // True if map layers window is visible
var LayerHeadingCount = 0;
var LayerHeadingOpen = new Array();
var FeatureLayers = new Array();
var LayerIds = "";
var LayersVisible = "";
var ActiveLayerId = "";

// Identify command variables
var VmlLayerId = "0";  // VML layer ID
var VmlObjectId = 0;   // VML object ID

// Map scales
var ScalePixelToFeet; // Raw map scale
var ScaleInchToFeet;  // Example: 1"=100'
var ScaleInchToInch;  // Example: 1"=1200"
var ScaleInchToMile;  // Example: 1"=0.5 Mile

// Acetate layer
var PointXyText = "";   // Geocode x,y,address

// Misc.
var IeFilters = false; // IE filters allowed
var WebSiteInitialized = false; //True if website initialized
var ActiveCursor = "default"; //Active cursor
var GovUser;     // True if government user
var ValidUser;   // True for signed-in users and gov users
var AtrTableWindow;   // Reference to atr table window
var MailLabelWindow;  // Reference to mail lable window
var PrevQuery = "";   // Previous query information
var PrintOptData = ""; // Print options information
var CompsMapList;      // Comps on/off list

//========================
// Check if frames loaded.
//========================
function checkReady() {
   if (IsOpera) {
      setTimeout("initWebSite()", 2000);
   } else {
      initWebSite();
   }
}
//====================
// Initialize website.
//====================
function initWebSite() {

   //See if IE filters and VML allowed
   try {
      if (main_frame.document.getElementById("map_img").filters) {
         IeFilters = true;
      }
   } catch(ex) {
   }
   //Netscape formating
   if (IsNN) {
      main_frame.document.getElementById("menuHeading_div").style.paddingBottom = "0px";
      main_frame.document.getElementById("menuHeading_div").style.overflow = "hidden";
      main_frame.document.getElementById("toolbar_div").style.overflow = "hidden";
      main_frame.document.getElementById("toolbar_div").style.paddingBottom = "3px";
   }
   //Get elements
   //alert (postBack_frame.name);
   PostBackForm = postBack_frame.document.getElementById("postBack_form");

   // Initialize postback objects.
   if (!PostBackForm) {
      alert("The website is temporarily unavailable.\n" +
       "There may be a problem with the ASP.Net State Service.");
      return
   }
   setPostBack();

   // Layer visibility cookies
   LayerIds = getCookie("LayerIds");
   LayersVisible = getCookie("LayersVisible");
   ActiveLayerId = getCookie("ActiveLayerId");

   // Layer visibility calling args
   var temp = getQSArg("LayerIds");
   if (temp != "") {
      LayerIds = temp;
   }
   temp = getQSArg("LayersVisible");
   if (temp != "") {
      LayersVisible = temp;
   }
   temp = getQSArg("ActiveLayerId");
   if (temp != "") {
      ActiveLayerId = temp;
   }

   // Display the map.
   main_frame.setMapImageElementSize();
   PostBackDone = true;

   var pin = getQSArg("pin");
   var mapExtent = getQSArg("MapExtent");

   if (pin != "") {
      zoomToParcel(pin);

   } else if (mapExtent != "") {
      var mapE = mapExtent.split(",");
      zoomInBox(mapE[0],mapE[1],mapE[2],mapE[3]);

   } else {
      zoomToStartExtent();
      main_frame.SaveFullExtent = true;
   }

   // Pop-up disclaimer
   if (!GovUser) {
      alert(Disclaimer);
   }
   // Finish init
   WebSiteInitialized = true;
}
//==========================
// Set the postback objects.
//==========================
function setPostBack() {
   // Document variables
   PostBackForm = postBack_frame.document.getElementById("postBack_form");
   PostBack.command = PostBackForm.command_hidden;
   PostBack.govUser = PostBackForm.govUser_hid;
   PostBack.validUser = PostBackForm.validUser_hid;
   PostBack.accountInUse = PostBackForm.accountInUse_hid;
   PostBack.mapImageHeight = PostBackForm.mapImageHeight_hidden;
   PostBack.mapImageWidth = PostBackForm.mapImageWidth_hidden;
   PostBack.mapImageSrc = PostBackForm.mapImageSrc_hidden;
   PostBack.xMinMap = PostBackForm.xMinMap_hidden;
   PostBack.yMinMap = PostBackForm.yMinMap_hidden;
   PostBack.xMaxMap = PostBackForm.xMaxMap_hidden;
   PostBack.yMaxMap = PostBackForm.yMaxMap_hidden;
   
   PostBack.x1 = PostBackForm.x1_hidden;
   PostBack.y1 = PostBackForm.y1_hidden;
   PostBack.x2 = PostBackForm.x2_hidden;
   PostBack.y2 = PostBackForm.y2_hidden;

   PostBack.layerIds = PostBackForm.layerIds_hid;
   PostBack.layersVisible = PostBackForm.layersVisible_hid;
   PostBack.activeLayerId = PostBackForm.activeLayerId_hid;

   PostBack.vmlLayerID = PostBackForm.vmlLayerID_hid;
   PostBack.vmlObjectID = PostBackForm.vmlObjectID_hid;
   PostBack.vmlFeatureClass = PostBackForm.vmlFeatureClass_hid;

   PostBack.pointXyText = PostBackForm.pointXyText_hid;
   PostBack.compsMapList = PostBackForm.compsMapList_hid;
   PostBack.errMsg = PostBackForm.errMsg_hid;
}
//=========================
// Tool shortcut functions.
//=========================
function zoomToStartExtent() {
   processTool("zoomToStartExtent");
}
function zoomToFullExtent() {
   if (main_frame.FullExtentImage == "") {
      main_frame.SaveFullExtent = true;
      processTool("zoomToFullExtent");
   } else {
      if (main_frame.FullExtentImage != main_frame.MapHistoryImage) {
         main_frame.addFullExtent();
      }
   }
}
function getMapViews() {
   if (PostBackDone) {
      data_frame.location.href = "getMapViews.aspx" + "?count=" + main_frame.MapHistoryCount;
   }
}
function email() {
   data_frame.location.href = "email.aspx" +
    "?xMinMap=" + main_frame.XMinMap +
    "&yMinMap=" + main_frame.YMinMap +
    "&xMaxMap=" + main_frame.XMaxMap +
    "&yMaxMap=" + main_frame.YMaxMap +
    "&activeLayerId=" + ActiveLayerId + 
    "&layerIds=" + LayerIds +
    "&layersVisible=" + LayersVisible +
    "&VmlObjectId=" + VmlObjectId;
}
function comps() {
   if ((VmlLayerId != ParcelLayerId) || (VmlObjectId < 1)) {
      if (ValidUser) {
         alert("Please identify a property before searching for comparables");
      } else {
         alert("You must Sign-In before using the comparable property search");
      }
   } else {
      if (ValidUser) {
         data_frame.location.href = "comps.aspx" + "?VmlObjectId=" + VmlObjectId;
      } else {
         signIn("comps");
      }
   }
}
function zoomToComps() {
   main_frame.FullExtentImage = "";
   processTool("zoomToComps");
   main_frame.enableRow("editDelete");
}
function zoomInBox(x1,y1,x2,y2) {
   processTool("zoomInBox",x1,y1,x2,y2);
}
function zoomInFixed(x1,y1) {
   processTool("zoomInFixed",x1,y1);
}
function zoomOutBox(x1,y1,x2,y2) {
   processTool("zoomOutBox",x1,y1,x2,y2);
}
function zoomOutFixed(x1,y1) {
   processTool("zoomOutFixed",x1,y1);
}
function pan(x1,y1,x2,y2) {
   processTool("pan",x1,y1,x2,y2);
}
function panFixed(x1,y1) {
   processTool("panFixed",x1,y1);
}
function zoomToActiveLayer() {
   processTool("zoomToActiveLayer");
}
function refreshMap() {
   processTool("refreshMap");
}
function identify(x1,y1) {
   data_frame.location.href = "identify.aspx" +
    "?govUser=" + GovUser +
    "&validUser=" + ValidUser +
    "&x1=" + x1 +
    "&y1=" + y1 +
    "&activeLayerId=" + ActiveLayerId + 
    "&mapImageWidth=" + main_frame.MapImageWidth +
    "&mapImageHeight=" + main_frame.MapImageHeight +
    "&xMinMap=" + main_frame.XMinMap +
    "&yMinMap=" + main_frame.YMinMap +
    "&xMaxMap=" + main_frame.XMaxMap +
    "&yMaxMap=" + main_frame.YMaxMap +
    "&layerIds=" + LayerIds +
    "&layersVisible=" + LayersVisible;
}
function legend() {
   data_frame.location.href = "legend.aspx" +
    "?mapImageWidth=" + main_frame.MapImageWidth +
    "&mapImageHeight=" + main_frame.MapImageHeight +
    "&xMinMap=" + main_frame.XMinMap +
    "&yMinMap=" + main_frame.YMinMap +
    "&xMaxMap=" + main_frame.XMaxMap +
    "&yMaxMap=" + main_frame.YMaxMap +
    "&layerIds=" + LayerIds +
    "&layersVisible=" + LayersVisible;
}
function zoomToFeature(layerID, objectID) {
   processTool("zoomToFeature", layerID, objectID);
}
function zoomXY() {
   if (PostBackDone) {
      data_frame.location.href = "zoomXY.aspx";
   }
}
function findAddress() {
   data_frame.location.href = "findAddress.aspx";
}
function overview() {
   data_frame.location.href = "overview.aspx" + 
   "?xMin=" + main_frame.XMinMap + "&yMin=" + main_frame.YMinMap + 
   "&xMax=" + main_frame.XMaxMap + "&yMax=" + main_frame.YMaxMap;
}
function zoomToPoint(x1,y1,labelText) {
   main_frame.FullExtentImage = "";
   processTool("zoomToPoint", x1, y1, labelText);
   main_frame.enableRow("editDelete");
}
function zoomToParcel(pin) {
   data_frame.location.href = "zoomToParcel.aspx?pin=" + pin;
}
function download() {
   if (ValidUser) {
      data_frame.location.href = "download.aspx";
   } else {
      signIn("download");
   }
}
function signIn(command) {
   data_frame.location.href = "signIn.aspx" + "?command=" + command; 
}
function deleteAllElements() {
   main_frame.disableRow("editDelete");
   initAllElements();
   main_frame.FullExtentImage = "";
   PointXyText = "";
   processTool("deleteAllElements");
}
function find() {
   if (PostBackDone) {
      data_frame.location.href = "find.aspx" + 
       "?govUser=" + GovUser +
       "&validUser=" + ValidUser;
   }
}
function activeLayerMenu() {
   top.data_frame.location.href = "selectLayer.aspx" + 
    "?activeLayerId=" + ActiveLayerId +
    "&govUser=" + GovUser +
    "&validUser=" + ValidUser;
}
function selectByGraphics() {
   data_frame.location.href = "selectByGraphics.aspx" + 
    "?activeLayerId=" + ActiveLayerId + 
    "&resultLayerId=" + main_frame.ResultLayerId +
    "&govUser=" + GovUser +
    "&validUser=" + ValidUser +
    "&averyType=" + main_frame.AveryType;

   if (main_frame.ActiveTool.id != "selectFeature") {
      main_frame.activateTool(main_frame.document.getElementById("selectFeature"));
   }
}
function selectByAtr() {
   data_frame.location.href = "selectByAtr.aspx" + 
    "?activeLayerId=" + ActiveLayerId + 
    "&govUser=" + GovUser +
    "&validUser=" + ValidUser +
    "&averyType=" + main_frame.AveryType;
}
function clearSelect() {
   var prevSelect = main_frame.NumSelect + VmlObjectId;
   VmlObjectId = 0;
   initSelect();

   if (MailLabelWindow) {
      if (!MailLabelWindow.closed) {
         if (main_frame.AddBuffer) {
            if (main_frame.ResultLayerId != ParcelLayerId) {
               MailLabelWindow.close();
            }
         } else {
            if (ActiveLayerId != ParcelLayerId) {
               MailLabelWindow.close();
            }
         }
      }
   }
   if (prevSelect > 0) {
      processTool("refreshMap");
   }
}
function zoomToSelect() {
   processTool("zoomToSelect");
}
function setTheme(theme) {
   if (theme != "Themes") {
      processTool("theme",theme);
   }
}
function mailLabel() {
   //if (ValidUser) {
      MailLabelWindow = window.open("mailLabel.aspx" + 
      "?activeLayerId=" + ActiveLayerId + 
      "&bufferDis=" + main_frame.SBuffer + 
      "&addBuffer=" + main_frame.AddBuffer + 
      "&resultLayerId=" + main_frame.ResultLayerId +
      "&query=" + main_frame.SQuery +
      "&averyType=" + main_frame.AveryType,
      "mailLabelWindow");

      PrevQuery = ActiveLayerId + main_frame.SBuffer + main_frame.AddBuffer + main_frame.ResultLayerId + main_frame.SQuery + main_frame.AveryType;
   //} else {
   //  signIn("mailLabel");
   //}
}
function openAtrTable() {
   AtrTableWindow = window.open("openAtrTable.aspx" + 
   "?activeLayerId=" + ActiveLayerId + 
   "&bufferDis=" + main_frame.SBuffer + 
   "&addBuffer=" + main_frame.AddBuffer + 
   "&resultLayerId=" + main_frame.ResultLayerId +
   "&sortField=" + main_frame.SortField +
   "&query=" + main_frame.SQuery +
   "&govUser=" + GovUser +
   "&validUser=" + ValidUser,
   "AtrTableWindow");

   PrevQuery = ActiveLayerId + main_frame.SBuffer + main_frame.AddBuffer + main_frame.ResultLayerId + main_frame.SQuery;
   main_frame.SortField = "";
}
function printOpt() {
   if (PostBackDone) {
      with (main_frame) {
         if ((ATextAndXYCount > 0) || (APointCount > 0) || (ALineCount > 0) || (APolyCount > 0) || (ACircleCount > 0)) {
            refreshMap();
         }
      }
      data_frame.location.href = "printOpt.aspx" + "?printOptData=" + PrintOptData + "&vmlObjectId=" + VmlObjectId;
   }
}
function printPreview() {
   window.open("printPreview.aspx" + 
   "?PrintOptData=" + PrintOptData +
   "&govUser=" + GovUser +
   "&validUser=" + ValidUser,
   "printPreviewWindow");
}
function metadata(layerId) {
   var metaData = MetadataDir + "/" + layerId + ".htm";
   window.open(metaData, "metadataWindow", "menubar,resizable=yes,scrollbars");
}
//====================
// Fix map visibility.
//====================
function checkMap() {
   var mf = main_frame;
   if (mf.Map_img && mf.Dyn_img) {
      if ((mf.Map_img.style.visibility == "hidden") && (mf.Dyn_img.style.visibility == "hidden")) {
         mf.Map_img.style.zIndex = 2;
         mf.Dyn_img.style.zIndex = 1;
         mf.Map_img.style.visibility = "visible";
         mf.Dyn_img.style.visibility = "hidden";
      }
   }
}
//===========
// Blend map.
//===========
function doBlendTran(toSrc) {
   var mf = main_frame;
   AnimateMap = true;

   if (IeFilters) {
      blendTranIE(mf.Map_img,toSrc,0.3);

   } else {
      mf.Dyn_img.src = toSrc;
      mf.Dyn_img.style.zIndex = 2;
      mf.Dyn_img.width = mf.Map_img.width;
      mf.Dyn_img.height = mf.Map_img.height;

      mf.Map_img.style.zIndex = 1;
      blendTran(mf.Map_img,mf.Dyn_img);
   }
}
//=============
// Init select.
//=============
function initSelect() {
   main_frame.NumSelect = 0;
   main_frame.SQuery = "";
   main_frame.disableRow("viewZoomSelected");

   if (VmlObjectId < 1) {
      main_frame.disableRow("selectionClearSelectedFeatures");
   }
   main_frame.disableRow("selectionZoomToSelectedFeatures");
   main_frame.disableRow("selectionOpenTable");

   if (data_frame.document.getElementById("selectByAtr_form") || 
       data_frame.document.getElementById("selectByGraphics_form")) {
      data_frame.enableTools();
   }
}
//==============
// Init acetate.
//==============
function initAllElements() {
   with (main_frame) {
      clearMeasureVar();
      ATextAndXYCount = 0;

      // Text
      ATextCount = 0;
      AText1.style.visibility = "hidden";
      AText2.style.visibility = "hidden";
      AText3.style.visibility = "hidden";
      AText4.style.visibility = "hidden";
      AText5.style.visibility = "hidden";

      // XY
      AXYCount = 0;
      AXY1.style.visibility = "hidden";
      AXY2.style.visibility = "hidden";
      AXY3.style.visibility = "hidden";
      AXY4.style.visibility = "hidden";
      AXY5.style.visibility = "hidden";

      // Point      
      APointCount = 0;

      // Line
      ALineCount = 0;
      ALineList = "";
      ALineXYCount = 0;
      
      // Polygon
      APolyCount = 0;
      APolyList = "";
      APolyXYCount = 0;

      // Circle
      ACircleCount = 0;

      // VML
      if (IeFilters) {
         APoint_vml.path = "m 0,0 l 0,0 e";
         ALine_vml.path = "m 0,0 l 0,0 e";
         APoly_vml.path = "m 0,0 l 0,0 0,0 0,0 e";
         ACircle1_vml.style.visibility = "hidden";
         ACircle2_vml.style.visibility = "hidden";
         ACircle3_vml.style.visibility = "hidden";
         ACircle4_vml.style.visibility = "hidden";
         ACircle5_vml.style.visibility = "hidden";
      }
   }

   if (main_frame.ActiveTool.id == "addText") {
      main_frame.AText = main_frame.AText1;
      main_frame.AText.value = "Text";
      main_frame.AText.size = 4;
      main_frame.ATextXPrev = 0;
      main_frame.ATextYPrev = 0;
   }
   if (main_frame.ActiveTool.id == "addXY") {
      main_frame.AXY = main_frame.AXY1;
      main_frame.AXY.value = "XY";
      main_frame.AXY.size = 4;
      main_frame.AXYXPrev = 0;
      main_frame.AXYYPrev = 0;
   }
}
//========================
// Submit server commands.
//========================
function processTool(command) {

   // Make sure previous server request is done
   if (PostBackDone) {
      PostBackDone = false;
      main_frame.MapHistoryOk = true;     // Enable new history entries

      // Get mouse coordinate arguments
      if (arguments.length > 2) {
         var x1 = arguments[1];
         var y1 = arguments[2];
         PostBack.x1.value = x1;
         PostBack.y1.value = y1;
      }
      if (arguments.length > 4) {
         var x2 = arguments[3];
         var y2 = arguments[4];
         PostBack.x2.value = x2;
         PostBack.y2.value = y2;
      }

      // Process command specific arguments
      if (command == "zoomToFeature") {
         VmlLayerId = arguments[1];
         VmlObjectId = arguments[2];

      } else if (command == "zoomToPoint") {
         PointXyText = arguments[1] + "," + arguments[2] + "," + arguments[3];

      } else if (command == "theme") {
         PostBackForm.theme_hid.value = arguments[1];
      }
      
      //=========================
      // Load acetate and select.
      //=========================
      loadAcetate();
      loadSelect();

      //==========================
      // Set postback information.
      //==========================
      PostBack.govUser.value = GovUser;
      PostBack.validUser.value = ValidUser;
      PostBack.command.value = command;
      PostBack.mapImageHeight.value = main_frame.MapImageHeight;
      PostBack.mapImageWidth.value = main_frame.MapImageWidth;

      PostBack.xMinMap.value = main_frame.XMinMap;
      PostBack.yMinMap.value = main_frame.YMinMap;
      PostBack.xMaxMap.value = main_frame.XMaxMap;
      PostBack.yMaxMap.value = main_frame.YMaxMap;

      PostBack.vmlLayerID.value = VmlLayerId;
      PostBack.vmlObjectID.value = VmlObjectId;

      PostBack.layerIds.value = LayerIds;
      PostBack.layersVisible.value = LayersVisible;
      PostBack.activeLayerId.value = ActiveLayerId;

      PostBack.pointXyText.value = PointXyText;
      PostBack.compsMapList.value = CompsMapList;

      //========================
      // Send request to server.
      //========================
      PostBackForm.target = "postBack_frame";
      showHourglass();
      PostBackBeg = false;
      PostBackForm.submit();
      window.setTimeout("unlockSite()", LockTimeout * 1000);
   }
}
//================
// Unlock website.
//================
function unlockSite() {
   if (!postBack_frame.document.getElementById("postBack_form")) {
      postBack_frame.location.href = "PostBack_WebForm.aspx";
      setPostBackDone();
      hideHourglass();
   }
}
//===============
// Gecko bug fix.
//===============
function refreshTitle() {
   title_frame.document.getElementById("title_form").submit();
}
//==============================================
// Process information returned from the server.
//==============================================
function processPostBack() {
   var command;
   var mapImageSrc;

   PostBackBeg = true;
   setPostBack();

   // Check for subscriber account in use.
   if (PostBack.accountInUse.value == "True") {
      if (!GovUser) {
         alert("Another user has signed-in using the same account.  This session will be terminated.");
         top.location.href = HomePage;
      }
   }

   // Init gov user variable.
   GovUser = false;
   if (PostBack.govUser.value == "True") {
      GovUser = true;
   }
   // Init valid user variable.
   ValidUser = false;
   if (PostBack.validUser.value == "True") {
      ValidUser = true;
   }

   // Process postback
   if (IsPostBack) {
      command = PostBack.command.value;

      // Init layer visibility
      LayerIds = PostBack.layerIds.value;
      LayersVisible = PostBack.layersVisible.value;
      ActiveLayerId = PostBack.activeLayerId.value;

      if (command == "theme") {
         setActiveLayer(ActiveLayerId);
         main_frame.FullExtentImage = "";
      }
      if (data_frame.document.getElementById("measure_form")) {
         data_frame.clearMeasureAll();
      }
      // Init acetate and selection.
      initAllElements();
      mapImageSrc = PostBack.mapImageSrc.value;
      //alert("Map Image Source=" + mapImageSrc);

      if (mapImageSrc != "") {
         main_frame.DynStep = 9999; //Set Dyn Zoom done
         AnimateMap = false;

         if (main_frame.Dyn_img.style.visibility == "visible") {
            main_frame.Map_img.src = mapImageSrc;
         } else {
            main_frame.Dyn_img.src = mapImageSrc;
         }
         main_frame.XMinMap = parseFloat(PostBack.xMinMap.value);
         main_frame.YMinMap = parseFloat(PostBack.yMinMap.value);
         main_frame.XMaxMap = parseFloat(PostBack.xMaxMap.value);
         main_frame.YMaxMap = parseFloat(PostBack.yMaxMap.value);

         // Compute map scales
         setMapScales();

         // Map layers
         if (LayersWindow) {
            if (command == "theme") {
               showLayers();
            } else { // Gray out layers not visible at current scale
               data_frame.grayOutLayers();
            }
         }
         // Display VML
         if (IeFilters) {
            var vmlGeometry = "";
            vmlGeometry += PostBackForm.vmlGeometry1_hid.value;
            vmlGeometry += PostBackForm.vmlGeometry2_hid.value;
            vmlGeometry += PostBackForm.vmlGeometry3_hid.value;
            vmlGeometry += PostBackForm.vmlGeometry4_hid.value;
            vmlGeometry += PostBackForm.vmlGeometry5_hid.value;
            vmlGeometry += PostBackForm.vmlGeometry6_hid.value;
            main_frame.displayVML(PostBack.vmlFeatureClass.value, vmlGeometry);
         }
         // Enable parcel specific tools
         main_frame.enableSelectTools();

         // Add to history entry.
         if (main_frame.MapHistoryOk) {
            main_frame.addToMapHistory(mapImageSrc);
         }
      } 
      if (IsNN) { //Gecko bug fix
         setTimeout("refreshTitle()", 500);
      }      
      setPostBackDone();

      // Refresh selected feature form
      main_frame.NumSelect = PostBackForm.numSelect_hid.value;

      if (PostBack.errMsg.value != "") {
         hideHourglass();
         alert(PostBack.errMsg.value);
         initSelect();

      } else if (main_frame.NumSelect == 0) {
         initSelect();

      } else {
         if (main_frame.NumSelect > MaxSelectedFeatures) {
            main_frame.disableRow("viewZoomSelected");
            main_frame.disableRow("selectionZoomToSelectedFeatures");
         } else {
            main_frame.enableRow("viewZoomSelected");
            main_frame.enableRow("selectionZoomToSelectedFeatures");
         }
         main_frame.enableRow("selectionOpenTable");

         if (data_frame.document.getElementById("selectByGraphics_form") || 
             data_frame.document.getElementById("selectByAtr_form")) {
            data_frame.enableTools();
         }
      }
      if (VmlObjectId > 0 || main_frame.NumSelect > 0) {
         main_frame.enableRow("selectionClearSelectedFeatures");
      }

      // Refresh menus with selectable layer
      if (command == "theme") {
         if (data_frame.document.getElementById("selectByAtr_form")) {
            selectByAtr();
         } else if (data_frame.document.getElementById("selectByGraphics_form")) {
            selectByGraphics();
         } else if (data_frame.document.getElementById("selectLayer_form")) {
            activeLayerMenu();
         }
      }
      // Refresh selection pop-up windows
      if (AtrTableWindow || MailLabelWindow) {
         var newQuery = ActiveLayerId + main_frame.SBuffer + main_frame.AddBuffer + main_frame.ResultLayerId + main_frame.SQuery;
         if (newQuery != PrevQuery) {

            if (AtrTableWindow) {
               if (!AtrTableWindow.closed) {
                  openAtrTable();
               }
            }
            if (MailLabelWindow) {
               if (!MailLabelWindow.closed) {
                  mailLabel();
               }
            }
         }
      }
      // Refresh map views if visible
      if (data_frame.document.getElementById("mv_form")) {
         getMapViews();
      }
      // Refresh legend if visible
      if (data_frame.document.getElementById("legend_form")) {
         legend();
      }
      // Refresh overview map if visible
      if (data_frame.document.getElementById("overview_form")) {
         overview();
      }

   // Initial page load goes goes here
   } else {
      IsPostBack = true;
   }
} 
//===================
// Set postback done.
//===================
function setPostBackDone() {
   main_frame.Map_img.style.cursor = ActiveCursor;
   if (IeFilters) {
      main_frame.Poly_vml.style.cursor = ActiveCursor;
   }
   main_frame.MapHistoryOk = false;
   PostBackDone = true;
}
//=================
// Show map layers.
//=================
function showLayers() {
   data_frame.location.href = "layers.aspx" + 
    "?govUser=" + GovUser +
    "&validUser=" + ValidUser +
    "&LayerIds=" + LayerIds +
    "&LayersVisible=" + LayersVisible;
}
//====================================
// Load selection data for server use.
//====================================
function loadSelect() {
   PostBackForm.numSelect_hid.value = main_frame.NumSelect;
   PostBackForm.sQuery_hid.value = main_frame.SQuery;
   PostBackForm.sBuffer_hid.value = main_frame.SBuffer;
   PostBackForm.addBuffer_hid.value = main_frame.AddBuffer;
   PostBackForm.resultLayerId_hid.value = main_frame.ResultLayerId;
}
//==================================
// Load acetate data for server use.
//==================================
function loadAcetate() {
   var i;
   var x,y;
   var aText;

   PostBackForm.aPoint_hid.value = "";
   PostBackForm.aCircle_hid.value = "";
   PostBackForm.aText_hid.value = "";

   // Text
   for (i=1; i<=main_frame.ATextCount; i++) {
      if (i != 1) {
         PostBackForm.aText_hid.value += "|";
      }
      if (i == 1) {
         aText = main_frame.AText1;

      } else if (i == 2) {
         aText = main_frame.AText2;

      } else if (i == 3) {
         aText = main_frame.AText3;

      } else if (i == 4) {
         aText = main_frame.AText4;

      } else if (i == 5) {
         aText = main_frame.AText5;
      }
      x = main_frame.ATextX[i]
      y = main_frame.ATextY[i]
      PostBackForm.aText_hid.value += x + "^" + y + "^" + aText.value;
   }
   // XY text
   for (i=1; i<=main_frame.AXYCount; i++) {
      if ((i != 1) || (main_frame.ATextCount > 0)) {
         PostBackForm.aText_hid.value += "|";
      }
      if (i == 1) {
         aText = main_frame.AXY1;

      } else if (i == 2) {
         aText = main_frame.AXY2;

      } else if (i == 3) {
         aText = main_frame.AXY3;

      } else if (i == 4) {
         aText = main_frame.AXY4;

      } else if (i == 5) {
         aText = main_frame.AXY5;
      }
      x = main_frame.AXYX[i]
      y = main_frame.AXYY[i]
      PostBackForm.aText_hid.value += x + "^" + y + "^" + aText.value;
   }
   // Points
   for (i=1; i<=main_frame.APointCount; i++) {
      if (i != 1) {
         PostBackForm.aPoint_hid.value += "|";
      }
      PostBackForm.aPoint_hid.value += main_frame.APointX[i] + "," + main_frame.APointY[i];
   }
   // Circles
   for (i=1; i<=main_frame.ACircleCount; i++) {
      if (i != 1) {
         PostBackForm.aCircle_hid.value += "|";
      }
      PostBackForm.aCircle_hid.value += main_frame.ACircleX[i] + "," + main_frame.ACircleY[i] + "," + main_frame.ACircleRad[i];
   }
   // Lines and polys
   PostBackForm.aLine_hid.value = main_frame.ALineList;
   PostBackForm.aPoly_hid.value = main_frame.APolyList;
}
//=================================
// Load layer lists for server use.
//=================================
function loadLayerLists(layerCount) {
   var i;
   LayerIds = "";
   LayersVisible = "";

   for (i=1; i<=layerCount; i++) {
      if (i != 1) {
         LayerIds += ",";
         LayersVisible += ",";
      }
      LayerIds += FeatureLayers[i].id;
      if (FeatureLayers[i].visible) {
         LayersVisible += "1";
      } else {
         LayersVisible += "0";
      }
   }
}
//====================
// Compute map scales.
//====================
function setMapScales() {
   var wStr;
   var xPixToFeet;
   var yPixToFeet;
   var scaleLabel;
   
   xPixToFeet = (main_frame.XMaxMap - main_frame.XMinMap) / main_frame.MapImageWidth;
   yPixToFeet = (main_frame.YMaxMap - main_frame.YMinMap) / main_frame.MapImageHeight;
   ScalePixelToFeet = (xPixToFeet + yPixToFeet) / 2; 
   ScaleInchToFeet =  ScalePixelToFeet * ScreenDPI;
   ScaleInchToInch =  ScaleInchToFeet * 12;
   ScaleInchToMile =  ScaleInchToFeet / 5280;
   //alert(ScalePixelToFeet + ", " + ScaleInchToFeet + ", " + ScaleInchToInch + ", " + ScaleInchToMile);

   //Scalebar Text
   //if (ScaleInchToFeet < 2640) {
   //   wStr = "1 inch = " + parseInt(ScaleInchToFeet) + " feet"
   //} else {
   //   wStr = parseInt(ScaleInchToMile * 10) / 10
   //   if (ScaleInchToMile < 2) {
   //      wStr = "1 inch = " + wStr + " mile"
   //   } else {
   //      wStr = "1 inch = " + wStr + " miles"
   //   }
   //}
   //scaleLabel = top.statusBar_frame.document.getElementById("scale_label");
   //scaleLabel.innerHTML = wStr;
}
//=========================
// Show/hide the hourglass.
//=========================
function showHourglass() {
   main_frame.document.getElementById("hourglass").style.visibility = "visible";
}
function hideHourglass() {
   if (main_frame) {
      var hg = main_frame.document.getElementById("hourglass");
      if (hg) {
         hg.style.visibility = "hidden";
      }
   }
}
//=====================
// Set the busy cursor.
//=====================
function setBusy(inElement,hand) {
   if (PostBackDone) {
      inElement.style.cursor = "default";
      if (hand) {
         inElement.style.cursor = "hand";
      }
   } else {
      inElement.style.cursor = "wait";
   }
}
//=========================
// Set selectable layer id.
//=========================
function setActiveLayer(id) {
   ActiveLayerId = id;
   clearSelect();
}
//===============
// Save settings.
//===============
function saveLayerSettings() {
   setCookie("LayerIds", LayerIds, 1);
   setCookie("LayersVisible", LayersVisible, 1);
   setCookie("ActiveLayerId", ActiveLayerId, 1);
}
//================
// Clear settings.
//================
function clearLayerSettings() {
   deleteCookie("LayerIds");
   deleteCookie("LayersVisible");
   deleteCookie("ActiveLayerId");
}
