//--------------------------------------------------------------

function inicio(iResolucion, iIdidioma){
	resolucion(iResolucion);
	obtenerResolucionLinks(iResolucion);
	imgAdjuntas(iIdidioma);
	externalLinks(iIdidioma);
	popupLinks(iIdidioma);
	CargarUtilidades();
}

// -------------------------------- 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;
				}
			}
		}
	}
}

//--------------------------------------------------------------

//Esta función modifica el alt de la imagenes que tiene imagen adjunta, advirtiendo que la amplicación se abrirá en ventana nueva
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)";
	   	}
	  }
	}
}

//--------------------------------------------------------------

//Como el atributo target no esta permitido usamos esta función para poder abrir enlaces en ventanas nuevas
//en el enlace debemos añadir el atributo rel="external", esta funcion lo detectará y pondrá el target mediante javascript

function externalLinks(iIdidioma){
 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"){
		   if(iIdidioma==1){
		   	anchor.title = anchor.title + " (Se abre en ventana nueva)";
		   }
		   if(iIdidioma==2){
		   	anchor.title = anchor.title + " (Open in a new window)";
		   }
       anchor.target = "_blank";
   }
 }
}

//--------------------------------------------------------------

//Como el atributo onclick no esta permitido usamos esta función para poder abrir enlaces en ventanas emergente
//en el enlace debemos añadir el atributo rel="popup", esta funcion lo detectará y pondrá el onclick mediante javascript

function popupLinks(iIdidioma){
 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") == "popup"){
		   if(iIdidioma==1){
		   	anchor.title = anchor.title + " (Se abre en ventana emergente)";
		   }
		   if(iIdidioma==2){
		   	anchor.title = anchor.title + " (Open in a popup window)";
		   }
       anchor.onclick = function() { window.open(this.href, null,"height=600,width=670,status=yes,toolbar=no,menubar=no,location=no"); return false; };
   }
 }
}


//--------------------------------------------------------------

//Esta función se encarga de mostrar las utilidades que utilizan javascript (que viene ocultas mediante css por defecto)
//además de mostrar los botones les añade el evento onclick con la funcion correspondiente,
//Esto es debido a que en el front utilizamos un <a href=""> para poder asignar un accesskey, a parte de que sería obligatorio usar eventos duplicados

function CargarUtilidades(){

	var oEnlace

	//Tratamiento de los botones de Servicios Generales
	oServicioImprimir = document.getElementById("servicioImprimir");
	if(oServicioImprimir){
		oServicioImprimir.style.display = "inline";
		oEnlace = oServicioImprimir.getElementsByTagName("A");
		oEnlace[0].href="javascript:Imprimir();"
	}

	oServicioVolver = document.getElementById("atajoVolver");
	if(oServicioVolver) {
		oServicioVolver.style.display = "inline";
		oEnlace = oServicioVolver.getElementsByTagName("A");
		oEnlace[0].href="javascript:volver();"
	}
	
}
//--------------------------------------------------------------

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 lanzarBusqueda() {
	if (document.getElementById("textobusqueda").value.length < 3) {
			alert("Debe introducir al menos 3 caracteres para poder realizar la búsqueda.");
			return false;
		}else{
			return true;
		}
}


function escribirFlash(sRuta,sAncho,sAlto,sColorFondo, sParametros, sStyle, FlashVars) {

      if (sColorFondo == "") {
            sColorFondo = '000000';
      } 

      if(navigator.appName=="Microsoft Internet Explorer") {
            var sGenerado = '<object type="application/x-shockwave-flash" width="' + sAncho + '"  height="' + sAlto + '" style="'+sStyle+'" >';
      } else {
            var sGenerado = '<object type="application/x-shockwave-flash" data="' + sRuta + '" width="' + sAncho + '"  height="' + sAlto + '" >';
      }

      sGenerado += '<param name="movie" value="' + sRuta + '" />';
	  sGenerado += '<param name="allowScriptAccess" value="sameDomain" />';
      sGenerado += '<param name="quality" value="high" />';
      //sGenerado += '<param name="bgcolor" value="#' + sColorFondo + '" />';
	  //sGenerado += '<param name="scale" value="noscale" />';
	  sGenerado += '<param name="salign" value="lt" />';
	  sGenerado += '<param name="wmode" value="opaque" />';
	  sGenerado += '<param name="flashVars" value="'+FlashVars+'" />';

      if (sParametros.indexOf(';')>-1) {
            var array_parametros = sParametros.split(';');
            for (var i=0; i<array_parametros.length-1; i++) {
            	sGenerado += '<param name="'+array_parametros[i].split("=")[0]+'" value="'+array_parametros[i].split("=")[1]+'" />';
            }
      }     

      sGenerado += '</object>';
	  
	  document.write(sGenerado);
}


