var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

var xhr = Class.create();
xhr.prototype = {
	//--- Methode = m, url = u, paramUrl = p
	//--- Function CallBack = c
	initialize: function (m,u,p,c){
	    //--- Objet supporté par le navigateur
	    this.http = this.getHTTPObject();
	    //--- méthode d'envoi des données : get ou post
	    this.methode = m;
	    //--- url de la page serveur appelée
	    this.url = u;
	    //--- Paramètres à transmettre à la page serveur appelée => forme de passage de param classique
	    this.paramUrl = p;
	    //--- Fonction appelée pour traiter le résultat
	    this.callBack = c;
	    // Donnée passée à la fonction send de l'objet ajax
	    this.data = null;
	},
	//--- Préparation des paramètres pour l'envoi
	setRequestInfo: function (){
	    if (this.methode == "POST"){
	    	this.headers = ["Content-type", "application/x-www-form-urlencoded"];
	    	this.data = this.paramUrl;
	    }
	    if (this.methode == "GET"){
	    	this.data = null;
	    	this.headers = null;
	    	this.url = this.url + "?" + this.paramUrl;
	    }
	},
	//--- Obtenir l'objet xmlhttp du navigateur
	getHTTPObject: function (){
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
	    try {
	      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	      } catch (e) {
	      try {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	        } catch (E) {
	        xmlhttp = false;
	        }
	      }
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	    try {
	      xmlhttp = new XMLHttpRequest();
	      } catch (e) {
	      xmlhttp = false;
	      }
	    }
	  return xmlhttp;
	},
	//--- Envoyer la requete
	Request: function (){
		//--- Définir les paramètres d'envoi
		var http = this.getHTTPObject();
		this.setRequestInfo();
		//--- Envoi
		http.callback = this.callBack;
		http.x = this.callBack;
		http.onreadystatechange = function (){
	    		//document.getElementById("buffer").innerHTML += http.readyState + "<br>";
	    		if (http.readyState == 4 && http.status == 200) {
	       		   	result = http.responseText;
       			   	//alert(http.x);
       			   	//alert(result);
       			   	if (http.x != null){
       			   	    eval(http.x+"(\""+result+"\")");
       			   	}else{
       			   	    eval(result);
       			   	 }
	    	    	}
		}
		http.open(this.methode,this.url,true);
		if (this.headers != null){
			http.setRequestHeader(this.headers[0],this.headers[1]);
		}
    		http.send(this.data);
	}
}