﻿addLoadEvent(function()
{
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
});


if(typeof popupDivList == 'undefined')
{
	popupDivList = new Array();
	popupTextDivList = new Array();
	popupScreenDivList = new Array();
	popupClientScriptList = new Array();
}

function AjaxPopupInitialise(popupDivId, popupTextDivId, popupScreenDivId, popupClientScriptId)
{
	popupDivList.push(popupDivId);
	popupTextDivList.push(popupTextDivId);
	popupScreenDivList.push(popupScreenDivId);
	popupClientScriptList.push(popupClientScriptId);
}

function EndRequest()
{
	setTimeout('ShowPopup()', 100);
}

function OnKeyPress(e)
{
	var keyCode  = window.event ? event.keyCode : e.keyCode;
	var esc = window.event ? 27 : e.DOM_VK_ESCAPE;

	if(keyCode == esc)
	{
		for(var nCount = 0; nCount < popupDivList.length; nCount++)
		{
			getById(popupScreenDivList[nCount]).style.display = 'none';
			document.body.onkeypress = null;
		}
	}
}

function ShowPopupScreen(popupDivId, popupTextDivId, popupScreenDivId, updateButtonId, show)
{
	getById(popupDivId).style.visibility = 'hidden';
	getById(popupTextDivId).style.overflow = 'hidden';
	getById(popupScreenDivId).style.display = show ? 'block' : 'none';

	if(show)
	{
		document.body.onkeypress = OnKeyPress;

		if(getById(popupTextDivId).innerHTML == '')
		{
			getById(updateButtonId).click();
		}
		else
		{
			EndRequest();
		}
	}
	else
	{
		document.body.onkeypress = null;
	}

	return false;
}

function ShowPopup()
{
	for(var nCount = 0; nCount < popupDivList.length; nCount++)
	{
		if(getById(popupScreenDivList[nCount]).style.display == 'block')
		{
			getById(popupTextDivList[nCount]).style.overflow = 'auto';
			getById(popupDivList[nCount]).style.marginTop = '-' + (getById(popupDivList[nCount]).offsetHeight / 2) + 'px';
			getById(popupDivList[nCount]).style.visibility = 'visible';
			eval(popupClientScriptList[nCount]);
		}
	}
}
