Bw.Widgets.Dialog = 
{
	superclassName: null,
	selfclassName: "Bw.Widgets.Dialog",
	
	create: function (url, scrollable, resizable, width, height, x, y)
	{
		var obj = document.createElement ('div');
		
		obj.setAttribute ("url", url);
		obj.setAttribute ("scrollable", scrollable);
		obj.setAttribute ("resizable", resizable);

		if (width) obj.setAttribute ("width", width);
		if (height) obj.setAttribute ("height", height);
		if (typeof x != 'undefined') obj.setAttribute ("x", x);
		if (typeof y != 'undefined') obj.setAttribute ("y", y);
		
		Bw.Core.bootstrap (obj, "Bw.Widgets.Dialog");
		
		return obj;
	},
	
	initialize: function ()
	{
		this.url = this.getAttribute ("url");
		this.name = this.getAttribute ("name");
		this.resizable = this.getAttribute ("resizable");
		this.scrollable = this.getAttribute ("scrollable");
		
		this.width = this.getAttribute ("width");
		this.height = this.getAttribute ("height");
		this.x = this.getAttribute ("x");
		this.y = this.getAttribute ("y");
		
		this.show ();
	},
	
	intParam: function (intValue, defaultValue)
	{
		if (typeof intValue == "undefined" || intValue == null || intValue == '')
		{
			if (typeof defaultValue == "function")
			{
				return defaultValue();
			}
			return defaultValue;
		}
		
		return parseInt (intValue);
	},
	
	show: function ()
	{		
		var o = this.win;
		if (o) return;
		
		var s = (this.scrollable && (this.scrollable == 'true' || this.scrollable == true)) ? 'yes' : 'no';
		var r = (this.resizable && (this.resizable == 'true' || this.resizable == true)) ? 'yes' : 'no';
		
		function centerX (width)
		{
			return (document.body.clientWidth / 2) - (width / 2);
		}
		
		function centerY (height)
		{
			return (document.body.clientHeight / 2) - (height / 2);
		}
		
		var w = this.intParam (this.width, 400);
		var h = this.intParam (this.height, 300);
		
		if (document.all)
		{
			w += 8;
			h += 34;
		}
		
		var x = this.intParam (this.x, function () { return centerX (w); });
		var y = this.intParam (this.y, function () { return centerY (h); });
		
		x += (window.screenX) ? window.screenX : window.screenLeft;
		y += (window.screenY) ? window.screenY : window.screenTop;
		
		if (window.showModalDialog) 
		{
			o = window.showModalDialog (this.url, self, 'help:no;center:no;dialogLeft:'+x+'px;dialogTop:'+y+'px;dialogHeight:'+h+'px;dialogWidth:'+w+'px;status:no;scroll:'+ s +';resizable:'+ r);
		}
		else
		{
			o = window.open (this.url, self, 'modal=yes,dialog=yes,top='+y+',left='+x+',height='+h+',width='+w+',status=no,scrollbars='+ s +',resizable='+ r);
			this.opener = o.opener;
		}
		
		this.win = o;
	},
	
	close: function ()
	{
		this.win.close();
	}
};

