/*****************************
* Menú principal
******************************/

//******* Rollover Functions ********//

var cacheArray=new Array(0);
function imageGroup() { if (this.total==null) { this.total=this.cached=this.rollovers=0; this.names=new Array(0); this.urls=new Array(0); this.count=new Array(0); this.i=new Object(); this.index=cacheArray.length; cacheArray[this.index]=this; this.defURL=''; this.add=imageGroup; } var a,j,k,args=arguments; for (j=0; j<args.length; j++) { k=this.total; a=args[j].split('|'); this.names[k]=a[0]; this.urls[k]=this.defURL+a[1]; this.total++; } }
function d_loadImages() {	if (document.images) { var j,c=cacheArray; for (j=0; j<c.length; j++) d_loadGroup(c[j]); } }
function d_loadGroup(obj,pre) { if (obj.loaded) return; obj.loaded=1; var k,img,stuff=''; for (k=0; k<obj.total; k++) { img=obj.i[obj.names[k]]=new Image(); if (!isNS4) { img.group=obj.index; img.num=k; img.onload=d_countImg; } if (isNS4) { stuff+='<IMG SRC="'+ obj.urls[k] +'" BORDER="0" ONLOAD="d_countImg('+obj.index+','+k+');"><BR>'; } img.src=obj.urls[k]; } if (isNS4) { if (pre) { document.newLayer('cacher'+obj.index,stuff,0); } else { var cacher=new Layer(0),c=cacher.document; c.write(stuff); c.close(); } } }
function d_countImg(n,k) { if (!isNS4) {n=this.group; k=this.num;} var obj=cacheArray[n]; if (obj.count[k]!=1) { obj.count[k]=1; obj.cached++; if (obj.cached==obj.total) {obj.rollovers=1; if (obj.onload) eval(obj.onload);} } }

//***********************************//

document.js = true;
var navReady=0;
var cnavReady=0;

var isIE=(document.all)?1:0;
var isNS4=(document.layers)?1:0;
var isNS6=((document.getElementById)&&(navigator.appName=='Netscape'))?1:0;
var isNS=(isNS4)?1:0;
var DHTML=(isIE||isNS4||isNS6)?1:0;
var isMac=(navigator.userAgent.indexOf('Mac')!=-1)?1:0;
var isIEMac=(isMac&&isIE)?1:0;
var isIE4Mac=(isIEMac&&(navigator.appVersion.indexOf('4.',4)!=-1))?1:0;
var isIE5Mac=(isIEMac&&(navigator.appVersion.indexOf('5.')!=-1))?1:0;

if (DHTML)
{
	xmargin = (isIE)?10:8; var ymargin=(isIE)?15:8;
	d_hidden = (isNS4)? 'hide':'hidden';
	d_visible = (isNS4)? 'show':'visible';

	currentNav=new Array(0);

	d_mouseY=0;	nsFix=0;

	d_navTimer=setTimeout("null",10);
	d_moveNavTimer = setInterval('null',1); clearInterval(d_moveNavTimer);
	d_popupTimer = setTimeout("null",0);

	d_navtabletop = '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">';
	d_navtabletop = d_navtabletop + '<TR><TD height=2 width=2 BGCOLOR="#EFEFEF">' + d_spacer(2, 2)+ '</TD><TD BGCOLOR="#EFEFEF"></TD><TD width=2 BGCOLOR="#EFEFEF">' + d_spacer(2, 2)+ '</TD></TR>';
	d_navtabletop = d_navtabletop + '<TR><TD width=2 BGCOLOR="#EFEFEF">' + d_spacer(2, 2)+ '</TD><TD BGCOLOR="#E0E0E0">';

	d_navtablebot = '</TD><TD WIDTH="2" BGCOLOR="#AAAAAA"><TD rowspan=2 BGCOLOR="#333333">' + d_spacer(2, 0)+ '</TD></TR>';
	d_navtablebot = d_navtablebot + '<TR height=2><TD COLSPAN="3" BGCOLOR="#AAAAAA"><td>' + d_spacer(2, 2)+ '</td><td></TD></TR>';
	d_navtablebot = d_navtablebot + '<TR height=2><td></td><TD colspan=3 BGCOLOR="#333333">' + d_spacer(0, 2)+ '</TD></TR></TABLE>';
	
	boxPics=new imageGroup(); boxPics.defURL='/_include/estilo/menu/dibujos/desplegable/';
	boxPics.add('flecha|flecha.gif','flecha_on|flecha_on.gif');

	cascadeNav=new Object(); menuList = new Object(); layers = new Object(); layers.EQ=new Array();
	var TempArgs;
}

//******* Basic DHTML Functions ********//

function equalizeLayers(n) { var k,l; var list=(n==null)?layers.EQ:arguments; for (k=0; k<list.length; k++) {l=d_getLayer(list[k]); if(l) d_equalize(l); } if (n==null) layers.EQ=new Array(); }
function d_getLayer(spec,base) { if (!isNS4) return getIt(spec); var j=0,temp=null; if (!base) base=document; if (base.layers[spec]) return base.layers[spec]; for (j=0; j<base.layers.length; j++) { temp=d_getLayer(spec,base.layers[j].document); if (temp) return temp; } return null; }
function getIt(id) { if (isIE) return document.all[id]; if (isNS6) return document.getElementById(id); }

function d_equalize(layer)
{
	if (layers[layer.id]) return;
	layer.getTop = new Function("return(parseInt(this.style.top))");
	layer.getLeft = new Function("return(parseInt(this.style.left))");
	layer.getHeight = new Function("if (isIE) return this.scrollHeight; if (isNS4) return this.document.height; if (isNS6) return this.offsetHeight;");
	layer.width2=0;
	layer.setClip = new Function ("l","t","r","b","if (isNS4) {this.clip.left=l; this.clip.top=t; this.clip.right=r; this.clip.bottom=b;} else { this.style.clip='rect('+t+' '+r+' '+b+' '+l+')'; }");
	layer.rewrite = new Function ("html","if (isIE||isNS6) this.innerHTML=html; if (isNS4) {this.document.write(html); this.document.close();}");
	layer.vis = new Function("n","this.style.visibility=(n)?d_visible:d_hidden; if (isNS6) {this.style.zIndex=(n)?this.z:eval(this.z)-1;}");
	layers[layer.id]=layer; if (isNS4)layer.style=layer; if (isNS6) { layer.z=layer.style.zIndex; if(layer.style.visibility==d_hidden)layer.vis(0); }
}

function layerTag(id,content,z,vis,l,t,w,h,extra)
{
	layers.EQ[layers.EQ.length]=id;
	if(w==0)w=1; if(!t)t=0;
	if(!l)l=0;
	if(!vis)vis=d_hidden;
	if(!z)z=10; if(!extra)extra='';
	if (!isNS4) {var stuff = '<DIV ID="'+id+'" STYLE="position:absolute; overflow:visible; left:'+l+'px; top:'+t+'px;'+((w)?(' width:'+w+'px;'):'')+((h)?(' height:'+h+'px;'):'')+' visibility:'+vis+'; z-index:'+z+'" '+extra+'>'; }
	if (isNS4)  {var stuff = '<LAYER NAME="'+id+'" left="'+l+'" top="'+t+'"'+((w)?(' width="'+w+'"'):'')+((h)?(' height="'+h+'"'):'')+' visibility="'+vis+'" z-index="'+z+'" '+extra+'>'; } return (stuff+content+((isNS4)?'</LAYER>':'</DIV>'));
}

function newLayer(id,content,z,vis,l,t,w,h,extra)
{
	var layer;
	
	if (isIE) { document.body.insertAdjacentHTML('BeforeEnd',layerTag(id,content,z,vis,l,t,w,h,extra)); layer=document.all[id]; }
	if (isNS4) { if (w==null)w=2000; layer=new Layer(w); layer.document.write(content); layer.document.close(); layer.left=(l)?l:0; layer.top=(t)?t:0; layer.height=(h!=null)?h:1; layer.zIndex=(z)?z:10; layer.width=layer.document.width; layer.visibility=(vis)?vis:d_visible; } d_equalize(layer); return (layer);
}

function d_writeLayer(id,content,z,vis,l,t,w,h,extra)
{
	this.writeln(layerTag(id,content,z,vis,l,t,w,h,extra));
	equalizeLayers();
}

if (DHTML) {	document.newLayer=d_writeLayer;	}


//******* End Basic DHTML Functions ********//


// body onload fix
var dhtmlnav=0; var dhtmlBrowser=0; if (document.images) dhtmlBrowser=1;

function d_init() { navReady=1; showCArrows(); if (document.prev) setTimeout("startPrev()",50); }

function d_initNav() { document.loaded=1; eval(onLoadStr); d_posCheck(); d_loadImages(); }
function whenPageLoaded(code) { onLoadStr+=code+'; '; } var onLoadStr='';
function d_posCheck() { if (DHTML) { var img=document.images.margincheck; if (img&&(!isMac)) { ymargin=img[(isNS4)?'y':'offsetTop']-10+((isNS6)?document.body.offsetTop:0); } var img=document.images.cnavCheck; cascadeNav.cpos=(img)?(getIy(img)-ymargin):0; } }

function d_navEnter(who) { if ((who==null)||(who==currentNav[0])) { clearTimeout(d_navTimer); if (isNS4) { if (nsFix==1) nsFix=2; else nsFix=1; } } }
function d_navExit(who) { if (!navReady) return; clearTimeout(d_popupTimer); if ((who!=null)&&(who!=currentNav[0])) return; if (isNS4) {if (nsFix==2) {nsFix=0; return;}  nsFix=0;} clearTimeout(d_navTimer); d_navTimer=setTimeout("d_endNav();",1000); }
function d_navOver(who) { if (DHTML) {d_startNav(who,arguments); }}
function d_navOut(who) { if (DHTML) { d_navExit(who); }}
function d_findMouse(e) { if (isNS4||isNS6) { d_mouseY=e.pageY;} if (isIE) { d_mouseY=event.clientY+document.body.scrollTop; } }
function d_startNav(who,args) { if (!navReady) return; d_navEnter(who); if (who==currentNav[0]) return; TempArgs=args; d_popupTimer=setTimeout("d_beginNav('"+who+"',0)",200); }
function d_beginNav(who,n) { d_navEnter(); d_endNav(); currentNav[0]=who; cascadeNav.args=(n)?TempArgs:new Object(); d_popupNav(who,1); }
function d_endNav() { var c=currentNav[0]; if (c==null) return; if (menuList[c]) { d_swapCArrow(c,0); d_hideLev(0); }	else { d_other(c); } currentNav[0]=null; }

function d_popupNav(who,lev,delay)
{
	if (lev>4) return;
	if (!menuList[who])
	{
		d_other(who,1); return;
	}
	if (delay!=null)
	{
		d_popupTimer=setTimeout("d_popupNav('"+who+"',"+lev+")",delay); return;
	}
	var l=layers[(isMac)?('ML_'+who):('menuLayer'+lev)];
	
	if (!l) return;
	if (isMac) l.lev=lev;
	
	if (who==currentNav[l.lev]) return;
	d_hideLev(l.lev-1);
	currentNav[l.lev]=who;
	if (!isMac) writeNavLayer(who,l.lev,l.id); d_setNavY(l);
	if(isMac){ l.style.zIndex=(60+2*lev); l.style.left=(xmargin-180+lev*180)} l.vis(1);
	if (l.lev>1) { d_toggleArrow(l.lev,1); } else { d_swapCArrow(currentNav[0],1);
	}
}
	
function d_other(who,n) { var l=layers[who]; if (!l) return; if (l.ready==0) return; l.vis(n); if(n) { layers.on=l; l.onmouseover=new Function("d_navEnter()"); l.onmouseout=new Function("if (!document.alert) d_navExit()");} else { layers.on=null; document.alert=0; if (document.navdisabled) navdisable(1);} }
function d_hideLev(num,delay)
{
	if (num>4) return;
	if (delay)
	{
		d_popupTimer=setTimeout("d_hideLev("+num+")",0); return;
	}

	var l,k=0;
	for (k=4; k>=(num+1); k--)
	{
		if (currentNav[k]!=null)
		{
			l=getML(k); l.vis(0);
			topLeft-=getIt(l.id+'_TB').offsetWidth+6;
			if (k>1) d_toggleArrow(k,0);
			if (l.clipped != null)
			{
				l.clipIt(0,2000);
				layers['menuLayer'+l.lev+'up'].vis(0);
				layers['menuLayer'+l.lev+'dn'].vis(0);
				alert(topLeft);
				l.clipped=null;

			}
			currentNav[k]=null;
		}
	}
	d_toggleArrow(num,1);
}

function d_toggleArrow(lev,show)
{
	var who=currentNav[lev],b=(isNS4)?getML(lev-1):window;
	var newimg=(show)?boxPics.i.flecha_on:boxPics.i.flecha;
	var img=b.document.images[who+'_ar'];
	if (img) {img.src=newimg.src;}
	if (isIE||isNS6) d_toggleCell(who+'_TR', show);
}

function d_toggleCell(id, show)
{
	var lnk=getIt(id);
	if (!lnk) return;
	lnk.bgColor=(show)?"F9F9F9":"E0E0E0";
}

var topLeft=0;

function d_setNavY(l)
{
	var db=document.body;
	var st=(isIE)?db.scrollTop:window.pageYOffset;
	var wh=(isIE)?db.clientHeight:window.innerHeight;
	var pb=((isIE)?db[(isMac)?'offsetHeight':'scrollHeight']:document.height)-((l.lev==1)?43:22)-((isNS6)?-1:(isIEMac)?0:1)*ymargin;
	var lh=l.getHeight();
	var wb=wh+st;
	
	if (wb>pb)wb=pb;
	var y=d_mouseY-Math.round(lh/2);
	var a2=cascadeNav.args[2];
	if ((l.lev==1)&&(a2)&&(y<a2+ymargin)) y=a2+ymargin;
	if (l.lev==1) y=24;
	if (l.lev>1)
	{
		var prevTop=getML(l.lev-1).getTop();
		if (y<(prevTop)) y=prevTop;
	}
	if ((y+lh)>wb)y=wb-lh;
	
	l.style.top=y;
	l.style.left=topLeft;
	topLeft+=getIt(l.id+'_TB').offsetWidth+6;
	if ((y+lh)>wb)
	{
		l.clipped=1;
		layers['menuLayer'+l.lev+'up'].style.top=y; layers['menuLayer'+l.lev+'dn'].style.top=wb-14;
		d_moveNav(l.id,0);
	}
}

function d_moveNav(id,s) { var who=layers[id]; if (who==null) { clearInterval(d_moveNavTimer); return; } var lh=who.getHeight(); var up=layers['menuLayer'+who.lev+'up'];  var dn=layers['menuLayer'+who.lev+'dn']; var y=who.getTop()+s; var uptop=up.getTop(); var dnbot=dn.getTop()+14; if(y>uptop) y=uptop; if((y+lh)<dnbot) y=dnbot-lh; up.vis((y<uptop)); dn.vis(((y+lh)>dnbot)); who.style.top=y; who.clipIt((y<uptop)?(uptop-y+8):0,((y+lh)>dnbot)?(dnbot-y-10):2000); if (((s<0)&&((y+lh)==dnbot))||((s>0)&&(y==uptop))) clearInterval(d_moveNavTimer); if (isIE4Mac) { var z=who.style.zIndex; who.style.zIndex=(z-1); who.style.zIndex=z; } }
function d_scrollNav(lev,s) { clearInterval(d_moveNavTimer); var l=getML(lev); if ((lev==0)||(!l)) return; d_moveNavTimer=setInterval("d_moveNav('"+l.id+"',"+s+")",50); }
function getIy(img) {if (isIE4Mac) return(parseXY(img)); return(img[(isNS4)?'y':'offsetTop']+((isNS6||isIE5Mac)?ymargin:0));} function getIx(img) {if (isIE4Mac) return(parseXY(img,'X')); return(img[(isNS4)?'x':'offsetLeft']+((isNS6||isIE5Mac)?xmargin:0));}
function parseXY(who,n) {var val=0; var num=who[(n=='X')?'offsetLeft':'offsetTop']; if(num)val+=num;  var oP=who.parentElement; if (oP) val+=parseXY(oP,n); return(val); }

function getML(lev) { return(layers[(isMac)?('ML_'+currentNav[lev]):('menuLayer'+lev)]); }

function IMG(url,w,h,b,ex) { return('<IMG SRC="/_include/estilo/menu/dibujos/desplegable/'+url+'" WIDTH="'+((w)?w:1)+'" HEIGHT="'+((h)?h:1)+'" BORDER="'+((b)?b:0)+'"'+((ex)?' '+ex:'')+'>');}
function d_spacer(w,h,b,ex) {return(IMG('vacio.gif',w,h,b,ex));}

function newNavMenu(who)
{
	menuList[who]=new Array();
	var j;
	for (j=1; j<arguments.length; j++)	{ menuList[who][j-1]=arguments[j]; }
}

function createNavLayer(lev,who) { if ((lev==1)&&(who.substring(0,5)=='cnav_')) { who=who.substring(5); chanArrows[chanArrows.length]=who; } menuList[who]=new Array(); var j; for (j=2; j<arguments.length; j++) { menuList[who][j-2]=arguments[j]; } }
if (DHTML) newNavMenu('blank',"blank|/|blank");

function genNavLayer(lev,who)
{
	var w=0;
	var id=(who)?('ML_'+who):('menuLayer'+lev);
	var build=d_navtabletop +((isMac||isNS4)?'':'<SPAN ID="'+id+'Area">')+writeNavLayer(((who)?who:'blank'),lev,id)+((isMac||isNS4)?'':'</SPAN>')+d_navtablebot;
	
	document.newLayer(id,build,(160+2*lev),d_hidden,(xmargin-150+lev*150),0,0,null,'ONMOUSEOVER="d_navEnter();" ONMOUSEOUT="d_navExit();"');
		
	var l=layers[id];
	l.lev=lev;
	if (!(isMac||isNS4)) equalizeLayers(id+'Area');
	l.clipIt=new Function ("t","b"," if (isNS4) {this.clip.top=t; this.clip.bottom=b;} else { this.style.clip='rect('+t+' 185 '+b+' 0)'; }");
}

function writeNavLayer(who,lev,id)
{
	var stuff='',menu = menuList[who];
	if (menu==null) return null;
	var j,a,url,submenu,txt;
	var stuff='<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="2" ID="'+ id+ '_TB">';
	for (j=0; j<menu.length; j++)
	{
		a=menu[j].split('|');
		url=a[1];
		if (url=='*') url=null; submenu=a[2];
		if (lev==4) submenu=null;
		if (submenu) stuff+='<TR ID="'+ submenu+'_TR">';
		else stuff+='<TR ID="'+ id + j + '_TR">';
		stuff+='<TD style="cursor:hand;" ONMOUSEOVER="'+((submenu)?('d_popupNav('+"'"+submenu+"'"+','+(LEV+((isMac)?'+1':1))+',0);" '):('d_hideLev('+LEV+',1);d_toggleCell('+"'"+id + j+"_TR'"+', 1);"')) + ' ONMOUSEOUT="' +((submenu)?('clearTimeout(d_popupTimer);" '):('d_toggleCell('+"'"+id + j+"_TR'"+', 0);"')) + 'ONCLICK="' + ((url)?('document.location.href=\''+url):'') +'\'" nowrap>';
		var LEV=(isMac)?('layers.'+id+'.lev'):lev;
		stuff+='&nbsp;&nbsp;'
		if (url||submenu) stuff+='<A HREF="' + ((url)?url:'javascript://nolink') + '" ONMOUSEOVER="'+((submenu)?('d_popupNav('+"'"+submenu+"'"+','+(LEV+((isMac)?'+1':1))+',0);" '):('d_hideLev('+LEV+',1);d_toggleCell('+"'"+id + j+"_TR'"+', 1);"')) + ' ONMOUSEOUT="' +((submenu)?('clearTimeout(d_popupTimer);" '):('d_toggleCell('+"'"+id + j+"_TR'"+', 0);"')) + '>';
		stuff+='<font class=men_dep_opc>'+a[0]+'</font>';
		if (url||submenu) stuff+='</A>';

		stuff+='&nbsp;&nbsp;'
		stuff+= '</TD><TD>'+ ((submenu)? IMG('flecha.gif',9,9,0,'NAME="'+submenu+'_ar"'):'') +'&nbsp;</TD></TR>';
	}
	stuff+='</TABLE>'; if ((who=='blank')||(isMac)) return stuff;
	if (isNS4) stuff=d_navtabletop+stuff+d_navtablebot;
	var l=layers[id+((isNS4)?'':'Area')]; l.rewrite(stuff); return null;
}

function writeLayers()
{
	if (!DHTML) return;
	if (isIE||isNS6) { xmargin=eval(document.body[(isIE)?'leftMargin':'offsetLeft']); ymargin=eval(document.body[(isIE)?'topMargin':'offsetTop']); }
	if (isNS4)
	{
		var mc=document.images.margincheck;
		if (mc)
		{
			xmargin=mc.x-1; ymargin=mc.y-87;
		}
	}
	document.newLayer('navconnect',IMG('spE0E0E0.gif',3,17),70,0,(xmargin+172),0);
	if (isMac) { var i; for(i in menuList) genNavLayer(1,i); }
	genNavLayer(1); genNavLayer(2); genNavLayer(3); genNavLayer(4);
}

//******* Second Level DHTML Functions ********//

function showCArrows() { if ((DHTML)&&(document.cnavCheck)) { var j,a=chanArrows; if (a.length>0) { for (j=0; j<a.length; j++) d_swapCArrow(a[j],0); cnavReady=1; } else setTimeout("showCArrows()",200); } }

function d_swapCArrow(who,n) { var img=document.images['ca_'+ who]; if (img) img.src=boxPics.i[(n)?'flecha_on':'flecha'].src; }
if (DHTML) { chanArrows= new Array(0);  }

//******* End Second Level DHTML Functions ********//

if (isNS4) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);

if (DHTML)
{
	document.onmousemove = d_findMouse;
	d_loadGroup(boxPics,1);
}

if (isNS4)
{
	document.newLayer('cacher_spacers',d_spacer(15,5)+ d_spacer(145,5)+ d_spacer(17,5)+ d_spacer(11,10)+ d_spacer(1,8)+ d_spacer()+ d_spacer(1,6)+ d_spacer(5,1)+ d_spacer(1,5)+ d_spacer(1,2));
	var d_winW=window.innerWidth;
	var d_winH=window.innerHeight;
	window.onresize=new Function("if ((d_winW!=window.innerWidth)||(d_winH!=window.innerHeight)) history.go(0);");
}


/*****************************
* Menú lateral
******************************/

function pon_color_opcion_menu_lateral(opcion, color)
{
	var lnk=getIt(opcion);
	if (!lnk) return;
	lnk.bgColor=color;
}


/*****************************
* Menú combo
******************************/

function activa_ocpion_menu_combo(menu, opciones)
{
	url=""
	for (i=2; i<=opciones; ++i)
	{
		var menu_actual = getIt(menu+i);
		longitud=menu_actual.value.length;
		url+=menu_actual.value;
		if ((i==2) && (menu_actual.value.slice(longitud-1, longitud))!="/") url=url+"/";
	}
	document.location.href=url;
		
	return true;
}
