ajax = Class.create();

ajax.prototype = {
	initialize: function(url, method, postBody, changeFunction, finishedFunction){
		this.method = method || 'post';
		this.changeFunction = changeFunction || "spinner";
		this.finishedFunction = finishedFunction || "spinner";
		this.postBody = postBody || "";
		this.transport = this.getTransport();
		this.request(url);
	},
	
	request: function(url){
		this.transport.open(this.method, url, true);
		this.transport.onreadystatechange = this.onStateChange.bind(this);
		if (this.method == 'post') {
			this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
		}
		this.transport.send(this.postBody);
	},
	
	onStateChange: function(){
		if (this.transport.readyState == 1) {
			eval(this.changeFunction);
		}
		else if (this.transport.readyState == 4 && this.transport.status == 200) {
			this.response = this.transport.responseText;
			eval(this.finishedFunction);
			this.transport.onreadystatechange = function(){};
		}
	},
	
	getTransport: function(){
		if(window.XMLHttpRequest) {	return new XMLHttpRequest(); }
		else if(window.ActiveXObject) {
			try { req = new ActiveXObject('Msxml2.XMLHTTP.4.0'); } catch(e) { try {	req = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {req = false; }} return req; }
		else {	return false; }
	}

}