/*
	Author: Matt Johnson
	Company: Bullhorn.co.uk
	Last Mod: 25/01/2008
*/
BullHorn.Ajax = function(dataURL) {
	if(dataURL) {
		this._dataURL = dataURL;
		if (this._dataURL.indexOf('?') > 0) {
			this._dataURL = String(this._dataURL) + '&bulljax_rand=';
		} else {
			this._dataURL = String(this._dataURL) + '?bulljax_rand=';
		}
		this._dataURL = String(this._dataURL) + String( Math.floor(Math.random()*999999999999999) );
	}
}
BullHorn.Ajax.prototype._dataURL = "data.txt";
BullHorn.Ajax.prototype._request = undefined;
BullHorn.Ajax.prototype.load = function() {
	this._request = this._getXMLHTTPRequest();
	var _this = this;
	this._request.onreadystatechange = function(){_this._onData()};
	this._request.open("GET", this._generateDataUrl(), true);
	this._request.send(null);
}
BullHorn.Ajax.prototype._generateDataUrl = function() {
	return this._dataURL;
}
BullHorn.Ajax.prototype._onData = function() {
	if(this._request.readyState == 4) {
		if(this._request.status == "200") {
			if(this.onDraw != undefined) {
				this.onDraw(this._request.responseText);
			}
		} else {
			if(this.onError != undefined) {
				this.onError({status:this._request.status, statusText:this._request.statusText});
			}
		}
		delete this._request;
	}
}
BullHorn.Ajax.prototype._getXMLHTTPRequest = function() {
	var xmlHttp;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHttp");
	} catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		} catch(e2) {
		}
	}
	if(xmlHttp == undefined && (typeof XMLHttpRequest != 'undefined')) {
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}