
// FUNCIONES GENERALES DE USO EN UNA WEB
// Requiere el archivo cabecera_visible.js para manejar capas

//inicializa_capas(); // Escribe el HTML de las capas, se le debe llamar desde el body con onload()

function abre_mapa (direccion) {
	document.getElementById("contenido").innerHTML='<iframe src="'+direccion+'" name="mapa" width=800 height=700 scrolling=no frameborder=0></iframe>';
	abrecapa();
}


function abrecapa () {
	idcapa=document.getElementById("capa_mapa");
	idcapa.style.visibility="visible";
	idcapa.style.display="block";
}

function cerrarcapa () {
	idcapa=document.getElementById("capa_mapa");
	idcapa.style.visibility="hidden";
	idcapa.style.display="none";
	document.getElementById("contenido").innerHTML="";
}

// *********************************************************************************************
// Funciones para comprobar cosas

function comprueba_form (formulario) {
	enviaok=0;
	elementoform=document.getElementById(formulario);
	if (elementoform.nombre.value=="") alert ("Por favor, inserte su nombre");
	else if (elementoform.telefono.value=="") alert ("Por favor, escriba su número de teléfono");
	else if (elementoform.poblacion.value=="") alert ("Debe escribir su población");
	else if (elementoform.provincia.value=="") alert ("¿De qué provincia es su población?");
	else if (elementoform.email.value=="") alert ("Debe escribir su correo electrónico");
	else if (elementoform.email.value!=elementoform.repemail.value) alert ("Debe escribir el mismo email en los dos recuadros");
	else if (elementoform.dni.value=="") alert ("Por favor, escriba su dni");
	else {
		if (comprueba_mail(elementoform.email.value)) enviaok=1;
		else alert ("El formato del correo electrónico es incorrecto");
	}
	if (enviaok==1) elementoform.submit();
}

function comprueba_mail(texto){ 

    var mailres = true;             
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
     
    var arroba = texto.indexOf("@",0); 
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
     
    var punto = texto.lastIndexOf("."); 
                 
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
     mailres = true; 
    else 
     mailres = false; 
                 
    return mailres; 
} 

// *********************************************************************************************
// Funciones para manejar capas

function capa_cerrar (id) {
	var capaescudo=document.getElementById('capa_escudo');
	capaescudo.style.display = 'none';
	capaescudo.style.visibility="hidden";
	
	var capa=document.getElementById(id);
	vista = (capa.style.display == 'none') ? 'block' : 'none';
	capa.style.display = vista;
	capa.style.visibility="hidden";
}

function capa_abrir (id,foto) {	
	xMoveTo("capa_escudo",0,xScrollTop());	
	document.getElementById('capa_escudo').style.display='block';
	document.getElementById('capa_escudo').style.visibility='visible';
	document.getElementById('img_foto_grande').src=foto;
	
	var capa=document.getElementById(id);
	vista = 'block';
	capa.style.display = vista;
	capa.style.visibility="visible";
	// centramos la capa con esto
	// requiere el archivo cabecera_visible.js
	xMoveTo(id,0,xScrollTop()+20);	
}


// *********************************************************************************************
// Funciones para abrir imagenes en las capas

function abreimg() {
	ruta=document.getElementById('misfotos').src;
	ruta=ruta.replace("miniaturas","imagenes");
	capa_abrir('capa_foto_grande',ruta);
}

function abrejpginmo() {
	ruta=document.getElementById('misfotos').src;
	capa_abrir('capa_foto_grande',ruta);
}


// *********************************************************************************************
// CAPAS NECESARIAS PARA PRESENTAR LAS IMAGENES

function inicializa_capas () {
	// Capa de google: capa_mapa_google
	// Capa de escudo: capa_escudo
	// Capa de imagenes: capa_foto_grande
	var h1 = document.createElement("h1");
	h1.innerHTML = '<div id="capa_mapa"  style="visibility:hidden;position: absolute; left: 0px; top: 100px; width: 100%; height: 100%;"><table align="center" width="800" border="0" cellpadding="0" cellspacing="3" bgcolor="#FFFFFF" style="border: 1px solid #336699"><tr><td align="right"><a href="javascript: cerrarcapa();"><font style="font-family: verdana; font-size: 10px; color: #000000">CERRAR (X)</font></a></td></tr><tr><td style="border: 1px solid #BFCDDD"><div id=contenido></div></td></tr></table></div><!-- CAPA DEL ESCUDO --><div id="capa_escudo" style="position: absolute; left: 0px; top: 0px; width:100%; height:100%; visibility:hidden;display:none;filter:alpha(opacity=80); opacity: 0.80; z-index:40; background-color: #333333"><table width="80%" height="100%" cellpadding="25" cellspacing="25" align="center"><tr><td width="100%" height="100%" style="border: 1px solid #333333">&nbsp;</td></tr></table></div><!-- CAPA DE LA FOTO --><div id="capa_foto_grande" style="position: absolute; left: 0px; top: 0px; width:100%; height:100%; visibility:hidden;display:none;z-index:80;"><table width="80%" height="80%" cellpadding="25" cellspacing="25" align="center"><tr><td align="center" valign="middle" width="100%" height="100%" style="border: 1px solid #000000"><img src="../images/blanco.gif" width=800 id="img_foto_grande" style="cursor:pointer" border="1" onClick="capa_cerrar(\'capa_foto_grande\');"/><br /><font face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF" size="1"><b>Pulse en la imagen para ocultar</b></font></td></tr></table>';
	document.body.appendChild(h1);
	//cambiafoto();
}

// *********************************************************************************************
// Browser Slide-Show script.
// With image cross fade effect for those browsers that support it.

var slideCache = new Array();

function RunSlideShow(pictureName,urldireccion,imageFiles,displaySecs)
{

var imageSeparator = imageFiles.indexOf(";");
var nextImage = imageFiles.substring(0,imageSeparator);
if (document.all) {
	document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
	document.getElementById(pictureName).filters.blendTrans.Apply();
}

document.getElementById(pictureName).src = urldireccion+ nextImage;
if (document.all) {
	document.getElementById(pictureName).filters.blendTrans.Play();
}

var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length) + ';' + nextImage;

setTimeout("RunSlideShow('"+pictureName+"','"+urldireccion+"','"+futureImages+"',"+displaySecs+")", displaySecs*1000);

// Cache the next image to improve performance.
imageSeparator = futureImages.indexOf(";");
nextImage = futureImages.substring(0,imageSeparator);
if (slideCache[nextImage] == null) {
	slideCache[nextImage] = new Image;
	slideCache[nextImage].src = nextImage;
}

}


