AJAX = function() {
	var params = '';
	var doPost = false;
	var usexml = false;
	var ajaxObject = function() {
		try {
			return window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		} catch(ex) {
		}
	};

	this.setPost = function(post) {
		doPost = post;
	}
	
	this.getParams = function() {
		return params;
	}

	this.getPost = function() {
		return doPost;
	}

	this.setXML = function(xml) {
		usexml = xml;
	}

	this.getXML = function() {
		return usexml;
	}

	this.onError = function(error) {
		alert(error);
	}

	this.execute = function(url, callbackFunc) {
		try {
			var ao = ajaxObject();
			ao.onreadystatechange = function() {
				if((ao.readyState == 4) && (ao.status == 200)) {
					if(usexml)
						callbackFunc(ao.responseXML);
					else
						callbackFunc(ao.responseText);
				}
			};
			this.addParam('hash', Math.random());
			if(doPost) {
				ao.open("POST", url, true);
				ao.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				ao.setRequestHeader("Content-length", params.length);
				ao.setRequestHeader("Connection", "close");
				ao.send(params);
			} else {
				if(params.length > 0)
					url += '?' + params;
				ao.open("GET", url);
				ao.send(null);
			}
		} catch(ex) {
			this.onError(ex);
		}
	}

	this.addParam = function(key, value) {
		var sep = '';
		if(params.length > 0)
			sep = '&';
		params += sep + key + '=' + encodeURIComponent(value);
	}
}
