var x = 0;
var myRequest = new Array();

function controlloDati(){
    applyFog();
    x++;
    var kgoCaptcha = document.getElementById('kgoCaptcha').value;
    var r = Math.random();
    myRequest[x] = CreateXmlHttpReq(function() {myVerificaHandler(x)});
    myRequest[x].open("GET","kgoModules/scripts/php/checkCaptcha.php?r=" + escape(r) + "&kgoCaptcha=" + escape(kgoCaptcha));
    myRequest[x].send(null);
}

function myVerificaHandler(x) {
    if (myRequest[x].readyState == 4 && myRequest[x].status == 200) {
        mySo = myRequest[x].responseText;
        if(mySo == 'ok'){
            controlloDati2();
        }else{
            alert('Ricopiare il Codice di Sicurezza nel campo apposito.');
            document.getElementById('kgoCaptcha').focus();
            document.getElementById('kgoCaptcha').value = '';
            cambiaCodice();
            stopLoading();
        }
    }
}

function controlloDati2(){
    var nome = document.getElementById('nome').value;
    var email = document.getElementById('email').value;
    var azienda = document.getElementById('azienda').value;
    var telefono = document.getElementById('telefono').value;
    var testo = document.getElementById('testo').value;
    if(azienda == ''){
        alert('Compilare il campo Azienda.');
        stopLoading();
        return false;
    }else if(nome == ''){
        alert('Compilare il campo Nome.');
        stopLoading();
        return false;
    }else if(telefono == ''){
        alert('Compilare il campo Telefono.');
        stopLoading();
        return false;
    }else if(testo == ''){
        alert('Compilare il campo Testo Libero.');
        stopLoading();
        return false;
    }else if(email == '' || (email.indexOf('@') < 1)){
        alert('Compilare il campo Email.');
        stopLoading();
        return false;
    }else if(!document.getElementById('privacy').checked){
        alert('Acconsentire al trattamento dei dati personali (privacy)');
        stopLoading();
        return false;
    }else{
        document.theForm.submit();
    }
}