/* Jx Manager
------------------------------------------------------------------*/
function JxManager() {
	this.requests = new Array();
}
JxManager.prototype.load = function (id, url, callBack) {
	if ( !this.requests[ id ] || !callBack ) {
		this.requests[ id ] = new JxReq(url);
		if (callBack) {
			this.requests[ id ].onCompletion = function() { eval(callBack);	};
		}
		
		this.requests[ id ].run();
	}
}
JxManager.prototype.get = function (id) {
	response = this.requests[ id ].response;
	this.requests[ id ] = null;
	return new Function("return "+response)();
}
var jxMan = new JxManager();

/* Jx Request
------------------------------------------------------------------*/
function JxReq(url) {
	this.resetData = function() {
  		this.response = false;
		this.failed = false;
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onCompletion = function() { };
		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};
	
	this.create = function() {
		try {
			this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlHttp = null;
			}
		}

		if (! this.xmlHttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlHttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};
	
	this.run = function() {
		if (this.failed) {
			this.onFail();
		} else if (this.xmlHttp) {
			var self = this;
			
			this.xmlHttp.open("GET", url, true);
		
			this.xmlHttp.onreadystatechange = function() {
				switch (self.xmlHttp.readyState) {
					case 4: {
						self.response = self.xmlHttp.responseText;
						self.responseStatus[0] = self.xmlHttp.status;
						self.responseStatus[1] = self.xmlHttp.statusText;
						
						if (self.responseStatus[0] == "200") {
							self.onCompletion();
						} else {
							self.onError();
						}
					} break;
				}
			};

			this.xmlHttp.send('');
		}
	}
	
	this.reset();
	this.create();
}