
if(!window.Prototype) alert("wpopup.js requires prototype.js")
if(!window.Extension) alert("wpopup.js requires extensions.js")

/**
@description PopUp tools

@created 13/07/2006

@updated 13/07/2006

@methods

	static WPopUp.openCenter(url, w, h, [name, extraWindowFeatures])
	static WPopUp.open(url, w, h, strWindowFeatures)

@example

	WPopUp.openCenter("http://www.bs2.com.br", 790, 500)

	WPopUp.open("http://php.bs2.com.br/php/info.php", "popup2",
				"left=0,top=0,width=1000,height=500,resizable=yes,scrollbars=yes,status=yes")

	WPopUp.open("http://neves.bs2.com.br", "popup3",
				{width:320, height:240, resizable:"yes"})

@see Referência de parâmetros para windowFeatures:
http://developer.mozilla.org/en/docs/DOM:window.open#Position_and_size_features
*/

/**
@class static
*/
var WPopUp = {

	/**
	 * url:string, w:number, h:number, name:string, extraWindowFeatures:string
	 **/
	openCenter : function(url, w, h, name, extraWindowFeatures)
	{
		var n = name || "popup"
		var L = window.screen.width/2 - w/2
		var T = window.screen.height/2 - h/2
		if (!w) w = screen.availWidth
		if (!h) h = screen.availHeight
		var strWindowFeatures = 
			"left=$L,top=$T,width=$w,height=$h,$extraWindowFeatures".tpl(
				{$L:L, $T:T, $w:w, $h:h, $extraWindowFeatures:extraWindowFeatures}
			);
		this.open(url, name, strWindowFeatures)
	},

	/**
	 * url:string, name:string, windowFeatures:[string, object]
	 **/
	open : function(url, name, windowFeatures)
	{
		if(typeof windowFeatures == "string")
		{
			strWindowFeatures = windowFeatures
		}
		else
		{
			var p = []
			$H(windowFeatures).each( function(pair)
				{
					p.push( "$k=$v".tpl({$k:pair.key, $v:pair.value}) )
				}
			)
			strWindowFeatures = p.join(",")
		}

		var wnd = window.open(url, name, strWindowFeatures)
		wnd.focus()
		return wnd
	}
}
