//--------------------------------------------
// AJAX Functions
//--------------------------------------------

function processReqChange() {

        try {
                ////console.log("state:"+this.req.readyState);
        } catch (e) {}

        if (this.req.readyState == 4) {         // quand le fichier est chargé
               

                if (this.req.status == 200) {                   // detécter problèmes de format


                        //eval(this.fonction_sortie+"(this.req.responseXML.documentElement)");
                       
                        eval(this.fonction_sortie+"(this.req.responseText)");
           
                } else {

                        alert("Il y avait un probleme avec le XML: " + this.req.statusText);

                }
        }
}
function AjaxRequest(url,fonction_sortie,params,id) {
   
        try {
        document.documentElement.style.cursor = "wait";

        this.url = encodeURI(url);
        this.fonction_sortie = fonction_sortie;
        this.params = params;
        this.id=id;

        var ajaxRequest = this;

    if (window.XMLHttpRequest) {

            this.req = new XMLHttpRequest();                                                                            // XMLHttpRequest natif (Gecko, Safari, Opera, IE7)

                this.req.onreadystatechange = function () { processReqChange(); }
                this.req.open("GET", this.url,true);
                this.req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
        this.req.send(null);

        } else if (window.ActiveXObject) {

            this.req = new ActiveXObject("Microsoft.XMLHTTP");                                           // IE/Windows ActiveX

        if (this.req) {
            this.req.onreadystatechange = this.req.onreadystatechange = function () { processReqChange(); }
            this.req.open("POST", this.url,false);
                        this.req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
            this.req.send(this.urlparams);
                }

    } else {

                alert("Votre navigateur ne connait pas l'objet XMLHttpRequest.");

        }
        } catch (e) {alert("ajax:AjaxRequest:url:"+url+" :"+e)}

        document.documentElement.style.cursor = "auto";

}
function AjaxRequestPost(url,urlparams,fonction_sortie,params,id) {
   
        document.documentElement.style.cursor = "wait";

        this.url = encodeURI(url);
        this.fonction_sortie = fonction_sortie;
        this.urlparams =encodeURI(urlparams);
        this.params = params;
        this.id=id;
        //alert(params);
 
        var ajaxRequest = this;

    if (window.XMLHttpRequest) {

            this.req = new XMLHttpRequest();                                                                            // XMLHttpRequest natif (Gecko, Safari, Opera, IE7)

                this.req.onreadystatechange = function () { processReqChange(); }
       
                this.req.open("POST", this.url,true);
                this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
        this.req.send(this.urlparams);


                try {
                //console.log("request: "+url);
                } catch (e) {}

        } else if (window.ActiveXObject) {

            this.req = new ActiveXObject("Microsoft.XMLHTTP");                                           // IE/Windows ActiveX

        if (this.req) {
            this.req.onreadystatechange = this.req.onreadystatechange = function () { processReqChange(); }
            this.req.open("POST", this.url,true);
                        this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
            this.req.send(this.urlparams);
                }

    } else {

                alert("Votre navigateur ne connait pas l'objet XMLHttpRequest.");

        }
        document.documentElement.style.cursor = "auto";

}



