var READY_STATE_COMPLETE=4;
var peticion_http = null;

function inicializa_xhr() 
{
    if (window.XMLHttpRequest) 
    {
        return new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) 
    {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }   
}

function crea_query_string() 
{
    var usuario = document.getElementById("usuario");
    return "usuario=" + usuario.value + "&nocache=" + Math.random();
}

function valida(url) 
{
    if(jcap()==true){
    peticion_http = inicializa_xhr();
    if(peticion_http) 
    {
        document.getElementById("encuesta").innerHTML = "procesando...";
        peticion_http.onreadystatechange = procesaRespuesta;
        peticion_http.open("POST", url, true);
        var query_string = crea_query_string();
        peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        peticion_http.send(query_string);
    }
    
    }
}

function procesaRespuesta() 
{
    if(peticion_http.readyState == READY_STATE_COMPLETE) 
    {
        if (peticion_http.status == 200) 
        {
            document.getElementById("encuesta").innerHTML = peticion_http.responseText;
            document.getElementById("formulario").style.display='none';
        }
    }
}