/*
  01/11/2004
  Archivo destinado a la gestión de los
  menús principal y secundario.
*/

//Función invocada en el onload de la página
//Manipula el menú
function CargarMenu(sMP, sMS){

 //Obtención de los puntos principales y secundarios
 var oDTSuperior = document.getElementById("MenuSuperior").getElementsByTagName("dl")[0].getElementsByTagName("dt");
 var oDDSuperior = document.getElementById("MenuSuperior").getElementsByTagName("dl")[0].getElementsByTagName("dd");
 var oDTInferior = document.getElementById("MenuInferior").getElementsByTagName("dl")[0].getElementsByTagName("dt");
 var oDDInferior = document.getElementById("MenuInferior").getElementsByTagName("dl")[0].getElementsByTagName("dd");

 //Tratamiento del primer y el último punto de menú principal
 //a fin de que no le aparezca el borde
 //Para el Menú del portal
 oDTSuperior[0].style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorstr=#C2CBD4, endColorstr=#CAD3DC, gradienttype=0)";
 oDTSuperior[oDTSuperior.length-1].style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorstr=#CAD3DC, endColorstr=#C2CBD4, gradienttype=0)";
 oDTSuperior[0].style.borderTop = "none";

 //Para el Menú del Plan URBAN
 oDTInferior[0].style.borderTop = "none";
 oDTInferior[oDTInferior.length-1].style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorstr=#CAD3DC, endColorstr=#C2CBD4, gradienttype=0)";

 //Tratamiento de los botones de Servicios Generales
 oServicioVolver = document.getElementById("ServicioVolver");
 oServicioVolver.style.visibility = "visible";

 if(navigator.appName!="Netscape"){
   oServicioFavoritos = document.getElementById("ServicioFavoritos");
   oServicioFavoritos.style.display = "inline";
 }

 oServicioImprimir = document.getElementById("ServicioImprimir");
 oServicioImprimir.style.display = "inline";

}

//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";
  }
 }

 //Cerrar los puntos de MS abiertos (si existen)
 var oDD = document.getElementById("MenuInferior").getElementsByTagName("dl")[0].getElementsByTagName("dd");
 for(i=0;i<oDD.length;i++){
  oDD[i].style.display = "none";
 }

}

//Una vez hecho clic sobre un punto de menú principal,
//se tratan sus puntos de menú secundario. Área URBAN.
function GestionarMenuInferior(oPMP){

 var iPMP = oPMP.id.split("-")[1];
 var oDD = document.getElementById("MenuInferior").getElementsByTagName("dl")[0].getElementsByTagName("dd");

 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 MP abiertos
 var oDD = document.getElementById("MenuSuperior").getElementsByTagName("dl")[0].getElementsByTagName("dd");
 for(i=0;i<oDD.length;i++){
  oDD[i].style.display = "none";
 }

}

function CambiarFondo(esto,iEstado){
 if(iEstado == 0){
  esto.style.backgroundColor = "#EAEAE0";
 } else {
  esto.style.backgroundColor = "#FEFDFD";
 }

}

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";

}

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, iIdidioma){
	resolucion(iResolucion);
	//window.alert(document.location.href);
	obtenerResolucionLinks(iResolucion);
	imgAdjuntas(iIdidioma)
}

//--------------------------------------------------------------
function imgAdjuntas(iIdidioma){
	 var imgs = document.getElementsByTagName("img");
	 for (var i=0; i<imgs.length; i++) {
		var img = imgs[i];
		var sClass = img.className
		if (sClass.indexOf("cursorAdjunto") != -1){

	   	if(iIdidioma==1){
	   		img.alt = img.alt+" (Se abre en ventana nueva)";
	   	}
	   	if(iIdidioma==2){
	   		img.alt = img.alt+" (Open in a new window)";
	   	}


	   }
	}

}