var timer_ajax;
var nb_timer = 0;
//************** init ajax ********************

function ajax_(fichier)
{
          timer_ajax = setTimeout("ajax_('"+fichier+"')",3000);
          nb_timer++;
          //var get_ = Math.random();
          //var get2_ = Math.random();
		  fichier += "&ch_en_cours_img="+ch_en_cours_img;//+"&rd=" + get_ + get2_;
          //alert(fichier);
          if(window.XMLHttpRequest) // FIREFOX
              xhr_object = new XMLHttpRequest();
          else if(window.ActiveXObject) // IE
              xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
          else
              return(false);
          xhr_object.open("GET", fichier, false);
          xhr_object.send(null);
          if(xhr_object.readyState == 4) {
            clearTimeout(timer_ajax);
            nb_timer = 0;
            return(xhr_object.responseText);
          }
          else {
            nb_timer++;
            if (nb_timer > 3) {
                nb_timer = 0;
                clearTimeout(timer_ajax);
                alert("Une erreur s'est produite, veuillez renouveller votre action");
                return(false);
            }
          }
}

function sendData(data, page, method, content, fct)
{
	data += "&ch_en_cours_img="+ch_en_cours_img;
    if(document.all) {
        //Internet Explorer
        var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
    }
    else {
        //Mozilla
        var XhrObj = new XMLHttpRequest();
    }

    //si on envoie par la méthode GET:
    if(method == "GET") {
        if(data == 'null') {
            XhrObj.open("GET", page);
        }
        else {
            XhrObj.open("GET", page+"?"+data);
        }
    }
    else if(method == "POST") {
        XhrObj.open("POST", page);
    }

	XhrObj.onreadystatechange = function() {
		if (XhrObj.readyState == 4 && XhrObj.status == 200) {
			if (content != null) {
				content.innerHTML = unescape(XhrObj.responseText) ;
			}
			if (fct != null) eval(fct);
			content = "";
			content = null;
		}
	}

    if(method == "GET") {
        XhrObj.send(null);
    }
    else if(method == "POST") {
        XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        XhrObj.send(data);
    }
}
