﻿// JScript File

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function ShowWindow(p_strPreId, p_intId)
{
HideWindows(p_strPreId);
document.getElementById(p_strPreId + p_intId).style.display = 'block';
}

function CloseWindow(p_strPreId)
{
    HideWindows(p_strPreId);
}

function HideWindows(p_strPreId)
{
    var l_objWindow = document.getElementById(p_strPreId+'0')
    var l_intCounter = 0;
    while(l_objWindow != null)
    {
        l_objWindow.style.display = 'none';
        l_intCounter++;
        l_objWindow = document.getElementById(p_strPreId + l_intCounter);
    }
}

function ShowPopup(p_objSource)
{

    var objOverlay = document.getElementById('Overlay');
	var objPopup = document.getElementById('Popup');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var rgx = new RegExp("\\D", "gi");
    var PopupTop = arrayPageScroll[1] + ((arrayPageSize[3] - 380) / 2);
    var PopupLeft = ((arrayPageSize[0] - 645) / 2);
    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';
    objPopup.innerHTML = document.getElementById(p_objSource).innerHTML;
    objPopup.style.top = PopupTop + 'px';
    objPopup.style.left = PopupLeft + 'px';
    DisplayPopup();
}

function DisplayPopup()
{
    document.getElementById('Popup').style.display = 'block';
}

function ClosePopup()
{
    var objOverlay = document.getElementById('Overlay');
    objOverlay.style.display = 'none';
	var objPopup = document.getElementById('Popup');
    
    objPopup.style.display = 'none'; 
    objPopup.innerHTML = '';
}

function iniPopup()
{
    if(document.getElementById('MapWindow_0') != null)
    {
        var objBody = document.getElementsByTagName("body").item(0);
	    // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	    var objOverlay = document.createElement("div");
	    objOverlay.setAttribute('id','Overlay');
	    //objOverlay.onclick = function () {hideLightbox(); return false;}
	    objOverlay.style.display = 'none';
	    objOverlay.style.position = 'absolute';
	    objOverlay.style.top = '0';
	    objOverlay.style.left = '0';
	    objOverlay.style.zIndex = '300';
 	    objOverlay.style.width = '100%';
	    objBody.insertBefore(objOverlay, objBody.firstChild);

        var objPopup = document.createElement("div");
	    objPopup.setAttribute('id','Popup');
	    objPopup.style.display = 'none';
	    objPopup.style.position = 'absolute';
	    objPopup.style.zIndex = '301';	
	    objBody.insertBefore(objPopup, objOverlay.nextSibling);
    }
}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

addLoadEvent(iniPopup);
