﻿/**
	WINDOW.OPEN() ENHACED VERSION
	Author: raohmaru <http://www.raohmaru.com>
	Version: 1.0.1
	Creation date: 30-09-09
	Revision date: 08-12-09
 */


if(!raoh || raoh == undefined) var raoh = {};
if(!raoh.windows || raoh.windows == undefined) raoh.windows = {};


raoh.windows.POPUP_BLOCKER_MESSAGE = "Debes activar la opción de abrir ventanas emergentes de tu navegador para poder ver la página."

raoh.windows._getPos = function(w, h)
{
	var nW = ((navigator.appVersion.indexOf("Mac") > 0) && document.all)? w-16 : w,
		nH = h;
	return {
		x : Math.round((screen.availWidth/2) - (nW/2)),
		y : Math.round((screen.availHeight/2) - (nH/2)),
		w : nW,
		h : nH
	};
};

raoh.windows.open = function(pag, name, w, h, s, alert_blocker)
{
	if(!pag || pag == "") return;

	if(isNaN(w)) w = 650;
	if(isNaN(h)) h = 500;
	if(s || s == "") s = "yes";
	
	if(!name || name == "")
	{
		name = pag.match(/([\w-]+)\.[A-Za-z]{2,6}$/);
		name = (name == null) ? "new_window" :  name[1];
	}
	
	var pos = raoh.windows._getPos(w,h),
		w_pop = window.open(pag, name, "width=" + pos.w + ", height=" + pos.h + ", top=" + pos.y + ", left=" + pos.x + ", scrollbars=" + s + ", resizable=1");
	
	if(alert_blocker || alert_blocker == undefined || alert_blocker == null)
		setTimeout(function()
		{
			if(!w_pop) alert( raoh.windows.POPUP_BLOCKER_MESSAGE );
		}, 1000);
	
	return w_pop;
};
