function ajax() {
	this.request = new XMLHttpRequestFactory();
}

/*
	Use buildFormData to encode data sent
	To "POST" - set action to "POST" and encode data
	To "GET"  - set action to "GET" and encode and tack the data on the url after adding a question mark
				and set data to null or empty string
*/
function ajax_call(action, url, data) {
	var obj = this;
    this.request.open(action,url,true);
    this.request.onreadystatechange = function() {
    	if(obj.request.readyState == 4) {
        	if(obj.request.status == 200) {
				obj.complete(obj.request.status,obj.request.statusText,obj.request.responseText,obj.request.responseXML);
			} else {
				alert("Ajax Error - " + obj.request.status + ": " + obj.request.statusText + "\nAction: " + action + "\nURL: "+ url + "\nData: " + data);
			}
        }
    }
	if(action.toUpperCase() == "POST") {
		this.request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	this.request.send(data);
}

function ajax_complete(status,statusText,responseText,responseHTML) {
}

ajax.prototype.complete = ajax_complete;
ajax.prototype.call = ajax_call;

ajax.prototype.buildFormData = function(data) {
	if(data == null)
		return "";
	var pairs = [];
	for(var name in data) {
		var value = data[name].toString();
		var pair = encodeURIComponent(name) + "=" + encodeURIComponent(value);
		pairs.push(pair);
	}
	return pairs.join("&");
}

