﻿// Global vartiables
var g_strLoadingImage = '/Images/Loading.gif';
var g_strCloseButton = '/Images/ClosePopup.gif';
var g_strTopImg = '/Images/PopupWindowTop.png';
var g_strBottomImg = '/Images/PopupWindowBottom.png';
var g_intPageScroll = 0;
var g_intPageWidth = 0;
var g_intPageHeight = 0;
var g_intWindowWidth = 0;
var g_intWindowHeight = 0;
var g_intXScroll = 0;
var g_intYScroll = 0;
var g_intStanWidth = 740;
var g_intStanHeight = 520;

var m_strSelectedId = '';
var m_blnHover = false;

function ShowPopup(p_strPre,p_intId)
{
    HideAll(p_strPre);
    m_strSelectedId = p_strPre+p_intId;
    document.getElementById(p_strPre+p_intId).style.display = 'block';
    m_blnHover = true;
}

function PopupHover()
{
    m_blnHover = true;
}

function HidePopup(p_strPre,p_intId)
{
    m_blnHover = false;
    setTimeout("DelayedHide('"+p_strPre+"',"+p_intId+")", 100);
}

function DelayedHide(p_strPre,p_intId)
{
    if(!m_blnHover)
        document.getElementById(p_strPre+p_intId).style.display = 'none';
}

//Set g_intPageScroll Y page scroll value
function getPageScroll()
{
	if (self.pageYOffset) {
		g_intPageScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		// Explorer 6 Strict
		g_intPageScroll = document.documentElement.scrollTop;
	} else if (document.body) {
	    // all other Explorers
		g_intPageScroll = document.body.scrollTop;
	}
	return g_intPageScroll;
}

//Set page width, height and window width, height
function getPageSize()
{
	if (window.innerHeight && window.scrollMaxY) {	
		g_intXScroll = document.body.scrollWidth;
		g_intYScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
	    // all but Explorer Mac
		g_intXScroll = document.body.scrollWidth;
		g_intYScroll = document.body.scrollHeight;
	} else { 
	    // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		g_intXScroll = document.body.offsetWidth;
		g_intYScroll = document.body.offsetHeight;
	}
	
	var g_intWindowWidth, g_intWindowHeight;
	if (self.innerHeight) {
	    // all except Explorer
		g_intWindowWidth = self.innerWidth;
		g_intWindowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
	    // Explorer 6 Strict Mode
		g_intWindowWidth = document.documentElement.clientWidth;
		g_intWindowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
	    // other Explorers
		g_intWindowWidth = document.body.clientWidth;
		g_intWindowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(g_intYScroll < g_intWindowHeight)
		g_intPageHeight = g_intWindowHeight;
	else
		g_intPageHeight = g_intYScroll;

	// for small pages with total width less then width of the viewport
	if(g_intXScroll < g_intWindowWidth){	
		g_intPageWidth = g_intWindowWidth;
	} else {
		g_intPageWidth = g_intXScroll;
	}
	
	var l_aryPageSize = new Array(g_intPageWidth,g_intPageHeight,g_intWindowWidth,g_intWindowHeight) 
	return l_aryPageSize;
}

//Wait function, Bad function!!
function Wait(p_intMilliSec)
{
    var l_intCounterX = 0;
    var l_datDate = new Date();
    var l_datCurrentDate = new Date();
    while(l_datCurrentDate-l_datDate < p_intMilliSec)
    {
        l_datCurrentDate = new Date();
        l_intCounterX++;
    }
}

function SetLightBox()
{
    var l_objBody = document.getElementsByTagName("body").item(0);

    //Create Overlay
    var l_objOverlay = document.createElement("div");
    l_objOverlay.setAttribute('id','Overlay');
    l_objOverlay.style.display = 'none';
    l_objOverlay.style.position = 'absolute';
    l_objOverlay.style.top = '0';
    l_objOverlay.style.left = '0';
    l_objOverlay.style.zIndex = '605';
    l_objOverlay.style.width = '100%';
    l_objBody.insertBefore(l_objOverlay, l_objBody.firstChild);

    //Create LightBox
    var l_objLightBox = document.createElement("div");
	l_objLightBox.setAttribute('id','LightBox');
	l_objLightBox.style.display = 'none';
	l_objLightBox.style.position = 'absolute';
	l_objLightBox.style.zIndex = '610';	
	l_objBody.insertBefore(l_objLightBox, l_objOverlay.nextSibling);
	
	var l_imgPreloadTopImg = new Image();
    l_imgPreloadTopImg.onload = function()
    {
        var l_objTopImg = document.createElement("img");
        l_objTopImg.src = g_strTopImg;
        l_objTopImg.setAttribute('id','PopupWindowTopImg');
		l_objLightBox.appendChild(l_objTopImg);
		
		var l_objContent = document.createElement("div");
	    l_objContent.setAttribute('id','PopupWindowContent');
	    l_objContent.style.position = 'relative';
	    l_objLightBox.appendChild(l_objContent);
    	
        var l_imgPreloadCloseButton = new Image();
        //Create Close button
        l_imgPreloadCloseButton.onload = function()
        {
            var l_objCloseButton = document.createElement("img");
            l_objCloseButton.src = g_strCloseButton;
            l_objCloseButton.setAttribute('id','CloseButton');
		    l_objCloseButton.setAttribute('title', 'Sluiten')
		    l_objCloseButton.onclick = function () {HideLightBox();}
		    l_objLightBox.appendChild(l_objCloseButton);
		    
		    var l_imgPreloadBottomImg = new Image();
            l_imgPreloadBottomImg.onload = function()
            {
                var l_objBottomImg = document.createElement("img");
                l_objBottomImg.src = g_strBottomImg;
                l_objBottomImg.setAttribute('id','PopupWindowBottomImg');
		        l_objLightBox.appendChild(l_objBottomImg);
            } 
            l_imgPreloadBottomImg.src = g_strBottomImg;
        } 
        l_imgPreloadCloseButton.src = g_strCloseButton;
    } 
    l_imgPreloadTopImg.src = g_strTopImg;
    
    
    
    
}

function ShowLightBox(p_strSource)
{
    var l_objOverlay = document.getElementById('Overlay');
    var l_objLightBox = document.getElementById('LightBox');
    var l_objContent = document.getElementById('PopupWindowContent');
    var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var l_imgPreloadImage = new Image();
	l_objContent.innerHTML = document.getElementById(p_strSource).innerHTML;
	
	l_objLightBox.style.opacity = 0;
	l_objLightBox.style.filter = 'alpha(opacity=0)';
    l_objLightBox.style.display = 'block';
    
	if(document.getElementById){
        l_intHeight = l_objContent.offsetHeight;
    }
    else if (document.layers){
        l_intHeight = l_objContent.clip.height;
    }
    //setTimeout("DelayedAlert()", 1000);
	//alert(l_intHeight);
    var lightboxTop = arrayPageScroll + ((arrayPageSize[3] - l_intHeight) / 2) - 26;
	var lightboxLeft = ((arrayPageSize[0] - 612) / 2);
	l_objOverlay.style.height = (g_intPageHeight + 'px');
    l_objOverlay.style.display = 'block';
    //l_objLightBox.style.display = 'block';
	l_objLightBox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	l_objLightBox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
    l_objLightBox.style.opacity = 1;
	l_objLightBox.style.filter = 'alpha(opacity=100)';
	
    return false;
}

function HideLightBox()
{
	var l_objOverlay = document.getElementById('Overlay');
	var l_objLightbox = document.getElementById('LightBox');
	l_objOverlay.style.display = 'none';
	l_objLightbox.style.display = 'none';
}

function DelayedAlert()
{
    var l_intHeight = 0;
    if(document.getElementById){
        l_intHeight = document.getElementById('PopupWindowContent').offsetHeight;
    }
    else if (document.layers){
        l_intHeight = document.getElementById('PopupWindowContent').clip.height;
    }
alert(l_intHeight);
}