/**
* PopupDialog object, can be opened either as a new window or as a modal dialog.
*
* @param url URL to page.
* @param title Name of window to open.
* @param width the width of the window
* @param height the height of the window (optional, default="popupDialog")
* @param resizable true if resizing of the window is allowed (optional, default=false)
* @param scrollbars true if scrollbars is allowed (optional, default=false)
*/

var debug = true;

PD_NORMALWIDTH = 427;

function PopupDialog(url, width, height, name, resizable, scrollbars, statusbar)
{
	if (debug) resizable = true;
	
	// Public functions
	this.open = PopupDialog_open;
	this.openModal = PopupDialog_openModal;
	this.getWindow = PopupDialog_getWindow;
	
	// Member variables:
	this.x = top.window.screenLeft + top.window.document.body.offsetWidth/2 - width/2 - 8;
	this.y = top.window.screenTop + top.window.document.body.offsetHeight/2 - height/2;
	this.window = null;
	this.opened = false;
	this.url = url;
	this.name = name;
	this.width = width;
	this.height = height;
	this.resizable = resizable;
	this.scrollbars = scrollbars;
	this.statusbar = statusbar;
	
	if (!this.name) this.name = "popupDialog";
}

function PopupDialog_open()
{
	var features = "width=" + this.width + ",height=" + this.height + ",resizable=" + (this.resizable?"yes":"no") + ",scrollbars=" + (this.scrollbars?"yes":"no") + ",menubar=no,status=no,left=" + this.x + ",top=" + this.y;
	this.window = window.open(this.url, this.name, features);
	
	return this.window;
}

function PopupDialog_openModal(args)
{
	var features = "dialogHeight:" + this.height + "px; dialogWidth:" + this.width + "px; dialogTop:" + this.y + "px; dialogLeft:" + this.x + "px; center:no; scroll:" + (this.scrollbars?"yes":"no") + ";resizable:" + (this.resizable?"yes":"no") + ";status:" + (this.statusbar?"yes":"no") + ";help:no;";
	return showModalDialog(this.url, args, features);
}

function PopupDialog_getWindow()
{
	return this.window;
}
