function addEvent(obj, e, func)
{
	if(obj.addEventListener) {
		obj.addEventListener(e, func, false);
	} else if(obj.attachEvent) {
		obj.attachEvent("on"+e, func);
	} else {
		obj["on"+e] = FC_menu;
	}	
}

//-------------------------------

function set_FCmenu()
{
	var allA = document.getElementsByTagName("A");
	for(var i=0; a=allA[i]; i++)
	{
		if(a.className == "home_acceso_anho")
		{
			a.onclick = change_FCmenu;
			a.onfocus = removeFocus;
			if(a.parentNode.getElementsByTagName("DIV")[0].style.display == "none") a.style.backgroundPosition = "38px -8px";
		}
	}
}

function change_FCmenu()
{
	var oDiv = this.parentNode.getElementsByTagName("DIV")[0];
	var d = oDiv.style.display;
		oDiv.style.display = (d == "inline") ? "none" : "inline";
	this.style.backgroundPosition = (d == "inline") ? "38px -8px" : "38px 12px";
}

//addEvent(window, "load", set_FCmenu);

function removeFocus()
{
	this.blur();	
}

//-------------------------------

function abreVent(url,nombre,params)
{
	window.open(url,nombre,params);
}

//-----------------------------------------------------------------------

EventManager =
{
	addEvent: function(obj, e, func)
	{
		if(obj.addEventListener)
		{
			obj.addEventListener(e, func, false);
		}
		else if(obj.attachEvent)
		{
			obj.attachEvent("on"+e, func);
		}
		else
		{
			obj["on"+e] = func;
		}
	},

	removeEvent: function(obj, e, func)
	{
		if(obj.removeEventListener)
		{
			obj.removeEventListener(e, func, false);
		}
		else if(obj.detachEvent)
		{
			obj.detachEvent("on"+e, func);
		}
		else
		{
			obj["on"+e] = null;
		}
	}
};

//-----------------------------------------------------------------------

function getPos(w,h)
{
	var nW = w;
	var nH = h;
	var list = {
		x : Math.round((screen.availWidth/2) - (nW/2)),
		y : Math.round((screen.availHeight/2) - (nH/2)),
		w : nW,
		h : nH
	}
	return list;
}

function openWin(pag,w,h,s)
{
	if(w == null) w = 650;
	if(h == null) h = 500;
	if(s == null) s = "yes";
	var pos = getPos(w,h);
	var name = pag.match(/([\w-]+)\.[A-Za-z]+$/);
		name = (name == null) ? "new_window" :  name[1];	
	var w_pop = window.open(pag, name, "width=" + pos.w + ", height=" + pos.h + ", top=" + pos.y + ", left=" + pos.x + ", scrollbars=" + s);

	setTimeout(function()
	{
		if(!w_pop) alert("Debes activar la opción de abrir ventanas emergentes de tu navegador para poder ver la página.");
	},1000);
	
	return w_pop;
}

//-----------------------------------------------------------------------

var internal_link = false;
function addExitPopup(pag,w,h,s)
{
	EventManager.addEvent(window, "load", function()
	{
		var anchors = document.getElementsByTagName('a'),
			href;
		for(var i=0; i<anchors.length; i++)
		{
			href = anchors[i].href.toLowerCase();
			if (!(href.indexOf("http://")!=-1 && href.indexOf("clima-x.com")==-1))
			{
				anchors[i].onclick = function()
				{
					internal_link = true;
				}
			}
		}
	});
	EventManager.addEvent(window, "unload", function exitPopup()
	{
		if(!internal_link)
		{
			var win = openWin(pag,w,h,s);
			if(win) win.blur();
		}
	});
}
