﻿// JScript File
var arcgisWebApp;
var isRTL = (document.documentElement.dir=="rtl"); // find out if the document has been set to right-to-left
var isIE = (Sys.Browser.agent == Sys.Browser.InternetExplorer);


/// <reference assembly="System.Web.Extensions" name="MicrosoftAjax.js"/>
Type.registerNamespace('ESRI.ADF.WebMappingApplication');
// function run at startup
function startUp() {
        // set window resize event handler
        //$addHandler(window,"resize", arcgisWebApp.adjustMapSizeHandler);
        arcgisWebApp.MapId = "ctl00_cphBody_Map1";
        arcgisWebApp.map = $find(arcgisWebApp.MapId);
        //arcgisWebApp.map = $jq("#ctl00_cphBody_Map1");
        map = arcgisWebApp.map;
        map.add_extentChanged(map_ExtentChanged);
        map.add_extentChanging(map_ExtentChanging);
        map.add_mouseDown(mouseDown);
        map.add_mouseUp(mouseUp);
        
        //only call if defined
        if (typeof addTips == 'function') {
            addTips();
        }

        //only call if defined
        if (typeof addTipsAddress == 'function') {
            addTipsAddress();
        }
        
        //arcgisWebApp.adjustMapSize();

        // because the toolbar is listed before the map control,
        //  make sure toolbar will be listening to changes in map extent
        var toolbar = $find("ctl00_cphBody_Toolbar1");
        
//        if (toolbar != null)
//            toolbar.add_onToolSelected(OnToolSelectHandler);
		if (map != null && toolbar!=null)
		{
		    //map.remove_extentChanged(toolbar._toolbarExtentChangedHandler); // just in case it is already present
			//map.add_extentChanged(toolbar._toolbarExtentChangedHandler);
			toolbar.add_onToolSelected(OnToolSelectHandler);
			window.setTimeout("resetMapHistory();", 1500);
		}
}

//Stop MapTip Details from showing when user is trying to zoom in/out
function mouseDown() {
    MouseDragging = true;
}

//rename MapTip Details when user is done zooming in/out
function mouseUp() {
    MouseDragging = false;
}

//need to move MapTips
function map_ExtentChanged() {
    //from MapTips.js
    updateMapTips();
}

//need to move MapTips
function map_ExtentChanging() {
    //from MapTips.js
    hideMapTips();
}

function resetMapHistory() {
//    map = arcgisWebApp.map;
//    var toolbar = $find("ctl00_cphBody_Toolbar1"); 
//	map._currentExtentHistory = 0;
//	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) 
{
    var r = Math.random().toString();
    PageMethods.CleanUp(r, 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 LogOut() {
    var r = Math.random().toString();
    PageMethods.CleanUp(r, LogOutResponse, LogOutResponse); 
}

function LogOutResponse(response) {
    // loginstatus should send back to login page
    document.location = "Login.aspx";
}

function toggleMagnifier() {
    var mag = $get("Magnifier1");
    if (mag!=null) { 
            toggleFloatingPanelVisibility('Magnifier1'); 
    } else 
        alert("Magnifier is not available"); 
    
}

function toggleConsolePanel(panelName) {
//    var panel = $get(panelName + "_Collapse");
//    if (panel) {
//        if (panel.style.display=="none") {
//            expandConsolePanel(panelName);
//        } else { 
//            collapseConsolePanel(panelName); 
//        }
//        arcgisWebApp.setTocHeight(); 
//    }             
}

function expandConsolePanel(panelName) {
//    var panel = $get(panelName + "_Collapse");
//    var image = $get(panelName + "_Image"); 
//    panel.style.display = "";
//    image.src = "images/collapse.gif";
//    image.alt = "Collapse";  
}

function collapseConsolePanel(panelName) {
//    var panel = $get(panelName + "_Collapse");
//    var image = $get(panelName + "_Image"); 
//    panel.style.display = "none";
//    image.src = "images/expand.gif";
//    image.alt = "Expand";  
}

function backForward(value) {
    map = $find("Map1");
    map.stepExtentHistory(value);
}

function setupCopyrightText() {
//    var crBounds = Sys.UI.DomElement.getBounds(arcgisWebApp.CopyrightText);
//    var pHeight = arcgisWebApp.getPageHeight();
//    arcgisWebApp.CopyrightText.style.top = (pHeight-crBounds.height) + "px";
//    var cr = $find("MapCopyrightText1");
//    if (cr!=null){
//        var template =  '<div style="width: 300px;background-color:#eee;border: solid 1px #aaa;padding: 0px; margin:0;" ><div style="background:#eee; margin:0; height: 20px; color: black">';
//        template += '<span style="float: ' + (isRTL?'right':'left') + '; padding: 0px 0px 0px 2px;"><b>{@title}</b></span>';
//        template += '<span style="float: ' + (isRTL?'left':'right') + '; cursor: pointer; padding: 0px 2px 0px 0px;" onclick="ESRI.ADF.UI.MapCopyrightText.closeClick(\''+cr.get_id()+'\');"><img id="CopyrightTextClose" src="images/dismiss.png" alt="Close" /></span>';
//        template += '</div><div style="padding: 2px 2px 2px 2px; background-color: white; color: black; font-size:x-small;">{@content}</div></div>';
//        cr.get_callout().set_template(template);
//    }
}

function MapCoordsMouseMove(sender, args) {
    var coords = args.coordinate;
    var roundFactor = Math.pow(10, arcgisWebApp.CoordsDecimals);
    window.status = (Math.round(coords.get_x()*roundFactor)/roundFactor)+ ", " + (Math.round(coords.get_y() * roundFactor)/roundFactor); 
}

function OnToolSelectHandler(sender, args) {
    if (args.name) {
        var mode = args.name;
        arcgisWebApp.currentMode = mode;
        
        //this line makes sure that the measure tool window stays closed. 
        if (mode!="Measure" && arcgisWebApp.lastMode=="Measure") closeMeasureToolbarTool();
        
        //this line makes sure that the select tool bar stays closed.
        if (mode!="Select" && arcgisWebApp.lastMode=="Select") closeSelectToolbarTool();
       
        if (mode!="MapIdentify" && arcgisWebApp.lastMode=="MapIdentify") {
             
             
            if (arcgisIdentifyTool!=null) closeIdentifyPanel();
        } 
        
        arcgisWebApp.lastMode = mode;
    }
}

function GetElementRectangle(element) {
    var rect = null;
    if (isIE) 
        rect = element.getBoundingClientRect(); 
    else {
        var bounds = Sys.UI.DomElement.getBounds(element); 
        rect = {"left":bounds.x, "top":bounds.y, "right":bounds.x+bounds.width, "bottom":bounds.y+bounds.height};
    }
    return rect;   
}

function setMapLeftPosition () {
    if (isRTL)
        setDividerLeftPosition();
    else {
        //var bounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay);
        var mLeft = 100; 
        //if (arcgisWebApp.PanelDisplay.style.display=="none")
        //    mLeft =  arcgisWebApp.PanelDisplayCell.clientWidth;
        //else   
        //    mLeft = arcgisWebApp.PanelDisplay.clientWidth + bounds.width;
        arcgisWebApp.MapDisplay.style.left = mLeft + "px";
        var mWidth = arcgisWebApp.getPageWidth() - mLeft; 
        if (mWidth<5) mWidth = 5; 
        arcgisWebApp.MapDisplay.style.width = mWidth + "px";
        arcgisWebApp.CurrentMapWidth = mWidth;
   } 
}

function setDividerLeftPosition () {
    var bounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay);
    var pWidth = arcgisWebApp.getPageWidth();
    var mWidth = 5; 
    var mLeft = 0; 
    if (arcgisWebApp.PanelDisplay.style.display=="none")
        mWidth = pWidth - arcgisWebApp.PanelDisplayCell.clientWidth;
    else 
        mWidth = pWidth - (arcgisWebApp.PanelDisplay.clientWidth + bounds.width);
    if (mWidth<5) mWidth = 5;
    arcgisWebApp.MapDisplay.style.left = "0px";  
    arcgisWebApp.PanelDisplayCell.style.left = mWidth + "px";
    arcgisWebApp.MapDisplay.style.width = mWidth + "px";
    arcgisWebApp.CurrentMapWidth = mWidth; 
}


function adjustMapAndCopyrightPosition() {
    var bounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay);
    var mLeft = bounds.x+ bounds.width;
    arcgisWebApp.MapDisplay.style.left = mLeft + "px"; 
    if (arcgisWebApp.CopyrightText) { 
        var crLeft =  parseInt(arcgisWebApp.CopyrightText.style.left);
        arcgisWebApp.CopyrightText.style.left = mLeft + "px";
    }
    var mWidth = arcgisWebApp.getPageWidth() - mLeft; 
    if (mWidth<5) mWidth = 5; 
    arcgisWebApp.MapDisplay.style.width = mWidth + "px";
    arcgisWebApp.CurrentMapWidth = mWidth;
}

//test function I created to check the sizes of stuff. 
function checkSizes() {
    var colmask_rightmenu = $get("colmask rightmenu");
    var colleft = $get("colleft");
    var col1 = $get("col1");
    var col2 = $get("col2");
    var wrapper = $get("wrapper");
    var bod = $get("bod");
    
//    alert("colmask_rightmenu.width: " + colmask_rightmenu.clientWidth + "\n" + 
//          "colleft.width: " + colleft.clientWidth + "\n" + 
//          "col1.width: " + col1.clientWidth + "\n" + 
//          "col2.width: " + col2.clientWidth + "\n" + 
//          "wrapper.width: " + wrapper.clientWidth +"\n" + 
//          "bod.width: " + bod.clientWidth);
   
}
	

// Common webpage object for manipulating page elements
ESRI.ADF.WebMappingApplication.WebPage = function() {
    this.MapId = "Map1";
    this.map = null;
    this.MapDisplay = $get("Map_Panel");
    this.PanelDisplay = $get("LeftPanelCellDiv");
    this.PanelDisplayCell = $get("LeftPanelCell");
    this.PanelScrollDiv = $get("LeftPanelScrollDiv");
    this.ToggleDisplay = $get("ToggleCell");
    this.PanelSlider = $get("PanelSlider");
    this.PanelDisplayTableCell = $get("LeftPanelTableCell");
    this.PanelBottomSlider = $get("PanelSliderBottom");
    this.ResultsPanel = $get("Results");
    this.TocPanel = $get("Toc_Panel");
    this.Results = $get("TaskResults1");
    this.Toc = $get("Toc1");
    this.ResultsPanelContents = $get("Results_Panel_Body");
    this.TocPanelContents = $get("Toc_Panel_Body");
    this.ResultsPanelResize = $find("Results_Panel_ResizeBehavior");
    this.TocPanelResize = $find("Toc_Panel_ResizeBehavior");
    this.NavigationTool = $get("Navigation1");
    this.CopyrightText = $get("Copyright_Panel");
    this.ZoomLevel = $get("ZoomLevel1");

    this.RightPanelWidth = 0;
    this.LeftPanelWidth = 0;
    this.ToggleWidth = 0;
    this.TitleBarHeight = 75;
    this.ToolBarHeight = 30;
    this.WindowWidth = 500;
    this.LeftOffsetX = 0;
    this.RightOffsetX = 0
    this.NavigationLeft = 0;
    this.CopyrightTextLeft = 0;
    this.DefaultMinDockWidth = 125;
    this.MinDockWidth = this.DefaultMinDockWidth;
    this.MapLeft = 262;
    this.LastMapWidth = 512;
    this.LastMapHeight = 512;
    this.CurrentMapWidth = 512;
    this.CurrentMapHeight = 512;
    this.HasScroll = false;
    this.LastHasScroll = false;
    this.DockMoving = false;
    this.reloadTimer = null;
    this.hasMeasure = false;
    this.Measure = null;
    this.MapUnits = null;
    this.CoordsDecimals = 3;
    this.currentMode = "Pan";
    this.lastMode = "Pan";

    this.setPageElementSizes = function() {
        // set body style - removes the scrollbar. 
        if (document.documentElement) {
            document.documentElement.style.overflow = "hidden";
            //document.documentElement.style.height = "100%"; 

        } else {
            document.body.style.overflow = "hidden";
            //document.body.style.height = "100%";
        }

        //this.adjustMapSizeCommon();

    }

    this.adjustMapSizeCommon = function() {

        // get the set widths and heights

        //        var rightDisplay = $get("col2");
        //        var mapPanel = $get("Map1");

        //        //loading panel
        //        var progressOverlay = document.getElementById("progressOverlay");

        //        this.RightPanelWidth = rightDisplay.offsetWidth + 2; //take border of 2 into account (1 for right, 1 for left)

        //        // get browser window dimensions
        //        var sWidth = this.getPageWidth();
        //        var sHeight = this.getPageHeight();

        //        // set map display dimensions
        //        var mWidth = sWidth - this.RightPanelWidth;
        //        var mHeight = sHeight - (this.TitleBarHeight + this.ToolBarHeight) + 1;
        //        this.MapLeft = this.LeftPanelWidth + this.ToggleWidth;

        //        this.MapDisplay.style.width = mWidth + "px";
        //        this.MapDisplay.style.height = mHeight + "px";

        //        this.CurrentMapWidth = mWidth;
        //        this.CurrentMapHeight = mHeight;
        //        progressOverlay.style.width = this.CurrentMapWidth;
        //        progressOverlay.style.height = this.CurrentMapHeight;

        //        var scrollBox = $get("scrollBox");
        //        scrollBox.style.height = (this.CurrentMapHeight + this.TitleBarHeight) + "px";
        //        scrollBox.style.width = this.RightPanelWidth - 2;

        //        //the scrollbox for the results tab. 
        //        var resultsScroll = $get("resultsScroll");
        //        resultsScroll.style.height = (this.CurrentMapHeight - 30) + "px";

        //        var TabContainer = $get("TabContainer1");
        //        TabContainer.style.height = (this.CurrentMapHeight + this.TitleBarHeight) + "px";

        //        var tabContainerBody = $get("TabContainer1_body");
        //        tabContainerBody.style.height = (this.CurrentMapHeight + this.TitleBarHeight) + "px";

    }

    // function for adjusting element sizes when brower is resized
    this.adjustMapSize = function() {

        //        this.adjustMapSizeCommon();

        //        // refresh the map 
        //        var m = $find(this.MapId);
        //        if (this.map != null)
        //            this.map.checkMapsize();
        //        else
        //            window.setTimeout("arcgisWebApp.adjustMapSize();", 1000);
        //        return false;
    }

    // handler for window resize
    this.adjustMapSizeHandler = function(e) {
        //window.clearTimeout(arcgisWebApp.reloadTimer);
        //arcgisWebApp.reloadTimer = window.setTimeout("arcgisWebApp.adjustMapSize();", 1000);
    }

    // get the page width
    this.getPageWidth = function() {
        var width = window.innerWidth;
        if (width == null) {
            if (document.documentElement && document.documentElement.clientWidth)
                width = document.documentElement.clientWidth
            else
                width = document.body.clientWidth;
        }
        return width;
    }

    //get the page height
    this.getPageHeight = function() {
        var height = 100;
        //var height = window.innerHeight;
        //        if (height == null) {
        //            if (document.documentElement && document.documentElement.clientHeight) {
        //                height = document.documentElement.clientHeight;
        //            }
        //            else {
        //                height = document.body.clientHeight;
        //            }
        //        }
        return height;

    }

    // sets the height of the Map Contents panel
    this.setTocHeight = function() {
        //        var tocLocation = Sys.UI.DomElement.getLocation(this.TocPanelContents);
        //        var leftLocation = Sys.UI.DomElement.getLocation(this.PanelDisplayCell);
        //        var pHeight = this.getPageHeight();
        //        var tHeight = pHeight - tocLocation.y - 13;
        //        if (isNaN(tHeight) || tHeight < 5) tHeight = 5;
        //        this.TocPanelContents.style.height = tHeight + "px";

    }

    // functions for Dock movement and sizing
    this.togglePanelDock = function() {
        if (arcgisIdentifyTool != null) {
            var dropdown = $get("dropdown_" + arcgisIdentifyTool.get_uniqueID());
            if (dropdown) dropdown.style.display = "none";
        }
        if (arcgisWebApp.PanelDisplay.style.display == "none") {
            arcgisWebApp.expandPanelDock();
        } else {
            arcgisWebApp.collapsePanelDock();
        }
    }

    this.expandPanelDock = function() {
        var image = document.images["CollapseImage"];
        var imgUrl = (isRTL) ? "images/expand_right.gif" : "images/collapse_left.gif";
        arcgisWebApp.PanelDisplay.style.display = "block";
        image.src = imgUrl;
        image.alt = "Collapse";
        arcgisWebApp.PanelSlider.style.cursor = "e-resize";
        arcgisWebApp.PanelBottomSlider.style.cursor = "e-resize";
        arcgisWebApp.adjustMapSize();
    }

    this.collapsePanelDock = function() {
        var image = document.images["CollapseImage"];
        var imgUrl = (isRTL) ? "images/collapse_left.gif" : "images/expand_right.gif";
        dockWidthString = arcgisWebApp.PanelDisplayCell.clientWidth + "px";
        arcgisWebApp.PanelDisplay.style.display = "none";
        image.src = imgUrl;
        image.alt = "Expand";
        arcgisWebApp.PanelSlider.style.cursor = "default";
        arcgisWebApp.PanelBottomSlider.style.cursor = "default";
        arcgisWebApp.adjustMapSize();
    }

    var startConsoleDragLeft = 0;
    this.startDockDrag = function(e) {
        if (!arcgisWebApp.DockMoving) {
            arcgisWebApp.MoveFunction = document.onmousemove;
            arcgisWebApp.UpFunction = document.onmouseup;
            arcgisWebApp.DockMoving = true;
            // hide the map addons while sliding the divider 
        }
        $addHandler(document, "mouseup", arcgisWebApp.stopDockDrag);
        if (arcgisWebApp.PanelDisplay.style.display != "none") {
            arcgisWebApp.WindowWidth = arcgisWebApp.getPageWidth();
            if (isRTL) {
                arcgisWebApp.LeftOffsetX = arcgisWebApp.PanelDisplay.clientWidth - e.clientX;
                var location = Sys.UI.DomElement.getLocation($get("LeftPanelTableCell"));
                arcgisWebApp.RightOffsetX = location.x - e.clientX;
                $addHandler(document, "mousemove", arcgisWebApp.moveDockDragRTL);
            } else {
                arcgisWebApp.LeftOffsetX = e.clientX - arcgisWebApp.PanelDisplay.clientWidth;
                var location = Sys.UI.DomElement.getLocation($get("Map_Panel"));
                arcgisWebApp.RightOffsetX = location.x - e.clientX;
                if (arcgisWebApp.CopyrightText) {
                    arcgisWebApp.CopyrightTextLeft = parseInt(arcgisWebApp.CopyrightText.style.left);
                    arcgisWebApp.CopyrightTextTop = parseInt(arcgisWebApp.CopyrightText.style.top);
                }
                $addHandler(document, "mousemove", arcgisWebApp.moveDockDrag);
            }
            startConsoleDragLeft = e.clientX;

        }
        e.preventDefault();
        e.stopPropagation();
    }

    this.moveDockDrag = function(e) {
        alert("moveDockDrag");
        var theButton = (Sys.Browser.agent == Sys.Browser.InternetExplorer) ? event.button : e.which;
        if (theButton == 0) arcgisWebApp.stopDockDrag(e);
        arcgisWebApp.LeftPanelWidth = e.clientX - arcgisWebApp.LeftOffsetX;
        arcgisWebApp.DockMoving = true;
        var sWidth = arcgisWebApp.getPageWidth();
        var x = e.clientX;
        var y = e.clientY;
        var rightWidth = 2;
        if (arcgisWebApp.CopyrightText) rightWidth = arcgisWebApp.CopyrightText.clientWidth + 10;
        if (x >= sWidth - rightWidth || y >= arcgisWebApp.getPageHeight() - 2 || y < 1 || x < arcgisWebApp.MinDockWidth) arcgisWebApp.stopDockDrag(e);
        if (arcgisWebApp.LeftPanelWidth > sWidth - arcgisWebApp.ToggleDisplay.clientWidth - rightWidth) arcgisWebApp.LeftPanelWidth = sWidth - arcgisWebApp.ToggleDisplay.clientWidth - rightWidth;
        if (arcgisWebApp.LeftPanelWidth < arcgisWebApp.MinDockWidth) arcgisWebApp.LeftPanelWidth = arcgisWebApp.MinDockWidth;
        var mapLeftString = (arcgisWebApp.LeftPanelWidth + arcgisWebApp.ToggleDisplay.clientWidth) + "px";
        var widthString = arcgisWebApp.LeftPanelWidth + "px";
        arcgisWebApp.PanelDisplay.style.width = widthString;
        arcgisWebApp.ResultsPanel.style.width = widthString;
        arcgisWebApp.TocPanel.style.width = widthString;
        var pWidth = arcgisWebApp.LeftPanelWidth;
        arcgisWebApp.ResultsPanelResize.set_MinimumWidth(pWidth);
        arcgisWebApp.TocPanelResize.set_MinimumWidth(pWidth);
        arcgisWebApp.ResultsPanelResize.set_MaximumWidth(pWidth);
        arcgisWebApp.TocPanelResize.set_MaximumWidth(pWidth);
        arcgisWebApp.ResultsPanelResize._handleHolder.style.width = pWidth + "px";
        arcgisWebApp.TocPanelResize._handleHolder.style.width = pWidth + "px";
        var width = arcgisWebApp.WindowWidth - arcgisWebApp.PanelDisplayCell.clientWidth;
        if (width < 1) width = 1;
        arcgisWebApp.MapDisplay.style.width = width + "px";
        arcgisWebApp.MapDisplay.style.left = mapLeftString;
        var leftDiff = e.clientX - startConsoleDragLeft;
        if (arcgisWebApp.CopyrightText) {
            var crLeft = arcgisWebApp.CopyrightTextLeft + leftDiff;
            if (crLeft < sWidth - arcgisWebApp.CopyrightText.clientWidth) {
                if (crLeft < arcgisWebApp.LeftPanelWidth + arcgisWebApp.ToggleDisplay.clientWidth) crLeft = arcgisWebApp.LeftPanelWidth + arcgisWebApp.ToggleDisplay.clientWidth;
                arcgisWebApp.CopyrightText.style.left = crLeft + "px";
                if (!isIE) arcgisWebApp.CopyrightText.style.top = arcgisWebApp.CopyrightTextTop + "px";
            }
        }
        if (arcgisIdentifyTool != null) {
            var dropdown = $get("dropdown_" + arcgisIdentifyTool.get_uniqueID());
            if (dropdown) dropdown.style.display = "none";
        }
        e.preventDefault();
        e.stopPropagation();
    }

    this.moveDockDragRTL = function(e) {
        var theButton = (Sys.Browser.agent == Sys.Browser.InternetExplorer) ? event.button : e.which;
        if (theButton == 0) arcgisWebApp.stopDockDrag(e);
        var sWidth = arcgisWebApp.getPageWidth();
        arcgisWebApp.LeftPanelWidth = sWidth - (e.clientX + arcgisWebApp.RightOffsetX);
        arcgisWebApp.DockMoving = true;
        var x = e.clientX;
        var y = e.clientY;
        var rightWidth = 2;
        if (arcgisWebApp.CopyrightText) rightWidth = arcgisWebApp.CopyrightText.clientWidth + 10;
        if (x <= rightWidth || y >= arcgisWebApp.getPageHeight() - 2 || y < 1 || x > sWidth - arcgisWebApp.MinDockWidth) arcgisWebApp.stopDockDrag(e);
        if (arcgisWebApp.LeftPanelWidth > sWidth - arcgisWebApp.ToggleDisplay.clientWidth - rightWidth) arcgisWebApp.LeftPanelWidth = sWidth - arcgisWebApp.ToggleDisplay.clientWidth - rightWidth;
        if (arcgisWebApp.LeftPanelWidth < arcgisWebApp.MinDockWidth) arcgisWebApp.LeftPanelWidth = arcgisWebApp.MinDockWidth;
        var mapLeftString = (arcgisWebApp.LeftPanelWidth + arcgisWebApp.ToggleDisplay.clientWidth) + "px";
        var widthString = arcgisWebApp.LeftPanelWidth + "px";
        arcgisWebApp.PanelDisplay.style.width = widthString;
        arcgisWebApp.ResultsPanel.style.width = widthString;
        arcgisWebApp.TocPanel.style.width = widthString;
        var pWidth = arcgisWebApp.LeftPanelWidth;
        arcgisWebApp.ResultsPanelResize.set_MinimumWidth(pWidth);
        arcgisWebApp.TocPanelResize.set_MinimumWidth(pWidth);
        arcgisWebApp.ResultsPanelResize.set_MaximumWidth(pWidth);
        arcgisWebApp.TocPanelResize.set_MaximumWidth(pWidth);
        arcgisWebApp.ResultsPanelResize._handleHolder.style.width = pWidth + "px";
        arcgisWebApp.TocPanelResize._handleHolder.style.width = pWidth + "px";
        var width = sWidth - (pWidth + arcgisWebApp.ToggleDisplay.clientWidth);
        if (width < 5) width = 5;
        arcgisWebApp.MapDisplay.style.width = width + "px";
        arcgisWebApp.PanelDisplayCell.style.left = width + "px";
        var leftDiff = e.clientX - startConsoleDragLeft;
        if (arcgisIdentifyTool != null) {
            var dropdown = $get("dropdown_" + arcgisIdentifyTool.get_uniqueID());
            if (dropdown) dropdown.style.display = "none";
        }
        e.preventDefault();
        e.stopPropagation();
    }

    this.stopDockDrag = function(e) {
        try {
            $removeHandler(document, "mouseup", arcgisWebApp.stopDockDrag);
            if (isRTL)
                $removeHandler(document, "mousemove", arcgisWebApp.moveDockDragRTL);
            else
                $removeHandler(document, "mousemove", arcgisWebApp.moveDockDrag);
        } catch (ex) {
            var dummy = ex;
        }
        if (arcgisWebApp.CopyrightText && !isIE)
            arcgisWebApp.CopyrightText.style.top = arcgisWebApp.CopyrightTextTop + "px";
        arcgisWebApp.DockMoving = false;
        arcgisWebApp.adjustMapSize();
        e.preventDefault();
        e.stopPropagation();
    }

    this.checkPanelScroll = function() {
        if (arcgisWebApp.PanelScrollDiv.scrollHeight > arcgisWebApp.PanelScrollDiv.clientHeight) {
            arcgisWebApp.HasScroll = true;
        } else {
            arcgisWebApp.HasScroll = false;
        }
        if (arcgisWebApp.HasScroll != arcgisWebApp.LastHasScroll)
            arcgisWebApp.adjustMapSize();
        arcgisWebApp.LastHasScroll = this.HasScroll;
        return false;
    }

    this.checkPanelWidths = function() {
        var maxWidth = 0;
        var node;
        for (var i = 0; i < arcgisWebApp.PanelDisplay.childNodes.length; i++) {
            if (arcgisWebApp.PanelDisplay.childNodes[i].tagName == "TABLE") {
                node = arcgisWebApp.PanelDisplay.childNodes[i];
                if (node.clientWidth > maxWidth) maxWidth = node.clientWidth;
            }
        }
        arcgisWebApp.PanelDisplay.style.width = maxWidth + "px";
        return false;
    }

    this.scrollDockToPanel = function(panelElement) {
        if (panelElement == null) return;
        var yPos = panelElement.offsetTop;
        arcgisWebApp.PanelScrollDiv.scrollTop = yPos;
    }

    ESRI.ADF.WebMappingApplication.WebPage.initializeBase(this);
}

ESRI.ADF.WebMappingApplication.WebPage.registerClass('ESRI.ADF.WebMappingApplication.WebPage');

arcgisWebApp = new ESRI.ADF.WebMappingApplication.WebPage();


if (typeof(Sys) !== 'undefined') { Sys.Application.notifyScriptLoaded(); }