﻿var ie = document.all;
var nn6 = document.getElementById && !document.all;

function UIDialog(pID, pVisibleOnLoad, pFocusOnShow, pFocusOnHide )
{
	// create and set properties.
	this.ID = pID;
	this.Panel = document.getElementById(this.ID);
	this.FocusOnShow = pFocusOnShow;
	this.FocusOnHide = pFocusOnHide;
	this.Overlay = document.getElementById(this.ID + "Overlay");
	this.IsModal = this.Panel.getAttribute("modal") == "yes";

	// default style values.
	if (nn6)
	{
		this.Overlay.style.opacity = ".5";
	}
	else
	{
		this.Overlay.style.filter = "alpha(opacity=50)";
	}

	// show or hide on init.
	if (pVisibleOnLoad)
	{
		this.Show()
	}
	else
	{
		this.Hide();
	}
}

UIDialog.prototype.Show = function()
{
	if (this.IsModal)
	{
		this.Overlay.style.display = "block";
	}
	this.Panel.style.display = "block";
	DOMCenter(this.Panel);
	FocusTo(this.FocusOnShow);
}

UIDialog.prototype.Hide = function()
{
	this.Overlay.style.display = "none";
	this.Panel.style.display = "none";
	FocusTo(this.FocusOnHide);
}

function FocusTo(pID)
{
	if (pID != "")
	{
		var e = document.getElementById(pID);
		if (e != null) { e.focus(); }
	}
}

function DOMCenter(pElement)
{
	var x0 = Math.floor((document.body.offsetWidth) / 2);
	var x1 = Math.floor(pElement.offsetWidth / 2);
	var y0 = Math.floor((document.body.offsetHeight) / 2);
	var y1 = Math.floor(pElement.offsetHeight / 2);
	pElement.style.left = x0 - x1;
	pElement.style.top = y0 - y1 + document.body.scrollTop;
}

