﻿// JScript File
var arcgisWebApp;
var m_map = "map1";
var m_t1 = "Toolbar1";
var m_t2 = "Toolbar2";
var ina = " is not available.";
var ewma = "ESRI.ADF.WebMappingApplication";
var m_undef = "undefined";
var m_sepdiv = "divsep"
var isIE = (Sys.Browser.agent == Sys.Browser.InternetExplorer);

Type.registerNamespace(ewma);

function startUp() {
    arcgisWebApp.map = $find(m_map);
    map = arcgisWebApp.map;
    
    if (typeof setUpMeasureEvent != m_undef) setUpMeasureEvent();

    var toolbar1 = $find(m_t1);
    if (arcgisWebApp.map != null && toolbar1 != null) {
        arcgisWebApp.map.remove_extentChanged(toolbar1._toolbarExtentChangedHandler); // just in case it is already present
        arcgisWebApp.map.add_extentChanged(toolbar1._toolbarExtentChangedHandler);
        toolbar1.add_onToolSelected(OnToolSelectHandler);
    }
    var toolbar2 = $find(m_t2);
    if (arcgisWebApp.map != null && toolbar2 != null) {
        arcgisWebApp.map.remove_extentChanged(toolbar2._toolbarExtentChangedHandler); // just in case it is already present
        arcgisWebApp.map.add_extentChanged(toolbar2._toolbarExtentChangedHandler);
        toolbar2.add_onToolSelected(OnToolSelectHandler);
    }
   
}
    function resizemap() {
        var lval = document.getElementById(m_sepdiv).style.left;
        var mywidth = document.body.clientWidth;
        var myheight = window.innerHeight;
        
        if (myheight == null) {
            if (document.documentElement && document.documentElement.clientHeight)
                myheight = document.documentElement.clientHeight;
            else
                myheight = document.body.clientHeight;
        }
        
        myheight = myheight - 130;
        
        if (lval=='0px')
            {
            mywidth = mywidth - 20;
            lval=10;
                
            document.getElementById('Navigation1').style.left = '20px';
            document.getElementById('ZoomLevel1').style.left = '40px';
	        //document.getElementById('ScaleBar1').style.left = '20px';
	        
            }
        else
            {
            mywidth = mywidth - 340;
            lval=320;
            
            document.getElementById('Navigation1').style.left = '340px';
            document.getElementById('ZoomLevel1').style.left = '360px';
	        //document.getElementById('ScaleBar1').style.left = '340px';
	        
            }
            
        var mp = document.getElementById(m_map);
        mp.style.left = lval+'px';
        mp.style.width = mywidth+'px';
        mp.style.height = myheight+'px';
        
        document.getElementById(m_sepdiv).style.height = myheight+'px';
        //document.getElementById('ScaleBar1').style.top = (myheight+70)+'px';
        //document.getElementById('UpdatePanelActivity').style.left = (lval+(mywidth/2))+'px';
        //document.getElementById('UpdatePanelActivity').style.top = (myheight/2)+'px';
            
    }
    
    function setdiv() {
	    var lval = document.getElementById(m_sepdiv).style.left;
	    var stitle = '';
	    var sleft = '';
	    if (lval=='320px')
	    {
		    lval='0px';
		    stitle='Click to show tool panel';
		    sleft = '-500px';
	    }
	    else
	    {
		    lval='320px';
		    stitle='Click to hide tool panel';
		    sleft = '0px';
	    }
	    document.getElementById(m_sepdiv).title = stitle;
	    document.getElementById(m_sepdiv).style.left = lval;
	    document.getElementById('selectionspanelLabel').style.left = sleft;
	    document.getElementById('selectionspanel1').style.left = sleft;
	    document.getElementById('selectionspanel2').style.left = sleft;
	    document.getElementById('RadiusPanel').style.left = sleft;
	    document.getElementById('pnlLook').style.left = sleft;
	        
	    resizemap();
	    
    }
    
function awakesep() {
    document.getElementById(m_sepdiv).style.backgroundColor='MidnightBlue';
    }    
    
function sleepsep() {
    document.getElementById(m_sepdiv).style.backgroundColor='White';
    }    
    
function resetMapHistory() {
    arcgisWebApp.map._currentExtentHistory = 0;
    var toolbar = $find(m_t1);
    var tbElem = Toolbars[toolbar._uniqueID];
    var backButton = tbElem.items[tbElem.btnMapBack];
    if (backButton) { backButton.disabled = true; }
    var forwardButton = tbElem.items[tbElem.btnMapForward];
    if (forwardButton) { forwardButton.disabled = true; }
    tbElem.refreshCommands();
}

// function to request closing of session items.... only called if at least one resource is local non-pooled
function CloseOut(logout) {
    PageMethods.CleanUp(CloseOutResponse, CloseOutResponse);
}

// response function to close out browser ... request sent to server by CloseOut()
function CloseOutResponse(response) {
    window.close();
    // if user selects No/Cancel in close dialog, send to close page 
    document.location = response;
}

function toggleFloat(floatname) {
    var myfloat = $get(floatname);
    if (myfloat != null) {
        toggleFloatingPanelVisibility(floatname);
    } else
        alert(floatname + ina);
}

function toggleOverviewMap(ovmname) {
    var ovm = $find(ovmname);
    if (ovm) {
        if (ovm.isVisible()) {
            ovm.hide();
        } else {
            ovm.show();
        }
    }
}

function backForward(value) {
    arcgisWebApp.map.stepExtentHistory(value);
}

function OnToolSelectHandler(sender, args) {
    if (args.name) {
        var mode = args.name;
        arcgisWebApp.currentMode = mode;
        if (mode != "Measure" && arcgisWebApp.lastMode == "Measure") closeMeasureToolbarTool();
        arcgisWebApp.lastMode = mode;
    }
}


// Common webpage object for manipulating page elements
ESRI.ADF.WebMappingApplication.WebPage = function() {
    ESRI.ADF.WebMappingApplication.WebPage.initializeBase(this);
}

ESRI.ADF.WebMappingApplication.WebPage.registerClass(ewma+'.WebPage');
arcgisWebApp = new ESRI.ADF.WebMappingApplication.WebPage();
if (typeof (Sys) !== m_undef) { Sys.Application.notifyScriptLoaded(); }
