// Las siguientes variables contienen el navegador. 

IE=(navigator.appName.indexOf('Microsoft') >= 0);
NS=(navigator.appName.indexOf('Netscape') >= 0);
OP=(navigator.userAgent.indexOf('Opera') >= 0);
V4=(parseInt(navigator.appVersion) >= 4);
V5=(parseInt(navigator.appVersion)>=5);
V5=(V5||navigator.appVersion.indexOf("MSIE 5")!=-1);
V5=(V5||navigator.appVersion.indexOf("MSIE 6")!=-1);
MAC=(navigator.userAgent.indexOf('Mac')!=-1);
FF=(navigator.userAgent.indexOf('Firefox')!=-1);


/********* funciones AJAX *********/
	
var objXmlHttp=null;

function respuestaAJAX () {
}

function peticionAJAX (valor) {
// Se hace la peticion mediante el objeto XMLHTTPRequest del cambio de color o el tamaño de fuente
	var URI = "../scripts/aaa.php";

	var myRandom=parseInt(Math.random()*99999999);  
		
	if (navigator.userAgent.indexOf("MSIE")>=0)	{ 
	// El navegador es MS Explorer.
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP"
		} 
		try { 
			objXmlHttp=new ActiveXObject(strName)
		} 	
		catch(e) { 
			alert("Error. Se ha de habilitar la ejecución de 'scripts'") 
			return 
		} 
	} 
	else {

//		if (navigator.userAgent.indexOf("Mozilla")>=0) {
		// El navegador no es explorer.
			objXmlHttp=new XMLHttpRequest()
//		}
	}
	objXmlHttp.onreadystatechange=respuestaAJAX;
	objXmlHttp.open("POST",URI + valor + "&random=" + myRandom, true);
	objXmlHttp.send(null);
}

function situarPagina (altoCuerpo, anchoCuerpo, yCuerpo) {
// Esta función reubica según la resolución de pantalla el tamaño de los diferentes elementos.

var anchoPagina = screen.availWidth;
var xTitulo = Math.max (((anchoPagina - anchoCuerpo)/2),170);
var anchoTitulo = anchoCuerpo;
 
  if (document.getElementById("titulo")) {
  		document.getElementById("titulo").style.width = anchoTitulo + "px";
  		document.getElementById("titulo").style.left = xTitulo + "px";
  		document.getElementById("titulo").style.top = 10 + "px";
  }
  if (document.getElementById("AAA")) {
	  	document.getElementById("AAA").style.width = 200 + "px";
	  	document.getElementById("AAA").style.left = xTitulo + anchoTitulo + 15 + "px";
//  		document.getElementById("AAA").style.left = Math.max (((anchoPagina-anchoCuerpo)/2) - 30 - 160,0) + "px";
  		document.getElementById("AAA").style.top = 30 + "px";
  }
  if (document.getElementById("color")) {
	  	document.getElementById("color").style.width = 80 + "px";
  		document.getElementById("color").style.left = xTitulo + anchoTitulo + 15 + "px";
//  		document.getElementById("color").style.left = Math.max (((anchoPagina-anchoCuerpo)/2) - 30 - 200,0) + "px";
  		document.getElementById("color").style.top = 5 + "px";
  }
  if (document.getElementById("idiomas")) {
	  	document.getElementById("idiomas").style.width = 96 + "px";
  		document.getElementById("idiomas").style.left = xTitulo + anchoTitulo + 15 + "px";
//  		document.getElementById("idiomas").style.left = Math.max (((anchoPagina-anchoCuerpo)/2) - 30 - 96,90) + "px";
  		document.getElementById("idiomas").style.top = 60 + "px";
  }
  if (document.getElementById("menu")) {
	  	document.getElementById("menu").style.width = 150 + "px";
	  	document.getElementById("menu").style.height = 260 + "px";
  		document.getElementById("menu").style.left = Math.max (((anchoPagina-anchoCuerpo)/2) - 30 - 150,0) + "px";
  		document.getElementById("menu").style.top = 150 + "px";
  }
  if (document.getElementById("situacion")) {
	  	document.getElementById("situacion").style.width = 350 + "px";
	  	document.getElementById("situacion").style.height = 85 + "px";
  		document.getElementById("situacion").style.left = Math.max (((anchoPagina-anchoCuerpo)/2) - 30 - 150,0) + "px";
  		document.getElementById("situacion").style.top = 5 + "px";
  }
  if (document.getElementById("acreditaciones")) {
	  	document.getElementById("acreditaciones").style.width = 150 + "px";
	  	document.getElementById("acreditaciones").style.height = 40 + "px";
  		document.getElementById("acreditaciones").style.left = Math.max (((anchoPagina-anchoCuerpo)/2) - 30 - 150,0) + "px";
  		document.getElementById("acreditaciones").style.top = 440 + "px";
  }
  if (document.getElementById("cuerpo")) {
	  	document.getElementById("cuerpo").style.width = anchoCuerpo + "px";
	  	document.getElementById("cuerpo").style.height = altoCuerpo + "px";
  		document.getElementById("cuerpo").style.left = Math.max (((anchoPagina-anchoCuerpo)/2),170) + "px";
  		document.getElementById("cuerpo").style.top = yCuerpo + "px";
  }
   if (document.getElementById("piePagina")) {
	  	document.getElementById("piePagina").style.width = anchoCuerpo + "px";
  		document.getElementById("piePagina").style.left = parseInt (document.getElementById("cuerpo").style.left) + "px";
  		document.getElementById("piePagina").style.top = altoCuerpo + parseInt (document.getElementById("titulo").style.top) + yCuerpo + "px";
  		document.getElementById("piePagina").style.height = 15 + "px";
  }
}

function cambiarColor (cambio) {
	switch (cambio) {
		case "bn":
  		if (document.getElementById("titulo")) {
  				document.getElementById("titulo").style.backgroundColor = "#ffffff";
  				document.getElementById("titulo").style.color = "#000000";
  		}
		  if (document.getElementById("piePagina")) {
	  			document.getElementById("piePagina").style.backgroundColor = "#ffffff";
  				document.getElementById("piePagina").style.color = "#000000";
 			}
  		if (document.getElementById("AAA")) {
	  			document.getElementById("AAA").style.backgroundColor = "#ffffff";
  				document.getElementById("AAA").style.color = "#000000";
		  }
 		 	if (document.getElementById("color")) {
	  			document.getElementById("color").style.backgroundColor = "#ffffff";
  				document.getElementById("color").style.color = "#000000";
  		}
 		 	if (document.getElementById("idiomas")) {
	  			document.getElementById("idiomas").style.backgroundColor = "#ffffff";
  				document.getElementById("idiomas").style.color = "#000000";
  		}
  		if (document.getElementById("menu")) {
	  			document.getElementById("menu").style.backgroundColor = "#ffffff";
	  			document.getElementById("menu").style.color = "#000000";
  		}
  		if (document.getElementById("situacion")) {
	  			document.getElementById("situacion").style.backgroundColor = "#ffffff";
	  			document.getElementById("situacion").style.color = "#000000";
  		}
  		if (document.getElementById("acreditaciones")) {
	  			document.getElementById("acreditaciones").style.backgroundColor = "#ffffff";
	  			document.getElementById("acreditaciones").style.color = "#000000";
  		}
  		if (document.getElementById("cuerpo")) {
  			document.getElementById("cuerpo").style.backgroundColor = "#ffffff";
  			document.getElementById("cuerpo").style.color = "#000000";
  		}
  		document.body.style.backgroundColor = "#ffffff";
  		document.body.style.color = "#000000";
  		var links = document.getElementsByTagName ("a");
  		var i=0;
  		for (i=0;i<links.length;i++) {
  			links[i].style.color  = "#000000";
  		}
			break;
		case "nb":
  		if (document.getElementById("titulo")) {
  				document.getElementById("titulo").style.backgroundColor = "#000000";
  				document.getElementById("titulo").style.color = "#ffffff";
  		}
		  if (document.getElementById("piePagina")) {
	  			document.getElementById("piePagina").style.backgroundColor = "#000000";
  				document.getElementById("piePagina").style.color = "#ffffff";
 			}
  		if (document.getElementById("AAA")) {
	  			document.getElementById("AAA").style.backgroundColor = "#000000";
  				document.getElementById("AAA").style.color = "#ffffff";
		  }
 		 	if (document.getElementById("color")) {
	  			document.getElementById("color").style.backgroundColor = "#000000";
  				document.getElementById("color").style.color = "#ffffff";
  		}
 		 	if (document.getElementById("idiomas")) {
	  			document.getElementById("idiomas").style.backgroundColor = "#000000";
  				document.getElementById("idiomas").style.color = "#ffffff";
  		}
  		if (document.getElementById("menu")) {
	  			document.getElementById("menu").style.backgroundColor = "#000000";
	  			document.getElementById("menu").style.color = "#ffffff";
  		}
  		if (document.getElementById("situacion")) {
	  			document.getElementById("situacion").style.backgroundColor = "#000000";
	  			document.getElementById("situacion").style.color = "#ffffff";
  		}
  		if (document.getElementById("acreditaciones")) {
	  			document.getElementById("acreditaciones").style.backgroundColor = "#000000";
	  			document.getElementById("acreditaciones").style.color = "#ffffff";
  		}
  		if (document.getElementById("cuerpo")) {
  			document.getElementById("cuerpo").style.backgroundColor = "#000000";
  			document.getElementById("cuerpo").style.color = "#ffffff";
  		}
  		document.body.style.backgroundColor = "#000000";
  		document.body.style.color = "#ffffff";
  		var links = document.getElementsByTagName ("a");
  		var i=0;
  		for (i=0;i<links.length;i++) {
  			links[i].style.color  = "#ffffff";
  		}
			break;
		case "color":
  		if (document.getElementById("titulo")) {
  				document.getElementById("titulo").style.backgroundColor = "#d8d9b9";
  				document.getElementById("titulo").style.color = "#800000";
  		}
		  if (document.getElementById("piePagina")) {
	  			document.getElementById("piePagina").style.backgroundColor = "#d8d9b9";
  				document.getElementById("piePagina").style.color = "#5d5d5d";
 			}
  		if (document.getElementById("AAA")) {
	  			document.getElementById("AAA").style.backgroundColor = "#d8d9b9";
  				document.getElementById("AAA").style.color = "#800000";
		  }
 		 	if (document.getElementById("color")) {
	  			document.getElementById("color").style.backgroundColor = "#d8d9b9";
  				document.getElementById("color").style.color = "#800000";
  		}
 		 	if (document.getElementById("idiomas")) {
	  			document.getElementById("idiomas").style.backgroundColor = "#d8d9b9";
  				document.getElementById("idiomas").style.color = "#800000";
  		}
  		if (document.getElementById("menu")) {
	  			document.getElementById("menu").style.backgroundColor = "#800000";
	  			document.getElementById("menu").style.color = "#ffffff";
  		}
  		if (document.getElementById("situacion")) {
	  			document.getElementById("situacion").style.backgroundColor = "#800000";
	  			document.getElementById("situacion").style.color = "#ffffff";
  		}
  		if (document.getElementById("acreditaciones")) {
	  			document.getElementById("acreditaciones").style.backgroundColor = "#d8d9b9";
	  			document.getElementById("acreditaciones").style.color = "#800000";
  		}
  		if (document.getElementById("cuerpo")) {
  			document.getElementById("cuerpo").style.backgroundColor = "#d8d9b9";
  			document.getElementById("cuerpo").style.color = "#5d5d5d";
  		}
  		document.body.style.backgroundColor = "#d8d9b9";
  		document.body.style.color = "#5d5d5d";
  		var links = document.getElementsByTagName ("a");
  		var i=0;
  		for (i=0;i<links.length;i++) {
  			links[i].style.color  = "#ffffff";
  		}
			break;
	}
	peticionAJAX ("?color=" + cambio);	
}

function ocultarMensaje () {
// Esta función oculta un mensaje.
 		document.getElementById("mensaje").style.visibility="hidden"
 		document.getElementById("mensaje").innerHTML=""
}

function mostrarMensaje (str) {
// Esta función muestra un mensaje.
 		document.getElementById("mensaje").style.visibility="visible"
 		document.getElementById("mensaje").innerHTML=str
}

// Si se cambia esta función debe modificarse también en pagina7.php.
function cambiarTamano (inc) {
// Esta función escribe el código HTML de cambio de tamaño de la fuente.
	var tamano;
	if (parseInt(document.getElementById("AAA").style.fontSize))
		tamano = parseInt(document.getElementById("AAA").style.fontSize)
	else
		tamano = 10;
	if (Math.abs (inc) > 1)
		tamano = inc;
	else
		tamano = tamano + inc;
		
	tamano = Math.min(tamano, 12);	
	tamano = Math.max(tamano, 10);	
	
	if (document.getElementById("cuerpo"))
			document.getElementById("cuerpo").style.fontSize = eval(tamano) + "pt";
	if (document.getElementById("menu")) 
			document.getElementById("menu").style.fontSize = eval(tamano) + "pt";
	if (document.getElementById("situacion")) 
			document.getElementById("situacion").style.fontSize = eval(tamano) + "pt";
	if (document.getElementById("linkPiePagina")) 
			document.getElementById("linkPiePagina").style.fontSize = eval(tamano) + "pt";
	if (document.getElementById("AAA")) 
			document.getElementById("AAA").style.fontSize = eval(tamano) + "pt";
			
	peticionAJAX ("?fuente=" + eval (tamano));
}

/********* pagina4.php *********/

function verificarCampos (listaIds, mensaje) {
// verifica que los campos que recibe como lista no estan vacíos
	var correcto = true;
	var ids = listaIds.split (",");
	var campo;
	for (campo in ids) 
		correcto = correcto && ((document.getElementById (ids [campo]).value)!="");
	if (!correcto)
		alert (mensaje);
	return correcto;
}
