// vemos si es ie
IE='\v'=='v';



function validaCampo(id, valor_incorrecto, id_capa_error, mensaje_aviso, clase_error, id_capa_cargando){
	var valor = $("#"+id).val();
	valor = trim(valor);
		
	if (valor == valor_incorrecto) {
		$("#"+id_capa_error).html(mensaje_aviso)
		.css("display", "table-cell");
		$("#"+id).focus()
		.addClass(clase_error);
		$("#"+id_capa_cargando).css("display", "none");
		return false;
	}
	
	return true;
}

function expandir_terminos(){

    if(!IE) capa = document.getElementById("ver_terminos");
    capa.style.display = "none";

    if(!IE) capa = document.getElementById("ocultar_terminos");
    capa.style.display = "block";

    if(!IE) capa = document.getElementById("terminos");
    capa.style.display = "block";

}

function ocultar_terminos(){

    if(!IE) capa = document.getElementById("ver_terminos");
    capa.style.display = "block";

    if(!IE) capa = document.getElementById("ocultar_terminos");
    capa.style.display = "none";

    if(!IE) capa = document.getElementById("terminos");
    capa.style.display = "none";

}


function 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;
}

// devuelve true si el texto es un dni

function dni(texto) {

    numero = texto.substr(0,texto.length-1);

    let = texto.substr(texto.length-1,1);

    numero = numero % 23;

    letra='TRWAGMYFPDXBNJZSQVHLCKET';

    letra=letra.substring(numero,numero+1);

    if (letra!=let) {

        return false;

    }else{

        return true;

    }

}

function confirma(pagina){
	if(confirm('¿Está seguro?')){
		window.location=pagina;
	}	
}


// funcion que comprueba que una cadena esté compuesta sólo por números
function es_numerico(valor){
    
    // temporal
    return true;

//    for (i = 0; i < valor.length; i++) {
//        if(isNaN(valor[i])){
//            return false;
//        }
//    }
//    return true;
}

//función que convierte un valor en entero
//si el valor enviado no puede convertirse devuelve 0
function toInt(valor){
    //intento convertir a entero.
    //si era un entero no le afecta, si no lo era lo intenta convertir
    valor = parseInt(valor);

    //comprobamos si es un valor entero
    if (isNaN(valor)) {
        //no es entero 0
        return 0;
    }else{
        //es un valor entero
        return valor;
    }
}

// comprueba que la cadena tenga el formato xx/xx/xxxx
function comprueba_formato_fecha(cadena){

    if (cadena == undefined || cadena.value == "" ) return false;
    if (!/^\d{2}\/\d{2}\/\d{4}$/.test(cadena.value)) return false;

    return true;
}


    function trim(v)
    {
        return v.replace(/^\s+/i, '').replace(/\s+$/i, '');
    }



