// JavaScript Modifié par Henri le 2011-10-06


function inscription(parent,mail) {
	
	var email=document.getElementById(mail).value;
	var div_news=document.getElementById(parent);
    var p_news=div_news.childNodes[3];
    var input_news=document.getElementById(mail);
	//alert(email);
	var xhr_object = null;
	if(window.XMLHttpRequest) // Firefox
	   xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
	   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   return;
	}

	xhr_object.open("GET", "inscription.php?value="+email, true);

	xhr_object.onreadystatechange = function() {

	   if(xhr_object.readyState!=0) {
		if(xhr_object.readyState<4) {
         // on ajoute un backroud loading pour le champ input email
         //alert(xhr_object.readyState);
         input_news.style.background="url(images/loading.gif)  no-repeat right";
		   
		    
	   }}	
	   if(xhr_object.readyState == 4) 
	   //alert(xhr_object.responseText);
		   var resultat=xhr_object.responseText;
	   //input_news.style.background="none";
	   //selon la reponseText,on affiche le message
	   if(resultat=="1"){
		  //alert(input_news.nextSibling.nodeName);
		   p_news.firstChild.nodeValue="votre email a été enregistré, vous allez recevoir un mail de confirmation";
		   p_news.setAttribute('class','newsletter_inscrit');
		   input_news.parentNode.removeChild(input_news.nextSibling);
		   input_news.parentNode.removeChild(input_news);
	   }
	   
	   if(resultat=="2") {
		  //alert(p_news.firstChild.nodeName);
		  p_news.firstChild.nodeValue="Email déja present dans la base de données";
		  p_news.setAttribute('class','newsletter_error');
		  input_news.style.background="none";
	   }
	   if(resultat=="3") {
		   p_news.firstChild.nodeValue="Email incorrecte";
			 p_news.setAttribute('class','newsletter_error');
	  }
		 
}

	xhr_object.send(null);
	
}
