/*
(c) 2008, Nikiforov Vladimir aka Volod
This file may be freely copied and used without any limitations.
*/

var windowID = 0;
var dialog = new DialogWindow();

function DialogWindow()
{
	this.dialogPlace = null;
}

dialog.createPlaceholder = function ()
{
	this.dialogPlace = document.createElement('div');
	with (this.dialogPlace.style)
	{
		display = 'none';
		position = 'absolute';
		background = '#CCC';
		border = '4px solid #AAA';
		padding = '5px';
		opacity = 0.95;
		filter = 'Alpha(Opacity=95)';
	}
	document.body.appendChild(this.dialogPlace);
}

dialog.cancel = function()
{
	document.windowID = 0;
	e = this.dialogPlace;
	e.style.display = 'none';
	//это окно нельзя медленно гасить, т.к. пришлось бы вставлять фактический код
	//закрытия ПОСЛЕ гашения, иначе если сделать два клика - будет каша
	return false;
}

dialog.show = function()
{
	//alert('show!');
	e = this.dialogPlace;
	e.style.visibility = 'hidden';//чтобы не прыгало по экрану, пока меняем style.left!
	e.style.display = 'block';//чтобы можно было определить ширину!
	a = getBounds(e);
	w = getClientCenterX() - a.width / 2; /**/
	h = getClientCenterY() - a.height / 2; /**/
	e.style.left = w + 'px';	
	e.style.top = h + 'px';
	e.style.visibility = 'visible';	
	return;
}

dialog.open = function (params)
{	
	if (this.dialogPlace == null)
	    this.createPlaceholder();
	
	if (! params.result)
		params.result = this.dialogPlace;
	
	sendRequest(params);
}
