﻿function openCountyLanduseManagerWindow()
{
    var theMap = getMap;
    var theKeys = getTheLanduseKeys();
    if(theKeys == undefined)
    {
        theKeys="";
    }

    var theURL
    if(theKeys=="")
    {
        theURL = "../../County_Landuse_Manager/LanduseManager.aspx"
    }
    else
    {
        theURL = "../../County_Landuse_Manager/LanduseManager.aspx?thePID=" + theKeys;
    }
     
    if(countyLanduseManagerWindow == null || countyLanduseManagerWindow.closed == true)
    {
        var countyLanduseManagerWindowProperties = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=500";
        countyLanduseManagerWindow = open(theURL, "CountyManagerEditor", countyLanduseManagerWindowProperties); 
    }
    else
    {
        countyLanduseManagerWindow.location.href = theURL;
        countyLanduseManagerWindow.focus();
    }
}

function refreshCountyLanduse() {
    var theMap = getMap();
    var countyLanduseLayers = theMap.getMapLayerGroup(countyLanduseLayerName).getMapLayers();
    var numberOfLayersInGroup = countyLanduseLayers.size();
    var i;
    for(i = 0; i < numberOfLayersInGroup; i++)
    {
        countyLanduseLayers.item(i).setRebuild(true);
    }
    var theSelection = theMap.getSelection();
    theSelection.clear();
    theMap.refresh();
    window.focus();
}

function getTheLanduseKeys()
{
    var theMap = getMap();
    var theKeys = "";
    var features = theMap.getSelection();
    if (features.getNumObjects() == 0)
    {
        return theKeys;
    }

    var layer = theMap.getMapLayer(countyLanduseLayerName);

    // Cycle through 'theObjects', getting key for each member and add it to 'theKeys'
    var theObjects = features.getMapObjectsEx(layer);    
    if(theObjects == undefined)
    {
        theKeys = -1;
    }
    else
    {
        for (i = 0; i < theObjects.size(); i++)
        {
            theKeys += theObjects.item(i).getKey() + ",";
        }
        var len = theKeys.length - 1;
        theKeys = theKeys.substr(0, len);
    }	
    return theKeys;
}