function Xget(url, id, onReady, noCache)
{
  var l;
  var xmlhttp = false;
  l = document.getElementById(id);

// wat doen met het %-teken?

  if (window.ActiveXObject) xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   else xmlhttp = new XMLHttpRequest();

  if (!xmlhttp) return false;

  if (!noCache) url += "&hash=" + Math.random();

  try
  {
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
      {
        if (xmlhttp.responseText && l) l.innerHTML = xmlhttp.responseText;
        onReady(xmlhttp.responseText);
      }
    }
    xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlhttp.send(null);
  }
  catch(e)
  {
    alert ('XMLHTTP-fout: ' + e.name + ': ' + e.message);
  }
}

function Xpost(url, p, onReady, id)
{
  var xmlhttp = false;
  var l = false;
  
  if (id) l = document.getElementById(id);

  if (window.ActiveXObject) xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    else xmlhttp = new XMLHttpRequest();

  try
  {
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
    xmlhttp.onreadystatechange=onReady;
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
      {
        if (xmlhttp.responseText && l) l.innerHTML = xmlhttp.responseText;
        if (onReady)
        {
          //(xmlhttp.responseXML) ? onReady(xmlhttp.responseXML) : 
          onReady(xmlhttp.responseText);
        }
      }
    }
    xmlhttp.send(p);
  }
  catch(e)
  {
    alert ('XMLHTTP-fout: ' + e.name + ': ' + e.message);
  }
}

function XpostXML(url, p, onReady, id)
{
  var xmlhttp = false;
  var l;

  if (id) l = document.getElementById(id);

  if (window.ActiveXObject) xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    else xmlhttp = new XMLHttpRequest();

  try
  {
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
    xmlhttp.onreadystatechange=onReady;
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
      {
        if (onReady)
        {
          onReady(xmlhttp.responseXML);
        }
      }
    }
    xmlhttp.send(p);
  }
  catch(e)
  {
    alert ('XMLHTTP-fout: ' + e.name + ': ' + e.message);
  }
}

function Xswap(url, id, myReady)
{
  l = document.getElementById(id);

  if (l.innerHTML.length <= 1)
    Xget(url, id, myReady, false);

  else
  {
    if (l.style.display == "") 
    {
      l.style.display = "none"
    }
    else
    {
      l.style.display = "";
    }
  }
}

function XFormSubmit(f, myReady, id)
{
  var p = "";
  var url = f.action;

  for (x=0; x<f.length; x++)
  {
    if (f[x].name)
    {
      if (f[x].type == "select-one")
      {
        p += f[x].name + '=' + f[x].options[f[x].selectedIndex].value + '&';
      }
      else
      if (f[x].type == "input" || f[x].type == "hidden")
        p += f[x].name + '=' + f[x].value + '&';
      if  (f[x].type == "checkbox" && f[x].checked)
        p += f[x].name + '=' + f[x].value + '&';
    }
  }

  if (Xpost(url, p, myReady, id)) return true;
}

// wrapper rond Xget voor RSH
/*
function Xgo( url, p, id, ready )
{
    var historyObj = {"params": [
            {"request": p}
        ]
    };

    dhtmlHistory.add( p, historyObj );
    historyStorage.put( 'param', 1 );
    historyStorage.toJSON( p );
  Xget(url + "?" + p, id, ready, false);
}
*/

function Xgo( url, p, id, ready )
{
    var historyObj = {"params": [
            {"request": p}
        ]
    };

    // historyString wordt door de historyengine gebruikt; mogen geen spaties inzitten
    historyString = p.replace(/\s/g, '_');
    dhtmlHistory.add( historyString, historyObj );
    historyStorage.put( 'param', 1 );
    historyStorage.toJSON( historyString );
  Xget(url + "?" + p, id, ready, false);
}