/*
  01/11/2004
  Archivo destinado a la gestión de los
  menús principal y secundario.
*/

function ActivarCursor(oImagen){

 oImagen.style.cursor = "pointer";

}


//Función invocada en el onload de la página
//Manipula el menú

function CargarMenu(sMP, sMS){
	
	//Tratamiento de los botones de Servicios Generales
 oServicioImprimir = document.getElementById('ServicioImprimir');
 oServicioImprimir.style.display = 'block';
 oServicioVolver = document.getElementById('ServicioVolver');
 oServicioVolver.style.display = 'block';
	
 //Obtención de los puntos principales y secundarios
 //Portal
 var oDTSuperior = document.getElementById("navegacion").getElementsByTagName("dl")[0].getElementsByTagName("dt");
 var oDDSuperior = document.getElementById("navegacion").getElementsByTagName("dl")[0].getElementsByTagName("dd");

 if(document.getElementById("navegacion").getElementsByTagName("dl")[1]){
	 var oDTMedio = document.getElementById("navegacion").getElementsByTagName("dl")[1].getElementsByTagName("dt");
 	 var oDDMedio = document.getElementById("navegacion").getElementsByTagName("dl")[1].getElementsByTagName("dd");
 }

 if(document.getElementById("navegacion").getElementsByTagName("dl")[2]){ 
	 var oDTInferior = document.getElementById("navegacion").getElementsByTagName("dl")[2].getElementsByTagName("dt");
	 var oDDInferior = document.getElementById("navegacion").getElementsByTagName("dl")[2].getElementsByTagName("dd");
}


 //Recorrido de la lista de puntos de menú secundario del portal
 //En un principio se ocultan, y se le añaden eventos para modificar la apariencia
	for(i=0;i<oDDSuperior.length;i++){
		//Si coincide con el menú activo
		if(sMP==oDDSuperior[i].id.split("-")[1]){
			//Se muestran los hijos del menú principal activo
			oDDSuperior[i].style.display = "block";
			//Se ilummina el punto secundario
			if(sMS==oDDSuperior[i].id.split("-")[2]){
				oDDSuperior[i].setAttribute("onmouseout","");
				oDDSuperior[i].style.backgroundColor = "#EAEEF0";
			}
		} else {
			oDDSuperior[i].style.display = "none";
		}
	}
 
	if(oDDMedio){
		for(i=0;i<oDDMedio.length;i++){
			//Si coincide con el menú activo
			if(sMP==oDDMedio[i].id.split("-")[1]){
				//Se muestran los hijos del menú principal activo
				oDDMedio[i].style.display = "block";
				//Se ilummina el punto secundario
				if(sMS==oDDMedio[i].id.split("-")[2]){
					oDDMedio[i].setAttribute("onmouseout","");
					oDDMedio[i].style.backgroundColor = "#EAEEF0";
				}
			} else {
				oDDMedio[i].style.display = "none";
			}
		}
	}
 
 	if(oDDInferior){
		for(i=0;i<oDDInferior.length;i++){
			//Si coincide con el menú activo
			if(sMP==oDDInferior[i].id.split("-")[1]){
				//Se muestran los hijos del menú principal activo
				oDDInferior[i].style.display = "block";
				//Se ilummina el punto secundario
				if(sMS==oDDInferior[i].id.split("-")[2]){
					oDDInferior[i].setAttribute("onmouseout","");
					oDDInferior[i].style.backgroundColor = "#EAEEF0";
				}
			} else {
				oDDInferior[i].style.display = "none";
			}
		}
	}
}

//Una vez hecho clic sobre un punto de menú principal,
//se tratan sus puntos de menú secundario. Portal.
function GestionarMenu(oPMP,tipoMenu){

 var iPMP = oPMP.id.split("-")[1];
 var oDD = document.getElementById("navegacion").getElementsByTagName("dl")[tipoMenu].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";
  }
 }

 //Cerrar los puntos de MS abiertos (si existen)
 //Para el menú inferior
 var oDD = document.getElementById("navegacion").getElementsByTagName("dl")[0].getElementsByTagName("dd");
 for(i=0;i<oDD.length;i++){
 iDD = oDD[i].id.split("-")[1];
  if(iDD!=iPMP){
  oDD[i].style.display = "none";
  }
 }
 
 oDD = document.getElementById("navegacion").getElementsByTagName("dl")[1].getElementsByTagName("dd");
 for(i=0;i<oDD.length;i++){
 iDD = oDD[i].id.split("-")[1];
  if(iDD!=iPMP){
  oDD[i].style.display = "none";
  }
 }
 
 oDD = document.getElementById("navegacion").getElementsByTagName("dl")[2].getElementsByTagName("dd");
 for(i=0;i<oDD.length;i++){
 iDD = oDD[i].id.split("-")[1];
  if(iDD!=iPMP){
  oDD[i].style.display = "none";
  }
 }

}


function CambiarFondoMP(esto, iEstado){
 if(iEstado == 0){
  esto.style.backgroundColor = "#D2E1E8";
  esto.style.background = "#D2E1E8 url(../../img/comunes/menu/flechag.gif) no-repeat";
  
 } else {
  esto.style.backgroundColor = "#9DBDC5";
  esto.style.background = "#9DBDC5 url(../../img/comunes/menu/flechagSelecionada.gif) no-repeat";
 }
}


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 ValidarLogin(oForm){
	//Comprobación de la existencia de datos en la validación.
	var user, passwd

	user = (oForm.cajaTextoUsuario.value == '');
	passwd = (oForm.cajaTextoClave.value == '');

	if (user || passwd)
		return false;
	else
		return true;
}

// -------------------------------- 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);
	externalLinks();
	
}


//--------------------------------------------------------------------------------

function externalLinks(){ 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
