﻿
// Javascript file for Web Mapping Application

var reloadTimer;
var webMapAppLeftPanelWidth = 262;
var webMapAppToggleWidth = 10;
var webMapAppTopBannerHeight = 80;
var newLoad = false;
var webMapAppCloseCallback = "";
var webMapAppCopyrightCallback = "";
var sCallBackFunctionInvocation = "";
var webMapAppMoveFunction = null;
var webMapAppMapDisplay = null;
var webMapAppPanelDisplay = null;
var webMapAppPanelDisplayCell = null;
var webMapAppPanelDisplayTableCell = null;
var webMapAppPanelScrollDiv = null;
var webMapAppToggleDisplay = null;
var webMapAppSpacerDiv = null;
var webMapAppPanelBottomSlider = null;
var webMapAppScaleBar = null;
var webMapAppCopyrightText = null;
var webMapAppWindowWidth = 500;
var webMapAppLeftOffsetX = 0;
var webMapAppRightOffsetX = 0
var webMapAppDefaultMinDockWidth = 125;
var webMapAppMinDockWidth = webMapAppDefaultMinDockWidth;
var webMapAppMapLeft = 262;
var webMapAppHasScroll = false;
var webMapAppLastHasScroll = false;
var m_measureToolbarId = "";
var isRedlining = false;
var preMapMode = '';

// function to set initial sizes of page elements
function setPageElementSizes() {
        // set body style 
        if (document.documentElement) {
            document.documentElement.style.overflow = "hidden";
            document.documentElement.style.height = "100%"; 
        } else {
            document.body.style.overflow = "hidden";
            document.body.style.height = "100%";
        }  
        // get necessary elements
        webMapAppMapDisplay = document.getElementById("Map_Panel");
        webMapAppPanelDisplay = document.getElementById("LeftPanelCellDiv");
        webMapAppPanelDisplayCell = document.getElementById("LeftPanelCell");
        webMapAppPanelScrollDiv = document.getElementById("LeftPanelScrollDiv");
        webMapAppToggleDisplay = document.getElementById("ToggleCell");
        webMapAppPanelSlider = document.getElementById("PanelSlider");
        webMapAppPanelDisplayTableCell = document.getElementById("LeftPanelTableCell");
        webMapAppPanelBottomSlider = document.getElementById("PanelSliderBottom");
        webMapAppScaleBar = document.getElementById("ScaleBar1");
        webMapAppCopyrightText = document.getElementById("CopyrightTextHolder");
        var headerDisplay = document.getElementById("PageHeader");
        var linkDisplay = document.getElementById("LinkBar");
        // set scroll on Dock
        webMapAppPanelScrollDiv.style.overflowY = "auto";
        if (isIE) {
            webMapAppPanelDisplay.style.overflow = "hidden";
        } 
        // get the set widths and heights
        webMapAppLeftPanelWidth = webMapAppPanelDisplay.clientWidth;
        webMapAppToggleWidth = parseInt(webMapAppToggleDisplay.style.width);
        webMapAppTopBannerHeight = headerDisplay.clientHeight + linkDisplay.clientHeight;
        // get browser window dimensions
        var sWidth = getWinWidth();
        var sHeight = getWinHeight();
        // set map display dimensions
        var mWidth = sWidth - webMapAppLeftPanelWidth - webMapAppToggleWidth;
        var mHeight = sHeight - webMapAppTopBannerHeight;
        webMapAppMapLeft = webMapAppLeftPanelWidth + webMapAppToggleWidth;
        webMapAppMapDisplay.style.width =  mWidth + "px";
        webMapAppMapDisplay.style.height = mHeight  + "px";
        if (webMapAppScaleBar!=null) {
            var sbWidth = webMapAppScaleBar.clientWidth;
            var sbHeight = webMapAppScaleBar.clientHeight;
            webMapAppScaleBar.style.left = (sWidth - sbWidth - 10) + "px";
            webMapAppScaleBar.style.top = (sHeight - sbHeight - 10) + "px";
            webMapAppScaleBar.style.width = "auto";
            webMapAppScaleBar.style.height = "auto";
        } 
        if (webMapAppCopyrightText!=null) {
            webMapAppCopyrightText.onmousedown = webMapAppGetCopyrightText;
            var crtHeight = webMapAppCopyrightText.clientHeight;
            webMapAppCopyrightText.style.left = (webMapAppMapLeft + 10) + "px";
            webMapAppCopyrightText.style.top = (sHeight - crtHeight - 10) + "px";
        }
        // set heights of left panel and toggle bar
        webMapAppToggleDisplay.style.height = mHeight  + "px";
        webMapAppPanelScrollDiv.style.height = mHeight  + "px";
        esriMaxFloatingPanelDragRight = sWidth - 15;
        esriMaxFloatingPanelDragBottom = sHeight - 15;

}

// function to toggle Dock visibility
function togglePanelDock() {
    if (webMapAppPanelDisplay.style.display=="none") {
        expandPanelDock();
    } else {
        collapsePanelDock();
    }     
}

function expandPanelDock() {
    var image = document.images["CollapseImage"];
    webMapAppPanelDisplay.style.display = "block";
    image.src = "images/collapse_left.gif";
    image.alt = "Collapse";
    webMapAppPanelSlider.style.cursor = "e-resize";
    webMapAppPanelBottomSlider.style.cursor = "e-resize"; 
    webMapAppMapLeft = webMapAppLeftPanelWidth + webMapAppToggleWidth;
    webMapAppMapDisplay.style.left =  webMapAppMapLeft + "px";
    AdjustMapSize(); 
}

function collapsePanelDock() {
    var image = document.images["CollapseImage"];
    dockWidthString = webMapAppPanelDisplayCell.clientWidth + "px";
    webMapAppPanelDisplay.style.display = "none";
    webMapAppPanelDisplayCell.style.width = "1px";
    image.src = "images/expand_right.gif";
    image.alt = "Expand";
    webMapAppPanelSlider.style.cursor = "default"; 
    webMapAppPanelBottomSlider.style.cursor = "default"; 
    webMapAppMapLeft = webMapAppToggleWidth; 
    webMapAppMapDisplay.style.left =  webMapAppMapLeft + "px";  
    AdjustMapSize();  
   
}  

// function for adjusting element sizes when brower is resized
function AdjustMapSize() {
   // set element widths 
    webMapAppPanelDisplay.style.width =  webMapAppLeftPanelWidth + "px";
    webMapAppToggleDisplay.style.width = webMapAppToggleWidth + "px";
   // get browser window dimensions 
    var sWidth = getWinWidth();
    var sHeight = getWinHeight();
    // calc dimensions needed for map
    var mWidth = sWidth - webMapAppPanelDisplayCell.clientWidth;
    var mHeight = sHeight - webMapAppTopBannerHeight;
    if (mWidth<5) mWidth = 5;
    if (mHeight<5) mHeight = 5;  
    webMapAppMapDisplay.style.width =  mWidth + "px";
    webMapAppMapDisplay.style.left =  webMapAppPanelDisplayCell.clientWidth + "px"; 
   // set heights on elements 
    webMapAppMapDisplay.style.height = mHeight  + "px";
    webMapAppToggleDisplay.style.height = mHeight  + "px";
    webMapAppPanelScrollDiv.style.height = mHeight  + "px";
    if (webMapAppScaleBar!=null) {
        var sbWidth = webMapAppScaleBar.clientWidth;
        var sbHeight = webMapAppScaleBar.clientHeight;
        webMapAppScaleBar.style.left = (sWidth - sbWidth - 10) + "px";
        webMapAppScaleBar.style.top = (sHeight - sbHeight - 10) + "px";
    } 
   // resize the map 
    window.setTimeout("resizeTheMap(" + mWidth + ", " + mHeight + ", false);", 500);
   // update map properties 
     
    var box = calcElementPosition("Map_Panel"); 
    map.containerLeft = box.left;
	map.containerTop = box.top;
    if (webMapAppCopyrightText!=null) {
        var crtHeight = webMapAppCopyrightText.clientHeight;
        webMapAppCopyrightText.style.left = (box.left + 10) + "px";
        webMapAppCopyrightText.style.top = (sHeight - crtHeight - 10) + "px";
    }
    return false;
}

// function for resizing map in Web Map App
function resizeTheMap(width, height, resizeExtent) {
    if (resizeExtent==null) resizeExtent = true;
    map.resize(width, height, resizeExtent);
    var div = document.getElementById("LeftPanelCellDiv"); 
    // update overview, if doc panel is expanded 
    if (ov!=null && div.style.display!="none") { 
        var argument = "ControlType=OverviewMap&EventArg=OverviewZoom";
        var context = ov.controlName; 
        eval(ov.callBackFunctionString);
    }
    return false; 
}

// handler for window resize
function AdjustMapSizeHandler(e) {
    window.clearTimeout(reloadTimer);
	reloadTimer = window.setTimeout("AdjustMapSize();",1000);
}

// function run at startup
function startUp() {
        
        //document.getElementById('SelectionResultsPanel').style.visibility = 'hidden';
        
        // set up identify mode for javascript
        map.ctrlMode = "MapIdentify";
        map.ctrlAction = "Point";
        map.ctrlCursor = "pointer";
        map.ctrlFunction = "MapIdClick(e)";
        if (newLoad) {
            // execute only on intial load.... not callbacks
            map.divObject.style.cursor = "wait";
            // move magnifier and measure toolbar to top left corner of map display 
            var box = calcElementPosition("Map_Panel"); 
            var mag = document.getElementById("Magnifier1");
            if (mag!=null && typeof(esriMagnifiers)!="undefined" && esriMagnifiers!=null) { 
                    floatingPanel = esriMagnifiers["Magnifier1"].floatingPanel; 
                    if (floatingPanel!=null) moveTo(box.left, box.top);
            }
            var tb = document.getElementById(m_measureToolbarId);
			if (tb!=null) {
			    tb.style.left = box.left + "px";
			    tb.style.top = box.top + "px";
			}
			var fp = document.getElementById("CopyrightText_Panel");
			if (fp!=null) {
			    floatingPanel = fp;
			    moveTo(box.left, box.top);
			}
 
        } 
        // set window resize event handler
       window.onresize = AdjustMapSizeHandler;
       for (var fp in FloatingPanels) {
            FloatingPanels[fp].onDockFunction = scrollDockToPanel;
       }
       document.getElementById('ChangeMapIndicator').style.visibility = 'hidden';   
       document.getElementById('TOCChangeIndicator').style.visibility = 'hidden';
       document.getElementById('BufferProgressIndicator').style.visibility = 'hidden';
       document.getElementById('QueryProgressIndicator').style.visibility = 'hidden';
       document.getElementById('SavedMapActivityDiv').style.visibility = 'hidden';
       document.getElementById('MapGenDiv').style.visibility = 'hidden';
}  

// function to request closing of session items.... only called if at least one resource is local non-pooled
function CloseOut() {
	var argument = "ControlID=Map1&ControlType=Map&EventArg=CloseOutApplication";
	var context = map.controlName;
	eval(webMapAppCloseCallback);
}

// response function to close out browser ... request sent to server by CloseOut()
function CloseOutResponse(response, context) {
    window.close(); 
    // if user selects Cancel in close dialog, send to close page 
    document.location = response; 
}


function startWebMapAppDockDrag(e) {
    webMapAppMoveFunction = document.onmousemove;
    document.onmouseup = stopWebMapAppDocDrag;  
    if (webMapAppPanelDisplay.style.display!="none") {
        webMapAppWindowWidth = getWinWidth();
        getXY(e); 
        webMapAppLeftOffsetX = mouseX - webMapAppPanelDisplay.clientWidth;
        var box = calcElementPosition("Map_Panel");
        webMapAppRightOffsetX = box.left - mouseX; 
        document.onmousemove = moveWebMapAppDockDrag;
        var ovPanel = document.getElementById("OverviewMap_Panel_BodyRow");
        var ovDisplay =  document.getElementById("OVDiv_OverviewMap_Panel_OverviewMap1");
        // because the panel cell will be as wide as the overview map image, keep the element width larger than the image. 
        if (FloatingPanels["OverviewMap_Panel"]!=null &&FloatingPanels["OverviewMap_Panel"].docked)
            webMapAppMinDockWidth = parseInt(ovDisplay.style.width) + 20;
        else    
            webMapAppMinDockWidth = webMapAppDefaultMinDockWidth; 
    }
    return false;  
}

function moveWebMapAppDockDrag(e) {
    getXY(e);
    webMapAppLeftPanelWidth =  mouseX - webMapAppLeftOffsetX;
    if (webMapAppLeftPanelWidth < webMapAppMinDockWidth) webMapAppLeftPanelWidth = webMapAppMinDockWidth; 
    var mapLeftString =  (webMapAppLeftPanelWidth + webMapAppToggleDisplay.clientWidth) + "px";
    //if (webMapAppPanelDisplayTableCell.clientWidth - webMapAppToggleDisplay.clientWidth > webMapAppLeftPanelWidth) webMapAppLeftPanelWidth = webMapAppPanelDisplayTableCell.clientWidth - webMapAppToggleDisplay.clientWidth;
    var widthString =  webMapAppLeftPanelWidth + "px";
    webMapAppPanelDisplay.style.width = widthString;
    //var width =  webMapAppWindowWidth - webMapAppMapDisplay.clientWidth;
    var width =  webMapAppWindowWidth - webMapAppPanelDisplayCell.clientWidth; 
    webMapAppMapDisplay.style.width = width + "px";
    webMapAppMapDisplay.style.left = mapLeftString;
    return false;
}

function stopWebMapAppDocDrag(e) {
    document.onmousemove = webMapAppMoveFunction;
    document.onmouseup = null;   
    webMapAppCheckPanelWidths();
    AdjustMapSize();  
    return false;
}

function OpenWindow(url) {
    window.open(url);
}

function webMapAppCheckPanelScroll() {
    if (webMapAppPanelScrollDiv.scrollHeight>webMapAppPanelScrollDiv.clientHeight) {
        webMapAppHasScroll = true;
    }  else {
        webMapAppHasScroll = false;
    }  
    //webMapAppCheckPanelWidths(); 
    if (webMapAppHasScroll!=webMapAppLastHasScroll)
        AdjustMapSize();
    webMapAppLastHasScroll = webMapAppHasScroll;    
    return false; 
}

function webMapAppCheckPanelWidths() {
    var maxWidth = 0;
    var node; 
    for (var i=0; i< webMapAppPanelDisplay.childNodes.length; i++) {
        if (webMapAppPanelDisplay.childNodes[i].tagName=="TABLE") {
            node = webMapAppPanelDisplay.childNodes[i];
            if (node.clientWidth>maxWidth) maxWidth = node.clientWidth; 
        }
    }  
     webMapAppPanelDisplay.style.width = maxWidth + "px";
    return false;
}

function webMapAppGetCopyrightText() {
	var argument = "ControlID=Map1&ControlType=Map&EventArg=GetCopyrightText";
	var context = map.controlName;
	eval(webMapAppCopyrightCallback);
	showFloatingPanel('CopyrightText_Panel');
}

function scrollDockToPanel(panelElement) {
    if (panelElement==null) return;
    var yPos = panelElement.offsetTop;
    webMapAppPanelScrollDiv.scrollTop = yPos;  
}

function toggleMagnifier() {
    var mag = document.getElementById("Magnifier1");
    if (mag!=null) { 
            toggleFloatingPanelVisibility('Magnifier1'); 
    } else 
        alert("Magnifier is not available"); 
}

function tempEvent(new_which)
{
    this.which = new_which;
    this.button = new_which;
}

function OpenRedliningDialog(e)
{
    toggleFloatingPanelVisibility('RedliningTask1');
    expandFloatingPanel('RedliningTask1');
    if (document.getElementById('RedliningTask1').style.display=='')
    {
        preMapMode = map.mode;
        var e = new tempEvent(leftButton);
        
        var oldisNav = isNav;
        isNav = true;
        ToolbarMouseDown( 'RedliningTask1_ITN_RedliningToolbar', 'ITN_MarkerTool', 'Tool', e);
        isNav = oldisNav;
        
    }
    else
    {
        if (map.mode.indexOf('ITN_')>0)
        {
            var e = new tempEvent(leftButton);
            
            var oldisNav = isNav;
            isNav = true;
            ToolbarMouseDown( 'Toolbar1', preMapMode, 'Tool', e);
            isNav = oldisNav;
        }
    }
}


//******************* IT Nexus added here down ********************************
function ViewPublicMaps()
{
    context = "ViewPublicMaps";
    ChangeClient();
}
function sortResults(columnName,sortAsc,OIDColumn)
{
    argument = 'ControlID=SelectionResultsPanel';
    argument += '&ControlType=FloatingPanel';
    argument += '&EventArg=SortAsc';
    argument += '&Column=' + columnName;
    argument += '&SortASC=' + sortAsc;
    argument += '&OIDColumnName=' + OIDColumn;
    eval(sCallBackFunctionInvocation)
}
function mouseOver()
{
    document.body.style.cursor = 'pointer';
}
function mouseLeave()
{
    document.body.style.cursor = 'default';
}
function HideAllProgressIndicators()
{
    document.getElementById('QueryProgressIndicator').style.visibility = 'hidden';
    document.getElementById('MapGenDiv').style.visibility = 'hidden';
    document.getElementById('TOCChangeIndicator').style.visibility = 'hidden';
    document.getElementById('BufferProgressIndicator').style.visibility = 'hidden';
    document.getElementById('ChangeMapIndicator').style.visibility = 'hidden';
    document.getElementById('SavedMapActivityDiv').style.visibility = 'hidden';
    document.getElementById('identifyActivityDiv').style.visibility = 'hidden';
}
function SaveMap()
{
    context = 'SaveMap';
    ChangeClient();
}
function BufferUseSelected()
{
    context = 'BufferUseSelected';
    ChangeClient();
}
function GetMap()
{
    context = 'GetMap';
    document.getElementById('SavedMapActivityDiv').style.visibility = 'visible';
    ChangeClient();
}
function RemoveMap()
{
    context = 'RemoveMap';
    ChangeClient();
}
function OpenPrintDialog()
{
   showFloatingPanel('PrintPanel');
}

function ViewMap()
{
       document.getElementById('MapGenDiv').style.visibility = 'visible';
       context = 'ViewMap';
       ChangeClient(); 
}
function QueryAddText(txt)
{
    var txtArea = document.getElementById("SQLTextArea");
    txtArea.value = txtArea.value + txt;
}
function QueryClearText()
{
    var txtArea = document.getElementById("SQLTextArea");
    txtArea.value = "";
}
function AddColumnSQL()
{
        var llist =document.getElementById("AttributeQueryPanel_ColumnListBox");

		 if (llist.selectedIndex > -1)
		 {
		   QueryAddText(llist[llist.selectedIndex].value + ' ');
	     }
}
function AddValueSQL()
{
         var llist =document.getElementById("AttributeQueryPanel_DistinctListBox");
		   
		 if (llist.selectedIndex > -1)
		 {
		   QueryAddText(' ' + llist[llist.selectedIndex].value);
	     }
}
function GetDistinctValues()
         {
          document.getElementById('QueryProgressIndicator').style.visibility = 'visible';
          context = 'GetDistinctValues';
          ChangeClient(); 
         }
function ExecuteSQL()
       {
          var sql = document.getElementById("SQLTextArea").value;
          if (sql !='')
          {
            document.getElementById('QueryProgressIndicator').style.visibility = 'visible';
            context = 'ExecuteSQL';
            ChangeClient();
          }
          else
          {
          alert('Please enter a query');
          } 
       }         
         
function ZoomToFeature(OID)
    {
        argument = 'ControlID=Map1';
        argument += '&ControlType=Map';
        argument += '&EventArg=ZoomToFeature';
        argument += '&OIDValue=' + OID;
        eval(sCallBackFunctionInvocation)
    }
function UpdateIDResults(feat)
{
    var context = map.controlName;
    argument = 'ControlID=Map1';
    argument += '&ControlType=Map';
    argument += '&EventArg=UpdateIDDisplay';
    argument += '&FeatureStr=' + feat;
    eval(sCallBackFunctionInvocation)
}
function FindAddress()
    {
         context = 'FindAddress';
         ChangeClient(); 
    }
function ZoomPrevious()
         {
          context = 'ZoomP';
          ChangeClient(); 
         }

function ZoomNext()
         {
          context = 'ZoomN';
          ChangeClient(); 
         }

function ChangeIDTypeDDL()
         {
            document.getElementById('identifyActivityDiv').style.visibility = 'visible';
            context = 'IDTypeDDL';
            ChangeClient(); 
         }
function ChangeSelTypeDDL()
         {
            context = 'SelTypeDDL';
            ChangeClient(); 
         }
function ChangeSelLayerDDL()
         {
            context = 'SelLayerDDL';
            ChangeClient(); 
         }
function ChangeAttributeLayerDDL()
         {
            context = 'AttributeLayerDDL';
            ChangeClient(); 
         }
function ChangeGeocodeService()
        {
            context = 'GeocodeServicesDDL';
            ChangeClient(); 
        }
         
function ClearSelection()
         {
         context = "ClearSelection";
         hideFloatingPanel('SelectionResultsPanel');
         ChangeClient();
         }
function ChangeMap(checkbox)
         {
         context = "ChangeMap";
         UpdateMapService(checkbox)
         }
function BufferClick()
         {
         document.getElementById('BufferProgressIndicator').style.visibility = 'visible';
         context = "Buffer"
         ChangeClient();
         }
function displaySettingsOnclick()
{
    context = "ChangeMapTransparency";
    ChangeClient();
}
function ChangeBufferGraphics()
{
    context = "ChangeBufferGraphics";
    ChangeClient();
}
function ExportToExcel()
{
    context = "ExcelExport";
    ChangeClient();
}


function UpdateMapService(checkbox)
{             
            document.getElementById('ChangeMapIndicator').style.visibility = 'visible';
            
            var n =checkbox.nextSibling;

            while (n.nodeType!=1)
            {
                n = n.nextSibling;
            }
           
            var val = n.childNodes[0].nodeValue;
            var ischecked = checkbox.checked;
            argument = 'ControlID=Map1';
            argument += '&ControlType=Map';
            argument += '&EventArg=ChangeMap';
            argument += '&SelectedValue=' + val;
            argument += '&IsChecked=' + ischecked
                                         
            eval(sCallBackFunctionInvocation)           
                   
}        
function ChangeClient()
         {
            var argument;
            
            if (context == 'GetDistinctValues') //Handle a request for distinct values
            {
              var Layer = document.getElementById('AttributeQueryPanel_AttributeLayerDDL').value;
              var llist =document.getElementById("AttributeQueryPanel_ColumnListBox");
              var Column = '';
              if (llist.selectedIndex > -1)
		        {      
		            Column = llist[llist.selectedIndex].value;
	            }
                         
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=GetDistinctValues'
              argument += '&LayerName=' + Layer;
              argument += '&ColumnName=' + Column;
            } 
            if (context == 'IDTypeDDL') //Handle a change in the Identify type dropdown
            {
              var ddlvalue = document.getElementById('IDResults_IDTypeDDL').value;
                         
              argument = 'ControlID=IDTypeDDL';
              argument += '&ControlType=DropDownList';
              argument += '&EventArg=ChangeSelectedValue';
              argument += '&SelectedValue=' + ddlvalue;  
            } 
            if (context == 'SelTypeDDL') //Handle a change in the selection type dropdown
            {
              var ddlvalue = document.getElementById('SelTypeDDL').value;
                         
              argument = 'ControlID=SelTypeDDL';
              argument += '&ControlType=DropDownList';
              argument += '&EventArg=ChangeSelectedValue';
              argument += '&SelectedValue=' + ddlvalue;
             } 
             
             if (context == 'GeocodeServicesDDL') //Handle a change in the selection type dropdown
            {
              var ddlvalue = document.getElementById('LocatePanel_GeocodeServicesDDL').value;
                         
              argument = 'ControlID=GeocodeServicesDDL';
              argument += '&ControlType=DropDownList';
              argument += '&EventArg=ChangeSelectedValue';
              argument += '&SelectedValue=' + ddlvalue;
            } 
            
            if (context == 'SelLayerDDL') //Handle a change in the selection layer dropdown
            {
              var ddlvalue = document.getElementById('BufferPanel_SelLayerDDL') .value;
              
              argument = 'ControlID=SelLayerDDL';
              argument += '&ControlType=DropDownList';
              argument += '&EventArg=ChangeSelectedValue';
              argument += '&SelectedValue=' + ddlvalue;
             }
             
             if (context == 'AttributeLayerDDL') //Handle a change in the Attribute query layer dropdown
            {
              var ddlvalue = document.getElementById('AttributeQueryPanel_AttributeLayerDDL') .value;
              
              argument = 'ControlID=AttributeLayerDDL';
              argument += '&ControlType=DropDownList';
              argument += '&EventArg=ChangeSelectedValue';
              argument += '&SelectedValue=' + ddlvalue;
            }   
            if (context == 'ExecuteSQL') //Handle a attribute query request
            {  
              var sql = document.getElementById("SQLTextArea").value;
              var layer = document.getElementById('AttributeQueryPanel_AttributeLayerDDL') .value;                          
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ExecuteSQL';
              argument += '&SQLTxt=' + sql;
              argument += '&LayerName=' + layer;
            } 
            if (context == 'ZoomP') //Handle a zoom previous request
            {                             
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ZoomPrevious';
            } 
            
            if (context == 'ZoomN') //Handle a zoom next request
            {                         
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ZoomNext';
            } 
            if (context == 'ClearSelection') //Handle a clear selection request
            {                         
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ClearSelection'
            } 
            
            if (context == 'ExcelExport') //Handle a export to Excel request
            {                         
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ExcelExport'
            } 
            
            if (context == 'BufferUseSelected') //Handle the Use Selected checkbox
            {     
              var ischecked = document.getElementById('UseSelectedCB').checked;
                                          
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=BufferUseSelected'
              argument += '&IsChecked=' + ischecked
            } 
            
            if (context == 'ChangeMapTransparency') //Handle a map transparency change request
            {                         
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ChangeTransparency';
              argument += '&Transparency=' + document.getElementById('txtTransparency').value;
            } 
            
            if (context == 'Buffer') //Handle a buffer request
            {                         
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=Buffer'
              argument += '&BufferDist=' + document.getElementById('BufferPanel_txtDist').value;
              argument += '&BufferUnits=' + document.getElementById('BufferPanel_BufferUnitsDDL').value;
              argument += '&SelLayer=' + document.getElementById('BufferPanel_FindLayerDDL').value;
              argument += '&SpatRelType=' + document.getElementById('BufferPanel_SpatialRelTypeDDL').value; 
              argument += '&ShowBuffer=' + document.getElementById('BufferPanel_cbShowBuffer').checked;
              argument += '&ShowSelected=' + document.getElementById('BufferPanel_cbShowSelected').checked;
             } 
             
             if (context == 'ChangeBufferGraphics') //Handle a buffer graphics change request
            {                         
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ChangeBufferGraphics';
              argument += '&ShowBuffer=' + document.getElementById('BufferPanel_cbShowBuffer').checked;
              argument += '&ShowSelected=' + document.getElementById('BufferPanel_cbShowSelected').checked; 
            } 
            if (context == 'FindAddress') //Handle a geocoding request
            {  
              var addr = document.getElementById("LocatePanel_AddressTxt").value;
              
              if(document.getElementById("LocatePanel_ZoneTxt"))
                    var zone = document.getElementById("LocatePanel_ZoneTxt").value;
              else
                    var zone = '';
              
              var gs = document.getElementById("LocatePanel_GeocodeServicesDDL").value;
                            
              if (addr.indexOf("&") > 0)
              {
                addr = addr.replace("&", "@");
              }
              
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=FindAddress';
              argument += '&Service=' + gs;
              argument += '&Address=' + addr;
              argument += '&Zone=' + zone;
            } 
            
            if (context == 'ViewMap') //Handle a map request
            {  
              var title = document.getElementById("PrintPanel_MapTitleTxt").value;
              var layout = document.getElementById("PrintPanel_MapSizeDDL").value;
              var createPDF = document.getElementById("cbPDF").checked;
             
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ViewMap';
              argument += '&createPDF=' + createPDF; 
              argument += '&MapTemplate=' +layout;
              argument += '&MapTitle=' + title;
           } 
           
           if (context == 'SaveMap') //Handle a map save request
            {  
              var map = document.getElementById("MapPanel_txtMapName").value;
              var isPublic =  document.getElementById('MapPanel_SavePublicCB').checked;                                             
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=SaveMap';
              argument += '&MapTitle=' + map;
              argument += '&IsPublic=' + isPublic;
           } 
            if (context == 'RemoveMap') //Handle a request to remove bookmark
            { 
              var MapID = '';
              var llist = document.getElementById("MapPanel_ListBoxMaps"); 
              if (llist.selectedIndex > -1)
		        {      
		            MapID = llist[llist.selectedIndex].value;
		        }                    
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=RemoveMap'
              argument += '&MapID=' + MapID;
            } 
            if (context == 'GetMap') //Handle a request to get a bookmark
            { 
              var MapID = '';
              var llist = document.getElementById("MapPanel_ListBoxMaps"); 
              if (llist.selectedIndex > -1)
		        {      
		            MapID = llist[llist.selectedIndex].value;
		        }                    
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=GetMap'
              argument += '&MapID=' + MapID;
            } 
             if (context == 'ViewPublicMaps') //Handle a request to display public maps
            { 
              var showPublicMaps =  document.getElementById('MapPanel_ViewPublicMapsCB').checked;                       
              
              if (showPublicMaps == true)
                document.getElementById('RemoveMapBtn').disabled=true;
              else
                document.getElementById('RemoveMapBtn').disabled=false;               
                
              argument = 'ControlID=Map1';
              argument += '&ControlType=Map';
              argument += '&EventArg=ViewPublicMaps';
              argument += '&ShowPublicMaps=' + showPublicMaps;
               
            }             
           eval(sCallBackFunctionInvocation)
}
