
function PonCursor() {
    document.getElementById("email").focus();
    document.getElementById("email").value = GetCookie("emailcomprador", document.cookie);
}

function Chequea() {
    var email = document.getElementById("email");
    var Texto = document.getElementById("texto");
    var Sigue = true;
    var a = 0;
    var CuentaArroba = 0;
    var PosArroba = -1;
    var CuentaPunto = 0;
    var PosPunto = -1;
    var CuentaDominio = 0;
    
    document.getElementById("id_enviar").disabled = true;
    
    if(email == null || email.value == "") {
        PonMensaje("Introduzca email");
        Sigue = false;
    }
    if(Sigue) {
        //comprobar que la direccion esté bien introducida
        if(email.value.charAt(0) == '@') {
            Sigue = false;
        }
        for(a = 0; a < email.value.length; a++) {
            if(email.value.charAt(a) == '@') {
                CuentaArroba++;
                PosArroba = a;
            }
        }
        if(CuentaArroba != 1) {
            Sigue = false;
        }
        
        //mirar si el nombre de usuario está bien
        if(Sigue) {
            Sigue = false;
            for(a = 0; a < PosArroba; a++) {
                if(email.value.charAt(a) >= 'a' && email.value.charAt(a) <= 'z') {
                    Sigue = true;
                }
            }
        }

        if(PosArroba != -1) {
            for(a = PosArroba; a < email.value.length; a++) {
                if(email.value.charAt(a) == '.') {
                    CuentaPunto++;
                    PosPunto = a;
                }
            }
        }
        if(CuentaPunto != 1) {
            Sigue = false;            
        }

        if(PosPunto != -1) {
            for(a = PosPunto + 1; a < email.value.length; a++) {
                CuentaDominio++;
            }
        }
        if(CuentaDominio < 2) {
            Sigue = false;
        }
        
        if(!Sigue) {
            PonMensaje("Introduzca una dirección de correo válida.")
        }
    }
    
    //si no introdujo o introdujo mal el email poner el cursor en ese campo
    if(!Sigue) {
        email.focus();
    }
    
    //comprobar si puso algo en el texto
    if(Sigue) {
        if(Texto.value.length == 0) {
            Sigue = false;
            PonMensaje("Introduzca un texto para contactar con Huella");
            Texto.focus();
        }
    }
    
    //enviar finalmente el formulario al servidor
    if(Sigue) {
        document.getElementById("enviando").style.visibility = "visible";
        return true;
    } else {        
        document.getElementById("id_enviar").disabled = false;        
        return false;
    }
}

function PaginaPrincipal() {
    document.location = "index.jsp";
}

function GetCookie (name, InCookie) {
    var prop = name + "="; 
    var plen = prop.length;
    var clen = InCookie.length;
    var i=0;
    if (clen>0) { 
        i = InCookie.indexOf(prop,0); 
        if (i!=-1) { 
            // Buscamos el valor correspondiente
            j = InCookie.indexOf(";",i+plen);
            if(j!=-1) 
                return unescape(InCookie.substring(i+plen,j));
            else 
                return unescape(InCookie.substring(i+plen,clen));
        }
        else {
            return "";
        }
    }
    else {
        return "";
    }
}

