function nuevoAjax(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function envia(email){
    
    var mensaje = "";
    var correcto = true;
    var filter=/^[a-zA-Z0-9_.-]{2,}@[a-zA-Z0-9_.-]{2,}\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,4})?$/;
    
    if(document.frmContacta.email.value == ""){
        mensaje += "- Rellene el email \n";
        correcto = false;
    }else{
        if(!(filter.test(document.frmContacta.email.value))){
            mensaje += "- Indique un email correcto \n"; 
            correcto = false;             
        }  
    }
    
    if(!document.frmContacta.acepto.checked){
        mensaje += "- Acepte la Poltica de Privacidad \n";
        correcto = false;
    }
    
    if(!correcto){
        alert(mensaje);
        return false;
    }else{
        ajax=nuevoAjax();
        ajax.open("POST", "/include/envia.php",true);
        ajax.onreadystatechange=function() {
            if (ajax.readyState==4) {
                alert(ajax.responseText);
            }
        }
        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
        ajax.send("email=" + email);
    }
}
