/* Jx Manager
------------------------------------------------------------------*/
function JxManager() {
	this.requests = new Array();

	this.load = function ( Id, Url, CallBack ) {
		var args = new Array();
		for ( var n = 3; n < arguments.length; n++ ) {
			args.push( arguments[ n ] );
		}
		
		if ( !this.requests[ Id ] || !CallBack ) {
			this.requests[ Id ] = new JxReq( Id, Url, args );
			if ( CallBack ) {
				if ( typeof CallBack != 'string' ) {
					this.requests[ Id ].onCompletion = CallBack;
				} else {
					this.requests[ Id ].onCompletion = function() { eval( CallBack ); };
				}
			}
			
			this.requests[ Id ].run();
		}
	}
	this.getResponse = function ( Id ) {
		response = this.requests[ Id ].response;
		this.clearResponse( Id );
		return new Function("return "+response)();
	}
	this.clearResponse = function ( Id ) {
		this.requests[ Id ] = null;
	}
}
var jxMan = new JxManager();

/* Jx Request
------------------------------------------------------------------*/
function JxReq( Id, Url, Args ) {
	this.id = Id;
	this.url = Url;
	this.args = Args;
	
	this.resetData = function() {
  		this.response = false;
		this.failed = false;
  	};

	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;
						
						if ( self.xmlHttp.status == "200" ) {
							self.onCompletion();
						} else {
							self.onError();
						}
					} break;
				}
			};

			this.xmlHttp.send('');
		}
	}
	
	this.reset();
	this.create();
}