/*
The taro AJAX template

By John Bakker. You may not use this for your own stuff unless you have my written (letter) permission.

*/


/* base 64 encoding nodig voor de libary */
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="                                             ;
function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
}
function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);


   return output;
}
function decode64(inp)
{
var out = ""; //This is the output
var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
var i = 0; //Position counter
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
var base64test = /[^A-Za-z0-9\+\/\=]/g;
if (base64test.exec(inp)) { //Do some error checking
alert("There were invalid base64 characters in the input text.\n" +
"Valid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?\n" +
"Expect errors in decoding.");
}
inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do { //Here’s the decode loop.
//Grab 4 bytes of encoded content.
enc1 = keyStr.indexOf(inp.charAt(i++));
enc2 = keyStr.indexOf(inp.charAt(i++));
enc3 = keyStr.indexOf(inp.charAt(i++));
enc4 = keyStr.indexOf(inp.charAt(i++));
//Heres the decode part. There’s really only one way to do it.
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
//Start to output decoded content
out = out + String.fromCharCode(chr1);
if (enc3 != 64) {
out = out + String.fromCharCode(chr2);
}
if (enc4 != 64) {
out = out + String.fromCharCode(chr3);
}
//now clean out the variables used
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < inp.length); //finish off the loop
//Now return the decoded values.
return out;
}



/* wat hulp functietjes*/
function getFirstAncestorByClassName(target,className) {
    var parent = target;
    while (parent = parent.parentNode) {
        if (hasClassName(parent,className)) {
            return parent;
        }
    }
    return null;
}
/* een eval functie om de functie uit te voeren*/
function readyhandle(tclass)
{

  eval('t = '+tclass);

  t.ready();
}
function TaroAJAX()
{
    this.Debug =0;
    this.Version ='1';
    this.xmlhttp=false;
    this.Sourcefile='empty.html';
    this.onReadyresponsecommand = 'this.doExecute(this.xmlhttp.responseText)';
    this.onFailresponsecommand = 'this.ReportFail(this.xmlhttp.responseText)';
    this.cn='';
    this.doctosend='';
   
    
    //if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
      //  this.xmlhttp = new XMLHttpRequest();
    //}
    if (window.XMLHttpRequest) { // Non-IE browsers

      this.xmlhttp = new XMLHttpRequest();

  

    } else if (window.ActiveXObject) { // IE

      this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

     

    }

    
    
    
    
}

TaroAJAX.prototype.doRequest = function()
{
 var url
 url = this.Sourcefile;
 this.xmlhttp.open("GET", url,true);

 eval('this.xmlhttp.onreadystatechange= function() {\nreadyhandle(\''+this.cn+'\');\n }');
 
  
 this.xmlhttp.send(null);
}
TaroAJAX.prototype.doPost = function()
{
 var url
 url = this.Sourcefile;
 
 this.xmlhttp.open("POST", url,true);
 //alert('test');
// alert(this.cn);
 eval('this.xmlhttp.onreadystatechange= function() {\nreadyhandle(\''+this.cn+'\');\n }');
 this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

 this.xmlhttp.send(this.doctosend);
}

TaroAJAX.prototype.ready = function()
{
 
  if (this.xmlhttp.readyState==4) {
  eval(this.onReadyresponsecommand);
  }
 }
TaroAJAX.prototype.doExecute = function(source)
{
    eval(source);

}
TaroAJAX.prototype.ReportFail = function(source)
{

    if(this.Debug==1)
    {
    alert('Request failed:'+this.xmlhttp.getAllResponseHeaders()+'\n===========\n'+source);
    }

}
