// ***********************************************
//   Proyecto ARPA AMENA
//
//   Requerimiento: Nuevo Menu Dinamico
//   Fecha Modificación : 26-06-2003
//   Autor Modificación : CPG
//
//   Requerimiento: ARPA_5_0_Portabilidad
//				Cuando se pinta un menú de primer nivel al final (lado derecho)
//				y los submenús que salen de él son de texto grande se va derecha y
//				debería irse a izquierda.
//				Además cuando no pintamos un menú de primer nivel intermedio da
//				un error de javascript y pinta mal
//   Fecha Modificación : 01-10-2003
//   Autor Modificación : Jose Mª de Mingo
//
//   Requerimiento: ARPA_RU_NPD1	
//   Autor Modificacion: Jose Antonio Porras Sánchez
//   Fecha Modificacion: 26/09/2006
//
// ***********************************************





var timer;

// Función que oculta la Capa de : Cargando....
function cargandoCapas(numMenus) 
{
	if( typeof top.frames(0).document.formulario != 'undefined' )
	{
		//window.clearTimeout( timer );
		if (document.layers) 
		{
			document.hidepage.display = 'none';
		}
		else 
		{
	  		document.all.hidepage.style.display = 'none';
			//imagen.style.visibility = 'visible';
			//menus.style.visibility = 'visible';
			//empezar(numMenus);
		}
	}
	else
	{
		//Para que le de tiempo a cargar la cabecera
		timer = window.setTimeout( "cargandoCapas2("+numMenus+")" , 200 );
	}
}// Fin de function cargando() 

function cargandoCapas2(numMenus)
{
	window.clearTimeout( timer );
	cargandoCapas(numMenus);
}

function empezar(total) 
{
	for(m=0;m<total;m++)
	{
		if (eval("typeof menu"+m+"!='undefined'"))
			eval("menu" + m + ".style.visibility = 'visible'");
	}
}

function BorrarTodo()
{
	//Cuando salgo de un menu borro todo lo activado
	for(i=0;i<activos.length;i++)
		DesMostrar(activos[i]);
	//Inicializo el array de activos
	activos = new Array();
}

function Mostrar(a) 
{
	BorrarTodo();
	lactivos = activos.length;
	activos[lactivos] = a;
	submenu = eval("popup" + a);
	submenu.style.visibility = 'visible';
}

function MostrarSigNivel(a,b) 
{
	Borrar(a);

	//Dejo activo el nivel del padre
	lactivos = activos.length;
	activos[lactivos] = b;
	objmenu = eval("popup" + b);
	objmenu.style.visibility = 'visible';

	objsubmenu = eval("menu" + b);
	//objsubmenu.style.backgroundColor = "#4466a5";
	
	if (eval("typeof x"+b+"!='undefined'"))
	{
		objletra = eval("x" + b);
		objletra.style.color = "#000000";
	}
	
	//Activo el siguiente nivel
	lactivos = activos.length;
	activos[lactivos] = a;
	submenu = eval("popup" + a);
	submenu.style.visibility = 'visible';
	
	objsubmenu = eval("menu" + a);
	//objsubmenu.style.backgroundColor = "#4466a5";
	
	objletra = eval("x" + a);
	//objletra.style.color = "#ff6600";
	objletra.style.color = "#713800";
}

function Borrar(menu) 
{
	var activosAux = new Array();
	var menuAux, lAux=0;
	longMenu=menu.length;
	//Recorro todo el array con los popups que se han activado
	for(i=0,j=0;i<activos.length;i++)
	{
		menuAux=""+activos[i];
		longMenuAux=menuAux.length;
		//si la longitud del menu guardado en el array de activados es mayor o igual que la del
		//menu actual será que el menu es hermano o hijo del menu actual y por lo tanto habrá
		//que desmostrarlo.
		if(longMenuAux>=longMenu-1)
			DesMostrar(menuAux);
		else  //Los que no desactivo los guardo en el vector activos
		{
			activosAux[j]=activos[i];
			j++;
		}
	}
	activos=new Array();
	activos=activosAux;
}

function DesMostrar(a) 
{
	
	if(  eval("typeof popup" + a + "!= 'undefined'") )
	{
		submenu = eval("popup" + a);
		submenu.style.visibility = 'hidden';
	}
	if(  eval("typeof menu" + a + "!= 'undefined'") )
	{
		objmenu = eval("menu" + a);
		//objmenu.style.backgroundColor = "#dcdada";
	}
	if(  eval("typeof x" + a + "!= 'undefined'") )
	{
		objmenu = eval("x" + a);
		objmenu.style.color = "#000000";
	}
}


//function EncenderNivelAct(a,b,c) 
//{	
//	// Ini ORANGE	
//	document.getElementById("flecha_sub_menu_"+a+"_"+b).src=c+'/images/flecha_menu_sec.gif';	
//	// Fin ORANGE
//	
//	Borrar(a);
//	
//	
//	lactivos = activos.length;
//	activos[lactivos] = b;
//	objmenu = eval("popup" + b);
//	objmenu.style.visibility = 'visible';
//	
//	objsubmenu = eval("menu" + a);
//	//objsubmenu.style.backgroundColor = "#4466a5";
//	
//	objletra = eval("x" + a);
//	//objletra.style.color = "#ff6600";
//	objletra.style.color = "#713800";
//	
//	objsubmenu = eval("menu" + b);
//	//objsubmenu.style.backgroundColor = "#4466a5";
//
//	if (eval("typeof x"+b+"!='undefined'"))
//	{
//		objletra = eval("x" + b);
//		//objletra.style.color = "#ff6600";
//		objletra.style.color = "#713800";
//	}
//}

//function ApagarNivelAct(a,b,c) 
//{
//	// Ini ORANGE	
//	document.getElementById("flecha_sub_menu_"+a+"_"+b).src=c+'/images/px.gif';		
//	// Fin ORANGE
//	
//	//alert("Apagar- a="+a+" b="+b);
//	objmenu = eval("menu" + a);
//	//objmenu.style.backgroundColor = "#dcdada";
//	
//	objletra = eval("x" + a);
//	objletra.style.color = "#000000";
//	
//	Borrar(b);
//}

// Funcion que recibiendo un identificador de menú devuelve
// el identificador del menú inmediatamente anterior.
function devolver_Menu_Anterior( menuComprobar )
{
	while( menuComprobar > 0 &&
		  eval("typeof menu"+menuComprobar+ "=='undefined'") )
	{
		menuComprobar = menuComprobar - 1;
	}
	return menuComprobar;
}

function colocar_niveles(datosMenu) 
{
	
	var izquierda=0;alto=0;posicion=0;anchoAnt=0;anchoAct=0;altoAnt=0;
	
	//ARPA_5_0
	//Tamaño de la pantalla (solo para explorer).
	var tamanno_pantalla = eval("document.body.clientWidth");
	//FIN ARPA_5_0
	
	datosNivel = datosMenu.split("|");
	if (datosNivel.length==1)  //Si estamos en el primer nivel
	{
		if(datosNivel[0]==0) 
			menu0.style.left=20; // ORANGE
			//menu0.style.left=3;
		else
		{
			ant = devolver_Menu_Anterior( datosNivel[0] - 1 );
			izquierda = eval("parseInt(menu" + ant + ".style.left.split('px'))");
			ancho = eval("parseInt(menu" + ant + ".scrollWidth)");
			posicion = izquierda + ancho;
			eval("menu" + datosNivel[0] + ".style.left = " + posicion);
		}
    	eval("menu" + datosNivel[0] + ".style.width = 3");
    }
    else
    {
		if (datosNivel.length==2)  //Si estamos en el segundo nivel
		{
			izquierda = eval("parseInt(menu" + datosNivel[1] + ".style.left.split('px'))");
			
			if(parseInt(datosNivel[1])==0)
				//posicion = izquierda+31;
				//posicion = izquierda+10; 
				posicion = izquierda;  // ORANGE
			else
				posicion = izquierda; // ORANGE
				//posicion = izquierda-7;
				
			
			//ARPA_5_0
			//Compruebo si la posicion más el ancho son menores que el tamaño de la pantalla
			//ya que sino es así tengo que modificar la posicion hacia la izquierda.
			//Primero recogo el ancho del submenú.
			anchoAct = eval("parseInt(popup"+datosNivel[1]+".scrollWidth)");
			//A este ancho le sumo la posicion de partida del submenú.
			var total = eval("parseInt(anchoAct) + parseInt(posicion)");
			if ( total > tamanno_pantalla )
			{
				//Si se pasa pondré como punto de partida desde donde iba a salir -
				//el ancho total y le sumare el ancho del menu de abajo.
				anchoAnt = eval("parseInt(menu" + datosNivel[1] + ".scrollWidth)");
				posicion = izquierda + anchoAnt - anchoAct - 14;
			}
			//FIN ARPA_5_0
			
			alto = eval("parseInt(menu"+datosNivel[1]+".scrollHeight)");
						
			alto = alto + 345 - (datosNivel[0]*20); // ORANGE
			//alto = alto + 326 - (datosNivel[0]*19);
			
			
		}
		else   //Los demás niveles
		{
			izquierda = eval("parseInt(popup" + datosNivel[0] + ".style.left.split('px'))");
			anchoAnt = eval("parseInt(popup" + datosNivel[0] + ".scrollWidth)");
			anchoAct = eval("parseInt(popup" + datosNivel[1] + ".scrollWidth)");
			altoAnt = eval("parseInt(popup" + datosNivel[0] + ".style.top)");
			alto = (altoAnt+(datosNivel[3]*20))-(datosNivel[2]*20);//ORANGE
			//alto = (altoAnt+(datosNivel[3]*19))-(datosNivel[2]*20);
			//alto = 230;
			posicion = izquierda - anchoAct;
			if (posicion>0)
				posicion++;
			else
				posicion = izquierda+anchoAnt;
		}
		eval("popup" + datosNivel[1] + ".style.width = 5");
		eval("popup" + datosNivel[1] + ".style.left = "+posicion);
		eval("popup" + datosNivel[1] + ".style.top = "+alto);
	}
}





function mostrarDiv(division,mostrar)
{
	if (desabilitarEnlace == false)
	{
		if (mostrar == true)		
		{
			eval(division+".style.display = 'block'");								
		}
		else
		{
			eval(division+".style.display = 'none'");
		}
	}
}
                             
//  USABILIDAD
// funcion de mostrar/ocultar menu
function muestraMenu(menu)
{
	if ( ultimoMenuPlano != "" && ultimoMenuPlano != menu )//AQQ
	{
		document.getElementById("F"+ ultimoMenuPlano).src = "images/Flecha_Orange_der_opa.gif";	//AQQ
	}
	
	ultimoMenuPlano="";//AQQ
	
	document.getElementById(menu).style.display = 'block';
	
	// cierro ultimo menu y actualizo ultimo menu abierto
	if ( ultimoMenu!="" && ultimoMenu!=menu )
	{
		document.getElementById(ultimoMenu).style.display = 'none';
		document.getElementById("F" + ultimoMenu).src = "images/Flecha_Orange_der_opa.gif";
		document.getElementById("T" + ultimoMenu).style.color = "";
		document.getElementById("T" + ultimoMenu).style.fontWeight = "";
	}

	// cambio ultimo submenu en caso de que estuviese activado
	if ( ultimoSubMenu != "" )
	{
		for (i=1; i<=ultimoNumSubMenu; i++)
		{
			// replego el submenu anterior
			if ( ultimoNumSubMenu>0 )
			{
				document.getElementById(ultimoSubMenu+i).style.display = 'none';
				document.getElementById(ultimoSubMenu+i+"l").style.display = 'none';
			}
		}
		
		document.getElementById("F" + ultimoSubMenu).src = "images/bullet_Cuadrado_Off.gif";
		document.getElementById("T" + ultimoSubMenu).style.color = "";
		document.getElementById("T" + ultimoSubMenu).style.fontWeight = "";
		ultimoSubMenu = "";
	}

	// cambio ultimo subsubmenu en caso de que estuviese activado
	if ( ultimoSubSubMenu != "" )
	{
		document.getElementById("F" + ultimoSubSubMenu).src = "images/bullet_Cuadrado_Off.gif";
		document.getElementById("T" + ultimoSubSubMenu).style.color = "";
		document.getElementById("T" + ultimoSubSubMenu).style.fontWeight = "";
		ultimoSubSubMenu = "";
	}

	if ( ultimoMenu != menu )
		ultimoMenu=menu;
	
	// actualizo flecha y color
	document.getElementById("F" + menu).src = "images/Flecha_Orange_abajo.gif";
	//document.getElementById("T" + menu).style.color = "#FF6600";
	document.getElementById("T" + menu).style.color = "#713800";
	document.getElementById("T" + menu).style.fontWeight = "bold";
	
	// cambio de foco
	window.focus();
	
	// para usabilidad
	// redimensiono el frame
	//redimensionaFrame('menu');
}

function cambiaLink(submenu)
{
	//alert("ultimoMenuPlano="+ultimoMenuPlano+" ultimoMenu="+ultimoMenu);
	document.getElementById("F" +submenu).src = "images/bullet_Cuadrado.gif";
	
	// cierro ultimo menu y actualizo ultimo menu abierto
	if ( ultimoMenu!="" && ultimoMenu!=submenu )
	{
		document.getElementById(ultimoMenu).style.display = 'none';
		document.getElementById("F" + ultimoMenu).src = "images/Flecha_Orange_der_opa.gif";
		document.getElementById("T" + ultimoMenu).style.color = "";
		document.getElementById("T" + ultimoMenu).style.fontWeight = "";
	}
	
	if ( ultimoMenuPlano != "" && ultimoMenuPlano != submenu )
	{
		document.getElementById("F"+ ultimoMenuPlano).src = "images/Flecha_Orange_der_opa.gif";	
	}
	
	ultimoMenuPlano=submenu;
	
	// cierro ultimo menu y actualizo ultimo menu abierto
	if ( ultimoSubMenu != "" && ultimoSubMenu != submenu )
	{
		
		document.getElementById("F" +submenu).src = "images/Flecha_Orange_abajo.gif";
		
		for (i=1; i<=ultimoNumSubMenu; i++)
		{
			
			// replego el submenu anterior
			if ( ultimoNumSubMenu>0 )
			{
				
				document.getElementById(ultimoSubMenu+i).style.display = 'none';
				
				document.getElementById(ultimoSubMenu+i+"l").style.display = 'none';
			}
		}
		
		// cambio la flecha
		document.getElementById("F" + ultimoSubMenu).src = "images/bullet_Cuadrado_Off.gif";
		
		// quito el color al menu seleccionado
		document.getElementById("T" + ultimoSubMenu).style.color = "";
		
		document.getElementById("T" + ultimoSubMenu).style.fontWeight = "";
		
	}     
	
}

// funcion de mostrar/ocultar menu
function muestraSubMenu(submenu, numero)
{
	
	// despliego este submenu
	for (i=1; i<=numero; i++)
	{
		document.getElementById(submenu+i).style.display = 'block';
		document.getElementById(submenu+i+"l").style.display = 'block';
	}
	
	// actualizo flecha, en caso de tener o no tener subsubmenu
	if ( numero>0 )
	 	document.getElementById("F" + submenu).src = "images/Flecha_Orange_abajo2.gif";
	else
		document.getElementById("F" + submenu).src = "images/bullet_Cuadrado.gif";
	
	// cierro ultimo menu y actualizo ultimo menu abierto
	if ( ultimoSubMenu != "" && ultimoSubMenu != submenu )
	{
		for (i=1; i<=ultimoNumSubMenu; i++)
		{
			// replego el submenu anterior
			if ( ultimoNumSubMenu>0 )
			{
				document.getElementById(ultimoSubMenu+i).style.display = 'none';
				document.getElementById(ultimoSubMenu+i+"l").style.display = 'none';
			}
		}
		
		// cambio la flecha
		document.getElementById("F" + ultimoSubMenu).src = "images/bullet_Cuadrado_Off.gif";
		
		// quito el color al menu seleccionado
		document.getElementById("T" + ultimoSubMenu).style.color = "";
		document.getElementById("T" + ultimoSubMenu).style.fontWeight = "";
	}
	
	// cambio ultimo subsubmenu en caso de que estuviese activado
	if ( ultimoSubSubMenu != "" )
	{
		document.getElementById("F" + ultimoSubSubMenu).src = "images/bullet_Cuadrado_Off.gif";
		document.getElementById("T" + ultimoSubSubMenu).style.color = "";

		ultimoSubSubMenu = "";
	}
	
	// actualizo el ultimo submenu con el actual
	if ( ultimoSubMenu != submenu )
	{
		ultimoSubMenu=submenu;
		ultimoNumSubMenu=numero;
	}

	// actualizo el color de mi padre
	document.getElementById("T" + ultimoMenu).style.color = "#000000";

	// actualizo el color de este submenu
	//document.getElementById("T" + submenu).style.color = "#FF6600";
	document.getElementById("T" + submenu).style.color = "#713800";
	document.getElementById("T" + submenu).style.fontWeight = "bold";
	
	// cambio de foco
	window.focus();
	
	
}

function seleccionaSubSubMenu(subsubmenu)
{
	// actualizo flecha y color
	document.getElementById("F" + subsubmenu).src = "images/bullet_Cuadrado.gif";
	//document.getElementById("T" + subsubmenu).style.color = "#FF6600";
	document.getElementById("T" + subsubmenu).style.color = "#713800";
	document.getElementById("T" + subsubmenu).style.fontWeight = "bold";
	
	// cambio ultimo subsubmenu
	if ( ultimoSubSubMenu != "" && ultimoSubSubMenu != subsubmenu )
	{
		document.getElementById("F" + ultimoSubSubMenu).src = "images/bullet_Cuadrado_Off.gif";
		document.getElementById("T" + ultimoSubSubMenu).style.color = "";
		document.getElementById("T" + ultimoSubSubMenu).style.fontWeight = "";
	}
	
	// actualizo ultimo subsubmenu
	if ( ultimoSubSubMenu != subsubmenu )
		ultimoSubSubMenu=subsubmenu;

	// actualizo el color de mi padre
	document.getElementById("T" + ultimoSubMenu).style.color = "#000000";

	// cambio de foco
	window.focus();
	
	// para usabilidad
	// redimensiono el frame
	//redimensionaFrame('menu');
}

function ejecutaMenu()
{
	document.getElementById("menuPrincipal").style.display = 'block';
}

function alternaCelda(fila, tipo, nivel)
{
	if (tipo=="in")
	{
		if (nivel=="1")
			//AQQ document.getElementById(fila).style.backgroundColor = "#F5F5F5";
			document.getElementById(fila).style.backgroundColor = "#E5E0CC";
		else if (nivel=="2")
			//AQQ document.getElementById(fila).style.backgroundColor = "#E6E8EC";
			document.getElementById(fila).style.backgroundColor = "#DEBF91";
		else if (nivel=="3")
			// AQQ document.getElementById(fila).style.backgroundColor = "#D7D8DB";   "#E3B898"
			document.getElementById(fila).style.backgroundColor = "#E2C6AE";
	}
	else if (tipo=="out")
	{
		// alterno en caso de salir
		if (nivel=="1")
			//AQQ document.getElementById(fila).style.backgroundColor = "#FFFFFF";
			document.getElementById(fila).style.backgroundColor = "#DDC599";
			
		else if (nivel=="2")
			document.getElementById(fila).style.backgroundColor = "#F4F5F7";
		else if (nivel=="3")
			document.getElementById(fila).style.backgroundColor = "#E7E8EA";
	}
}

// para usabilidad
//function redimensionaFrame(frame)
//{
//	//captura el iframe en cuestion y lo redimensiona
//	iframme=window.top.document.getElementById(frame);
//	iframme.style.height=document.body.scrollHeight;
//}
	
	