//this script takes a single sort order (descending, ascending or alphabetical) and passes it via AJAX magicks to the category tagchart script
//it then updates the relevant div on the page with the results.
function taglistAjax(sort) {
	
	//the url of the tagchart script with the sort order appended
	var url='/interactive/taglist/taglist_include.php?sort='+sort;


	//create new xmlHttpRequest object, depending on whether compliant browser or crappy IE
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	//decide what function to use to process returned info from server
	request.onreadystatechange = taglist_processRequest;
	
	//send actual request to script using GET method
	request.open("GET", url, true);
	request.send(null);
	
}//end tagchartAjax(sort)



//this processes the AJAX states and stuff returned from server
function taglist_processRequest() {

	// 'catch' the 5 states AJAX can be in and do something in each state
	if(request.readyState == 0)
		document.getElementById('taglist_ajax').innerHTML = 'Uninitialized';

	if(request.readyState == 1)
		document.getElementById('taglist_ajax').innerHTML = "<p align=\"center\"><img src=\"/interactive/taglist/images/ajax_loading.gif\"/></p>"; //loading
/*
	if(request.readyState == 2)
		document.getElementById('categorylist_ajax').innerHTML = "Loaded!";
	if(request.readyState == 3)
		document.getElementById('categorylist_ajax').innerHTML = "Interacting...";
*/

	if(request.readyState == 4) {
		
		// if everything is okay
 		if (request.status==200) {
			//pass response from server into variable
		 	var response = request.responseText;
			document.getElementById('taglist_ajax').innerHTML = response;			
		 }
		 
		 else {
			 // if status != 200 there was an error.
			 var error_message = 'Problem retrieving the data: ' + xmlhttp.statusText
		}
	}
}// end taglist_processRequest()
