//////////////////////////// menu superior
function findposx(s,level)
 {
 	if (level == 0)
 	{
 		var cnt = 2;
 		var idx = 0;
 	}
 	else
 	{
 		var cnt = 2;
 		var idx = 0;
 	}
 	var curLeft = 0;
 	if (s.offsetParent)
 	{
 		while (s.offsetParent && (idx < cnt))
 		{
 		
 			curLeft += s.offsetLeft;
 			s = s.offsetParent;
 			idx+=1;
 		}
 
 
 	}
 	
 	else if (s.x) { curLeft += s.x; }
 
 	return curLeft;
 
 	
 }
 
 function findposy(s,level)
 {
 	if (level == 0)
 	{
 		var cnt = 2;
 		var idx = 0;
 	}
 	else
 	{
 		var cnt = 2;
 		var idx = 0;
 	}
 	var curTop = 0;
 	if (s.offsetParent)
 	{
 		while (s.offsetParent && (idx < cnt))
 		{
 			curTop += s.offsetTop;
 			s = s.offsetParent;
 			idx +=1;
 
 		}
 
 
 	}
 	else if (s.x) { curTop += s.x; }
 
 	return curTop;
 	
 }
 
 function setmenus(s)
 {
 	curmenu = s;
 
 }
 
 function setsubmenus(s)
 {
 	submenu = s;
 	var x = submenu.substring(0,3)
 	x = x + '0';
 	curmenu = x;
 
 }
 
 function expand(s)
 {
 
 	curmenu = s.id;
 	var x = s.id;
 	var count = parseInt(x,10);
 	count += 100;
 	if (count < 1000)
 	{
 		x = '0' + count;
 	}
 	else
 	{
 		x = count;
 	}
 	var td = document.getElementById(x);
 	var posx = findposx(s,0);
 	var posy = findposy(s,0) + menuheight;
 
 	if (td != null)
 	{ 
 		td.style.left = "" + posx + "px";
 		td.style.top = "" + posy + "px";
 
 		td.style.display = 'block';
 
 	}
 }
 
 function checkpos(s)
 {
 
 	stop = window.setTimeout("collapse('"+s+"')",005);
 }
 
 function checksubpos(s)
 {
 	stopsub = window.setTimeout("collapsesub('"+s+"')",005);
 }
 
 function collapsesub(s)
 {
 
 	if (s.substring(0,3) != submenu.substring(0,3))
 	{
 
 		var td = document.getElementById(s);
 		if (td != null)
 		{ 
 			var x = s;
 			var count = parseInt(x,10);
 			count += 1;
 			if (count < 1000)
 			{
 				x = '0' + count;
 			}
 			else
 			{
 				x = count;
 			}
 			td = document.getElementById(x);
 			if (td != null)
 			{
 				td.style.display = 'none';
 			}
 
 		}
 
 
 	}
 
 	if (s.substring(0,1) != curmenu.substring(0,1) || curmenu == '0') 
 	{
 
 		var td = document.getElementById(s);
 		if (td != null)
 		{ 
 			var x = s;
 			var y = x.substring(0,2);
 			y = y + '00';
 			td = document.getElementById(y);
 
 			if (td != null)
 			{
 				td.style.display = 'none';
 			}
 		
 		}
 	}
 
 
 
 }
 
 function collapse(s)
 {
 	
 	if (s.substring(0,1) != curmenu.substring(0,1))
 	{
 		var td = document.getElementById(s);
 		if (td != null)
 		{ 
 			var x = s;
 			var count = parseInt(x,10);
 			count += 100;
 			if (count < 1000)
 			{
 				x = '0' + count;
 			}
 			else
 			{
 				x = count;
 			}
 			td = document.getElementById(x);
 			if (td != null)
 				{ td.style.display = 'none';}
 		
 		}
 	}
 
 }
 
 function expandsub(s,direction)
 {
 	submenu = s.id;
 	var x = s.id;
 	var count = parseInt(x,10);
 	count += 1;
 	if (count < 1000)	{
 		x = '0' + count;
 	}
 	else
 	{
 		x = count;
 	}
 
 	var td = document.getElementById(x);
 	if (direction == 'right')
 	{	
 		var posx = findposx(s,1) + menuwidth;
 	}
	else
 	{
 		var posx = findposx(s,1) - menuwidth;
 
 	}
 
 	var posy = findposy(s,1);
 	if (td != null)
 	{ 
 		td.style.left = "" + posx + "px";
 		td.style.top = "" + posy + "px";
 		td.style.display = 'block';
 	}
 
 
 }
 
 function Menu()
 {
 	this.addItem = addItem;
 	this.addsubmenu = addsubmenu;
 	this.addsubmenuitem = addsubmenuitem;
 	this.addlevel2menu = addlevel2menu;
 	this.addlevel2menuitem = addlevel2menuitem;
 
 	this.showMenu = showMenu;
 	thousands = 0;
 	hundreds = 0;
 	tens = 0;
 	digits = 0;
 	
 	htmlstr="";
 	htmlstr += "<!--GMENU Version 2.1-->";
 	htmlstr += "<table cellpadding=0 cellspacing=0 border=0 class='gmenu'><tr><!--GMENUITEMS--></tr></table><!--SUBMENU-->";
 	htmlstr += "<!--End of Gmenu-->";
 
 }
 
 function addItem(menuname,lnk)
 {
 	var id = "";
 	hundreds = 0;
 	tens = 0;
 	digits = 0;
 
 	id = "" + thousands + hundreds + tens + digits + "";
 	menustr = "";
 	menustr+= "<td class=\"gmenu\" width=\""+menuwidth+"\" id=\""+id+"\" onmouseover=\"expand(this)\" onmouseout=\"setmenus('');checkpos('"+id+"')\"><a href='"+lnk+"' class=\"gmenu\">"+menuname+"</a></td>";
 	menustr+="<!--GMENUITEMS-->";
 	htmlstr = htmlstr.replace("<!--GMENUITEMS-->",menustr);
 	thousands+=1;
 }
 
 function addsubmenu()
 {
 	var id = "";
 	hundreds = hundreds + 1;
 	currentthousands = thousands - 1;
 	htmlstr = htmlstr.replace("<!--SUBMENUITEMS-->",'');	
 	id = "" + currentthousands + hundreds + tens + digits + "";
 	pid = "" + currentthousands + "000";
 	menustr = "";
 	menustr+="<div id=\""+id+"\" class=\"submenu\" style=\"position:absolute;left:0;top:0;display:none;z-index:10\" onmouseover=\"setmenus('"+id+"')\" onmouseout=\"setmenus('');checkpos('"+pid+"')\"><!--SUBMENUITEMS--></div>";
 	menustr+="<!--SUBMENU-->";
 	htmlstr = htmlstr.replace("<!--SUBMENU-->",menustr);	
 }
 
 function addsubmenuitem(name,lnk,direction,alt)
 {
 	var id = "";
 	tens = tens + 1;
 	digits = 0;
 	currentthousands = thousands - 1;
 	id = "" + currentthousands + hundreds + tens + digits + "";
 	menustr = ""; 	if (direction == 'left') 	{
 		menustr+="<a id=\""+id+"\" href=\""+lnk+"\" onmouseover=\"setsubmenus('"+id+"');expandsub(this,'left')\" onmouseout=\"setsubmenus('');checksubpos('"+id+"')\">"+name+"</a>"; 	} 	
		else if (direction == 'nuevo') {
menustr+="<a id=\""+id+"\" href=\""+lnk+"\" target=_blank\" onmouseover=\"setsubmenus('"+id+"');expandsub(this,'left')\" onmouseout=\"setsubmenus('');checksubpos('"+id+"')\">"+name+"</a>"; 	} 	else 	{ 		menustr+="<a id=\""+id+"\" href=\""+lnk+"\" title=\""+alt+"\" onmouseover=\"setsubmenus('"+id+"');expandsub(this,'right')\" onmouseout=\"setsubmenus('');checksubpos('"+id+"')\">"+name+"</a>";  	}
 	menustr+="<!--SUBMENUITEMS-->";
 	htmlstr = htmlstr.replace("<!--SUBMENUITEMS-->",menustr);
 
 }
 
 function addlevel2menu()
 {
 	var id = "";
 	currentthousands = thousands - 1;
 	digits+=1;
 	htmlstr = htmlstr.replace("<!--LEVEL2ITEMS-->",'');	
 	id = "" + currentthousands + hundreds + tens + digits + "";
 	pid = "" + currentthousands + hundreds + tens + "0";
 	menustr = "";
 	menustr+="<div id=\""+id+"\" class=\"level2menu\" style=\"position:absolute;display:none;z-index:10\" onmouseover=\"setsubmenus('"+id+"')\" onmouseout=\"setsubmenus('');checksubpos('"+pid+"')\"><!--LEVEL2ITEMS--></div>";
 	menustr+="<!--SUBMENU-->";
 	htmlstr = htmlstr.replace("<!--SUBMENU-->",menustr);	
 	
 
 }
 
 function addlevel2menuitem(name,lnk,direccion)
 {
 
 	menustr = "";
 	if (direccion == 'nuevo') {
		menustr+="<a href="+lnk+"\ target=_blank+'>"+name+"</a>";
	}
		else
		{
			
	menustr+="<a href='"+lnk+"'>"+name+"</a>";
		}
 	menustr+="<!--LEVEL2ITEMS-->";
 
 	htmlstr = htmlstr.replace("<!--LEVEL2ITEMS-->",menustr);
 
 
 }
 
 
 function showMenu()
 {
 //	alert(htmlstr);
 	document.writeln(htmlstr);
 
 }
 
 // texto alt
 
 window.onerror = null;
var tooltip_attr_name = "tooltip";
var tooltip_blank_text = ""; //
var tooltip_newline_entity = ""; // 
var tooltip_max_width = 0; // 

window.onload = function(e){
	if (document.createElement) tooltip.d();
}

tooltip = {

	t: document.createElement("DIV"),
	c: null,
	g: false,

	m: function(e){
		if (tooltip.g){
			oCanvas = document.getElementsByTagName(
			(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
			)[0];
			x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
			y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
			tooltip.a(x, y);
		}
	},

	d: function(){
		tooltip.t.setAttribute("id", "tooltip");
		//tooltip.t.style.filter = "alpha(opacity=85)"; // buggy in ie5.0
		document.body.appendChild(tooltip.t);
		a = document.all ? document.all : document.getElementsByTagName("*");
		aLength = a.length;
		for (var i = 0; i < aLength; i++){

			//if (a[i].tagName == "A" || a[i].tagName == "BUTTON" || (a[i].tagName == "INPUT" && (a[i].type == "submit" || a[i].type == "button" || a[i].type == "reset"))) a[i].onclick = self.focus;

			if (!a[i]) continue;

			tooltip_title = a[i].getAttribute("title");
			tooltip_alt = a[i].getAttribute("alt");
			tooltip_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tooltip_blank_text;
			if (tooltip_title || tooltip_blank){
				a[i].setAttribute(tooltip_attr_name, tooltip_blank ? (tooltip_title ? tooltip_title + " " + tooltip_blank_text : tooltip_blank_text) : tooltip_title);
				if (a[i].getAttribute(tooltip_attr_name)){
					a[i].removeAttribute("title");
					if (tooltip_alt && a[i].complete) a[i].removeAttribute("alt");
					tooltip.l(a[i], "mouseover", tooltip.s);
					tooltip.l(a[i], "mouseout", tooltip.h);
				}
			}else if (tooltip_alt && a[i].complete){
				a[i].setAttribute(tooltip_attr_name, tooltip_alt);
				if (a[i].getAttribute(tooltip_attr_name)){
					a[i].removeAttribute("alt");
					tooltip.l(a[i], "mouseover", tooltip.s);
					tooltip.l(a[i], "mouseout", tooltip.h);
				}
			}
			if (!a[i].getAttribute(tooltip_attr_name) && tooltip_blank){
				//
			}
		}
		document.onmousemove = tooltip.m;
		window.onscroll = tooltip.h;
		tooltip.a(-99, -99);
	},

	s: function(e){
		d = window.event ? window.event.srcElement : e.currentTarget;
		if (!d.getAttribute(tooltip_attr_name)) return;
		s = d.getAttribute(tooltip_attr_name);
		if (tooltip_newline_entity){
			s = s.replace(/\&/g,"&amp;");
			s = s.replace(/\</g,"&lt;");
			s = s.replace(/\>/g,"&gt;");
			s = s.replace(eval("/" + tooltip_newline_entity + "/g"), "<br />");
			tooltip.t.innerHTML = s;
		}else{
			if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
			tooltip.t.appendChild(document.createTextNode(s));
			//tooltip.t.innerText = s;
		}
		if (d.getAttribute("drug")){tooltip.t.style.background = d.getAttribute("drug")}
		tooltip.c = setTimeout("tooltip.t.style.visibility = 'visible';", 50);
		tooltip.g = true;
	},

	h: function(e){
		tooltip.t.style.visibility = "hidden";
		if (!tooltip_newline_entity && tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
		clearTimeout(tooltip.c);
		tooltip.g = false;
		tooltip.a(-99, -99);
	},

	l: function(o, e, a){
		if (o.addEventListener) o.addEventListener(e, a, false); // was true--Opera7b workaround!
		else if (o.attachEvent) o.attachEvent("on" + e, a);
			else return null;
	},

	a: function(x, y){
		oCanvas = document.getElementsByTagName(
		(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
		)[0];

		w_width = window.innerWidth ? window.innerWidth + window.pageXOffset : oCanvas.clientWidth + oCanvas.scrollLeft;
		w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop;

		tooltip.t.style.width = "auto";

		t_width = window.event ? tooltip.t.clientWidth : tooltip.t.offsetWidth;
		t_height = window.event ? tooltip.t.clientHeight : tooltip.t.offsetHeight;

		if ((tooltip_max_width) && (t_width > tooltip_max_width)){
			tooltip.t.style.width = tooltip_max_width + "px";
			t_width = window.event ? tooltip.t.clientWidth : tooltip.t.offsetWidth;
		}

		t_extra_width = 7; // CSS padding + borderWidth;
		t_extra_height = 5; // CSS padding + borderWidth;

		tooltip.t.style.left = x + 8 + "px";
		tooltip.t.style.top = y + 8 + "px";

		while (x + t_width + t_extra_width > w_width){
			--x;
			tooltip.t.style.left = x + "px";
			t_width = window.event ? tooltip.t.clientWidth : tooltip.t.offsetWidth;
		}

		while (y + t_height + t_extra_height > w_height){
			--y;
			tooltip.t.style.top = y + "px";
			t_height = window.event ? tooltip.t.clientHeight : tooltip.t.offsetHeight;
		}
	}
}

