﻿// JScript File
//<![CDATA[
function showPick(url)
{
	var bodyElement = document.documentElement ? document.documentElement : document.body;
	//var bodyheight = window.innerHeight?window.innerHeight:bodyElement.clientHeight;
	var div = document.getElementById("divPic");
	div.style.display = 'block';
	div.style.top = bodyElement.scrollTop + (bodyElement.clientHeight - div.offsetHeight) / 2 + "px";
	div.style.left = (bodyElement.clientWidth - div.offsetWidth) / 2 + "px";

	document.getElementById("galIfr").src = url;
}
function PopUp(width, height, value, header, isURL, isClosable, isFetchedOut)
{
	if (typeof (isURL) == "undefined")
		isURL = true;
	if (typeof (isClosable) == "undefined")
		isClosable = true;
	if (typeof (width) == "undefined")
		width = 640;
	if (typeof (height) == "undefined")
		height = 480;
	if (typeof (isFetchedOut) == "undefined")
		isFetchedOut = true;
	if (typeof (value) == "undefined")
	{
		value = "<h1 style='font-size:36; color:red; font-weight:bold;'>Error</h1>"
		isURL = false;
		isClosable = false;
		isFetchedOut = true;
		width = 640;
		height = 480;
	}

	if (isFetchedOut)
	{
		document.documentElement.style.overflowX = "hidden";
		document.documentElement.style.overflowY = "hidden";
		document.documentElement.style.overflow = "hidden";
	}

	var divBack = document.getElementById("divBack");
	var divFront = document.getElementById("divFront");
	var ifrPopUp = document.getElementById("ifrPopUp");
	var btnClose = document.getElementById("btnClose");
	//var spnHeader = document.getElementById("spnPopUpHeader");

	var scrolltop;
	if (window.pageYOffset)
	{
		scrolltop = window.pageYOffset;
	}
	else
	{
		scrolltop = document.documentElement.scrollTop;
	}

	var bodyElement = document.documentElement;
	divBack.style.width = bodyElement.clientWidth + "px";
	divBack.style.height = (scrolltop + bodyElement.clientHeight) + "px";
	divBack.style.display = isFetchedOut ? "block" : "none";
	divFront.style.width = width + "px";
	divFront.style.height = (height + (isClosable ? 40 : 0)) + "px";
	divFront.style.left = (bodyElement.clientWidth - width) / 2 + "px";
	divFront.style.top = (scrolltop + (bodyElement.clientHeight - (height + (isClosable ? 40 : 0))) / 2) + "px";
	divFront.style.display = "block";
	ifrPopUp.width = width + "px";
	ifrPopUp.height = height + "px";

	if (isURL)
	{
		ifrPopUp.src = value;
	}
	else
	{
		var ifrPopUpBody = IframeBody();
		ifrPopUpBody.style.overflow = "hidden";
		ifrPopUpBody.style.marginTop = "0px";
		ifrPopUpBody.style.marginRight = "0px";
		ifrPopUpBody.style.marginBottom = "0px";
		ifrPopUpBody.style.marginLeft = "0px";

		var div = document.createElement("div");
		div.style.width = "100%";
		div.innerHTML = value;
		ifrPopUpBody.innerHTML = "";
		AppendChild(ifrPopUpBody, div);
	}

	if (!isClosable)
	{
		btnClose.style.display = "none";
	}

	//spnHeader.innerHTML = header;

	var oldOnResize = window.onresize;
	if (!oldOnResize)
	{
		window.onresize = function () { resize(width, height, isClosable); };
	}
	else
	{
		window.onresize = function ()
		{
			oldOnResize();
			resize(width, height, isClosable);
		}
	}
}

function AppendChild(Obj, Child)
{
	if (Child.outerHTML)
		Obj.innerHTML = Child.outerHTML;
	else
		Obj.appendChild(Child);
}

function IframeBody()
{
	var ifr = document.getElementById("ifrPopUp");
	var rv;
	if (document.getElementById("ifrPopUp").contentDocument)
	{
		rv = document.getElementById("ifrPopUp").contentDocument;
	}
	else
	{
		// IE 
		rv = document.frames["ifrPopUp"].document;
	}

	var bodies = rv.getElementsByTagName("body");
	var body = bodies[0];

	body.style.marginTop = 0;
	body.style.marginLeft = 0;
	body.style.marginBottom = 0;
	body.style.marginRight = 0;

	return body;
}

function resize(width, height, isClosable)
{
	document.documentElement.style.overflow = "hidden";
	var divBack = document.getElementById("divBack");
	var divFront = document.getElementById("divFront");

	var bodyElement = document.documentElement;
	divBack.style.width = bodyElement.clientWidth + "px";
	divBack.style.height = (bodyElement.scrollTop + bodyElement.clientHeight) + "px";
	divFront.style.left = (bodyElement.clientWidth - width) / 2 + "px";
	divFront.style.top = (bodyElement.scrollTop + (bodyElement.clientHeight - (height + (isClosable ? 22 : 0))) / 2) + "px";
}
//]]>

