﻿// 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);
var fActiveMenu = false;
var oOverMenu = false;

/// <reference assembly="System.Web.Extensions" name="MicrosoftAjax.js"/>
Type.registerNamespace('ESRI.ADF.WebMappingApplication');
// function run at startup
function startUp() {
        if (document.getElementsByClassName == undefined) {
            document.getElementsByClassName = function(className) {
                var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
                var allElements = document.getElementsByTagName("*");
                var results = [];

                var element;
                for (var i = 0; (element = allElements[i]) != null; i++) {
                    var elementClass = element.className;
                    if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
                        results.push(element);
                }

                return results;
            }
        }


        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 taskResults = $find("TaskResults1");
        var adjustMapDisplay = false;
        taskResults.add_taskResultNodeInserted(function() {
            var panel = $get("Results_Panel_Collapse");
            if (panel && panel.style.display=="none") {
                expandConsolePanel("Results_Panel");
                arcgisWebApp.MapDisplay.style.left = getMapLeft(); + "'px";
                adjustMapDisplay = true;
            } else 
            arcgisWebApp.adjustMapSize();
            if (!isRTL) adjustMapAndCopyrightPosition(adjustMapDisplay);
        });
        var panel = $get("Results_Panel_Collapse");
        if (panel!=null) panel.style.display = "none";
        // 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
		
        map.add_extentChanged(function() {UpdateCatList();} );  // extent changes that do not trigger ExentChanging
	//	map.add_mapResized(function(){resizeTabContent();} );
		
		// 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();
		}
        // set window resize event handler
        window.setTimeout('$addHandler(window,"resize", arcgisWebApp.adjustMapSizeHandler);', 1000); 
      
       //Set the inital visibility of the LIMIC Layer to hidden
       var layercollection = map.get_layers();
       var limicLayer = layercollection.get_layer(1);
      limicLayer.set_visible(false);
       map.refreshLayer(layercollection.get_layer(1));       
      
}


////////////Functions for mutually exclusive radio buttons////////////////////
var searchOption = false

function setShemp(setting, prefixLength) {
    searchOption = setting
     for (var i = 0; i < document.forms[0].SearchType.length; i++) {
        if (document.forms[0].SearchType[i].checked) {
            break
        }
    }
       var autoComplete = $find('ACEB');
       if (!autoComplete) return;
       var Search = document.forms[0].SearchType[i].nextSibling.nodeValue    
       autoComplete.set_contextKey(Search);
       autoComplete.set_minimumPrefixLength(prefixLength);
 }
 
 
////////////End functions for mutually exclusive radio buttons////////////////////
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
       var autoComplete = $find('ACEB');
       if (!autoComplete) return;
       var SearchType = autoComplete._contextKey;
       var SearchText = myfield.value;
       //tab mode, category, place name, filter by 
       LogisSend('tab2', 'None', SearchText, 'None');
       GGTabs.expandit(1);
   return false;
   }
else
   return true;
}

function Print(){
if (isIE)
    {
        var w = window.open("","");
        var d = w.document;
        d.open();
        var m = $get('Map1');
        var t = $get('Logis_Panel_inner');
        d.writeln('<html xmlns:v="urn:schemas-microsoft-com:vml">');
        d.writeln('<head>');
        d.writeln('<title>PrintPage</title>');
        d.writeln('<style>');
        d.writeln('v\\:*');
        d.writeln('{');
        d.writeln('behavior: url(#default#VML); ');
        d.writeln('}');
        d.writeln('</style>');
        d.writeln('</head>');
        d.writeln('<body>');
        d.writeln(m.innerHTML);       
        d.writeln('<br />');
        d.writeln(t.innerHTML);   
        d.writeln('</body>');      
        d.writeln('</html>'); 
        d.close();
    }else{
        var w = window.open("http://localhost/ggov/SVG/map.htm" ,"");
        //var w = window.open("" ,"");
        var d = w.document;
        d.open();
        var printDiv = document.getElementById('printMapDiv');
        var m = $get('Map1');
        d.innerHTML = (m.innerHTML)
        d.close();


   }
}


function toggleLimicPhoto()
{
 	var layercollection = map.get_layers();
    var limicLayer = layercollection.get_layer(1);
         if (limicLayer._visible){
            limicLayer.set_visible(false);
         }else{
            limicLayer.set_visible(true);
         }
    map.refreshLayer(layercollection.get_layer(1));
   
}

function addAGSOnlineLayerToMap()
{
	//var map = $find(mapID);
	var layercollection = map.get_layers();

	layercollection.insert($create(ESRI.ADF.Layers.AdfTileDirectAccess,{
		"id":"Map1_Shaded Relief",
		"serverUrl":"http://services.arcgisonline.com/cache_wc/ESRI_ShadedRelief_World_2D/Layers/_alllayers",
		"extent":new ESRI.ADF.Geometries.Envelope(-180,-90,180,90),
		"tileOrigin":new ESRI.ADF.Geometries.Point(-180,90),
		"imageFormat":"jpg",
		"tileUrlGeneratorFunction":arcgisVirtualDirectoryTileUrlGenerator_jpg,
		"opacity":1,
		"levels":
		[new ESRI.ADF.Layers.LevelInfo(512,512,4,8,0.087890625,0.087890625,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,8,16,0.0439453125,0.0439453125,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,16,32,0.02197265625,0.02197265625,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,32,64,0.010986328125,0.010986328125,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,64,128,0.0054931640625,0.0054931640625,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,128,256,0.00274658203125,0.00274658203125,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,256,512,0.001373291015625,0.001373291015625,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,512,1024,0.0006866455078125,0.0006866455078125,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,1025,2049,0.000343322753906249,0.000343322753906249,0,0),
		new ESRI.ADF.Layers.LevelInfo(512,512,2048,4096,0.000171661376953125,0.000171661376953125,0,0)],
		"visible":true}),0);
}



// handler for map extent change 
function UpdateCatList() {
	 map = arcgisWebApp.map;
	    if (map!=null) {
          var mapwidth = parseInt(map.get_element().clientWidth);
            var unitsperpixel = map.get_extent().get_width()/ mapwidth;
            var scale = getMapScale(unitsperpixel);

            ///////////////////////////////////////////////////////////////////////////
            var tds = document.getElementsByClassName('link');
            
            for (t = 0; t < tds.length; t++) {
                //alert(tds[t].firstChild.nodeValue)
                //alert(tds[t].nextSibling.firstChild.nodeValue)
                 var scaleDependcell = (tds[t]);
                 var cellScale = (tds[t].nextSibling.firstChild.nodeValue);
                 if (cellScale > scale) {
                     scaleDependcell.attributes["class"].value = "link"
                 } else {

                 scaleDependcell.attributes["class"].value = "nonlink"       
                 }
             }
            
            tds = document.getElementsByClassName('nonlink');

            for (t = 0; t < tds.length; t++) {
                //alert(tds[t].firstChild.nodeValue)
                //alert(tds[t].nextSibling.firstChild.nodeValue)
                var scaleDependcell = (tds[t]);
                var cellScale = (tds[t].nextSibling.firstChild.nodeValue);
                if (cellScale > scale) {
                    scaleDependcell.attributes["class"].value = "link"
                } else {

                    scaleDependcell.attributes["class"].value = "nonlink"
                }
            } 
            ///////////////////////////////////////////////////////////////////////////////

            
//           var table = document.getElementById('treetable');   
//             //var jObj = new Object();
//             for (i=0; i<table.rows.length; i++) {
//                var row = table.rows[i];
//                var cell = row.cells[0]
//                alert(cell.nodeName);
//                var chldTable = row.cells[0].firstChild
//                alert(cell.nodeName);
//                var hidecell = row.cells[2]
//                       if (row.cells[2].firstChild.nodeValue >= scale) {                           
//                            
//                          cell.attributes["class"].value = "link"                  
//                         
//                        } else {
//                           
//                            cell.attributes["class"].value = "nonlink"      
//                        }

//                 for (j=0; j<row.cells.length; j++) {
//                        alert(row.cells[j].firstChild.nodeValue)
//                       
//                          //var cellval =  theCell.firstChild.nodeValue;
//                          //jObj[topRow.cells[i].innerHTML] = myRow.cells[i].innerHTML;
//                }   
     //        }                 
	    }
	   
	}
	
	
	
	function getMapScale (unitsperpixel) {
	    /// <summary>
	    /// Gets current map scale
	    /// </summary>
	    /// <param name="unitsperpixel" type="Number">Number of units per pixel</param>
	    
        var unitsperinch = unitsperpixel * 96;
        var factor = 1;
        var units = "Meter"
        var MeterFactor = 39.37007874;
        switch(units) {
            case "Feet": factor = this.FeetFactor; break;
            case "Meter": factor = MeterFactor; break;
            case "Inches": factor = 1; break;
            case "DecimalDegrees":
            default: factor = this.DegreeFactor * this.MeterFactor; break;
        }
        return Math.round(factor * unitsperinch);
    }
    
	function showListings(e) {
        var targ;
        if (!e)
          {
          var e = window.event;
          }
        if (e.target)
          {
          targ = e.target;
          }
        else if (e.srcElement)
          {
          targ = e.srcElement;
          }
        if (targ.nodeType == 3) // Safari bug
          {
          targ = targ.parentNode;
          }
           var msg; 
           
         if (targ.attributes["class"].value == "link") // Safari bug
          { 
         
          arcgisLogisControl.showRowData(targ);
          GGTabs.expandit(1);
          }   
          if (targ.attributes["class"].value == "nonlink") // Safari bug
          {         
           var scalecell = targ.nextSibling.firstChild.nodeValue
           msg = "The minimum scale at which " + targ.firstChild.nodeValue + " items can be displayed is 1:" + scalecell + ". To view these locations, zoom in using your scroll wheel or hold the shift key to drag a box.";
           alert(msg);
          }      
                
     }
     
//     /////////////FUNCTIONS FOR AMENITY FILTER DROP DOWN/////////////////
//function mouseSelect(e, text)
//{
//		if (oOverMenu == false)
//		{
//			oOverMenu = false;
//			document.getElementById(fActiveMenu).style.display = "none";
//			fActiveMenu = false;
//			arcgisLogisControl.filterRowData(text);
//			return false;
//		}
//		return false;
//}
// 
//function filterMenuActivate(idPickList, idMenu, idSel)
//{
//	if (fActiveMenu) return mouseSelect(0);
// 
//	oMenu = document.getElementById(idMenu);
//	oPickList = document.getElementById(idPickList);
//	nTop = oPickList.offsetTop + oPickList.offsetHeight;
//	nLeft = oPickList.offsetLeft;
////	while (oPickList.offsetParent != document.body)
////	{
////		oPickList = oPickList.offsetParent;
////		nTop += oPickList.offsetTop;
////		nLeft += oPickList.offsetLeft;
////	}
//	oMenu.style.left = nLeft;
//	oMenu.style.top = nTop;
//	oMenu.style.display = "";
//	fActiveMenu = idMenu;
//	document.getElementById(idSel).focus();
//	return false;
//}
// 
//function textSet(idEdit, text)
//{
//	document.getElementById(idEdit).value = text;
//	oOverMenu = false;
//	mouseSelect(0, text);
//	document.getElementById(idEdit).focus();
//}

///////////////END FUNCTIONS FOR AMENITY FILTER DROP DOWN/////////////////
function resetMapHistory() {
    map = arcgisWebApp.map;
    var toolbar = $find("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 toggleOverviewMap() {
    var ovm = $find("OverviewMap1"); 
    var toolbarobj = $find("Toolbar1"); 
	var toolbar =(toolbarobj!=null) ? Toolbars[toolbarobj._uniqueID] : null;
    var imageTag = "Toolbar1OverviewMapToggleImage";
    var toolbarItemName = "OverviewMapToggle"; 
    var showImage = (isRTL ? "images/show-overview-map2.png" : "images/show-overview-map.png"); 
    var hideImage = (isRTL ? "images/hide-overview-map2.png" : "images/hide-overview-map.png");	
    var img = document.images[imageTag];
    if (ovm) {
        if(ovm.isVisible()) {
            ovm.hide();
            if (toolbar!=null) { 
                toolbar.items[toolbarItemName].selectedImage = showImage;
                toolbar.items[toolbarItemName].defaultImage = showImage;
                toolbar.items[toolbarItemName].hoverImage = showImage; 
                 if (img!=null) { 
                    img.alt = "Show OverviewMap";
                    img.title = "Show OverviewMap";
                }
                switchImageSourceAndAlphaBlend(img,toolbar.items[toolbarItemName].defaultImage);  
            }   
        } else {
            ovm.show();
            if (toolbar!=null) {   
                toolbar.items[toolbarItemName].selectedImage = hideImage;
                toolbar.items[toolbarItemName].defaultImage = hideImage;
                toolbar.items[toolbarItemName].hoverImage = hideImage;  
                 if (img!=null) { 
                    img.alt = "Hide OverviewMap";
                    img.title = "Hide OverviewMap";
                }
                switchImageSourceAndAlphaBlend(img,toolbar.items[toolbarItemName].defaultImage); 
            }
            if (isRTL) adjustRTLElements();     
        } 
    }  
}

function toggleConsolePanel(panelName) {
    var panel = $get(panelName + "_Collapse");
    if (panel) {
        if (panel.style.display=="none") {
            expandConsolePanel(panelName);
        } else { 
            collapseConsolePanel(panelName); 
        }
        arcgisWebApp.setTocHeight(); 
        window.setTimeout("arcgisWebApp.MapDisplay.style.left = getMapLeft(); + 'px';", 500) ; 
    }             
}

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);
        cr.get_callout().set_animate(false);
    }
}

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;
        if (mode!="Measure" && arcgisWebApp.lastMode=="Measure") closeMeasureToolbarTool();
        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 
        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 () {
    var mWidth = getMapWidth();
    arcgisWebApp.MapDisplay.style.left = "0px";  
    arcgisWebApp.PanelDisplayCell.style.left = mWidth + "px";
    arcgisWebApp.MapDisplay.style.width = mWidth + "px";
    arcgisWebApp.CurrentMapWidth = mWidth; 
}


function adjustMapAndCopyrightPosition(adjustMapDisplay) {
    if (adjustMapDisplay==null) adjustMapDisplay = false;
    var bounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay);
    var mLeft = bounds.x+ bounds.width;
    if (arcgisWebApp.CopyrightText) { 
        var crLeft =  parseInt(arcgisWebApp.CopyrightText.style.left);
        arcgisWebApp.CopyrightText.style.left = mLeft + "px";
    }
    if (adjustMapDisplay) 
        arcgisWebApp.MapDisplay.style.left =  mLeft + "px";
}

function adjustRTLElements() {
    // these elements must be manually adjusted in right-to-left mode 
    if (arcgisWebApp.CopyrightText) {
        arcgisWebApp.CopyrightText.style.left = "0px";
    }
    var ovm = $get("OverviewMap1");
    if (ovm)
        ovm.style.left = "0px";
    if (!isIE) {
        var dbounds = Sys.UI.DomElement.getBounds(arcgisWebApp.ToggleDisplay);
        var navp = $get("Navigation_Panel");
        if (navp) {
            var nbounds = Sys.UI.DomElement.getBounds(navp); 
            navp.style.left = (dbounds.x - nbounds.width) + "px";
        }
    }
    var tmenu = $get("TaskMenu");
    if (tmenu) tmenu.className = "appFloat1"; 
}	

// 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.LOGIS_PanelDiv = $get("Logis_Panel");
	this.LOGIS_PanelInDiv = $get("Logis_Panel_inner");
	this.LOGIS_Tab1Div = $get("GGOV_Tab1");
	this.LOGIS_Tab2Div = $get("GGOV_Tab2");
	this.LOGIS_Tab3Div = $get("GGOV_Tab3");
	this.Logis_ProgDiv = $get("Logis_Prog");
	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() {
        // 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");
        // get the set widths and heights
        this.LeftPanelWidth = this.PanelDisplay.clientWidth;
        this.ToggleWidth = parseInt(this.ToggleDisplay.style.width);
        this.TopBannerHeight = headerDisplay.clientHeight + linkDisplay.clientHeight;
        // get browser window dimensions
        var sWidth = this.getPageWidth();
        var sHeight = this.getPageHeight();
        // set map display dimensions
        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;
        // set heights of left panel and toggle bar
        this.ToggleDisplay.style.height = mHeight  + "px";
        this.PanelScrollDiv.style.height = mHeight  + "px";
		this.LOGIS_PanelDiv.style.height = (mHeight - 40)  + "px"; ///////////////////////*****************////////
		this.LOGIS_PanelInDiv.style.height = (mHeight - 50)  + "px"; ///////////////////////*****************////////
       this.LOGIS_Tab1Div.style.height = (mHeight - 100)  + "px";
	   this.LOGIS_Tab2Div.style.height = (mHeight - 100)  + "px";
	   this.LOGIS_Tab3Div.style.height = (mHeight - 100)  + "px";
       
        this.Logis_ProgDiv.style.top = (mHeight - 20)  + "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";
        }
	}

	// function for adjusting element sizes when brower is resized
	this.adjustMapSize = function() {
	   // set element widths 
	    this.PanelDisplay.style.width =  this.LeftPanelWidth + "px";
	    this.ToggleDisplay.style.width = this.ToggleWidth + "px";
	   // get browser window dimensions 
	    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.LOGIS_PanelDiv.style.height = (mHeight - 40)  + "px";
	    this.LOGIS_PanelInDiv.style.height = (mHeight - 50)  + "px"; //////////////////////*****************////////
          this.Logis_ProgDiv.style.top = (mHeight - 20)  + "px";
           this.LOGIS_Tab1Div.style.height = (mHeight - 100)  + "px";
	   this.LOGIS_Tab2Div.style.height = (mHeight - 100)  + "px";
	   this.LOGIS_Tab3Div.style.height = (mHeight - 100)  + "px";
        this.CurrentMapHeight = mHeight;
	    this.setTocHeight();
	    
	    // calc dimensions needed for map
	    var mWidth = getMapWidth();
	    if (mWidth<5) mWidth = 5;
	    if (mHeight<5) mHeight = 5;  
	    setMapLeftPosition();
	   // set heights 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);
	    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();    
	    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";
        //this.LOGISPanelContents.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"; 
	    window.setTimeout('arcgisWebApp.adjustMapSize();',500); 
	    
	}
	
	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"; 
	    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;
	        // 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) {
	    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(); }
