
var xmlHttp = false;
init();

function init() {
  if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
  }
}

function callServer() {
  if (xmlHttp.readyState!=0) {
    xmlHttp.onreadystatechange = function() {};
    xmlHttp.abort();
    xmlHttp = false;
    init();
  }
  
  document.getElementById("captcha_result").innerHTML = '';
  var url = "/scripts/captcha/verif.php?key="+document.getElementById("inputcaptcha").value;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);
}

function updatePage() {
  if(xmlHttp.readyState == 4) {
    response = xmlHttp.responseText;
    response = response+'';
    if (response==1) {
      document.getElementById("captcha_result").innerHTML = '<b><font color="green">Reponse OK</font></b>';
    } else {
      document.getElementById("captcha_result").innerHTML = '<b><font color="red">Reponse incorrect - corrigez svp</font></b>';
    }
  }
}