function AjaxRequest(url, query_string, callback) {
	if (query_string != "" && query_string.charAt(0) != "&") query_string = "&"+query_string; //make sure query string begins with "&"
	this.xmlhttp = this.initializeAjax();
	this.sendAndLoad(url, query_string, callback);
}

AjaxRequest.prototype.initializeAjax = function() {
	if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) { // code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

AjaxRequest.prototype.sendAndLoad = function(url, query_string, callback) { 
	try  {
		var xmlhttp = this.xmlhttp;
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) { //xmlhttp has received response
				var response = xmlhttp.responseText;
				callback(response);
			}
		};
		xmlhttp.open("GET", url+"?sid="+Math.random()+query_string, true); //NOTE: add on the Math.random() to the end as a variable to prevent caching
		xmlhttp.send(null);
	} catch(e) {
		this.reportAjaxError(e, url, "populating");
	}
}

AjaxRequest.prototype.reportAjaxError = function(err, url, action) {
	window.alert(err + " -- " + action);
}



function AjaxRequestPost(url, query_string, params, callback) { //when sending lots of data
	if (query_string != "" && query_string.charAt(0) != "&") query_string = "&"+query_string; //make sure query string begins with "&"
	this.xmlhttp = this.initializeAjax();
	this.sendAndLoad(url, query_string, params, callback);
}

AjaxRequestPost.prototype.initializeAjax = function() {
	if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) { // code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

AjaxRequestPost.prototype.sendAndLoad = function(url, query_string, params, callback) {
	try  {
		var xmlhttp = this.xmlhttp;
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) { //xmlhttp has received response
				var response = xmlhttp.responseText;
				callback(response);
			}
		};
		xmlhttp.open("POST", url+"?"+"sid="+Math.random()+query_string, true); //NOTE: add on the Math.random() to the end as a variable to prevent caching
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params);
	} catch(e) {
		this.reportAjaxError(e, url, "populating");
	}
}

AjaxRequestPost.prototype.reportAjaxError = function(err, url, action) {
	window.alert(err + " -- " + action);
}

