var hdiSjax = new Object();

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

hdiSjax.getAjaxRequest = function(url, parameters, callbackfunc, filetype) {
	hdiSjax.ajaxObject = createAjaxObject(); //recreate ajax object to defeat cache problem in IE
	if (hdiSjax.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, false);
		this.ajaxObject.send(null);
	}
}

hdiSjax.postAjaxRequest = function(url, parameters, callbackfunc, filetype) {
	hdiSjax.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, false);
		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;
}
