function GetBrowserHeight() 
{
    var ret = 0;
   
    if (typeof window.innerHeight  == 'number') 
       ret = window.innerHeight;
    else if(document.documentElement && document.documentElement.clientHeight)
        ret = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight) 
        ret = document.body.clientHeight;

    return ret;
}  

function GetBrowserWidth() 
{
    var ret = 0;
   
    if (typeof window.innerWidth  == 'number') 
       ret = window.innerWidth;
    else if(document.documentElement && document.documentElement.clientWidth)
        ret = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
        ret = document.body.clientWidth;

    return ret;
}  

var dialogName = "";

function SetOverlayPositionTest() {
    if (dialogName == "")
        return;
    var dialog = document.getElementById(dialogName);
	if ((dialog != null) && (dialog.style.display != "none"))
		SetOverlayPosition();
	dialog = null;
}

function SetOverlayPosition() 
{
    var shadow = document.getElementById("shadowOverlay");
    var dialog = document.getElementById(dialogName);

	var nWidth = GetBrowserWidth();
	var nHeight = GetBrowserHeight();
    shadow.style.width = nWidth + "px";
    shadow.style.height = nHeight + "px";
    dialog.style.left = parseInt((nWidth - dialog.offsetWidth) / 2) + "px";
    dialog.style.top = parseInt((nHeight - dialog.offsetHeight) / 2) + "px";

    shadow = null;
    dialog = null;
}

function ShowDialog(name) 
{
	if (name == "")
		return;
	if (dialogName == name)
		return;
	CloseDialog();
	dialogName = name;
    var shadow = document.getElementById("shadowOverlay");
    var dialog = document.getElementById(dialogName);

    shadow.style.display = "block"; 
    dialog.style.display = "block";

    SetOverlayPosition();

    shadow = null;
    dialog = null;             
}

function CloseDialog() 
{
	if (dialogName == "")
		return;
    var shadow = document.getElementById("shadowOverlay");
    var dialog = document.getElementById(dialogName);

    dialog.style.display = "none";
    shadow.style.display = "none";

    dialogName = "";
    shadow = null;
    dialog = null;
}

window.onresize = SetOverlayPositionTest;

