﻿// 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() {

    //jslog.info("startup() called");
        
    if (isRTL) 
        document.images["CollapseImage"].src = "images/expand_right.gif";      
        
        arcgisWebApp.MapId = "Map1";
        arcgisWebApp.map = $find(arcgisWebApp.MapId);
        map = arcgisWebApp.map;
    // set up references to the console panels
    arcgisWebApp.ResultsPanelResize = $find("Results_Panel_ResizeBehavior");
    arcgisWebApp.TocPanelResize = $find("Toc_Panel_ResizeBehavior");
	    // set up task results panel to auto open on update... 
        var adjustMapDisplay = false;

    var panel = $get("Results_Panel_Collapse");
    if (panel != null) panel.style.display = "block";
        // because the toolbar is listed before the map control,
        //  make sure toolbar will be listening to changes in map extent
        var toolbar = $find("Toolbar1");
		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);
		}
		
		// hide identify window when extent changes, especially when back or forward are clicked
		map.add_extentChanging(function() {if (arcgisIdentifyTool!=null) closeIdentifyPanel();} ); // for start of continuous panning or zoom animation
		map.add_extentChanged(function() {if (arcgisIdentifyTool!=null) closeIdentifyPanel();} );  // extent changes that do not trigger ExentChanging
		
		// set the copyright callout template 
		window.setTimeout("setupCopyrightText();",100);
    arcgisWebApp.setTocHeight();
    if (arcgisWebApp.Toc == null)
        arcgisWebApp.TocPanel.style.display = "none";
        map.add_mouseMove(MapCoordsMouseMove);
		
		var ov = $find("OverviewMap1");
		if (ov!=null) {
            toggleOverviewMap();
		    if (isRTL) {
		        var ovExt = $find("DockExtender4");
		        ovExt.set_alignment(ESRI.ADF.System.ContentAlignment.TopLeft);
		    }
    if (!isRTL) {
        arcgisWebApp.TocPanelResize.add_resize(adjustMapAndCopyrightPosition);
        arcgisWebApp.ResultsPanelResize.add_resize(adjustMapAndCopyrightPosition);
    } else {
        adjustRTLElements();
        window.setTimeout('$addHandler(window,"resize", keepTasksOnRight);', 2000);
    }
    // set window resize event handler
    window.setTimeout('$addHandler(window,"resize", arcgisWebApp.adjustMapSizeHandler);', 1000);
    var tc = $get("TaskMenuCell");
    if (tc) tc.style.visibility = "visible";
    if (typeof setUpMeasureEvent != "undefined") setUpMeasureEvent();
    if (isRTL) {
        // unhide page elements. . . initial hiding set in class and required for IE RTL smooth startup display
        arcgisWebApp.MapDisplay.style.visibility = "visible";
        arcgisWebApp.PanelDisplayCell.style.visibility = "visible";
        arcgisWebApp.ToggleDisplay.style.visibility = "visible";
    }
		}
		
		if (!isRTL) {

		} else  {
		    adjustRTLElements();
		}
        
        var tc = $get("TaskMenuCell");
        if (tc) tc.style.visibility = "visible";
        
        // set window resize event handler
        window.setTimeout('$addHandler(window,"resize", arcgisWebApp.adjustMapSizeHandler);', 1000); 
}






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 () {
    //jslog.info("setMapLeftPosition() called");
    if (isRTL)
        setDividerLeftPosition();
    else 
        setMapWidth();
}


function getMapLeft()
{
    var bounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay);
    var mLeft = isRTL ? 0 : bounds .x +  bounds.width;
    return mLeft;
}

function getMapWidth()
{
    var bounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay);
    var mLeft = 0; 
    var bounds2 = Sys.UI.DomElement.getBounds(arcgisWebApp.PanelDisplay); 
    var pWidth = arcgisWebApp.getPageWidth();
    var mWidth = 5; 
    if (isRTL) {
        if (arcgisWebApp.PanelDisplay.style.display=="none")
            mWidth = pWidth - bounds.width; 
        else 
            mWidth = pWidth - bounds2.width - 8; 
    
    } else {
        if (arcgisWebApp.PanelDisplay.style.display=="none")
            mLeft =  arcgisWebApp.PanelDisplayCell.clientWidth;
        else   
            mLeft = arcgisWebApp.PanelDisplay.clientWidth + bounds.width;
        mWidth = arcgisWebApp.getPageWidth() - mLeft; 
    }
    if (mWidth<5) mWidth = 5;
    return mWidth;
}

function setMapWidth()
{
    var mLeft = getMapLeft();
     arcgisWebApp.MapDisplay.style.left = mLeft + "px";
    var mWidth = getMapWidth(); 
    if (mWidth<5) mWidth = 5; 
    arcgisWebApp.MapDisplay.style.width = (mWidth) + "px";
    arcgisWebApp.CurrentMapWidth = mWidth; 
}

function setDividerLeftPosition () {
    //jslog.info("setDividerLeftPosition() called");
    var mWidth = getMapWidth();
    arcgisWebApp.MapDisplay.style.left = "0px";  
    arcgisWebApp.PanelDisplayCell.style.left = mWidth + "px";
    arcgisWebApp.MapDisplay.style.width = mWidth + "px";
    arcgisWebApp.CurrentMapWidth = mWidth; 
}

function setDividerTopPosition () {
    //jslog.info("setDividerTopPosition() called");
    var mHeight = getMapHeight2();
     // set heights of left panel and toggle bar
    arcgisWebApp.ToggleDisplay.style.height = mHeight  + "px";
    arcgisWebApp.PanelScrollDiv.style.height = mHeight  + "px";
    arcgisWebApp.MapDisplay.style.height = mHeight + "px";  
    arcgisWebApp.PanelDisplayCell_Bottom.style.top = mHeight + "px";
    arcgisWebApp.CurrentMapHeight = mHeight; 
    
    arcgisWebApp.webMapAppBottomTBCellDiv_DS.style.top = (mHeight + arcgisWebApp.TopBannerHeight + arcgisWebApp.ToggleHeight + 3) + "px";
    arcgisWebApp.webMapAppBottomTBCellDiv_AL.style.top = (mHeight + arcgisWebApp.TopBannerHeight + arcgisWebApp.ToggleHeight + 3) + "px";
}

//function adjustBottomPanelElements() {

//    if(webMapAppBottomPanelHeight > 15) {
//        webMapAppPanelDisplay_Bottom.style.height =  webMapAppBottomPanelHeight-15 + "px";
//    } else {
//        webMapAppPanelDisplay_Bottom.style.height =  webMapAppBottomPanelHeight + "px";
//    }
//    
//    webMapAppToggleDisplay2.style.height = webMapAppToggleHeight + "px";
//    
//    var sWidth = getWinWidth();
//    var bWidth = sWidth - 2;
//    var sHeight = getWinHeight()-5;

//    var mWidth = sWidth - webMapAppPanelDisplayCell.clientWidth;
//    
//    webMapAppPanelDisplayCell_Bottom.style.display = "none";
//    webMapAppPanelDisplayCell_Bottom.style.width = bWidth + "px";
//    webMapAppToggleDisplay2.style.width = bWidth + "px";
//    webMapAppPanelScrollDiv_Bottom.style.width = bWidth + "px";
//    webMapAppPanelDisplayCell_Bottom.style.display = "block"; 
//    
//    webMapAppBottomTBCellDiv_DS.style.left = "393px";
//    webMapAppBottomTBCellDiv_AL.style.left = "524px";

//    
//    var mHeight;
//    if (!bottomDocked) {
//        mHeight = sHeight - webMapAppTopBannerHeight - webMapAppPanelDisplayCell_Bottom.clientHeight+5;
//        webMapAppPanelDisplayCell_Bottom.style.top = mHeight  + "px";
//        webMapAppBottomTBCellDiv_DS.style.top = (mHeight + webMapAppTopBannerHeight + 10 + 3) + "px";
//        webMapAppBottomTBCellDiv_AL.style.top = (mHeight + webMapAppTopBannerHeight + 10 + 3) + "px";
//    } else {
//        bottomDocked = false;
//    }
//}

function getMapHeight2() {
    var bounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay_Bottom);
    var mTop = 0; 
    var bounds2 = Sys.UI.DomElement.getBounds(arcgisWebApp.PanelDisplay_Bottom); 
    var pHeight = arcgisWebApp.getPageHeight();
    var mHeight = 5; 
  
    if (arcgisWebApp.PanelDisplay_Bottom.style.display=="none")
        mHeight = pHeight - bounds.height - 80; 
    else 
        mHeight = pHeight - bounds2.height - 80 - 8; 
 
    if (mHeight<5) 
        mHeight = 5;
        
    return mHeight;
}



// 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.PanelDisplay_Bottom = $get("BottomPanelCellDiv");      //GFB
	this.PanelDisplayCell_Bottom = $get("BottomPanelCell");      //GFB
	this.PanelScrollDiv_Bottom = $get("BottomPanelScrollDiv");      //GFB
	this.ToggleDisplay_Bottom = $get("ToggleCellBottom");      //GFB
	this.PanelSlider_Left = $get("PanelSliderLeft");      //GFB
	this.PanelDisplayTableCell_Bottom = $get("BottomPanelTableCell");      //GFB
	this.PanelSlider_Right = $get("PanelSliderRight");      //GFB
	this.webMapAppBottomTBCellDiv_DS = null;
    this.webMapAppBottomTBCellDiv_AL = null;

	
	this.NavigationTool = $get("Navigation1");
	this.CopyrightText = $get("Copyright_Panel");
	this.ZoomLevel = $get("ZoomLevel1");
	
	this.LeftPanelWidth = 322;
	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 = 322;
	this.LastMapWidth = 512;
	this.LastMapHeight = 512;
	this.CurrentMapWidth = 512;
	this.CurrentMapHeight = 512;
	
	this.BottomPanelHeight = 202;  // GFB
	this.ToggleHeight = 10;  //GFB
	this.WindowHeight = 500;    // GFB
	this.TopOffsetY = 0;   // GFB
	this.BottomOffsetY = 0;   // GFB
	this.DefaultMinBottomDockHeight = 125;
	this.MinBottomDockHeight = this.DefaultMinBottomDockHeight;
	
	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.BottomDockMoving = false;   // GFB
	
	this.setPageElementSizes = function() {
	    //jslog.info("setPageElementSizes() called");
        // set body style 
        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.PanelScrollDiv_Bottom.style.overflow = "hidden";    // GFB
        
        // get then set widths and heights
        this.LeftPanelWidth = this.PanelDisplay.clientWidth;   // need to know for map left
        this.ToggleWidth = parseInt(this.ToggleDisplay.style.width);   // need to know for map left
        this.TopBannerHeight = headerDisplay.clientHeight + linkDisplay.clientHeight;   // need to know for map top
        
        this.BottomPanelWidth = this.PanelDisplay_Bottom.clientHeight;   // GFB - need to know for map height
        this.ToggleHeight = parseInt(this.ToggleDisplay_Bottom.style.height);   // GFB - need to know for map height
        
        // get browser window dimensions
        var sWidth = this.getPageWidth();    // total page width
        var sHeight = this.getPageHeight();  // total page height
        
        // set map display dimensions
        var mHeight = sHeight - this.TopBannerHeight - this.ToggleHeight;         // GFB - Need to subtract bottom toggle for map height 
        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;
        
        // set heights of left panel and toggle bar
        this.ToggleDisplay.style.height = mHeight  + "px";
        this.PanelScrollDiv.style.height = mHeight  + "px";
        
        // set widths of bottom panel and toggle bar
        this.ToggleDisplay_Bottom.style.width = sWidth  + "px";   // GFB
        this.PanelScrollDiv_Bottom.style.width = sWidth  + "px";   // GFB
		
        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";   // GFB -  don't worry yet
        this.ResultsPanel.style.width = widthString;
        this.TocPanel.style.width = widthString;
        
        $addHandler(document.images["CollapseImageBottom"], "mousedown", this.toggleBottomDock);  // GFB
        $addHandler(this.PanelSlider_Left, "mousedown", this.startBottomDockDrag);  // GFB
		$addHandler(this.PanelSlider_Right, "mousedown", this.startBottomDockDrag);  // GFB
		
		if (isRTL) {
		    this.PanelDisplayCell.style.left = mWidth + "px";     // GFB -  don't worry because we are set to ltr
        }
        
        this.PanelDisplayCell_Bottom.style.top = mHeight + "px";  // GFB - initially sets bottom panel to locate at bottom
        
        this.webMapAppBottomTBCellDiv_DS = document.getElementById("BottomTBCellDiv_DS");
        this.webMapAppBottomTBCellDiv_AL = document.getElementById("BottomTBCellDiv_AL");
         
        
        this.webMapAppBottomTBCellDiv_DS.style.top = (mHeight + this.TopBannerHeight + this.ToggleHeight + 3) + "px";
        this.webMapAppBottomTBCellDiv_DS.style.left = "391px";   //393px
        this.webMapAppBottomTBCellDiv_DS.style.display = "block";
        
        this.webMapAppBottomTBCellDiv_AL.style.top = (mHeight + this.TopBannerHeight + this.ToggleHeight + 3) + "px";
        this.webMapAppBottomTBCellDiv_AL.style.left = "522px";  // 524px
        this.webMapAppBottomTBCellDiv_AL.style.display = "block";    
        
	}

	// function for adjusting element sizes when brower is resized
	this.adjustMapSize = function() {
	   //jslog.info("adjustMapSize() called");
	   // set element widths 
	    this.PanelDisplay.style.width =  this.LeftPanelWidth + "px";
	    this.ToggleDisplay.style.width = this.ToggleWidth + "px";
	    
	   // set element heights 
	    this.PanelDisplay_Bottom.style.height =  this.BottomPanelHeight + "px";    // GFB
	    this.ToggleDisplay_Bottom.style.height = this.ToggleHeight + "px";    // GFB
	    //this.webMapAppBottomTBCellDiv_DS.style.top = this.BottomPanelHeight + "px";
        //this.webMapAppBottomTBCellDiv_DS.style.left = "393px"; 
        //this.webMapAppBottomTBCellDiv_DS.style.display = "none";
        
        //this.webMapAppBottomTBCellDiv_AL.style.top = this.BottomPanelHeight + "px";
        //this.webMapAppBottomTBCellDiv_AL.style.left = "524px"; 
        //this.webMapAppBottomTBCellDiv_AL.style.display = "none";    
       
	   
	   // get browser window dimensions 
	    var sWidth = this.getPageWidth();
	    var sHeight = this.getPageHeight();
	    //var mHeight = sHeight - this.TopBannerHeight - this.ToggleHeight;   // GFB - Need to subtract bottom toggle for map height 
	    var mHeight = getMapHeight2();
	    
        // set widths of bottom panel and toggle bar
        this.ToggleDisplay_Bottom.style.width = sWidth  + "px";   // GFB
        this.PanelScrollDiv_Bottom.style.width = sWidth  + "px";   // GFB
	    
//        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 mHeight = getMapHeight2();
        // set heights of left panel and toggle bar
        arcgisWebApp.ToggleDisplay.style.height = mHeight  + "px";
        arcgisWebApp.PanelScrollDiv.style.height = mHeight  + "px";
        arcgisWebApp.MapDisplay.style.height = mHeight + "px";  
        arcgisWebApp.PanelDisplayCell_Bottom.style.top = mHeight + "px";
        arcgisWebApp.CurrentMapHeight = mHeight; 
        //this.setTocHeight();
        this.TocPanelContents.style.height = (mHeight-122) + "px";
        
        arcgisWebApp.webMapAppBottomTBCellDiv_DS.style.top = (mHeight + arcgisWebApp.TopBannerHeight + arcgisWebApp.ToggleHeight + 3) + "px";
        arcgisWebApp.webMapAppBottomTBCellDiv_AL.style.top = (mHeight + arcgisWebApp.TopBannerHeight + arcgisWebApp.ToggleHeight + 3) + "px";
        
        
	    // calc dimensions needed for map
	    //var mWidth = getMapWidth();   // GFB - not sure we need this
	    //if (mWidth<5) mWidth = 5; // GFB - not sure we need this
	    //if (mHeight<5) mHeight = 5; // GFB - not sure we need this 
	    setMapLeftPosition();
	    
	    //setDividerTopPosition();
	    



	    // set widths on elements 
	    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(); 
	    }
	    
	    // refresh the map 
	    // var m =  $find(this.MapId);  // GFB - not sure we need this
	    if (this.map!=null) {
	        if (this.LastMapWidth!=this.CurrentMapWidth || this.LastMapHeight!=this.CurrentMapHeight) {
	            this.map.checkMapsize();
	            //jslog.info("map.checkmapsize called 2");
	        }
	    } else {
	        window.setTimeout("arcgisWebApp.adjustMapSize();", 1000); 	 
	    }
	    
	         
	    if (isRTL) 
	        adjustRTLElements();    
	        
	    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 = 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() {
	    //jslog.info("togglePanelDOck() called");
        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() {
	    //jslog.info("expandPanelDock() called");
	    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"; 
	    window.setTimeout('arcgisWebApp.adjustMapSize();',500); 
	    
	}
	
	this.collapsePanelDock = function() {
	    //jslog.info("collapsePanelDock() called");
	    var image = document.images["CollapseImage"];
	    var imgUrl = (isRTL) ? "images/collapse_left.gif" : "images/expand_right.gif";
	    //dockWidthString = arcgisWebApp.PanelDisplayCell.clientWidth + "px";  // GFB - not sure we need this
	    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) {
	    //jslog.info("startDockDrag() called");
	    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;
                //jslog.info("");
                //jslog.info("panel display clientwidth: " + arcgisWebApp.PanelDisplay.clientWidth);
                //jslog.info("e.clientX: " + e.clientX);
                //jslog.info("left offset: " + arcgisWebApp.LeftOffsetX);
	            var location = Sys.UI.DomElement.getLocation($get("LeftPanelTableCell"));
	            arcgisWebApp.RightOffsetX = location.x - e.clientX;
	            //jslog.info("location.x: " + location.x);
	            //jslog.info("e.clientX: " + e.clientX);
	            //jslog.info("right offset: " + arcgisWebApp.RightOffsetX);
	            //jslog.info("");
	            $addHandler(document, "mousemove", arcgisWebApp.moveDockDragRTL);
	        } else {   
                arcgisWebApp.LeftOffsetX = e.clientX - arcgisWebApp.PanelDisplay.clientWidth;
                //jslog.info("left offset: " + arcgisWebApp.LeftOffsetX);
	            var location = Sys.UI.DomElement.getLocation($get("Map_Panel"));
	            arcgisWebApp.RightOffsetX = location.x - e.clientX;
	            //jslog.info("right offset: " + arcgisWebApp.RightOffsetX);
	            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) {
	    //jslog.info("moveDockDrag() called");
	    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) {
	   // jslog.info("moveDockDragRTL() called");
	    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) {
	   // jslog.info("stopDOckDrag() called");
	    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.startBottomDockDrag = function(e) {
	    //jslog.info("startBottomDockDrag() called");
	    if (!arcgisWebApp.BottomDockMoving) {
	        arcgisWebApp.MoveFunction = document.onmousemove;
	        arcgisWebApp.UpFunction = document.onmouseup; 
	        arcgisWebApp.BottomDockMoving = true;
	    }
	    $addHandler(document, "mouseup",  arcgisWebApp.stopBottomDockDrag);
	    if (arcgisWebApp.PanelDisplay_Bottom.style.display!="none") {
	        arcgisWebApp.WindowHeight = arcgisWebApp.getPageHeight();
	        
            arcgisWebApp.TopOffsetY = arcgisWebApp.PanelDisplay_Bottom.clientHeight - e.clientY;
            //jslog.info("top offset: " + arcgisWebApp.TopOffsetY);
            var location = Sys.UI.DomElement.getLocation($get("BottomPanelTableCell"));
            arcgisWebApp.BottomOffsetY = location.y - e.clientY;
            //jslog.info("bottom offset: " + arcgisWebApp.BottomOffsetY);
//            if (arcgisWebApp.CopyrightText) {
//                arcgisWebApp.CopyrightTextLeft = parseInt(arcgisWebApp.CopyrightText.style.left);
//                arcgisWebApp.CopyrightTextTop = parseInt(arcgisWebApp.CopyrightText.style.top);  
//            }
            $addHandler(document, "mousemove", arcgisWebApp.moveBottomDockDrag);
 
	        //startConsoleDragLeft = e.clientX;  // Not sure yet
	         
	    }
        e.preventDefault();
        e.stopPropagation();
	}    
	
	this.moveBottomDockDrag = function(e) {
	    
	    var theButton = (Sys.Browser.agent == Sys.Browser.InternetExplorer) ? event.button : e.which;      
	    if (theButton==0) arcgisWebApp.stopBottomDockDrag(e);
	    
	    
	    
	    
	    
	    var sHeight =  arcgisWebApp.getPageHeight();
	    arcgisWebApp.BottomPanelHeight =  sHeight - (e.clientY + arcgisWebApp.BottomOffsetY);// + arcgisWebApp.TopBannerHeight + arcgisWebApp.ToggleHeight;
	    
	            //jslog.info("-------------------------------")
	    	    //jslog.info("sHeight: " + sHeight);
	            //jslog.info("e.clientY: " + e.clientY);
	            //jslog.info("bottom offset: " + arcgisWebApp.BottomOffsetY);
	            //jslog.info("bottom panel height before top: " + (sHeight - (e.clientY + arcgisWebApp.BottomOffsetY)));
	            //jslog.info("top height: " + (arcgisWebApp.TopBannerHeight + arcgisWebApp.ToggleHeight));
	            //jslog.info("bottom panel height: " + arcgisWebApp.BottomPanelHeight);
	            //jslog.info("-------------------------------")
	            
	            
	            
	    arcgisWebApp.BottomDockMoving = true;
	    var x = e.clientX;
	    var y = e.clientY;
	    var bottomHeight = 2;

	    if (y<=bottomHeight || x>=arcgisWebApp.getPageWidth()-2 || x<1 || y>sHeight - arcgisWebApp.MinBottomDockHeight) 
	        arcgisWebApp.stopBottomDockDrag(e);
	    if (arcgisWebApp.BottomPanelHeight>sHeight-arcgisWebApp.ToggleDisplay_Bottom.clietHeight-bottomHeight) 
	        arcgisWebApp.BottomPanelHeight=sHeight-arcgisWebApp.ToggleDisplay_Bottom.clietHeight-bottomHeight;
	    if (arcgisWebApp.BottomPanelHeight < arcgisWebApp.MinBottomDockHeight) 
	        arcgisWebApp.BottomPanelHeight = arcgisWebApp.MinBottomDockHeight; 
	    
	    var mapTopString =  (arcgisWebApp.BottomPanelHeight + arcgisWebApp.ToggleDisplay_Bottom.clientHeight) + "px";
	    var heightString =  arcgisWebApp.BottomPanelHeight + "px";
	    arcgisWebApp.PanelDisplay_Bottom.style.height = heightString;
        
        var pHeight = arcgisWebApp.BottomPanelHeight;
        var height = sHeight - (pHeight + arcgisWebApp.ToggleDisplay_Bottom.clientHeight) - (arcgisWebApp.TopBannerHeight);
	    if (height<5) 
	        height = 5; 
	    arcgisWebApp.MapDisplay.style.height = height + "px";
	    arcgisWebApp.PanelDisplayCell_Bottom.style.top = height + "px";
	    
	    document.getElementById('TableContainer').style.height = (pHeight - 32) + "px";
            
        e.preventDefault();
        e.stopPropagation();
	}
    
	this.stopBottomDockDrag = function(e) {
	    //jslog.info("stopBottomDockDrag() called");
	    try {
            $removeHandler(document, "mouseup", arcgisWebApp.stopBottomDockDrag);
            $removeHandler(document, "mousemove", arcgisWebApp.moveBottomDockDrag);
	    } catch (ex) {
	        var dummy = ex;
	    } 
        if (arcgisWebApp.CopyrightText && !isIE) 
            arcgisWebApp.CopyrightText.style.top = arcgisWebApp.CopyrightTextTop + "px";
	    arcgisWebApp.BottomDockMoving = false;    
	    arcgisWebApp.adjustMapSize();
	        e.preventDefault();
	        e.stopPropagation();

    }

	// functions for Dock movement and sizing
	this.toggleBottomDock = function() {
	    //jslog.info("toggleBottomDock() called");
        if (arcgisIdentifyTool != null) {
            var dropdown = $get("dropdown_" + arcgisIdentifyTool.get_uniqueID());
            if (dropdown) dropdown.style.display = "none";
        }             
	    if (arcgisWebApp.PanelDisplay_Bottom.style.display=="none") {
	        arcgisWebApp.expandBottomDock();
	    } else {
	        arcgisWebApp.collapseBottomDock();
	    }     
	}
	
	this.expandBottomDock = function() {
	    //jslog.info("expandBottomDock() called");
	    var image = document.images["CollapseImageBottom"];
	    var imgUrl = "images/collapse_down.gif";
	    arcgisWebApp.PanelDisplay_Bottom.style.display = "block";
	    image.src = imgUrl;
	    image.alt = "Collapse";
	    arcgisWebApp.PanelSlider_Left.style.cursor = "n-resize";
	    arcgisWebApp.PanelSlider_Right.style.cursor = "n-resize"; 
	    //setDividerTopPosition2();
	    window.setTimeout('arcgisWebApp.adjustMapSize();',500); 
	}
	
	this.collapseBottomDock = function() {
	    //jslog.info("collapseBottomDock() called");
	    var image = document.images["CollapseImageBottom"];
	    var imgUrl = "images/expand_up.gif";
	    arcgisWebApp.PanelDisplay_Bottom.style.display = "none";
	    image.src = imgUrl;
	    image.alt = "Expand";
	    arcgisWebApp.PanelSlider_Left.style.cursor = "default"; 
	    arcgisWebApp.PanelSlider_Right.style.cursor = "default"; 
	    //setDividerTopPosition2();
	    window.setTimeout('arcgisWebApp.adjustMapSize();',500);  
	}
			
	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(); 
}
