var Comm = new Object();
Comm.getTransport = function() {
	var req = false;
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}	
	return req;
}

Comm.wrappedStatechange = function(obj) {
	return function() {
		Comm.statechange.call(obj);
	}
}

Comm.Request = function(url, async, success, fail) {
	this.success = success;
	this.fail = fail;
	this.req = Comm.getTransport();
	if ( this.req ) {
		if ( async ) {
			this.req.onreadystatechange = Comm.wrappedStatechange(this);
		}
		this.req.open("GET", url, async);
		this.req.send("");
		if ( !async ) {
			Comm.statechange.call(this);
		}
	}
}

Comm.emptyfunction = function () {
}

Comm.statechange = function() {
	if ( this.req.readyState == 4 ) { // loaded
		if ( this.req.status == 200 ) {
			if ( typeof(this.success) == "function" ) {
				this.success(this.req.responseText, this.req.getResponseHeader("Content-type"));
			}
		} else {
			if ( typeof(this.fail) == "function" ) {
				this.fail(this.req.status, this.req);
			}
		}
		this.req.onreadystatechange = Comm.emptyfunction;
	}

}



