var hdiAjax = new Object();

hdiAjax.basedomain = window.location.protocol + '//' + window.location.hostname;
hdiAjax.ajaxObject = createAjaxObject();
hdiAjax.filetype = "txt";
hdiAjax.addrandomnumber = 0; //Set to 1 or 0.

hdiAjax.getAjaxRequest = function(url, parameters, callbackfunc, filetype) {
	hdiAjax.ajaxObject = createAjaxObject(); //recreate ajax object to defeat cache problem in IE
	if (hdiAjax.addrandomnumber == 1) //Further defeat caching problem in IE?
		var parameters = parameters + "&ajaxcachebust=" + new Date().getTime();
	if (this.ajaxObject) {
		this.filetype = filetype;
		this.ajaxObject.onreadystatechange = callbackfunc;
		this.ajaxObject.open('GET', url + "?" + parameters, true);
		this.ajaxObject.send(null);
	}
}

hdiAjax.postAjaxRequest = function(url, parameters, callbackfunc, filetype) {
	hdiAjax.ajaxObject = createAjaxObject(); //recreate ajax object to defeat cache problem in IE
	if (this.ajaxObject) {
		this.filetype = filetype;
		this.ajaxObject.onreadystatechange = callbackfunc;
		this.ajaxObject.open('POST', url, true);
		this.ajaxObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajaxObject.setRequestHeader("Content-length", parameters.length);
		this.ajaxObject.setRequestHeader("Connection", "close");
		this.ajaxObject.send(parameters);
	}
}

function createAjaxObject(){
	var httpRequest = false;
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType)
			httpRequest.overrideMimeType('text/xml');
	}
	else if (window.ActiveXObject) { // if IE
		try {httpRequest = new ActiveXObject("Msxml2.XMLHTTP");} 
		catch(e) {
			try {httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e){}
		}
	}
	return httpRequest;
}
