
// ----------------------------------------------------------------------------
//   __   _  __    __  _____    _____   _____   _____   _     _ 
//  |  \ | | \ \  / / |  _  \  /  _  \ |  _  \ | ____| | |   / /
//  |   \| |  \ \/ /  | |_| |  | | | | | | | | | |__   | |  / / 
//  | |\   |   \  /   |  _  /  | | | | | | | | |  __|  | | / /  
//  | | \  |   / /    | | \ \  | |_| | | |_| | | |___  | |/ /   
//  |_|  \_|  /_/     |_|  \_\ \_____/ |_____/ |_____| |___/    
//
// ----------------------------------------------------------------------------
//
// Script écrit par Cédric Nirousset (cedric@nyrodev.com)
//		Entreprise NyroDev : http://www.nyrodev.com
//
// Ce code est strictement réservé à son utilisation.
// Toute modifcation ou réutilisation est interdite par son auteur.
//
// Pour toutes questions, merci de me contacter.
//
// ----------------------------------------------------------------------------

function XRequest(call, async) {
 this.xhr = null;
 var moi = this;
 this.fctCallback = call;
 if (!async) {
  async = true;
 }
 this.async = async;

 if(window.XMLHttpRequest) {
  // Firefox
  this.xhr = new XMLHttpRequest();
 } else if (window.ActiveXObject) {
  // Internet Explorer
  try {
   this.xhr = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e) {
   this.xhr = new ActiveXObject("Msxml2.XMLHTTP");
  }
 } else {
  // XMLHttpRequest non supporté par le navigateur 
  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
  return; 
 }
 
 this.checkState = function() {
  var act = moi.fctCallback+'(';
  if (moi.xhr.readyState == 4) {
   if (moi.xhr.status == 200) {
    act+= moi.xhr.readyState;
   } else {
    // Erreur de chargement de fichier
    act+= '5';
   }
  } else {
   act+= moi.xhr.readyState;
  }
  act+= ');';
  eval(act);
 }
 
 this.getText = function() {
  return this.xhr.responseText;
 }
 
 this.getXML = function() {
  return this.xhr.responseXML;
 }
 
 this.getError = function() {
  return this.tabError[this.xhr.status];
 }
 
 this.envoi = function(filename,datas,method) {
  filename+= "?";
  if (method == null) {
   method = "GET";
  }
  var strData = "";
  if (datas != null) {
   for(data in datas) {
    strData+= data+"="+datas[data]+"&";
   }
  }
  this.xhr.onreadystatechange = this.checkState;
  if (method == "POST") {
   this.xhr.open(method, filename, true);
   this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   this.xhr.send(strData);
  } else {
   this.xhr.open(method, filename+strData, this.async);
   this.xhr.send(null);
  }
 }

 this.tabError = new Array();
 this.tabError[100] = "Continue";
 this.tabError[101] = "Switching protocols";
 this.tabError[200] = "OK";
 this.tabError[201] = "Created";
 this.tabError[202] = "Accepted";
 this.tabError[203] = "Non-Authoritative Information";
 this.tabError[204] = "No Content";
 this.tabError[205] = "Reset Content";
 this.tabError[206] = "Partial Content";
 this.tabError[300] = "Multiple Choices";
 this.tabError[301] = "Moved Permanently";
 this.tabError[302] = "Found";
 this.tabError[303] = "See Other";
 this.tabError[304] = "Not Modified";
 this.tabError[305] = "Use Proxy";
 this.tabError[307] = "Temporary Redirect";
 this.tabError[400] = "Bad Request";
 this.tabError[401] = "Unauthorized";
 this.tabError[402] = "Payment Required";
 this.tabError[403] = "Forbidden";
 this.tabError[404] = "Not Found";
 this.tabError[405] = "Method Not Allowed";
 this.tabError[406] = "Not Acceptable";
 this.tabError[407] = "Proxy Authentication Required";
 this.tabError[408] = "Request Timeout";
 this.tabError[409] = "Conflict";
 this.tabError[410] = "Gone";
 this.tabError[411] = "Length Required";
 this.tabError[412] = "Precondition Failed";
 this.tabError[413] = "Request Entity Too Large";
 this.tabError[414] = "Request-URI Too Long";
 this.tabError[415] = "Unsupported Media Type";
 this.tabError[416] = "Requested Range Not Suitable";
 this.tabError[417] = "Expectation Failed";
 this.tabError[500] = "Internal Server Error";
 this.tabError[501] = "Not Implemented";
 this.tabError[502] = "Bad Gateway";
 this.tabError[503] = "Service Unavailable";
 this.tabError[504] = "Gateway Timeout";
 this.tabError[505] = "HTTP Version Not Supported";
 
}
function encode(str) {
 str = escape(str);
 return str;
}
function decode(str) {
 str = unescape(str);
 return str;
}