function MapApplet() {
        this._bBtnReady = false;

    this._bWaitingForResizeResponse = false;

    this._bCenterInputShown = false;

        this._bSetDocWait = false;

    this._oInputMask = null;

        this.enableBtn = function () {
        oMapApplet._bBtnReady = true;
    }

        this.disableBtn = function () {
        oMapApplet._bBtnReady = false;
    }

        this.btnReady = function () {
        return ((typeof(oMapApplet) != 'undefined')
                &&
                oMapApplet._bBtnReady);
    }

        this._showCenterInput = function() {
        oMapApplet._bCenterInputShown = true;
        oBox.suspend();
        oDrag.suspend();

                var oCenterBtnImg =
            document.getElementById('btnImg3');
        var iImgPageLeft = oCenterBtnImg.offsetLeft;
        var iImgPageTop = oCenterBtnImg.offsetTop;
        var oParent = oCenterBtnImg.offsetParent;
        while (oParent) {
            iImgPageLeft += oParent.offsetLeft;
            iImgPageTop += oParent.offsetTop;
            oParent = oParent.offsetParent;
        }

        oMapApplet._showInputMask();
        var oCenterInput =
            document.getElementById('centerInput');
        oCenterInput.style.left = (iImgPageLeft + oCenterBtnImg.width) +  'px';
        oCenterInput.style.top = iImgPageTop + 'px';
        oCenterInput.style.visibility = 'visible';
        document.getElementById('localCenterAtVal').focus();
    }

        this.hideCenterInput = function() {
        oBox.resume();
        oDrag.resume();
        var oCenterInput =
            document.getElementById('centerInput');
        oCenterInput.style.visibility = 'hidden';
        var oForm = document.getElementById('queryForm');
                oMapApplet._updAllBtnImgs(oForm.cb.value);
        oMapApplet._hideInputMask();
        oMapApplet._bCenterInputShown = false;
    }

        this._showInputMask = function() {
        if (oMapApplet._oInputMask == null) {
            oMapApplet._initInputMask();
        }
        oMapApplet._setMaskIncompatibleCtrl('hidden');
        oMapApplet._oInputMask.style.display = 'block';
    }

        this._hideInputMask = function() {
        if (oMapApplet._oInputMask == null) {
            oMapApplet._initInputMask();
        }
        oMapApplet._setMaskIncompatibleCtrl('visible');
        oMapApplet._oInputMask.style.display = 'none';
    }

        this._initInputMask = function() {
        oMapApplet._oInputMask = document.getElementById('centerInputMask');
        oMapApplet._oInputMask.style.width = document.body.scrollWidth + 'px';
        oMapApplet._oInputMask.style.height = document.body.scrollHeight + 'px';
                oMapApplet._oInputMask.style.filter = 'alpha(opacity=50)';
    }

        this._setMaskIncompatibleCtrl = function(sVisibility) {
        if (aGlobal['oIeVer'].bIsIePre7) {
            var aCtrl = ['ssf'];
            for (var i=0; i<aCtrl.length; i++) {
                var oCtrl = document.getElementById(aCtrl[i]);
                if (oCtrl) {
                    oCtrl.style.visibility = sVisibility;
                }
            }
        }
    }

        this.processCenterInputKeypress = function(oEvt) {
                var bNeedMoreInput = true;

        if (!oEvt) {
            oEvt = window.event;
        }
        var iKeyCode = (aGlobal['oIeVer'].bIsIe
                        ? oEvt.keyCode
                        :                           oEvt.which);
        if (iKeyCode == 13) {
            
            oMapApplet.submitCenterInput();

                        bNeedMoreInput = false;
                }
        return bNeedMoreInput;
    }

        this.submitCenterInput = function() {
        var bNeedMoreInput = true;

        var oCenterAtType =
            document.getElementById('localCenterAtType');

        var sCenterAtType =
            oCenterAtType.options[oCenterAtType.selectedIndex].value;

        var sCenterAtVal =
            document.getElementById('localCenterAtVal').value;

        var sCenterAtScale =
            document.getElementById('localCenterAtScale').value;

        if (/^\s*$/.test(sCenterAtVal)) {
                        if (sCenterAtType == 'nts') {
                alert(oMapApplet.oExeParam.aXlate['Please specify an NTS map sheet.']);
            } else {
                alert(oMapApplet.oExeParam.aXlate['Please specify a latitude and longitutde.']);
            }
        } else {
                        var bValOk = ((sCenterAtType == 'nts')
                          ? oMapApplet._parseNts(sCenterAtVal)
                          : oMapApplet._parseLatLong(sCenterAtVal));
            if (bValOk) {
                                oMapApplet.hideCenterInput();
                var oForm = document.getElementById('queryForm');
                oForm.centerAtType.value =
                    sCenterAtType;
                oForm.centerAtVal.value =
                    sCenterAtVal;
                oForm.centerAtScale.value =
                    sCenterAtScale;
                oMapApplet.submitForm();
                bNeedMoreInput = false;
            }
        }
        return bNeedMoreInput;
    }

        this._parseNts = function(sNtsId) {
        var bOk = false;
        var aMatch = /^\s*(\d+)(?:\s*([a-z])(?:\s*(\x2f?)(\d+)\s*([a-z]?))?)?(\s*\x2f?\s*(?:n|s)\.?\s*(?:e|w)\.?)?\s*$/i.exec(sNtsId);
        if (aMatch == null) {
                        alert(oMapApplet.oExeParam.aXlate['Please ensure that the NTS name'] +
                  ' (' + sNtsId + ') ' +
                  oMapApplet.oExeParam.aXlate['is in the correct format.']);

        } else if ((aMatch[1] > 120) &&
                   (aMatch[1] != 340) &&
                   (aMatch[1] != 560)) {
            alert(oMapApplet.oExeParam.aXlate['Please ensure that the bracketed number'] +
                  ', ' + oMapApplet._bracketPart(aMatch, 1) + ', ' +
                  oMapApplet.oExeParam.aXlate['is from 0 to 120, 340, or 560.']);

        } else if ((aMatch[2] != '')
                   &&
                   (((aMatch[1] % 10) >= 7)
                    ||
                    (aMatch[1] >= 120))
                   &&
                   !/[a-h]/i.exec(aMatch[2])) {
            alert(oMapApplet.oExeParam.aXlate['Please ensure that the bracketed letter'] +
                  ', ' + oMapApplet._bracketPart(aMatch, 2) + ', ' +
                  oMapApplet.oExeParam.aXlate['is from A to H.'] + ' ' +
                  oMapApplet.oExeParam.aXlate['The NTS sheet is above latitude 68.']);

        } else if ((aMatch[2] != '')
                   &&
                   !/[a-p]/i.exec(aMatch[2])) {
            alert(oMapApplet.oExeParam.aXlate['Please ensure that the bracketed letter'] +
                  ', ' + oMapApplet._bracketPart(aMatch, 2) + ', ' +
                  oMapApplet.oExeParam.aXlate['is from A to P.']);

        } else if ((aMatch[4] != '')
                   &&
                   (aMatch[4] == 0) ||
                   (aMatch[4] > 16)) {
            alert(oMapApplet.oExeParam.aXlate['Please ensure that the bracketed number'] +
                  ', ' + oMapApplet._bracketPart(aMatch, 4) + ', ' +
                  oMapApplet.oExeParam.aXlate['is from 1 to 16.']);

        } else if ((aMatch[5] != '')
                   &&
                   !/[a-h]/i.exec(aMatch[5])) {
            alert(oMapApplet.oExeParam.aXlate['Please ensure that the bracketed letter'] +
                  ', ' + oMapApplet._bracketPart(aMatch, 5) + ', ' +
                  oMapApplet.oExeParam.aXlate['is from A to H.']);

        } else {
            bOk = true;
        }

        return bOk;
    }

        this._bracketPart = function(aPart, iIdx) {
        return ((iIdx > 1)
                ? aPart.slice(1, iIdx).join('')
                : '') +
               '[' + aPart[iIdx] + ']' +
               aPart.slice(iIdx+1).join('');
    }

        this._parseLatLong = function(sLatLong) {
        var bOk = false;
        var aMatch = /^\s*([\+\-]?[0-9\.]+)(\s*(?:\,|\s)\s*)([\+\-]?[0-9\.]+)\s*$/.exec(sLatLong);
        if (aMatch == null) {
            alert(oMapApplet.oExeParam.aXlate['Please ensure that the entered value'] +
                  ' (' + sLatLong + ') ' +
                  oMapApplet.oExeParam.aXlate['is a pair of lattitude and longitude numbers separated by a comma (,) or space.']);
        } else {
            var iMinX = -32;
            var iMaxX = -142;
            var iMinY = 40;
            var iMaxY = 86;
            var fCenterAtY = aMatch[1];
            var fCenterAtX = aMatch[3];
            if ((fCenterAtY < iMinY) || (fCenterAtY > iMaxY)) {
                alert(oMapApplet.oExeParam.aXlate['Please ensure that the bracketed latitude'] +
                      ', ' + oMapApplet._bracketPart(aMatch, 1) + ', ' +
                      oMapApplet.oExeParam.aXlate['is from'] +
                      ' ' + iMinY + ' ' +
                      oMapApplet.oExeParam.aXlate['to'] +
                      ' ' + iMaxY + '.');
            } else if ((fCenterAtX < iMaxX) || (fCenterAtX > iMinX)) {
                alert(oMapApplet.oExeParam.aXlate['Please ensure that the bracketed longitude'] +
                      ', ' + oMapApplet._bracketPart(aMatch, 3) + ', ' +
                      oMapApplet.oExeParam.aXlate['is from'] +
                      ' ' + iMinX + ' ' +
                      oMapApplet.oExeParam.aXlate['to'] +
                      ' ' + iMaxX + '.');
            } else {
                bOk = true;
            }
        }
        return bOk;
    }

        this.copyStatusToLayerProxy = function(oGroup, sProxyId) {
        document.getElementById(sProxyId).value = (oGroup.checked
                                                   ? '1'
                                                   : '');
    }

        this.updateOthersInGroup = function(sGroupId, bChecked) {
        var iGroupIdx = (/^.+?(\d+)$/.exec(sGroupId))[1];
        var sLayerIdRoot = 'a' +
                           '-' +
                           iGroupIdx +
                           '-';
        var sLegendIdRoot = 'e_' +
                            sLayerIdRoot;
        var oLegend;
        var iLayerIdx = -1;
                do {
                        iLayerIdx++;

                        var iLegendIdx = 0;

                        while (                   (oLegend = document.getElementById(sLegendIdRoot +
                                                      iLayerIdx +
                                                      '_' +
                                                      iLegendIdx++))
                   ||
                                      (oLayer = document.getElementById(sLayerIdRoot + iLayerIdx))) {
                if (oLegend) {
                                        if (oLegend.tagName == 'INPUT') {
                        oLegend.checked = bChecked;
                    }
                } else if (oLayer) {
                                        if (oLayer.tagName == 'INPUT') {
                        oLayer.checked = bChecked;
                    }
                    iLegendIdx = 0;
                    iLayerIdx++;
                }
            }
        } while (iLegendIdx > 1);
    }

        this.updateGroupStatus = function(sLegendId) {
        var iGroupIdx =
            (/\-(.+)\-/
             .exec(sLegendId))[1];
        var sLegendIdRoot =
            'e_a-' +
            iGroupIdx +
            '-';
        var sLayerIdRoot = 'a-' +
                           iGroupIdx +
                           '-';
        var oLegend;
        var iLayerIdx = -1;
        var bFoundChecked = false;
        do {
            iLayerIdx++;
            var iLegendIdx = 0;
            while ((oLegend = document.getElementById(sLegendIdRoot +
                                                      iLayerIdx +
                                                      '_' +
                                                      iLegendIdx++))
                   ||
                   (oLayer = document.getElementById(sLayerIdRoot + iLayerIdx))) {
                if (oLegend) {
                    if (oLegend.tagName == 'INPUT') {
                        if (oLegend.checked) {
                            bFoundChecked = true;
                            break;
                        }
                    }
                } else if (oLayer) {
                    if (oLayer.tagName == 'INPUT') {
                        if (oLayer.checked) {
                            bFoundChecked = true;
                            break;
                        }
                    }
                    iLegendIdx = 0;
                    iLayerIdx++;
                }
            }
        } while ((iLegendIdx > 1) && (!bFoundChecked));
        document
        .getElementById('g' + iGroupIdx)
        .checked = bFoundChecked;
    }

        this.updateOthersInLayer = function(sId, bChecked) {
        var sLayerIdRoot = (/^(.+\_)\d+$/.exec(sId))[1];
        var iIdx = 0;
        var oLegend;
        while (oLegend = document.getElementById(sLayerIdRoot + iIdx++)) {
            oLegend.checked = bChecked;
        }
    }

        this.mouseOver = function(sBtnImgId) {
        if (oMapApplet.btnReady()) {
            var iBtnIdx = (/(\d+)$/.exec(sBtnImgId))[1];
            document.images[sBtnImgId].src = oMapApplet.oExeParam.aBtnImg[iBtnIdx].oImgOver.src;
        }
    }

        this.mouseOut = function(sBtnImgId) {
        if (oMapApplet.btnReady()) {
            var oForm = document.getElementById('queryForm');
            var sClickedBtnId = oForm.cb.value;
            var iClickedBtnIdx = (/(\d+)$/.exec(sClickedBtnId))[1];
            var iBtnIdx = (/(\d+)$/.exec(sBtnImgId))[1];
            if (                (iBtnIdx != iClickedBtnIdx)
                &&
                                ((iBtnIdx != '3')
                 ||
                 !oMapApplet._bCenterInputShown)) {
                                document.images[sBtnImgId].src = oMapApplet.oExeParam.aBtnImg[iBtnIdx].oImgOut.src;
            }
        }
    }

        this.clickBtn = function(sBtnId) {
        var x = 0;
        if (oMapApplet.btnReady()) {
                        var oForm = document.getElementById('queryForm');
            var iBtnIdx = (/(\d+)$/.exec(sBtnId))[1];
            var bUpdBtnBar = true;
            if (sBtnId == 'btn0') {
                                oDrag.disable();
                oBox.setCursor('crosshair');
                oForm.cb.value = sBtnId;
                oBox.enableDraw();
                oForm.zd.value = 1;
                oMapApplet._bSetDocWait = true;
                            } else if (sBtnId == 'btn1') {
                                oDrag.disable();
                oBox.setCursor('crosshair');
                oForm.cb.value = sBtnId;
                oBox.disableDraw();
                oForm.zd.value = -1;
                oMapApplet._bSetDocWait = true;
                            } else if (sBtnId == 'btn2') {
                                oDrag.enable('mapMainImg',
                            function(iDragDistX, iDragDistY) {
                                oMapApplet._updateDrag(iDragDistX, iDragDistY);
                            });
                oBox.setCursor('move');
                oForm.cb.value = sBtnId;
                                oForm.zd.value = 100;
                oMapApplet._bSetDocWait = true;

                            } else if (sBtnId == 'btn3') {
                                oMapApplet._showCenterInput();
            } else if (sBtnId == 'btn4') {
                                oMapApplet._resetPageNbr();
                oForm.zd.value = -999;
                if ((oForm.cb.value ==
                     'btn1')
                    ||
                    (oForm.cb.value ==
                     'btn2')) {
                                        oForm.cb.value =
                                      'btn0';
                } else if (oForm.cb.value ==
                                      'btn5') {
                                        oForm.cb.value =
                        'btn0';
                    if (                        (/([^\/]+\.php)/.exec(oForm.action))[1] ==
                        'showIdentified.php') {
                        oForm.action =
                            oForm
                            .action
                            .replace(/([^\/]+)\.php/,
                                     'showQuery.php');
                    }
                    oForm.ie.value = '';
                }
                oMapApplet._bSetDocWait = true;
                oMapApplet.submitForm();
                            } else if (sBtnId == 'btn5') {
                                oDrag.disable();
                oBox.setCursor('crosshair');
                oForm.cb.value = sBtnId;
                oBox.enableDraw();
                oMapApplet._bSetDocWait = true;
                oForm.zd.value = 0;
                                oForm.action =
                    oForm.action.replace(/([^\/]+)\.php/,
                                         'showIdentified.php');
                            } else if (sBtnId == 'btn6') {
                                bUpdBtnBar = false;
                var sMapSrc = document
                              .getElementById('mapMainImg')
                              .src;
                                var aMatch =
                    /{$oUrl->getFieldName(Url::S_MAIN_NAME)}\=([^\=\.]+\.gif)/
                    .exec(sMapSrc);

                if (!aMatch) {
                                        var oRe = new RegExp('([^\=\.\/]+\.gif)');
                    aMatch = oRe.exec(sMapSrc);
                }
                if (aMatch) {
                    var sMapFileLoc = aMatch[1];
                    document.location.href=
                        'saveMap.php' +
                        '?' + 'imgLoc=' +
                               sMapFileLoc;
                } else {
                    alert('Error(MapApplet): Cannot extract map file name.');
                }
            }
            if ((sBtnId !=
                 'btn5')
                &&
                (sBtnId !=
                 'btn6')) {
                                if ((/([^\/]+\.php)/.exec(oForm.action))[1] ==
                    'showIdentified.php') {
                                        oForm.action =
                        oForm
                        .action
                        .replace(/([^\/]+)\.php/,
                                                                  'showQueriedShowing.php');
                }
                                oForm.ie.value = '';

            }

            if (bUpdBtnBar) {
                                oMapApplet._updAllBtnImgs(sBtnId);
            }
        }
        return false;
    }

        this._resetPageNbr = function() {
        var oObj = document
                   .getElementById('qsp');
        if (oObj) {
            oObj.value = '';
        }

        var oObj =
            document
            .getElementById('isp');
        if (oObj) {
            oObj.value = '';
        }
    }

        this._updAllBtnImgs = function(sActiveBtnId) {
        var iBtnIdx = (/(\d+)/.exec(sActiveBtnId))[1];
        for (iId in oMapApplet.oExeParam.aBtnImg) {
            var oBtnImg = document.images['btnImg' + iId];
            if (oBtnImg) {
                oBtnImg.src = ((iId == iBtnIdx)
                               ? oMapApplet.oExeParam.aBtnImg[iId].oImgOver.src
                               : oMapApplet.oExeParam.aBtnImg[iId].oImgOut.src);
            }
        }
    }

        this._initBox = function(sMapAnchorId, sMapImgId) {
        var oParam = {
            sWaitImgId: 'mapWaitImg',
            sWaitImgLoc: 'map/images/statsCan/loadMap.gif',
                        aMap: [{sAnchorId: sMapAnchorId,
                    sImgId: sMapImgId}],

                        sLeftBorder: 'leftBorder',
            sRightBorder: 'rightBorder',
            sTopBorder: 'topBorder',
            sBottomBorder: 'bottomBorder',

                        sLineTransparentImg: 'map/images/transparent_pixel.gif',

                        sLineColor: '#FF0000',
            iLineThickness: 2,
            iCrossHairSize: 10,
            bTrace: false,

                        fnOnClick: function(oInfo) {
                oMapApplet._boxOnClick(oInfo);
            },
            fnOnDrawEnd: function(oInfo) {
                oMapApplet._boxOnDrawEnd(oInfo);
            }
        };
                oBox.init(oParam);
    }

        this._boxOnClick = function(oInfo) {
        var oForm = document.getElementById('queryForm');
        var oAnchor = document.getElementById('mapAnchor');
        if ((/([^\/]+\.php)/.exec(oForm.action))[1] ==
            'showIdentified.php') {
                        oForm.ie.value =
                (oInfo.oCursor.iX - oAnchor.offsetLeft - 5) +
                ',' +
                (oInfo.oCursor.iY - oAnchor.offsetTop - 5) +
                ',' +
                (oInfo.oCursor.iX - oAnchor.offsetLeft + 5) +
                ',' +
                (oInfo.oCursor.iY - oAnchor.offsetTop + 5);
            oMapApplet.submitForm();
        } else {
                        oMapApplet._resetPageNbr();
            oForm.cp.value =
                (oInfo.oCursor.iX - oAnchor.offsetLeft) +
                ',' +
                (oInfo.oCursor.iY - oAnchor.offsetTop);
            oMapApplet.submitForm();
        }
        return true;
    }

        this._boxOnDrawEnd = function(oInfo) {
                oMapApplet._resetPageNbr();
        var oForm = document.getElementById('queryForm');
        if (oForm.cb.value ==
            'btn0') {
                        oForm.ze.value =
                Math.min(oInfo.oBound.iStartX, oInfo.oBound.iEndX) +
                ',' +
                Math.min(oInfo.oBound.iStartY, oInfo.oBound.iEndY) +
                ',' +
                Math.max(oInfo.oBound.iStartX, oInfo.oBound.iEndX) +
                ',' +
                Math.max(oInfo.oBound.iStartY, oInfo.oBound.iEndY);
        } else {
                        oForm.ie.value =
                Math.min(oInfo.oBound.iStartX, oInfo.oBound.iEndX) +
                ',' +
                Math.min(oInfo.oBound.iStartY, oInfo.oBound.iEndY) +
                ',' +
                Math.max(oInfo.oBound.iStartX, oInfo.oBound.iEndX) +
                ',' +
                Math.max(oInfo.oBound.iStartY, oInfo.oBound.iEndY);
        }
        oMapApplet.submitForm();
        return true;
    }

        this.init = function() {

              oUtil.setDocWaitCursor();
       oMapApplet._saveEnvDim(false);
       if (oMapApplet.oExeParam.bHasMainImgDim) {
           oMapApplet._enableMainMapCanvas();
           oMapApplet._doneLoadMaps();
       } else {
                      oMapApplet._setMainImgDim();
           oMapApplet._loadMaps();
       }
    }

    this._pxBarReleaseCallback = function(iPxBarWidth) {
        oMapApplet._updateMapScale(iPxBarWidth);
        oMapApplet.submitForm();
    }

    this._updateMapScale = function(iPxBarWidth) {
        var aMapScaleParam = oMapApplet.oExeParam.aMapScaleParam;
        var iMapWidth =
                        document.getElementById('mapMainImg').width;
        var iScale = Math.floor(aMapScaleParam.iMapExt /
                                (iMapWidth / (iPxBarWidth * aMapScaleParam.fInchesPerUnit)));
        document
        .getElementById('iDotsPerInch')
        .value = iPxBarWidth;

        var sCommaScale = iScale.toString()
                          .split('').reverse().join('')
                          .replace(/(\d\d\d)(?=\d)(?!\d*\.)/g, "$1,")
                          .split('').reverse().join('');
        document.getElementById('scaleVal').firstChild.nodeValue = sCommaScale;
    }

    this.updateCenterAtHelp = function(sHelpId, oSel) {
        document.getElementById(sHelpId).firstChild.nodeValue =
            ((oSel.options[oSel.selectedIndex].value == 'latLong')
             ? oMapApplet.oExeParam.aXlate['Example: 62.11,-93.4']
             : oMapApplet.oExeParam.aXlate['Example: 56p9']);
    }

        this._handleResize = function(oDomBrowserEvt) {
        if (!oMapApplet._bWaitingForResizeResponse) {
                        oMapApplet._bWaitingForResizeResponse = true;
            oUtil.setDocWaitCursor();

            document
            .getElementById('wr')
            .value='1';

            oMapApplet._setMainImgDim();
            oMapApplet.submitForm();
        }
    }

        this.submitLink = function(sPhpName, oIdToSet) {
        if (oMapApplet.btnReady()) {
            var oForm = document.getElementById('queryForm');
            if (/\S+/.test(sPhpName)) {
                oForm.action = oForm.action.replace(/([^\/]+\.php)/, sPhpName);
            }
            if (arguments.length == 2) {
                for (var sId in oIdToSet) {
                    var oEle = document.getElementById(sId);
                    if (oEle == null) {
                        alert('Error(MapApplet): Form has no element with the id: ' + sId);
                    } else {
                        oEle.value = oIdToSet[sId];
                    }
                }
            }
            oMapApplet.submitForm();
        }
    }

        this.onSubmit = function() {
        if (oMapApplet.btnReady()) {
            oMapApplet.disableBtn();
            oMapApplet._updateOffScale();
            oMapApplet._updateGroupExpandStatus();
            oMapApplet._saveEnvDim(false);
            if (oMapApplet._bSetDocWait) {
                oUtil.setDocWaitCursor();
            }
        }
    }

        this.submitForm = function() {
        oQuery.submitForm();
    }
        this._getWinDim = function() {
        var oBody = document.getElementById('pageBody');

        var sBodyTopMargin =
            (oBody.currentStyle
             ?                oBody.currentStyle['marginTop']
             : (window.getComputedStyle
                ?                   document.defaultView.getComputedStyle(oBody, null)
                  .getPropertyValue('margin-top')
                : '0'));

        var iBodyTopMargin = (/(\d+)/.exec(sBodyTopMargin))[1];

        var sBodyBotMargin =
            (oBody.currentStyle
             ? oBody.currentStyle['marginBottom']
             : (window.getComputedStyle
                ? document.defaultView.getComputedStyle(oBody, null)
                  .getPropertyValue('margin-bottom')
                : '0'));

        var iBodyBotMargin = (/(\d+)/.exec(sBodyBotMargin))[1];

        return {'iWinWidth': ((window.innerWidth)
                              ? window.innerWidth
                              : ((document.compatMode == 'CSS1Compat')
                                 ? document.documentElement.clientWidth
                                 : document.body.clientWidth)),
               'iWinHeight': ((window.innerHeight)
                              ? window.innerHeight
                              : ((document.compatMode == 'CSS1Compat')
                                 ? document.documentElement.clientHeight
                                 : document.body.clientHeight)) -
                             iBodyTopMargin -
                             iBodyBotMargin};
    }

        this._saveEnvDim = function(bIsResize) {
        var oForm = document.getElementById('queryForm');
        oWinDim = oMapApplet._getWinDim();
        oForm.ww.value = oWinDim.iWinWidth;
        oForm.wh.value = oWinDim.iWinHeight;
        if (!bIsResize) {
                        var oGroupList =
                document.getElementById('groupList');

            var sMenuWidth = (oGroupList
                              ? oGroupList.style.width
                              : '');
            if (sMenuWidth != '') {
                oForm
                .lmw                .value = /\d+/.exec(sMenuWidth);
            }

            var sMenuHeight = (oGroupList
                               ? oGroupList.style.height
                               : '');
            if (sMenuHeight != '') {
                oForm
                .lmh                .value = /\d+/.exec(sMenuHeight);
            }
        }
        oForm.qh.value =
            document.getElementById('queryTab').offsetHeight;

        oForm.bh.value =
            document.getElementById(oMapApplet.oExeParam.sBannerId).offsetHeight;
    }

        this._setMainImgDim = function() {
        var oForm = document.getElementById('queryForm');

        var iMapHeight =
            parseInt(oForm.wh.value) -
            parseInt(oForm.bh.value) -
            parseInt(oForm.qh.value) -
            oMapApplet.oExeParam.iScaleBarImgHeight -
            0 * 2 -
            12 * 2;
        if (iMapHeight < 300) {
            iMapHeight = 300;
        }
        var oMapImg = document.getElementById('mapMainImg');
        var iMapWidth = Math.floor(iMapHeight * 1.6);
        if (iMapWidth > 800) {
            iMapWidth = 800;
            iMapHeight = iMapWidth / 1.6;
        }
        oMapImg.height = iMapHeight;
        oMapImg.width = iMapWidth;
        oForm.mh.value = iMapHeight;
        oForm.mw.value = iMapWidth;
    }

        this._loadMaps = function() {
        var oRefImg = document.getElementById('refImg');
        oRefImg.src = 'map/images/transparent_pixel.gif';

        oMapApplet._enableMainMapCanvas();
        var oMapImg = document.getElementById('mapMainImg');
        var sUrl = 'makeMainImg.php' +

                      oMapApplet.oExeParam.sQueryStr +

                      'mw=' +
                          oMapImg.width +

                      '&mh=' +
                          oMapImg.height +

                      '&mn=' +
                          oMapApplet.oExeParam.sMapMainImgName +

                      '&rn=' +
                          oMapApplet.oExeParam.sMapRefImgName +

                      '&sbn=' +
                          oMapApplet.oExeParam.sScaleBarImgName +

                      '&random=' + Math.random();
        oMapImg.src = sUrl;
                oMapImg.onload = function(){
            oMapApplet._loadRefScale();
        };
    }

        this._enableMainMapCanvas = function() {
                var oMapImg = document.getElementById('mapMainImg');
        var oMapAnchor = document.getElementById('mapAnchor');
        oMapAnchor.style.width = oMapImg.width + 'px';
        oMapAnchor.style.height = oMapImg.height + 'px';
                var iMapAnchorPageLeft = oMapAnchor.offsetLeft;
        var iMapAnchorPageTop = oMapAnchor.offsetTop;
        var oParent = oMapAnchor.offsetParent;
        while (oParent) {
            iMapAnchorPageLeft += oParent.offsetLeft;
            iMapAnchorPageTop += oParent.offsetTop;
            oParent = oParent.offsetParent;
        }
        var oWaitImg = document.getElementById('mapWaitImg');
        oWaitImg.style.left =
            (iMapAnchorPageLeft + oMapImg.width/2 - oWaitImg.width/2) + 'px';
        oWaitImg.style.top =
            (iMapAnchorPageTop + oMapImg.height/2 - oWaitImg.height/2) + 'px';
                document.getElementById('mapMainImgCanvas')
        .style.visibility = 'visible';
    }

        this._refreshMainMap = function() {
        oUtil.setDocWaitCursor();
        var oMapImg = document.getElementById('mapMainImg');
        var sUrl =
            'makeMainImg.php' +
            oMapApplet.oExeParam.sQueryStr
            .replace(/(&pd=)[^=&]+/, '$1')
                        .replace(/(&cp=)[^=&]+/, '$1')
            .replace(/(&zd=)[^=&]+/, '$1')
            .replace(/(&ze=)[^=&]+/, '$1') +
            'mw=' + oMapImg.width +
            '&mh=' + oMapImg.height +
            '&rn=' + oMapApplet.oExeParam.sMapRefImgName +
            '&sbn=' + oMapApplet.oExeParam.sScaleBarImgName +
            '&ext=976393.652084%2C-452654.414112%2C2087472.83641%2C234995.203017' +
            '&random=' + Math.random();
        oMapImg.src = sUrl;
        oMapImg.onload = oUtil.restoreCursor;
        return false;
    }

        this._loadRefScale = function() {
        oMapApplet._initPanBar();
        var oRefImg = document.getElementById('refImg');
                oRefImg.onload = function(){
            oMapApplet._doneLoadMaps();
        };
        oRefImg.src = oMapApplet.oExeParam.sMapRefImgUrl + '?random=' + Math.random();
                oRefImg.border = 1;

        var oScaleBarImg =
            document.getElementById('scaleBar');

        oScaleBarImg.src = oMapApplet.oExeParam.sScaleBarImgUrl + '?random=' + Math.random();
    }

        this._doneLoadMaps = function() {
        oMapApplet.enableBtn();
        oMapApplet._setLayerMenuDim();
        oMapApplet._initBox('mapAnchor', 'mapMainImg');
        oUtil.restoreCursor();
        if (/\S+/.test(oMapApplet.oExeParam.sCurBtnId)) {
                        oMapApplet.clickBtn(oMapApplet.oExeParam.sCurBtnId);
        } else {
                        oMapApplet.clickBtn('btn0');
        }
        if (oMapApplet.oExeParam.bSetMainMapOnWinResize) {
                        if (window.captureEvents) {
                 window.captureEvents(Event.RESIZE);
            }
            window.onresize = function() {
                oMapApplet._handleResize();
            }
        }
        var oMapImg = document.getElementById('mapMainImg');
        oPxBar.init('pxBar', 'len', Math.floor(parseInt(oMapImg.width)/2),
                    function(iVal){
                        oMapApplet._pxBarReleaseCallback(iVal);
                    });
        oPxBar.enable();

                oMapApplet._updateMapScale(oPxBar.getPxBarWidthVal());
        oQuery.enableSubmit();
                oUtil.updStat();
    }

        this._initPanBar = function() {
        var oMapImg = document.getElementById('mapMainImg');
        var iMainImgHeight = oMapImg.height;
        var iMainImgWidth = oMapImg.width;
        var iVerPanBarVariableImgHeight =
            (iMainImgHeight - 68)/4;
        var iPanBarCornerImgWidth =
            11 +
            1;
        var iPanBarCornerImgHeight =
             11 +
             1;
        var iPanBarCornerHorFillerWidth =
            iVerPanBarVariableImgHeight -
            22;
        var iHorPanBarOffCenterWidth =
            (iMainImgWidth - 68 -
             (22 * 2) -
             (iPanBarCornerHorFillerWidth * 2)) / 2;

        document.getElementById('nwwCornerImg').height = iVerPanBarVariableImgHeight;
        document.getElementById('neeCornerImg').height = iVerPanBarVariableImgHeight;
        document.getElementById('wnCenterImg').height = iVerPanBarVariableImgHeight;
        document.getElementById('enCenterImg').height = iVerPanBarVariableImgHeight;
        document.getElementById('wsCenterImg').height = iVerPanBarVariableImgHeight;
        document.getElementById('esCenterImg').height = iVerPanBarVariableImgHeight;
        document.getElementById('swwCornerImg').height = iVerPanBarVariableImgHeight;
        document.getElementById('seeCornerImg').height = iVerPanBarVariableImgHeight;

        document.getElementById('nwCorner').width = iPanBarCornerImgWidth;
        document.getElementById('nwCornerImg').width = iPanBarCornerImgWidth;
        document.getElementById('neCorner').width = iPanBarCornerImgWidth;
        document.getElementById('neCornerImg').width = iPanBarCornerImgWidth;
        document.getElementById('swCornerImg').width = iPanBarCornerImgWidth;
        document.getElementById('seCornerImg').width = iPanBarCornerImgWidth;

        document.getElementById('nwCornerImg').height = iPanBarCornerImgHeight;
        document.getElementById('neCornerImg').height = iPanBarCornerImgHeight;
        document.getElementById('swCornerImg').height = iPanBarCornerImgHeight;
        document.getElementById('seCornerImg').height = iPanBarCornerImgHeight;

        document.getElementById('nwnCorner').width = iPanBarCornerHorFillerWidth;
        document.getElementById('nwnCornerImg').width = iPanBarCornerHorFillerWidth;
        document.getElementById('nenCorner').width = iPanBarCornerHorFillerWidth;
        document.getElementById('nenCornerImg').width = iPanBarCornerHorFillerWidth;
        document.getElementById('swsCornerImg').width = iPanBarCornerHorFillerWidth;
        document.getElementById('sesCornerImg').width = iPanBarCornerHorFillerWidth;

        document.getElementById('nwCenter').width = iHorPanBarOffCenterWidth;
        document.getElementById('nwCenterImg').width = iHorPanBarOffCenterWidth;
        document.getElementById('neCenter').width = iHorPanBarOffCenterWidth;
        document.getElementById('neCenterImg').width = iHorPanBarOffCenterWidth;
        document.getElementById('swCenterImg').width = iHorPanBarOffCenterWidth;
        document.getElementById('seCenterImg').width = iHorPanBarOffCenterWidth;
    }

        this.setPanBar = function(sColor, aColorId, sImgName, aImgId) {
        if (oMapApplet.btnReady()) {
            for (var i=0; i<aColorId.length; i++) {
                document.getElementById(aColorId[i]).bgColor = sColor;
            }
            for (var i=0; i<aImgId.length; i++) {
                try {
                    document.getElementById(aImgId[i]).src =
                        oMapApplet.oExeParam.aPanBarImg[sImgName].src;
                } catch(e) {
                    alert(e.description + ': ' + aImgId[i]);
                }
            }
        }
    }

        this.pan = function(sDir) {
        if (oMapApplet.btnReady()) {
            oMapApplet._resetPageNbr();
                        oMapApplet.clickBtn('btn2');
            oUtil.setDocWaitCursor();

            document
            .getElementById('pd')
            .value = sDir;

            oMapApplet.submitForm();
        }
        return false;
    }

        this._updateDrag = function(iDragDistX, iDragDistY) {
        oMapApplet._resetPageNbr();
        var oForm = document.getElementById('queryForm');

        oForm
        .dd        .value = iDragDistX + ',' + iDragDistY;

        oMapApplet.submitForm();
        return true;
    }

        this._updateOffScale = function() {
        var aOff = new Array();
        for (var i=0; i<oMapApplet.oExeParam.aSelOffScale.length; i++) {
            var oCheckBox = document.getElementById(oMapApplet.oExeParam.aSelOffScale[i]);
            if (oCheckBox &&
                !oCheckBox.checked) {
                aOff[aOff.length] = oMapApplet.oExeParam.aSelOffScale[i];
            }
        }

        var aOn = new Array();
        for (var i=0; i<oMapApplet.oExeParam.aDeSelOffScale.length; i++) {
            var oCheckBox = document.getElementById(oMapApplet.oExeParam.aDeSelOffScale[i]);
            if (oCheckBox &&
                oCheckBox.checked) {
                aOn[aOn.length] = oMapApplet.oExeParam.aDeSelOffScale[i];
            }
        }
        var oForm = document.getElementById('queryForm');
        oForm.lOff.value = aOff.join(',');
        oForm.lOn.value = aOn.join(',');
    }

        this._updateGroupExpandStatus = function() {
        var iGroupIdx = 0;
        var aExp = new Array();
        while (oGroup =
               document.getElementById('g' +
                                       iGroupIdx)) {
            if (oMapApplet._groupIsExp(oGroup)) {
                aExp[aExp.length] = iGroupIdx
            }
            iGroupIdx++;
        }

                if ((oGroup = document.getElementById('g' + 99))
            &&
            oMapApplet._groupIsExp(oGroup)) {
            aExp[aExp.length] = 99;
        }
        document
        .getElementById('lEm')
        .value = aExp.join(',');
    }

        this._groupIsExp = function(oGroup) {
        var oTr = oGroup;
        while (oTr.tagName != 'TR') {
            oTr = oTr.parentNode;
        }
        var oTbl = oTr;
        while (oTbl.tagName != 'TABLE') {
            oTbl = oTbl.parentNode;
        }
        return ((oTbl.rows[(oTr.rowIndex + 1)].cells[0].style.display != 'none'));
    }

        this._setLayerMenuDim = function() {
        var oGroupList = document.getElementById('groupList');
        if (oGroupList) {
            
            var iOffsetTop = oGroupList.offsetTop;
            if (oGroupList.offsetParent.id == 'layerMenu') {
                
                iOffsetTop += oGroupList.offsetParent.offsetTop;
            }
            var oLayerMenu =
                document.getElementById('layerMenu');

            var oMapMainImg =
                document.getElementById('mapMainImg');

            var iLayerMenuHeight =
                document
                .getElementById('lmh')
                .value;

            if (iLayerMenuHeight == '') {
                
                var iMenuHeight = oMapMainImg.height - iOffsetTop +
                                  12 * 2;

                var iMinHeight =
                    document.getElementById('refImg').height;

                if (iMenuHeight < iMinHeight) {
                    iMenuHeight = iMinHeight;
                }
                                oGroupList.style.height = iMenuHeight + 'px';
            }

            var iLayerMenuWidth =
                document
                .getElementById('lmw')
                .value;

            if (iLayerMenuWidth == '') {
                                iLayerMenuWidth =
                    document
                    .getElementById('layerMenuTd')
                    .offsetWidth -
                                        40;

                var iMinWidth = document
                                .getElementById('refImg')
                                .width;

                if (iLayerMenuWidth < iMinWidth) {
                    iLayerMenuWidth = iMinWidth;
                }
                                oGroupList.style.width = iLayerMenuWidth + 'px';
            }
        }
    }

        this.setRowBackground = function(oCurTag, sColor) {
                var oTr = oCurTag;
        while (oTr.tagName != 'TR') {
            oTr = oTr.parentNode;
        }

                var oTbl = oTr;
        while (oTbl.tagName != 'TABLE') {
            oTbl = oTbl.parentNode;
        }

                var aCurRowCell = oTbl.rows[oTr.rowIndex].cells;
        for (var i=0; i<aCurRowCell.length; i++) {
            var oCell = aCurRowCell[i];
            if (oCell.className != 'noBackgroundChange') {
                oCell.style.backgroundColor = sColor;
            }
        }
        return false;
    }

        this.toggleNextRowDisplay = function(oCurTag) {
                var oTr = oCurTag;
        while (oTr.tagName != 'TR') {
            oTr = oTr.parentNode;
        }

                var oTbl = oTr;
        while (oTbl.tagName != 'TABLE') {
            oTbl = oTbl.parentNode;
        }

                var aNextRowCell = oTbl.rows[(oTr.rowIndex + 1)].cells;
        var bCurIsHide = true;
        for (var i=0; i<aNextRowCell.length; i++) {
            var oCell = aNextRowCell[i];
            bCurIsHide = !(oCell.style.display == 'none');
            oCell.style.display = ((oCell.style.display == 'none')
                                   ?                                      ((document.all && !window.opera)
                                      ?                                         'block'
                                      :                                         'table-cell')
                                   :                                      'none');
        }
        oCurTag.src = (bCurIsHide
                       ? oMapApplet.oExeParam.oExpand.src
                       : oMapApplet.oExeParam.oCollapse.src);
        return false;
    }

        this._showObj = function(oObj) {
        var aName = [];
        for (var sName in oObj) {
            aName.push(sName);
        }
        alert(aName.join(', '));
    }

    this._showComputedFont = function(oObj) {
        var aAttr = (oObj.currentStyle
                     ? ['fontWeight', 'fontSize', 'fontSizeAdjust', 'fontStyle',
                        'fontVariant']
                     : ['font-weight', 'font-size', 'font-size-adjust', 'font-style',
                        'font-variant']);
        var aDsp = [];
        for (var i=0; i<aAttr.length; i++) {
            aDsp.push(aAttr[i] + ': ' +
                      (oObj.currentStyle
                       ?                          oObj.currentStyle[aAttr[i]]
                       : (window.getComputedStyle
                          ?                             document.defaultView.getComputedStyle(oObj, null)
                            .getPropertyValue(aAttr[i])
                          : '0')));
        }
        alert(aDsp.join(', '));
    }
}

new MapApplet();
