﻿// JScript File

var orgHeight;

function load()
{
    try
    {
        if (opener.document.mapForm == null)
            document.getElementById('div_Button4').style.visibility = 'hidden';
        opener.document.mapForm.waitReport.style.visibility = 'hidden';
    }
    catch (err)
    {}
    
    orgHeight = getHeight();
    window.onresize = redo;  
}

function getHeight()
{
    var myHeight = 0;
    if (typeof(window.innerHeight) == 'number') 
        myHeight = window.innerHeight;
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
        myHeight = document.documentElement.clientHeight;
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
        myHeight = document.body.clientHeight;
        
    return myHeight;
}

//Reload the window on a resize event
function redo() 
{   
    var newHeight = getHeight();
    if (orgHeight != newHeight)
    {        
        //Ignore popup warnings bar adjustments. 
        if ((newHeight < orgHeight) && (newHeight + 32 > orgHeight))
            return;
        orgHeight = newHeight;
        location.href = location.href;
    }
}

          
function loadMap()
{
    var reportID = document.getElementById('ReportID');       
    var locked = opener.document.mapForm.LockedForm;
    var url = opener.location.protocol + '//' + opener.location.host + opener.location.pathname;
    if (locked.value == "Y")
        opener.location.href = url + "?ReportID=" + reportID.value;
    else
        opener.location.href = url + "?ReportHandler=" + reportID.value;
    window.close();
}

function Adjust(x,y,deltaX,deltaY,z)
{
	var offset=268435456;
	var radius=offset/Math.PI;

	function LToX(x)
	{
		return Math.round(offset+radius*x*Math.PI/180);
	}

	function LToY(y)
	{
		return Math.round(offset-radius*Math.log((1+Math.sin(y*Math.PI/180))/(1-Math.sin(y*Math.PI/180)))/2);
	}

	function XToL(x)
	{
		return ((Math.round(x)-offset)/radius)*180/Math.PI;
	}

	function YToL(y)
	{
		return (Math.PI/2-2*Math.atan(Math.exp((Math.round(y)-offset)/radius)))*180/Math.PI;
	}

	return {x:XToL(LToX(x)+(deltaX<<(21-z))),y:YToL(LToY(y)+(deltaY<<(21-z)))};
}
