
var reusable_remoteDoc;

reusable_init = function(urlList,parentList)
{
  var urls = urlList.split(";");
  var parents = new Array();
  if(parentList){ parents = parentList.split(";"); }
  for(var x = 0;x < urls.length;x++)
  {
    new reusable_document(urls[x], parents[x]);
  }
}

reusable_document = function(url,parent)
{
  this.parent = parent;
  this.load(url);
}

reusable_document.prototype.load = function(url)
{
  if (window.XMLHttpRequest)
  {  //Mozilla code
    this.remoteDoc=new XMLHttpRequest();
    this.remoteDoc.onreadystatechange = this.docStateChange.bind(this);
    this.remoteDoc.open("GET",url,true);
    this.remoteDoc.send(null);
  }
  else if (window.ActiveXObject)
  {  //IE code
    this.remoteDoc=new ActiveXObject("Microsoft.XMLHTTP")
    if (this.remoteDoc)
    {
      this.remoteDoc.onreadystatechange = this.docStateChange.bind(this);
      this.remoteDoc.open("GET",url,true)
      this.remoteDoc.send()
    }
  }
}

reusable_document.prototype.docStateChange = function()
{
  if (this.remoteDoc.readyState == 4)
  {
    if (this.remoteDoc.status == 200)
    {  //Status ok
      this.applyContent();
    }
  }
}

reusable_document.prototype.applyContent = function()
{
  if(this.parent)
  {
    document.getElementById(this.parent).innerHTML += this.remoteDoc.responseText;
  }
  else
  {
    document.body.innerHTML += this.remoteDoc.responseText;
  }
  delete this;
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function(arg1, arg2, arg3, arg4) {
    __method.apply(object, arguments);
  }
}

