//use AJAX in a threadsafe manner
function callViaAJAX(url, method, parameters, callback){

	function stateChangeBindFunction(){
					
		if (xmlHTTP.readyState == 4) {

			if (xmlHTTP.status == 200) {

				if (stateChangeFunction){

					stateChangeFunction(xmlHTTP.responseText);
					
				} else {
					//alert('no callback defined');
				}
			} else {
				stateChangeFunction("There was a problem retrieving the data:\n" + xmlHTTP.status + ":\t" + xmlHTTP.statusText + "\n" + xmlHTTP.responseText);
			}
		} 
	}

	// use a local variable to hold our request and callback until the inner function is called...
	var xmlHTTP = null;
	var stateChangeFunction = callback;	

	// create XML request, set function to onreadystate change and send
	if (window.XMLHttpRequest) {
		// Non IE
		xmlHTTP = new XMLHttpRequest();
		
		xmlHTTP.onreadystatechange = stateChangeBindFunction;
		xmlHTTP.open(method, url, true);
		if (method=='POST') {
			xmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
			xmlHTTP.setRequestHeader("Content-length", parameters.length);
			xmlHTTP.setRequestHeader("Connection", "close");
			xmlHTTP.send(parameters);
		} else {
			xmlHTTP.send(null);
		}
		
	} else if (window.ActiveXObject) {
		//IE
		xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlHTTP) {
			xmlHTTP.onreadystatechange = stateChangeBindFunction;
			xmlHTTP.open(method, url, true);
			if (method=='POST') {
				xmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
				xmlHTTP.setRequestHeader("Content-length", parameters.length);
				xmlHTTP.setRequestHeader("Connection", "close");
				xmlHTTP.setRequestHeader("Connection", "close");
				xmlHTTP.send(parameters);
			} else {
				xmlHTTP.send();
			}
			
		}
	}
}


function canAJAX(){

	var xmlHTTP = null;
		
	if (window.XMLHttpRequest) {
		// Non IE
		xmlHTTP = new XMLHttpRequest();

		if (xmlHTTP) {
			return true;
		} else {
			return false;
		}
			
	} else if (window.ActiveXObject) {
		//IE
		var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.")!=-1) ? 1 : 0; 
		if (is_ie5 == 1) {
			//Assume no AJAX if IE 5.
			return false;
		}
		xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlHTTP) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
	
}

function doSomething(text) { 

alert(text); 

} 
