// XmlHttpRequest Class By Kwisatz 2005

XhrArray = new Array();

function    XhrStatusChange()
{
  for (var i = 0; i < XhrArray.length; ++i)
    if (XhrArray[i].req && XhrArray[i].req.readyState == 4)
    {
      if (XhrArray[i].div)
      {
        if (XhrArray[i].req.status == 200)
        {
    			if (!XhrArray[i].append)
    			  document.getElementById(XhrArray[i].div).innerHTML = XhrArray[i].req.responseText;
    			else
    			  document.getElementById(XhrArray[i].div).innerHTML += XhrArray[i].req.responseText;
        }
        else
          document.getElementById(XhrArray[i].div).innerHTML = 'Connection Impossible...';
       }
      XhrArray[i].clear();
      if (XhrArray[i].func)
        XhrArray[i].func();
    }
}

xhr = function()
{
  this.req = 0;
  this.page = '';
  this.mod = 'POST';
  this.div = 'contenu';
  this.cache = 0;
  this.func = 0;
  this.append = false;
  this.data = '';
  XhrArray.push(this);

  this.clear = function()
  {
    this.data = '';
    this.req = 0;
  }

  this.setFuncData = function(func)
  {
    this.func = func;
  }

  this.setAppend = function(flag)
  {
    this.append = flag;
  }

  this.setDiv = function(div)
  {
    this.div = div;
  }

  this.setPage = function(page)
  {
    this.page = page;
  }

  this.setPost = function()
  {
    this.method = 'POST';
  }

  this.setData = function(data)
  {
    this.data = data;
  }

  this.setGet = function()
  {
    this.method = 'GET';
  }

  this.post = function()
  {
    if (window.XMLHttpRequest)
      this.req = new XMLHttpRequest();
    else if (window.ActiveXObject)
      this.req = new ActiveXObject('Microsoft.XMLHTTP');
    else
      return;

    this.req.onreadystatechange = XhrStatusChange;
    this.req.open(this.mod, this.page, true);
    if (this.method == 'POST') {
			this.req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		  this.req.send(this.data);
		}
	  else
      this.req.send(this.cache++);
  }
}