var seleccionadoactual="";

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Constructor
function elemConstruir(texto,url,target,aux){
	this.texto=texto
	this.url=url
	this.target=target
	this.aux=aux
	this.hijos=new Array()
	this.esHoja=esHoja
	this.addHijo=addHijo
	this.getHtmlVertical=getHtmlVertical
	this.getHtmlVerticalSub=getHtmlVerticalSub
	this.getHtmlMapa=getHtmlMapa
	this.getIdNivelRecursivo=getIdNivelRecursivo
	this.getValue=getValue

	return this
}

function esVisibleElementoMapa(strId,strIdSelec,nivelDifMax){
	var strIdNivel=strId.split(".").length
	var strIdSelecNivel=strIdSelec.split(".").length
	var nivelDif=strIdNivel-strIdSelecNivel
	if (nivelDifMax<0) nivelDifMax=5000
	if(nivelDif<=nivelDifMax && strId.indexOf(strIdSelec)==0){
		//alert(strId+"-"+strIdSelec+"-"+nivelDif)
		return true
	}
	return
}

function getHtmlMapa(nivel,strId,strIdSelec,nivelDifMax){
		nivel_max=100
	if (nivel>0 && nivel<nivel_max && (esVisibleElementoMapa(strId,strIdSelec,nivelDifMax)) || false){
		var clase="menuVerticalTexto"
		var texto=this.aux
		//Negrita
		var esAnc=esAncestro(strId,strIdSelec)
		if (esAnc) {
			texto=texto.bold()
			if (!this.esHoja())	clase="menuVerticalTextoAncestro"
		}
		
		//Sangrado
		var sangrado=""
		for (var j=1;j<nivel;j++){
			sangrado+="&nbsp;"
		}
		
		//Ruta relativa de iconos y enlaces
		pathRel=pathRelPref+pathRelGet(strIdSelec,this.url)
		var url=urlGet(this.url,pathRel)

		
		//Icono a presentar
		var	iconoNombre="no_desplegado.gif"
		if (strId==strIdSelec) iconoNombre="seleccionado.gif"
		if (esAnc){
			if (!this.esHoja()) iconoNombre="desplegado.gif"
		}
		
		//Separación vertical entre elementos
		if (nivel<nivelAnterior){
			clase="menuVerticalFinNivel"+nivel
		}
		nivelAnterior=nivel
		
		strIdNormalizado=normalizarId(strId)
		
		if (typeof(pathRelPref)=="undefined")
		pathRelPref=""

		//var iconoRuta=pathRel + '../inc/images/';
		var iconoRuta=pathRel;
		//<table border="0" cellspacing="0" cellpadding="0"><tr><td>&nbsp;<td>&nbsp;</td></tr></table>

		if (nivel<=1){
			menuHtml+='<tr><td height="1" valign="top" align="right"><table cellspacing="0" cellpadding="0" height="1"><tr>'+'<td class="'+clase+'"><a id="'+strIdNormalizado+'Href" href="' +url+ '" class="mapa1">'+texto+''+''+'</a></td></tr><tr><td height="1" bgcolor="#FF0000"><img id="'+strIdNormalizado+'Image" src="' +iconoRuta+'spacer.gif" width="100%" height="2"></td></tr></table></td></tr>'+'\n';
		} else {
			menuHtml+='<tr><td height="1" valign="top" align="right"><table cellspacing="0" cellpadding="0" height="1"><tr>'+'<td valign="top"><img id="'+strIdNormalizado+'Image" src="' +iconoRuta+'arrow.jpg" border=0 vspace="8"></td>'+'<td class="'+clase+'">&nbsp;<a id="'+strIdNormalizado+'Href" href="' +url+ '" class="mapa2">'+texto+''+''+'</a></td></tr></table></td></tr>'+'\n';
		}
	}
	if (this.hijos.length>0) {
		for (var i=0;i<this.hijos.length;i++){
			this.hijos[i].getHtmlMapa(nivel+1,(strId=="")?strId+i:strId+"."+i,strIdSelec,nivelDifMax)
		}
	}
}

function getMapa(id,nivelDifMax){
	menuHtml=""
	nivelAnterior=0
	menu_vertical.getHtmlMapa(0,"",id,nivelDifMax)
	str='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
  		'<tr align="center">'+
		 	menuHtml+
			'</tr>'+
			'</table>'
	document.write(str)
}

function esHoja(){
	if (this.hijos.length==0) return true
}

function esAncestro(strId,strIdSelec){
	var i
	var strIdSelecArray=strIdSelec.split(".")
	var strIdArray=strId.split(".")
	var k=Math.min(strIdSelecArray.length,strIdArray.length)
	if(strIdArray.length<=strIdSelecArray.length){
		for (i=0;i<k;i++){
			if (strIdArray[i]!=strIdSelecArray[i]) return false
		}
		return true
	}
	return false
}

function esHijo(strId,strIdSelec){
	var i
	var strIdSelecArray=strIdSelec.split(".")
	var strIdArray=strId.split(".")
	var k=Math.min(strIdSelecArray.length,strIdArray.length)
	if(strIdArray.length<=strIdSelecArray.length){
		for (i=0;i<k;i++){
			if (strIdArray[i]!=strIdSelecArray[i]) return 
		}
		return true
	}
}

function esVisible(strId,strIdSelec){
	var i
	var strIdSelecArray=strIdSelec.split(".")
	var strIdArray=strId.split(".")
	var k=Math.min(strIdSelecArray.length,strIdArray.length)
	if(strIdArray.length<=strIdSelecArray.length+1){
		for (i=0;i<k;i++){
			if (strIdArray[i]!=strIdSelecArray[i]) {
				if (strIdArray.length==i+1) return true
				else return
			}
		}
		return true
	}
}

function menuSeleccionado(texto){
	return (texto.indexOf('_on.')<0) ? texto.replace('.', '_on.') : texto;
}

function menuOnmouseover(id,ruta,texto){
	if (normalizarId(seleccionadoactual)!=normalizarId(id)){
		texto = menuSeleccionado(texto);
		MM_swapImage(id+"Image","",ruta+texto)
	}
}

function menuOnmouseout(){
	MM_swapImgRestore()	
	//alert(getEtiqueta(id+"Href"))
}

function normalizarId(id){
	return id.replace(".","a")
}

function pathRelGet(strIdSelec,url){
	var strIdSelecNivel=strIdSelec.split(".").length
	if (typeof(menu_horizontal_existe)!="undefined"){
		if (menu_horizontal_existe) strIdSelecNivel++
	}
	var pathRel=""		

	for (var j=0;j<strIdSelecNivel;j++){
		pathRel+="../"
	}
	return pathRel
}

function urlGet(url,pathRel){
	if (url.indexOf("mailto:")==0 || url.indexOf("http://")==0)
		return url
	else 
		return pathRel+url
}

function getHtmlVertical(nivel,strId,strIdSelec){
	nivel_max=10
	if (nivel>0 && nivel<nivel_max && (esVisible(strId,strIdSelec) || false)){
		var clase="menuVerticalTexto"
		var texto=this.texto
		//Negrita
		var esAnc=esAncestro(strId,strIdSelec)
		if (esAnc) {
			if(nivel>1) texto = menuSeleccionado(texto);
			if (!this.esHoja())	clase="menuVerticalTextoAncestro"
		}
		
		//Sangrado
		var sangrado=""
		for (var j=1;j<nivel;j++){
			sangrado+="&nbsp;"
		}
		
		//Ruta relativa de iconos y enlaces
		pathRel=pathRelPref+pathRelGet(strIdSelec,this.url)
		//var url=urlGet(this.url,pathRel) //Para pruebas
		var url=urlGet(this.url,"/")
		
		//Icono a presentar
		var	iconoNombre="no_desplegado.gif"
		if (strId==strIdSelec) iconoNombre="seleccionado.gif"
		if (esAnc){
			if (!this.esHoja()) iconoNombre="desplegado.gif"
		}
		
		//Separación vertical entre elementos
		if (nivel==2) 
			clase="menuVerticalNivel2"
		if (nivel>2){
			clase="menuVerticalNivel"+nivel
		}
		if (nivel<nivelAnterior){
			clase="menuVerticalFinNivel"+nivel
		}
		nivelAnterior=nivel
		
		strIdNormalizado=normalizarId(strId)
		
		if (typeof(pathRelPref)=="undefined") 
		pathRelPref=""

		//var iconoRuta=pathRel + '_img/menu_vertical/' + nivel + '/'
		//var iconoRuta=pathRel + '../inc/images/menu/' //Para pruebas
		//var iconoRuta='/inc/images/menu/'
		var iconoRuta='./inc/'
		//<table border="0" cellspacing="0" cellpadding="0"><tr><td>&nbsp;<td>&nbsp;</td></tr></table>

		//menuHtml+='<tr><td height="1" valign="top"><table cellspacing="0" cellpadding="0" height="1"><tr>'+'<td class="'+clase+'" valign="top">'+sangrado+'<img id="'+strIdNormalizado+'Image" src="' +iconoRuta+iconoNombre+'">&nbsp;</td>'+'<td class="'+clase+'"><a id="'+strIdNormalizado+'Href" href="' +url+ '" class="'+clase+'" onmouseout="menuOnmouseout()" onmouseover="menuOnmouseover(\''+strIdNormalizado+'\',\''+iconoRuta+'\')">'+texto+''+''+'</a></td></tr></table></td></tr>'+'\n'
		if (nivel<=1){
		menuHtml+='<tr><td><a id="'+strIdNormalizado+'Href" href="' +url+ '"><img id="'+strIdNormalizado+'Image" src="' +iconoRuta+texto+'" border="0"></a></td></tr>'+'\n'
		}
		else{
		menuHtml+='<tr><td><a id="'+strIdNormalizado+'Href" href="' +url+ '" class="menuVerticalTexto" onmouseout="menuOnmouseout()" onmouseover="menuOnmouseover(\''+strIdNormalizado+'\',\''+iconoRuta+'\',\''+texto+'\')"><img id="'+strIdNormalizado+'Image" src="' +iconoRuta+texto+'" border="0"></a></td></tr>'+'\n'
			
		}

	}
	if (this.hijos.length>0) {
		for (var i=0;i<this.hijos.length;i++){
			this.hijos[i].getHtmlVertical(nivel+1,(strId=="")?strId+i:strId+"."+i,strIdSelec)
		}
	}
}

function getHtmlVerticalSub(nivel,strId,strIdSelec){
	if (nivel>3 && nivel<5 && (esVisible(strId,strIdSelec) || false)){
		var clase="menuVerticalTexto"
		var texto=this.texto
		//Negrita
		var esAnc=esAncestro(strId,strIdSelec)
		if (esAnc) {
			texto=texto.bold()
			if (!this.esHoja())	clase="menuVerticalTextoAncestro"
		}
		
		//Sangrado
		var sangrado=""
		for (var j=1;j<nivel;j++){
			sangrado+="&nbsp;"
		}
		
		//Ruta relativa de iconos y enlaces
		pathRel=pathRelPref+pathRelGet(strIdSelec,this.url)
		//var url=urlGet(this.url,pathRel) //Para pruebas
		var url=urlGet(this.url,"/")
		
		
		//Icono a presentar
		var	iconoNombre="no_desplegado_sub.gif"
		if (strId==strIdSelec) iconoNombre="seleccionado_sub.gif"
		if (esAnc){
			if (!this.esHoja()) iconoNombre="desplegado_sub.gif"
		}
		
		//Separación vertical entre elementos
		if (nivel>=2) 
			clase="menuVerticalNivel"+(nivel-1)
		if (nivel<nivelAnterior){
			clase="menuVerticalFinNivel"+(nivel-1)
		}
		nivelAnterior=nivel
		
		strIdNormalizado=normalizarId(strId)
		
		if (typeof(pathRelPref)=="undefined") 
		pathRelPref=""

		var iconoRuta=pathRel + '/inc/images/menu/'
		//<table border="0" cellspacing="0" cellpadding="0"><tr><td>&nbsp;<td>&nbsp;</td></tr></table>

		//menuHtml+='<tr><td height="1" valign="top"><table cellspacing="0" cellpadding="0" height="1"><tr>'+'<td class="'+clase+'" valign="top">'+sangrado+'<img id="'+strIdNormalizado+'Image" src="' +iconoRuta+iconoNombre+'">&nbsp;</td>'+'<td class="'+clase+'"><a id="'+strIdNormalizado+'Href" href="' +url+ '" class="'+clase+'" onmouseout="menuOnmouseout()" onmouseover="menuOnmouseover(\''+strIdNormalizado+'\',\''+iconoRuta+'\')">'+texto+'</a></td></tr></table></td></tr>'+'\n'
		menuHtml+='<tr><td><a id="'+strIdNormalizado+'Href" href="' +url+ '" class="menuVerticalTexto" onmouseout="menuOnmouseout()" onmouseover="menuOnmouseover(\''+strIdNormalizado+'\',\''+iconoRuta+'\',\''+texto+'\')"><img id="'+strIdNormalizado+'Image" src="' +iconoRuta+texto+'" border="0"></a></td></tr>'+'\n'
	}
	if (this.hijos.length>0) {
		for (var i=0;i<this.hijos.length;i++){
			this.hijos[i].getHtmlVerticalSub(nivel+1,(strId=="")?strId+i:strId+"."+i,strIdSelec)
		}
	}
}

function addHijo(texto,url,target,aux){
	var hijo=new elemConstruir(texto,url,target,aux)
	this.hijos[this.hijos.length]=hijo
	return hijo
}


//Funcion general para llamar al menu
function getMenuVertical(id){
	menuHtml=""
	nivelAnterior=0
	menu_vertical.getHtmlVertical(0,"",id)
	str='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
  		'<tr align="center">'+
		 	menuHtml+
			'</tr>'+
			'</table>'
	document.write(str);
}

function getMenuVerticalSub(id){
	menuHtml=""
	nivelAnterior=0
	menu_vertical.getHtmlVerticalSub(0,"",id)
	str='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
  		'<tr align="center">'+
		 	menuHtml+
			'</tr>'+
			'</table>'
	document.write(str)
}

//Funcion general para llamar al menu
function reverseString(cadena){
	cadena = cadena.toString();
	var aux = '';
	var l = cadena.length;
	for(a=0; a<=l; a++)
		aux += cadena.substr(l-a, 1);
	return(aux);
}

function getIdNivelRecursivo(nivel,strId){
	//alert(this.url);
	url_item=reverseString(this.url)
	url_pagina=reverseString(document.location)
	url_pagina=url_pagina.substring(0,url_item.length)
	
	//alert (url_pagina+"\n"+url_item+"\n"+(url_item==url_pagina))
	if (url_item==url_pagina){
		idNivel=strId
		return
	}
	if (this.hijos.length>0) {
		for (var i=0;i<this.hijos.length;i++){
			this.hijos[i].getIdNivelRecursivo(nivel+1,(strId=="")?strId+i:strId+"."+i)
		}
	}
}

function getIdNivel(elem){
	idNivel=""
	elem.getIdNivelRecursivo(0,"")
	return idNivel
}

function getValue(nivel,texto,campo){
	if (nivel>0 || false){
		v=this.texto==texto
		//alert(this.texto+" --- "+ texto+" --- "+ this.aux +" --- "+ v)
		if (this.texto==texto){
			resultado=eval("this."+campo)
		}
	}
	if (this.hijos.length>0) {
		for (var i=0;i<this.hijos.length;i++){
			this.hijos[i].getValue(nivel+1,texto,campo)
		}
	}
}

function escapar_ampersand(str){
	str=str.replace("&","%26")
	return str
}