function ajaxFunction() { 
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
	try {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	    try {
	        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {
	        alert("Your browser does not support AJAX!");
	        return false;
	    }
	}
    }

    return xmlHttp;
}


function createRequestObject(){
   var req;
   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }
   return req;
}


// Make the XMLHttpRequest array
var http_array = new Array();


function handleResponse(div){
	var i = 0;
	
	for(i=0;i<http_array.length;i++){
		if(http.readyState == 4 && http.status == 200){
		  // Text returned from PHP script
		  var response = http_array[i].responseText;	  
		  if(response) {
			 // delete array value
			 http_array.splice(i,1);
			 i--;
			 // Update ajaxTest content
			 document.getElementById(div).innerHTML = response;
		  }
		}
		
	}
}

function replaceChars(entry) {
	out = "&"; // replace this
	add = "<<amp;>>"; // with this
	temp = "" + entry; // temporary holder
	
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}


function search_festival(jaar, letter){	
	http = createRequestObject()
	
	var parameters = 'jaar='+jaar+'&letter='+letter;
	
	http.open('post', 'http://www.festivalinfo.nl/ajx/search_festival.php');
	
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	http.onreadystatechange = new Function("handleResponse('festival')");
	
	http_array.push(http);
}

