/**
 * BrowserWindow class
 * js.controls.BrowserWindow
 *
 * This class is used to create a BrowserWindow
 * <example>
 *	var win = new BrowserWindow('rules','rules.html');
 * 	win.open();
 * </example>
 */
 

/**
 * Constructor
 */
 function BrowserWindow(name/*:String*/, url/*:String=""*/)
 {
	 this.name 	= name;
	 this.url 	= !Utils.isEmpty(url) ? url : "";
 }
 
 BrowserWindow.prototype = {
	 dataType : "BrowserWindow",
	 
	 name 	: '',
	 url 	: '',
	 x 		: 0,
	 y 		: 0,
	 width 	: 640,
	 height : 480,
	 
	 status		: true,
	 toolbar	: true,
	 location	: true,
	 menubar	: true,
	 titlebar	: true,
	 directories: true,
	 resizable	: true,
	 scrollbars	: true,
	 
	 fullscreen : false,
	 
	 _win : null,
	 
	 open : function( url/*:String=""*/)/*:void*/
	 {
	    if(!Utils.isEmpty(url)) this.url = url;
	        
		 var settings/*:String*/ = this.getWindowSettings();
		 this._win = window.open(this.url, this.name, settings);
		 
		  if(!this._win)
		 	alert("This Pop-up window might have been blocked, please allow popups on this site to continue.\n(look for a yellow bar at the top of the browser window for more information)");
	 },
	 
	 close : function()/*:void*/
	 {
		 if(this._win == null) return;
		 this._win.close();
	 },
	 
	 center : function()/*:void*/
	 {
		var w = (screen.availWidth)? screen.availWidth : 1024;
		var h = (screen.availHeight)? screen.availHeight : 768;  
		this.x = (w - this.width)/2;
		this.y = (h - this.height)/2;
	 },
	 
	 getWindowSettings : function()/*:String*/
	 {
		 var arr/*:Array*/ = [
		 	"width=" 	+ this.width,
		 	"height=" 	+ this.height,
		 	"top=" 		+ this.y, 
		 	"left=" 	+ this.x,
		 	"status=" 	+ this.boolToNum(this.status),
		 	"toolbar=" 	+ this.boolToNum(this.toolbar),
		 	"location=" + this.boolToNum(this.location),
		 	"menubar=" 	+ this.boolToNum(this.menubar),
			"titlebar=" + this.boolToNum(this.titlebar),
			"directories=" 	+ this.boolToNum(this.directories),
			"resizable=" 	+ this.boolToNum(this.resizable),
			"scrollbars=" 	+ this.boolToNum(this.scrollbars),
			"fullscreen=" 	+ this.boolToNum(this.fullscreen)
		];
		 
		return arr.join(",");
	 },
	 
	 boolToNum : function (value/*:Boolean*/) /*:Number*/
	 {
		 return (value)? 1 : 0;
	 }
}