//***************************************************************************************
//***************************************************************************************
// This section contains the DHTML Popup funtions..
//
// These functions call a Javascrpt funtion that creates a DHTML popup on the page with 
// a IFrame in it. The background is grayed out and scrolling is disabled.
//***************************************************************************************
//***************************************************************************************

//_______________________________________________________________________________________
// This function gets the size of the windows content for different browsers.
function getWindowSize() 
{ 
	var WindowSize = [0, 0]; 

	if (typeof window.innerWidth != 'undefined') 
	{ 
		WindowSize = [
			window.innerWidth, 	
			window.innerHeight
		]; 
	} 
	else if (typeof document.documentElement != 'undefined' 
		&& typeof document.documentElement.clientWidth != 
		'undefined' && document.documentElement.clientWidth != 0) 
	{ 
		WindowSize = [
			document.documentElement.clientWidth, 
			document.documentElement.clientHeight
		]; 
	} 
	else 
	{ 
	WindowSize = [ 
		document.getElementsByTagName('body')[0].clientWidth, 
		document.getElementsByTagName('body')[0].clientHeight 
	]; 
	} 

	return WindowSize; 
}

function showGrayBackground()
{
    var windowSize		= getWindowSize();
    var bodyTag			= document.getElementsByTagName('body')[0];
	var	ammountScrolled = document.documentElement.scrollTop + "px";


	// create Gray Background Div
	var divBackground	= document.createElement("div");
		divBackground.id			= "popup_GrayBackground";
		divBackground.className		= "popup_GrayBackground";
		divBackground.style.height	= windowSize[1];
		divBackground.style.width	= windowSize[0];
		divBackground.style.top		= ammountScrolled;
		
	bodyTag.appendChild(divBackground);		
	
   	// Disable Scolling
	window.onscroll = new Function("window.scrollTo(" + document.documentElement.scrollLeft + ", " + document.documentElement.scrollTop + ")");
}

function hideGrayBackground()
{
    var bodyTag			= document.getElementsByTagName('body')[0];
    var divBackground	= document.getElementById("popup_GrayBackground");
    bodyTag.removeChild(divBackground);
    
	window.onscroll = new Function("");
}

//_______________________________________________________________________________________
// This function creates the popup. It does so by creating two div objects one for the 
// gray transparent background and the other for holding the IFrame. The second has a
// table so that the I-Frame is centered. The style's for the objects are mainly set
// in the PublicAdmin Style sheet.
function showPopup(width,height,url)
{
	var windowSize		= getWindowSize();
	var bodyTag			= document.getElementsByTagName('body')[0];
	var	ammountScrolled = document.documentElement.scrollTop + "px";
	
	showGrayBackground();
	
	// Create IFrame Container Div, Containing Table and IFrame.
	var divContainer	= document.createElement("div");
		divContainer.className			= "popup_Container";
		divContainer.id					= "popup_Container";
		divContainer.style.top		= ammountScrolled;
		var table	= document.createElement("table");
			table.className = "popup_Container_table";
		var tr		= document.createElement("tr");
			tr.className = "popup_Container_tr";
		var tbody   = document.createElement("tbody");
		
		var td		= document.createElement("td");
			td.className = "popup_Container_td";
			
			var iframe = document.createElement("iframe");
				iframe.id = "popup_Container_iframe";
				iframe.src = url;
				iframe.style.height = height;
				iframe.style.width = width;
				iframe.frameBorder = 0;
				iframe.className = "popup_Iframe";
				
			td.appendChild(iframe);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
			table.style.height = windowSize[1];
			table.style.width = windowSize[0];
		divContainer.appendChild(table);
		
	// Add the Divs to the body object
	bodyTag.appendChild(divContainer);
}

//_______________________________________________________________________________________
// This function removes the Divs that were added for the popup and allows scolling again
function hidePopup()
{
	var bodyTag			= document.getElementsByTagName('body')[0];
	var divContainer	= document.getElementById("popup_Container");

	bodyTag.removeChild(divContainer);
	
    hideGrayBackground();
}

//_______________________________________________________________________________________
// This function Reloads the page
function reloadPage()
{
	window.location = window.location;
}
