var cl=new Object();

/*--- form saver object for cross-browser requests ---*/

function SaveForm(formname,ondone,url)
{
  var p = '';
  if (url==null)
     url = '../formhandler.ashx';
  for (var i=0;i<document.forms[0].elements.length;i++)
  {     
     el = document.forms[0].elements[i];
     if (el.type=='checkbox')
     {
        if (el.checked) p+='&' + el.name + '=on';
     }
     else if ((el.name!='__VIEWSTATE') && (el.name!='__EVENTVALIDATION') && (el.value!='') && (el.name!=''))
     {
        p += '&' + el.name + '=' + encodeURIComponent(el.value);
      }
  }
  new cl.ContentLoader(url + '?f=' + formname + p,ondone);
};

cl.ContentLoader=function(url,ondone)
{
  this.req=null;
  this.ondone=ondone;
  this.success=false;
  this.msg='';
  this.loadXMLDoc(url);
};

cl.ContentLoader.prototype.loadXMLDoc=function(url)
{
  if (window.XMLHttpRequest)
    this.req=new XMLHttpRequest();
  else if (window.ActiveXObject)
    this.req=new ActiveXObject("Microsoft.XMLHTTP");
  if (this.req)
  {
    try
    {
      var loader=this;
      this.req.onreadystatechange=function()
      {
        cl.ContentLoader.onReadyState.call(loader);
      };
      this.req.open('GET',url,true);
      this.req.send(null);
    }
    catch (err)
    {
      this.ondone.call(this);
    }
  }
};

cl.ContentLoader.onReadyState=function()
{
  var req=this.req;
  var ready=req.readyState;
  if (ready==4)
  {
    var httpStatus=req.status;
    this.msg = req.responseText;
    if ((httpStatus==200) || (httpStatus==0))
    {
      this.success = true;
      if (this.msg=='') this.msg='Bedankt';
    }
    else
    {
      this.success = false;
      if (this.msg=='') this.msg='Er is een fout opgetreden';
    }    
    this.ondone.call(this);
  }
};
