﻿// JScript File

var mapResizeTimer = null;
var mapNavWidthPadding = 6;
var mapNavHeightPadding = 0;
var mapNavWidthMin = 400;
var mapNavHeightMin = 550;
var curFooterHeight = 0;
var curHeaderHeight = 0;

// resize other page controls when map area resizes
function ResizePageControls(newW, newH)
{
    // sets the Locator Div right position
    var LocDiv = document.getElementById('locatorDiv');
    LocDiv.style.right = 0;
    LocDiv.style.bottom = curFooterHeight;
    
    // sets the Toc Div Height
    var TOCdiv = document.getElementById('contentPanel');
    TOCdiv.style.height = newH - 5;
}


// returns MapNavigator width based on current screen size
function GetMapNavWidth()
{
    var leftoffset = 0;
    var table = document.getElementById('bodyTable');
    if (table && table.rows && table.rows.length > 0 && table.rows[0].cells && table.rows[0].cells.length > 2)
    {
        var row = table.rows[0];
        var cell = row.cells[0];
        if (cell.style)
        {
            if (cell.style.display != 'none' && cell.style.width)
            {
                leftoffset += parseInt(cell.style.width);
            }
        }
        cell = row.cells[1];
        if (cell.style && cell.style.width)
        {
            leftoffset += parseInt(cell.style.width);
        }
    }   
    var newWidth = MDNGetClientWidth() - (mapNavWidthPadding + leftoffset);
    return newWidth > mapNavWidthMin ? newWidth : mapNavWidthMin;
}


// returns MapNavigator height based on current screen size
function GetMapNavHeight()
{
    var div = document.getElementById('headerDIV');
    if (div!=null && div.style!=null && div.style.height!= null)
    {
        curHeaderHeight = parseInt(div.style.height);
    }
    div = document.getElementById('footerDIV');
    if (div!=null && div.style!=null && div.style.height!= null)
    {
        curFooterHeight = parseInt(div.style.height);
    }
    var agt=navigator.userAgent.toLowerCase();
    var is_ie6    = (agt.indexOf("msie")!=-1 );

    if(is_ie6){
         mapNavHeightPadding = 0;
    }
    else{
         mapNavHeightPadding = 40;
    }
    var newHeight = MDNGetClientHeight() - (curHeaderHeight + curFooterHeight + mapNavHeightPadding);
    return newHeight > mapNavHeightMin ? newHeight : mapNavHeightMin;
}


// used in body onresize
var inContentCellToggle = false;


// toggle left content area
function ToggleContentCell()
{
    inContentCellToggle = true;
    var table = document.getElementById('bodyTable');
    var img = document.getElementById('imgContentToggle');
    var mapImg = GetMapNavImageArea();

    var offset = 0;
    
    // get offset
    var table = document.getElementById('bodyTable');
    if (mapImg && table && table.rows && table.rows.length > 0 && table.rows[0].cells && table.rows[0].cells.length > 0 && table.rows[0].cells[0].style && table.rows[0].cells[0].style.width)
    {
        offset = parseInt(table.rows[0].cells[0].style.width);
    }
    if (img && table && table.rows && table.rows.length > 0 && table.rows[0].cells && table.rows[0].cells.length > 2)
    {
        var cell = table.rows[0].cells[0];
        if (cell.style)
        {

            if (cell.style.display == 'none') 
            {
                cell.style.display = 'block';
                img.src = 'Images/collapse-left.gif';
                if (mapImg && offset)
                {
                    mapNavWidthPadding = 0;
                }
            }
            else
            {
                cell.style.display = 'none';
                img.src = 'Images/expand-right.gif'; 
                if (mapImg && offset)
                {
                    mapNavWidthPadding = 0;
                }           
            }
            BrowserResizeEvent();
        }
    }
    inContentCellToggle = false;
}


//toggles the Locator Map on and off
function ToggleLocator()
{
    var elem = document.getElementById('locatorDiv');
	if (elem)
	{
	    if (elem.style.visibility == 'hidden') 
	    {
	        elem.style.visibility = 'visible'; 
	    }
	    else 
	    {
	        elem.style.visibility = 'hidden';        
	    }
	}
}

//pre-handler for the toolset buttons
var identifyOn = false;
function ToolsetButtonClickPreHandler(mode)
{ 
    // if we did not select a command
    if (mode != "Zoom All" && mode != "Clear All" && mode != "Toggle Overview")
    {
        ClearIdentifyMode();
    }              
  
	return true;
}

//called at the beginning of the handling the map client state sent back from the server in an out-of-band callback
function MDNPreMapStateChangeComplete(state)
{
    // pop-up errors
    if (state.Error&&state.Error.length>0)
    {
        alert("Error has occurred in the application. Please contact the system administrator.");
    }
}


//called at the end of the handling the map client state sent back from the server in an out-of-band callback
function MDNPostMapStateChangeComplete(state)
{
}


