﻿// JScript File
//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

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
    var pageHeight, pageWidth;
    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 showPopUp(height, width, url)
{
    //debugger;
    
    var objPopUpOverlay = document.getElementById('popUpOverlayDIV');
    var objPopUp = document.getElementById('popUpDIV');
    var objPopUpIFrame = document.getElementById('popUpIFrame');
    var objPopUpToolbar = document.getElementById('popUpToolBarDIV');
    var objPopUpClose = document.getElementById('popUpCloseDIV');
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    // set height of Overlay to take up whole page and show
    objPopUpOverlay.style.height = (arrayPageSize[1] + 'px');
    objPopUpOverlay.style.display = 'block';
    
    //pause(1000);
    
    // Position IFrame...
    objPopUpIFrame.style.left = "3px";
    objPopUpIFrame.style.top = "23px";
    objPopUpIFrame.style.width = (width - 6) + "px";
    objPopUpIFrame.style.height = (height - 26) + "px";
    
    // Position Toolbar...
    objPopUpToolbar.style.left = "0px";
    //objPopUpToolbar.style.top = (height - 23) + "px";
    objPopUpToolbar.style.top = "0px";
    objPopUpToolbar.style.width = width + "px";
    objPopUpToolbar.style.height = "20px";

    // Position Close DIV...
    objPopUpClose.style.left = "0px";
    objPopUpClose.style.top = (height - 26) + "px";
    objPopUpClose.style.width = width + "px";
    objPopUpClose.style.height = "20px";
    
    // show popup
    var popUpTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2);
    var popUpLeft = ((arrayPageSize[0] - 20 - width) / 2);
	
    objPopUp.style.top = (popUpTop < 0) ? "0px" : popUpTop + "px";
    objPopUp.style.left = (popUpLeft < 0) ? "0px" : popUpLeft + "px";
    objPopUp.style.width = width + "px";
    objPopUp.style.height = height + "px";        
    
    objPopUp.style.display = 'block';
    objPopUpIFrame.src = url;
}

function closePopUp()
{
    var objPopUpOverlay = document.getElementById('popUpOverlayDIV');
    var objPopUp = document.getElementById('popUpDIV');

    objPopUpOverlay.style.display = 'none';
    objPopUp.style.display = 'none';
}