/*Tamano de texto*/
FUENTE_DEFAULT = 20;
FUENTE_ACTUAL = 9;
FUENTE_MASPEQUENA = 7;
FUENTE_MASGRANDE = 16;

function MasTxt(div) {
FUENTE_ACTUAL = FUENTE_ACTUAL+2;
    if (FUENTE_ACTUAL > FUENTE_MASGRANDE) {
    FUENTE_ACTUAL = FUENTE_MASGRANDE
    }
var divID = document.getElementById(div);
divID.style.fontSize = FUENTE_ACTUAL+"pt";
}

function MenosTxt(div) {
FUENTE_ACTUAL = FUENTE_ACTUAL-2;
    if (FUENTE_ACTUAL < FUENTE_MASPEQUENA) {
    FUENTE_ACTUAL = FUENTE_MASPEQUENA
    }
var divID = document.getElementById(div);
divID.style.fontSize = FUENTE_ACTUAL+"pt";
}
/*Tamano de texto*/

// Funciones que calcula el tamaño del ancho de la capa al valor 'porcentaje'      
function tamano_capas01(porcentaje) {
	document.getElementsByName("porcentaje01")[0].style.width = porcentaje + "%";
	return true;
}

function tamano_capas02(porcentaje) {
	document.getElementsByName("porcentaje02")[0].style.width = porcentaje + "%";
	return true;
}

function tamano_capas03(porcentaje) {
	document.getElementsByName("porcentaje03")[0].style.width = porcentaje + "%";
	return true;
}

/* Apartado del Mapa de imagen*/

function cargar(x, y, z, nombre, direccion, poblacion, telefono) {
	
	// Control de excepciones -> si no recibimos los valores por parámetro los inicializamos por defecto
	/*if (x == 0) {
		x = 38.994589;	
	};
	if (y == 0) {
		y = -1.851089;
	};
	if (z == 0) {
		z = 15;
	};	
	if (dir == "") {
		dir = "C/Plaza de Cervantes 15<br>Bajo - 02002<br>Albacete";
	};	*/
	
	x = parseFloat(x);
	y = parseFloat(y);
	z = parseFloat(z);

	// Nos hacempos la cadena a mostrar en el bocadillo de Google dependiendo de los valores que se nos pasen por parámetro
	cadenadir = "";
	if (nombre != "") { // recibimos el nombre
		cadenadir += "- " + nombre + " -";
	};
	if (direccion != "") { // recibimos la dirección
		cadenadir += "<br>" + direccion;
	};
	if (poblacion != "") { // recibimos la dirección
		cadenadir += "<br>" + poblacion;
	};
	if (telefono != "") { // recibimos la dirección
		cadenadir += "<br>" + telefono;
	};
	
if (GBrowserIsCompatible()) {
  var mapaAlbacete = new GMap2(document.getElementById("mapaAlbacete"));
  mapaAlbacete.addControl(new GSmallMapControl());
//  mapaAlbacete.addControl(new GMapTypeControl());
  mapaAlbacete.setCenter(new GLatLng(x, y), z); // 15 -> zoom
//mapaAlbacete.setCenter(new GLatLng(38.994589, -1.851089), 15); // 15 -> zoom
/*  mapaAlbacete.openInfoWindow(mapaAlbacete.getCenter(),
                   document.createTextNode("C/ Feria 121, 02006"));*/
// Creates a marker at the given point with the given number label
function createMarker(point, number) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(cadenadir);
	 //marker.openInfoWindowHtml("C/Plaza de Cervantes 15<br>Bajo - 02002<br>Albacete");
  });
  return marker;
}

var bounds = mapaAlbacete.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();

  var point = new GLatLng(x, y);
  //var point = new GLatLng(38.994589, -1.851089);
  mapaAlbacete.addOverlay(createMarker(point,2));
}
}

/* Apartado del Mapa de imagen*/

/*****************************************************************************************/
/******************************VALIDACIÓN DE LOS FORMULARIOS******************************/
/*****************************************************************************************/

// Función general que indica si todos los campos del primer formulario están rellenos
// Le pasamos a la función como variable booleana ficheros que determinará si es necesario cambiar el tipo de formulario a binario para el envío de ficheros o no
// En los campos tipo radio, suponemos que alguna de las opciones está seleccionada ( checked ) por defecto.
// En los campos tipo select, suponemos que la opción que no debe ser pasada tiene valor vacío ( value="" ). 
function validar(formu, archivos) {
    // Calculamos la longitud de elementos del formulario para recorrer el bucle
    longi = formu.elements.length;
    for (i = 0; i < longi; i++) {
        // Recuperamos el objeto del formulario que toque en cada bucle
        campo = formu.elements[i];
        // Para el caso en el que el campo sea de tipo texto
        if (campo.type == 'text' || campo.type == 'textarea') {
            if (campo.value == "") // No se ha rellenado -> mostramos el error
            {
                alert("Se debe rellenar el campo " + campo.name);
                return false;
            }
        }
        // Tipo de campo radiobutton (check)
        else if (campo.type == 'radio') {
            longiradio = campo.length;
            relleno = false;
            // Bucle que comprueba todos los radios y verifica que al menos uno esté activado
            for (j = 0; j < longiradio; j++) {
                if (campo[j].checked) {
                    relleno = true;
                }
                if (!relleno) {
                    alert("Se debe marcar alguna opción en el campo " + campo.name);
                    return false;
                }
            }
        }
        // Tipo de campo una selección única válida
        else if (campo.type == 'select-one') {
            if (campo.options[campo.selectedIndex].value == "") {
                alert("Se debe seleccionar una opción en el campo " + campo.name);
                return false;
            }
        }
    }
    // En la variable booleana controlamos si antes de hacer el submit del formulario tenemos que cambiar a tipo de envío binario por si usamos archivos
    if (archivos == 'true') {
        //	alert("ficheros == true");		
        //Cambiamos el tipo de codificación del formulario para que pueda enviar datos binarios, ya que va a enviar archivos
        formu.encoding = "multipart/form-data";
        formu.submit();
        return true;
    } else { // Formulario sin archivos
        //	alert("ficheros <> true");
        formu.submit();
        return true;
    }
}

// Función que se encarga de la validación del email
function IsEmailValid(mail) {
    var AtSym = mail.indexOf('@');
    var Period = mail.lastIndexOf('.');
    var Space = mail.indexOf(' ');
    var Length = mail.length - 1;   // Array is from 0 to length-1
    if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym + 1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length) ||             // Must be atleast one valid char after '.'
    (Space != -1))                    // No empty spaces permitted
    {
        //      alert('Por favor, inserta un e-mail con un formato válido');
        //    Temp.focus();
        return false;
    } else {
        return true;
    }
}

/* VALIDACION DE FORMULARIOS */

function validar_sugerencia(formulario) {
    // Comprueba el correo electrónico
    //if ((formulario.email.value.indexOf('@', 0) == -1) || (formulario.email.value.length < 5)) {
    var AtSym = formulario.email.value.indexOf('@');
    var Period = formulario.email.value.lastIndexOf('.');
    var Space = formulario.email.value.indexOf(' ');
    var Length = formulario.email.value.length - 1;         // Array is from 0 to length-1
    if ((AtSym < 1) ||                                      // '@' cannot be in first position
    (Period <= AtSym + 1) ||                                // Must be atleast one valid char btwn '@' and '.'
    (Period == Length) ||                                   // Must be atleast one valid char after '.'
    (Space != -1))                                          // No empty spaces permitted
    {
        alert("Escriba una dirección de correo válida en el campo \"Correo electrónico\".");
        formulario.email.focus();
        return (false);
    }
    // Comprueba que la longitud de la sugerencia es mayor de cuatro caracteres.
    if (formulario.comentarios.value=="") {
        alert("El campo \"Comentarios\" es obligatorio.");
        formulario.comentarios.focus();
        return (false);
    }

    // Comprueba si se aceptan las condiciones
    if (formulario.avisolegal.checked==false) {
        alert("Debe ACEPTAR el Aviso Legal y la Política de Privacidad.");
        return (false);
    }

    return (true);
}
