/*

sendRequest('te_vullen_div', 'naar_url.php', Array('get_waardes'), Array(this.value voor bv textfield waarde));
*/


function createRequestObject() {
  
     var req;
    
     if(window.XMLHttpRequest){
      req = new XMLHttpRequest();
     } else if(window.ActiveXObject) {
      req = new ActiveXObject("Microsoft.XMLHTTP");
     } else {
      req = NULL;
      alert('Probleem met het aanmaken van het XMLHttpRequest object');
     }
    
     return req;
    
  }
    
    var http = createRequestObject();
    
    /* BEGIN IE BUG FIX */
    
    var aDiv = new aDiv();
    
    function setDiv(theDiv) {
    
    this.theDiv = theDiv;
    
  }
  
  function getCurrentDiv() {
  
    if(this.theDiv != "") { 
		//document.getElementById(aDiv.getCurrent()).innerHTML = "Bezig met ophalen ...";
    	return this.theDiv;
	}
    else
      alert('Geen div geset');
  
  }
    
    function aDiv(theDiv) {
    
    this.theDiv = theDiv || '';
    this.set = setDiv;
    this.getCurrent = getCurrentDiv;
    
  }
    
    /* EIND IE BUG FIX */
    
    function sendRequest(theDiv, page, gets, values) {
    	
		
       if(gets.length != values.length) {
          alert('sendRequest: arg3 and arg4 != length');
       } else {
    
       var pageString = page +'?';
    
       aDiv.set(theDiv);
	   
       for (i = 0; i < gets.length; i++) {
        pageString += gets[i] +'='+ values[i] +'&';
       }
	   //document.getElementById(theDiv).innerHTML = "Bezig met ophalen ...";
       http.open('get', pageString);
       http.onreadystatechange = handleResponse;
       http.send(null);
       
    }
    
    }
    function handleResponse() {
    	
       if(http.readyState == 4 && http.status == 200){
          if(http.responseText) {
             //if(document.getElementById(aDiv.getCurrent()).innerHTML == "Bezig met ophalen ..." || 	document.getElementById(aDiv.getCurrent()).innerHTML == ""){
			 	document.getElementById(aDiv.getCurrent()).innerHTML = http.responseText;
				//alert('ok');
			 /*}
			 else {
				 document.getElementById(aDiv.getCurrent()).innerHTML = ""
			 }*/
          } 
		  else {
             document.getElementById(aDiv.getCurrent()).innerHTML = "Fout bij ophalen reacties";
          }
    
       } 
	   else {
          document.getElementById(aDiv.getCurrent()).innerHTML = "Bezig met ophalen ...";
       }
    
    }
	
	
	
	
	
	


// xml POST form
function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    var form     = document.forms['f1'];
    //var word = form.word.value;
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
    //document.getElementById("result").innerHTML = str;
}

function closeDivs(divs){
	for(var i=0; i<divs.length; i++){
		document.getElementById(divs[i]).innerHTML = "";
	}
}