function Xpost(url, p, id, onReady)
{
  var xmlhttp = false;
  var l;
  var content;

  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.substring(0,20).indexOf('Warning') <0 )
        {
          hideIbox();
          
          if (xmlhttp.responseText && l) l.innerHTML = xmlhttp.responseText;
          if (onReady)
          {
            //(xmlhttp.responseXML) ? onReady(xmlhttp.responseXML) : 
            onReady(xmlhttp.responseText);
          }
        }
        else
          alert ('Serverfout! Neem contact op met info@voetbaltravel.nl voor meer informatie.' + xmlhttp.responseText );
      }
    }
    xmlhttp.send(p);
  }
  catch(e)
  {
    alert ('XMLHTTP-fout: ' + e.name + ': ' + e.message);
  }
}

function XpostXML(url, p, id, onReady)
{
  var xmlhttp = false;
  var l;

  showIbox('#loading_content','', parseQuery('height=80&width=70') );

  if (id) 
  {
    l = document.getElementById(id);
//    l.innerHTML = '<img src="./pics/loading.gif" />';
  }

  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)
      {
        hideIbox();        
        if (onReady)
        {
          if ( !xmlhttp.responseXML )
          { 
            alert ('Geen XML ontvangen: ' + xmlhttp.responseText);
          }
          onReady(xmlhttp.responseXML);
        }
      }
    }
    xmlhttp.send(p);
  }
  catch(e)
  {
    alert ('XMLHTTP-fout: ' + e.name + ': ' + e.message);
  }
}

function XFormSubmit(f, id, myReady, xml)
{
  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 + '&';
      }

      if ( f[x].type == "select-multiple" )
      {
        p += f[x].name + '=';
        for ( i=0; i<f[x].options.length; i++ )
        {
          if ( f[x].options[i].selected == true )
          {
            p += f[x].options[i].value + ',';
          }
        }
        p += '&';
      }
      
      if (f[x].type == "radio" && f[x].checked)
      {
        p += f[x].name + '=' + f[x].value + '&';
      }


      else
      if (f[x].type == "input" || f[x].type == "text" || f[x].type == "textarea" || f[x].type == "hidden")
        p += f[x].name + '=' + (f[x].value) + '&';


//        p += f[x].name + '=' + encodeURIComponent(f[x].value) + '&';
      if  (f[x].type == "checkbox" && f[x].checked)
        p += f[x].name + '=' + f[x].value + '&';
    }
  }

  (xml) ? Xpost(url, p, id, myReady) : XpostXML(url, p, id, myReady);
}
