var xhr = null;
function getXhr(){
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
	else if(window.ActiveXObject){ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		xhr = false;
	}
}

function ajx_captcha(myForm,codefct){
	getXhr();
  	document.getElementById('cresultctrl').value=-1;
 	if(document.getElementById('cctrlimg').value!="")
  		document.getElementById('wait_captcha').innerHTML="Code en cours de vérification...";
  	else
  		document.getElementById('wait_captcha').innerHTML="&nbsp;";

  	xhr.open("GET","crypt/verifier.php?code="+myForm.cctrlimg.value,true);
  	xhr.send(null);
  	
  	// On défini ce qu'on va faire quand on aura la réponse
  	xhr.onreadystatechange = function(){
  		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
  		if(xhr.readyState == 4){
  			if(xhr.status == 200){
  				document.getElementById('cresultctrl').value = xhr.responseText;
  				if(xhr.responseText==0){
  				  	if(document.getElementById('cctrlimg').value!="")
  						document.getElementById('wait_captcha').innerHTML="Votre code est incorrect";
  				}
  				else
  					document.getElementById('wait_captcha').innerHTML="Code correct";
				if(codefct == 1)
					validFormOr(myForm);
				if(codefct == 2)
					validFormAvis(myForm);
				if(codefct == 3)
					validFormProposer(myForm);
				if(codefct == 4)
					validFormAmi(myForm);
  			}
  		}
  	}

	return false;
}

