/*
  01/11/2004
  Archivo destinado a la gestión de los
  menús principal y secundario.
*/



//Una vez hecho clic sobre un punto de menú principal,
//se tratan sus puntos de menú secundario. Portal.
function GestionarMenuSuperior(oPMP){

 var iPMP = oPMP.id.split("-")[1];
 var oDD = document.getElementById("MenuSuperior").getElementsByTagName("dl")[0].getElementsByTagName("dd");

 oPMP.unselectable = "on";

 for(i=0;i<oDD.length;i++){
  iDD = oDD[i].id.split("-")[1];
  if(iDD==iPMP){
   // si pertenece al punto seleccionado: abrir puntos de menú
   oDD[i].style.display = "block";
  }else{
  // si no pertenece al punto seleccionado: cerrar puntos de menú
   oDD[i].style.display = "none";
  }
 }

}

// Función que cambia el estilo de los MS
function CambiarFondoMS(esto, iEstado){
// Hacemos que permanezcan visibles.
//	clearTimeout(IDOcultarMenuSecundario);
//	clearTimeout(IDOcultarMenuSecundario2);
	var oHijo = esto.firstChild;
	if(iEstado == 0){
		if (esto.className != "menuTerHome")
			{
			esto.style.backgroundColor = "#8396A4";
			oHijo.style.cssText = "color: #FFFFFF;";
			}
		
	} else {
		if (esto.className != "menuTerHome")
			{
			esto.style.backgroundColor = "#D2D9E3";
			oHijo.style.cssText = "color: #333333;";
			}
	}
}

//Función que cambia el estilo de los MT
function CambiarFondoMT(esto, iEstado){
	var oHijo = esto.firstChild;
	if (iEstado == 0)
		{
		esto.style.backgroundColor = "#8396A4";
		oHijo.style.color = "#FFFFFF";
		}
	else
		{
		esto.style.backgroundColor = "#D2D9E3";
		oHijo.style.color = "#333333";
		}
}

function CambiarFondo(esto,iEstado){
	var oHijo = esto.firstChild;
	if(iEstado == 0){
		//esto.style.cssText = "background: #DBD3D5 url(../../img/comunes/fondos/menuLateral.gif) left repeat-y;";
		esto.style.backgroundColor="#E7E3D7";
		esto.style.backgroundImage="url(../../img/comunes/fondos/menuLateral.gif)";
		esto.style.backgroundPositionX="left";
		esto.style.backgroundRepeat="repeat-y";
		oHijo.style.cssText = "color: #333333;";
	} else {
		//esto.style.cssText = "background: #891536 url(../../img/comunes/fondos/menuLateralSeleccionado.gif) left repeat-y;";
		esto.style.backgroundColor="#891536";
		esto.style.backgroundImage="url(../../img/comunes/fondos/menuLateralSeleccionado.gif)";
		esto.style.backgroundPositionX="left";
		esto.style.backgroundRepeat="repeat-y";
		oHijo.style.cssText = "color: #FFFFFF;";
	}

}

function VerImagen(iIdImagen){

 var windowImagen;
 windowImagen = window.open("popup/popupimagen.asp?idimagen="+iIdImagen,"Imagen","width=100,height=100,top=10,left=10,scrollbars=yes,resizable=yes");

}

function ActivarCursor(oImagen){

 oImagen.style.cursor = "pointer";

}

// -------------------------------- ESTADISTICAS: RESOLUCION ----------------------------
//--------------Función para obtener la resolución mediante la "carga" (llamada) de una página oculta
// En el GET no hace falta pasar la ruta completa de la página a llamar
function resolucion(iResolucion){
	var xmlHttp
	if (iResolucion == 0) {
		if (window.ActiveXObject){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
			xmlHttp.open("GET", "resolucion.asp?resolucion="+screen.width+"*"+screen.height, false);
			xmlHttp.send();
		} else {
			xmlHttp = new XMLHttpRequest();
			xmlHttp.open("GET", "resolucion.asp?resolucion="+screen.width+"*"+screen.height, false);
			xmlHttp.send(null);
		}
	}
}

// En caso de que el navegador sea antiguo y no funcione el sistema anterior se usa la siguiente función para
// cambiar todos los enlaces de la página principal y poder obtener la resolución
function obtenerResolucionLinks(iResolucion) {
	if (iResolucion == 0){
		var i;
		var screenW = screen.width;
		var screenH = screen.height;
		var host = location.host;
		for (i=0;i<document.links.length;i++) {
			enlace = document.links[i].href;
			// Eliminar aquellos enlaces externos que, por lo tanto, no nos van a ayudar a obtener la resolución
			// eso lo hacemos mediante "host". Consideramos externo todo aquél enlace que no contenga "host"
			if ((enlace.indexOf("javascript") == -1)&&(enlace.indexOf(host) != -1)) {
				// además que no se añada a los enlaces "falsos" y a los que no tienen otros parámetros
				if ((enlace.indexOf("?") != -1)&&(enlace.indexOf("#") == -1)) {
					document.links[i].href=document.links[i].href+'&r='+screenW+'*'+screenH;
				}
			}
		}
	}
}

function inicio(iResolucion){
	resolucion(iResolucion);
	//window.alert(document.location.href);
	obtenerResolucionLinks(iResolucion);
}