﻿var arcgisWebApp
var reloadTimer
var webMapAppLeftPanelWidth = 262
var webMapAppToggleWidth = 10
var webMapAppTopBannerHeight = 80
var newLoad = false
var webMapAppCloseCallback = ""
var webMapAppCopyrightCallback = ""
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_mapID = 'ctl00_MapContentPlaceHolder_Map1'
Type.registerNamespace('ESRI.ADF.WebMappingApplication')
function setPageElementSizes() {
    document.body.style.overflow = "hidden"
    document.body.style.height = "100%"
    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("MasterPageHeaderDiv")
    var linkDisplay = document.getElementById("LinkBar")
    webMapAppPanelScrollDiv.style.overflowY = "auto"
    if (isIE) {
        webMapAppPanelDisplay.style.overflow = "hidden"
    }
    webMapAppLeftPanelWidth = webMapAppPanelDisplay.clientWidth
    webMapAppToggleWidth = parseInt(webMapAppToggleDisplay.style.width)
    webMapAppTopBannerHeight = headerDisplay.clientHeight + 0
    var sWidth = getWinWidth()
    var sHeight = getWinHeight()
    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"
    }
    webMapAppToggleDisplay.style.height = mHeight + "px"
    webMapAppPanelScrollDiv.style.height = mHeight + "px"
}
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_2.3.4.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"
    image.src = "images/expand_right_2.3.4.gif"
    image.alt = "Expand"
    webMapAppPanelSlider.style.cursor = "default"
    webMapAppPanelBottomSlider.style.cursor = "default"
    webMapAppMapLeft = webMapAppToggleWidth
    webMapAppMapDisplay.style.left = webMapAppMapLeft + "px"
    AdjustMapSize()
}
function AdjustMapSize() {
    webMapAppPanelDisplay.style.width = webMapAppLeftPanelWidth + "px"
    webMapAppToggleDisplay.style.width = webMapAppToggleWidth + "px"
    var sWidth = getWinWidth()
    var sHeight = getWinHeight()
    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"
    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"
    }
    window.setTimeout("resizeTheMap(" + mWidth + ", " + mHeight + ", false);", 500)
    var box = calcElementPosition("Map_Panel")
    var map = $find(m_mapID)
    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 resizeTheMap(width, height, resizeExtent) {
    if (resizeExtent == null) resizeExtent = true
    var map = $find(m_mapID)
    map.resize(width, height, resizeExtent)
    var div = document.getElementById("LeftPanelCellDiv")
    if (ov != null && div.style.display != "none") {
        var argument = "ControlType=OverviewMap&EventArg=OverviewZoom"
        var context = ov.controlName
        eval(ov.callBackFunctionString)
    }
    return false
}
function AdjustMapSizeHandler(e) {
    window.clearTimeout(reloadTimer)
    reloadTimer = window.setTimeout("AdjustMapSize();", 1000)
}
function startUp() {
    var map = $find(m_mapID)
    map.ctrlMode = "MapIdentify"
    map.ctrlAction = "Point"
    map.ctrlCursor = "pointer"
    map.ctrlFunction = "MapIdClick(e)"
    if (newLoad) {
        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 fp = document.getElementById("CopyrightText_Panel")
        if (fp != null) {
            floatingPanel = fp
            moveTo(box.left, box.top)
        }
        var toolbar = $find("Toolbar1")
        if (map != null && toolbar != null) {
            toolbar.add_onToolSelected(OnToolSelectHandler)
        } 
    }
    window.onresize = AdjustMapSizeHandler
    for (var fp in FloatingPanels) {
        FloatingPanels[fp].onDockFunction = scrollDockToPanel
    } 
}
function CloseOut() {
    var argument = "ControlID=Map1&ControlType=Map&EventArg=CloseOutApplication"
    var map = $find(m_mapID)
    var context = map.controlName
    eval(webMapAppCloseCallback)
}
function CloseOutResponse(response, context) {
    window.close()
    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")
        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"
    var widthString = webMapAppLeftPanelWidth + "px"
    webMapAppPanelDisplay.style.width = widthString
    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
    }
    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 map = $find(m_mapID)
    var context = map.controlName
    eval(webMapAppCopyrightCallback)
    showFloatingPanel('CopyrightText_Panel')
}
function OnToolSelectHandler(sender, args) {
    if (args.name) {
        var mode = args.name
        arcgisWebApp.currentMode = mode
        if (mode != "MapIdentify" && arcgisWebApp.lastMode == "MapIdentify") {
            if (arcgisIdentifyTool != null) closeIdentifyPanel()
        }
        arcgisWebApp.lastMode = mode
    } 
}
function closeIdentifyPanel() {
    if (Sys.Browser.agent == Sys.Browser.Firefox && Sys.Browser.version >= 3)
        window.setTimeout("arcgisIdentifyTool.clearOutCallout();", 500)
    else
        arcgisIdentifyTool.clearOutCallout()
}
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 StartSpatialDownload(SelectedLayerControlID, FeaturesControlID, IndicatorPanelControlID) {
    var layer
    var features
    var layerRadioBtnList = document.getElementById(SelectedLayerControlID)
    var layerRadioListItems = layerRadioBtnList.getElementsByTagName('tbody')[0].getElementsByTagName('tr')
    for (i = 0; i < layerRadioListItems.length; i++) {
        var layerRadioBtn = document.getElementById(SelectedLayerControlID + "_" + i)
        if (layerRadioBtn.checked == true) {
            layer = layerRadioBtn.value
        } 
    }
    features = getSelectedFeature(FeaturesControlID)
    var progressIndicator = document.getElementById(IndicatorPanelControlID)
    progressIndicator.style.display = ''
    return "action=ExecuteDownload&Layer=" + layer + "&Features=" + features + "&IndicatorPanelControlID=" + IndicatorPanelControlID
}
function UpdatePolygonLink(LinkControlID, DownloadURL) {
    var link = document.getElementById(LinkControlID)
    link.innerHTML = "<a href='" + DownloadURL + "'>Click here to download selected Polygon Feature(s)</a>"
}
function UpdatePointLink(LinkControlID, DownloadURL) {
    var link = document.getElementById(LinkControlID)
    link.innerHTML = "<a href='" + DownloadURL + "'>Click here to download selected Point Feature(s)</a>"
}
function featureRadioBtnOnClick(FeaturesControlID) {
    var features = getSelectedFeature(FeaturesControlID)
    return "action=FeatureListOnClick&Features=" + features
}
function getSelectedFeature(FeaturesControlID) {
    var featureRadioBtnList = document.getElementById(FeaturesControlID)
    var featureRadioListItems = featureRadioBtnList.getElementsByTagName('tbody')[0].getElementsByTagName('tr')
    for (x = 0; x < featureRadioListItems.length; x++) {
        var featureRadioBtn = document.getElementById(FeaturesControlID + "_" + x)
        if (featureRadioBtn.checked == true) {
            return featureRadioBtn.value
        } 
    } 
}
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.LeftPanelWidth = 262
    this.ToggleWidth = 10
    this.TopBannerHeight = 80
    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() {
        if (document.documentElement) {
            document.documentElement.style.overflow = "hidden"
            document.documentElement.style.height = "100%"
            this.PanelDisplay.style.overflow = "hidden"
        } else {
            document.body.style.overflow = "hidden"
            document.body.style.height = "100%"
        }
        this.PanelScrollDiv.style.overflow = "hidden"
        var headerDisplay = $get("PageHeader")
        var linkDisplay = $get("LinkBar")
        this.LeftPanelWidth = this.PanelDisplay.clientWidth
        this.ToggleWidth = parseInt(this.ToggleDisplay.style.width)
        this.TopBannerHeight = headerDisplay.clientHeight + linkDisplay.clientHeight
        var sWidth = this.getPageWidth()
        var sHeight = this.getPageHeight()
        var mHeight = sHeight - this.TopBannerHeight
        this.MapLeft = this.LeftPanelWidth + this.ToggleWidth
        var mWidth = getMapWidth()
        this.MapDisplay.style.width = mWidth + "px"
        this.MapDisplay.style.height = mHeight + "px"
        this.CurrentMapWidth = mWidth
        this.CurrentMapHeight = mHeight
        this.ToggleDisplay.style.height = mHeight + "px"
        this.PanelScrollDiv.style.height = mHeight + "px"
        esriMaxFloatingPanelDragRight = sWidth - 15
        esriMaxFloatingPanelDragBottom = sHeight - 15
        $addHandler(document.images["CollapseImage"], "mousedown", this.togglePanelDock)
        $addHandler(this.PanelBottomSlider, "mousedown", this.startDockDrag)
        $addHandler(this.PanelSlider, "mousedown", this.startDockDrag)
        var widthString = this.LeftPanelWidth + "px"
        this.ResultsPanel.style.width = widthString
        this.TocPanel.style.width = widthString
        if (isRTL) {
            this.PanelDisplayCell.style.left = mWidth + "px"
        } 
    }
    this.adjustMapSize = function() {
        this.PanelDisplay.style.width = this.LeftPanelWidth + "px"
        this.ToggleDisplay.style.width = this.ToggleWidth + "px"
        var sWidth = this.getPageWidth()
        var sHeight = this.getPageHeight()
        var mHeight = sHeight - this.TopBannerHeight
        this.LastMapWidth = this.CurrentMapWidth
        this.LastMapHeight = this.CurrentMapHeight
        this.MapDisplay.style.height = mHeight + "px"
        this.ToggleDisplay.style.height = mHeight + "px"
        this.PanelScrollDiv.style.height = mHeight + "px"
        this.CurrentMapHeight = mHeight
        this.setTocHeight()
        var mWidth = getMapWidth()
        if (mWidth < 5) mWidth = 5
        if (mHeight < 5) mHeight = 5
        setMapLeftPosition()
        var widthString = this.PanelDisplay.style.width
        this.ResultsPanel.style.width = widthString
        this.TocPanel.style.width = widthString
        this.ResultsPanelResize.set_MinimumWidth(this.LeftPanelWidth)
        this.TocPanelResize.set_MinimumWidth(this.LeftPanelWidth)
        this.ResultsPanelResize.set_MaximumWidth(this.LeftPanelWidth)
        this.TocPanelResize.set_MaximumWidth(this.LeftPanelWidth)
        this.ResultsPanelResize._handle.style.width = this.LeftPanelWidth + "px"
        this.TocPanelResize._handle.style.width = this.LeftPanelWidth + "px"
        this.ResultsPanelContents.style.width = widthString
        this.TocPanelContents.style.width = widthString
        if (this.LastMapWidth != this.CurrentMapWidth || this.LastMapHeight != this.CurrentMapHeight) {
            var cr = $find("MapCopyrightText1")
            if (cr != null)
                cr.get_callout().hide()
            if (arcgisIdentifyTool != null) closeIdentifyPanel()
        }
        var m = $find(this.MapId)
        if (this.map != null) {
            if (this.LastMapWidth != this.CurrentMapWidth || this.LastMapHeight != this.CurrentMapHeight) {
                this.map.checkMapsize()
            }
        } else
            window.setTimeout("arcgisWebApp.adjustMapSize();", 1000)
        if (isRTL) adjustRTLElements()
        var tc = $get("TaskMenuCell")
        if (tc) tc.style.visibility = "visible"
        return false
    }
    this.adjustMapSizeHandler = function(e) {
        var tc = $get("TaskMenuCell")
        if (tc && isRTL) tc.style.visibility = "hidden"
        window.clearTimeout(arcgisWebApp.reloadTimer)
        arcgisWebApp.reloadTimer = window.setTimeout("arcgisWebApp.adjustMapSize();", 1000)
    }
    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
    }
    this.getPageHeight = function() {
        var height = window.innerHeight
        if (height == null) {
            if (document.documentElement && document.documentElement.clientHeight)
                height = document.documentElement.clientHeight
            else
                height = document.body.clientHeight
        }
        return height
    }
    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"
    }
    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_2.3.4.gif" : "images/collapse_left_2.3.4.gif"
        arcgisWebApp.PanelDisplay.style.display = "block"
        image.src = imgUrl
        image.alt = "Collapse"
        arcgisWebApp.PanelSlider.style.cursor = "e-resize"
        arcgisWebApp.PanelBottomSlider.style.cursor = "e-resize"
        window.setTimeout('arcgisWebApp.adjustMapSize();', 500)
    }
    this.collapsePanelDock = function() {
        var image = document.images["CollapseImage"]
        var imgUrl = (isRTL) ? "images/collapse_left_2.3.4.gif" : "images/expand_right_2.3.4.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"
        window.setTimeout('arcgisWebApp.adjustMapSize();', 500)
    }
    var startConsoleDragLeft = 0
    this.startDockDrag = function(e) {
        if (!arcgisWebApp.DockMoving) {
            arcgisWebApp.MoveFunction = document.onmousemove
            arcgisWebApp.UpFunction = document.onmouseup
            arcgisWebApp.DockMoving = true
        }
        $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) {
        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 = getMapWidth()
        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()
    }
    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(); }
