﻿// JScript 檔

// Javascript file for Web Mapping Application
       // 9.2->9.3
var map;

var reloadTimer;
var webMapAppLeftPanelWidth = 262;
var webMapAppToggleWidth = 10;
var webMapAppTopBannerHeight = 80;
var newLoad = false;
var webMapAppCloseCallback = "";
var webMapAppCopyrightCallback = "";
var webMapAppMoveFunction = null;

var webMapAppWholeDisplay = null;
var webMapAppTocDisplay = null;
var webMapAppMapDisplay = null;
var webMapAppPanelDisplay = null;
var webMapAppmsgDisplay = null;
var webMapAppOvDisplay = 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 webMapAppTocPanelWidth = 0;
var webMapAppmsgPanelWidth = 0;

var webMapAppLeftOffsetX = 0;
var webMapAppRightOffsetX = 0
var webMapAppDefaultMinDockWidth = 125;
var webMapAppMinDockWidth = webMapAppDefaultMinDockWidth;
var webMapAppMapLeft = 262;
var webMapAppHasScroll = false;
var webMapAppLastHasScroll = false;

// function to set initial sizes of page elements
function setPageElementSizes() {
        // set body style 
        document.body.style.overflow = "hidden";
        document.body.style.height = "100%"; 
        // get necessary elements
        webMapAppWholeDisplay = document.getElementById("Whole_Panel");
        webMapAppTocDisplay = document.getElementById("Toc_Panel");
        webMapAppMapDisplay = document.getElementById("Map_Panel");
        webMapAppmsgDisplay = document.getElementById("msg_Panel");
        webMapAppOvDisplay = document.getElementById("Overview_Panel");
        var linkDisplay = document.getElementById("LinkBar");
        

        // get the set widths and heights
        webMapAppTocPanelWidth = webMapAppTocDisplay.clientWidth;
        webMapAppmsgPanelWidth = webMapAppmsgDisplay.clientWidth;
        webMapAppTopBannerHeight = linkDisplay.clientHeight;
        // get browser window dimensions
        var sWidth = getWinWidth();
        var sHeight = getWinHeight();
        // set map display dimensions
        var mWidth = sWidth - webMapAppTocPanelWidth - webMapAppmsgPanelWidth;
        var mHeight = sHeight - 30;      //webMapAppTopBannerHeight;
//        alert ('mWidth=' + webMapAppMapDisplay.style.width);
        webMapAppMapLeft = webMapAppTocPanelWidth;
        webMapAppMapDisplay.style.width =  mWidth + "px";
        webMapAppMapDisplay.style.height = mHeight  + "px";

        if (webMapAppCopyrightText!=null) {
            webMapAppCopyrightText.onmousedown = webMapAppGetCopyrightText;
            var crtHeight = webMapAppCopyrightText.clientHeight;
            webMapAppCopyrightText.style.left = (webMapAppMapLeft + 10) + "px";
            webMapAppCopyrightText.style.top = (sHeight - crtHeight - 10) + "px";
        }
        // set heights of left panel and toggle bar
}


// function for adjusting element sizes when brower is resized
function AdjustMapSize() {
   // set element widths 
   // get browser window dimensions 
    var sWidth = getWinWidth();
    var sHeight = getWinHeight();
    var mWidth = sWidth - webMapAppTocDisplay.clientWidth - webMapAppmsgDisplay.clientWidth;       //webMapAppPanelDisplayCell.clientWidth;
    alert('AdjustMapSize');
    var mHeight = sHeight - 30;  //- webMapAppTopBannerHeight;
    if (mWidth<5) mWidth = 5;
    if (mHeight<5) mHeight = 5;  
    webMapAppMapDisplay.style.width =  mWidth + "px";
    webMapAppMapDisplay.style.left =  webMapAppTocDisplay.clientWidth + "px";     //webMapAppPanelDisplayCell.clientWidth + "px"; 
   // set heights on elements 
    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";
    } 
   // resize the map 
    alert('AdjustMapSize');
    window.setTimeout("resizeTheMap(" + mWidth + ", " + mHeight + ", false);", 500);
   // update map properties 
     
    var box = calcElementPosition("Map_Panel"); 
    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 for resizing map in Web Map App
function resizeTheMap(width, height, resizeExtent) {
    if (resizeExtent==null) resizeExtent = true;
    map.resize(width, height, resizeExtent);
    var div = document.getElementById("LeftPanelCellDiv"); 
    // update overview, if doc panel is expanded 
    if (ov!=null && div.style.display!="none") { 
        var argument = "ControlType=OverviewMap&EventArg=OverviewZoom";
        var context = ov.controlName; 
        eval(ov.callBackFunctionString);
    }
    return false; 
}

// handler for window resize
function AdjustMapSizeHandler(e) {
    window.clearTimeout(reloadTimer);
//	reloadTimer = window.setTimeout("AdjustMapSize();",1000);
//    alert('AdjustMapSizeHandler');
}

// function run at startup
function startUp() {
        // set up identify mode for javascript
        map = $get('Map1'); 	// 9.2->9.3
        map.ctrlMode = "MapIdentify";
        map.ctrlAction = "Point"; 
        map.ctrlCursor = "pointer";
        map.ctrlFunction = "MapIdClick(e)";

        // set window resize event handler
//         alert('startUp');
      window.onresize = AdjustMapSizeHandler;
}  


function OpenWindow(url) {
    window.open(url);
}

