


if (typeof(tora) == "undefined")
	tora = new Object;

if (typeof(tora.asio) == "undefined")
	tora.asio = new Object;

// namespace tora { namespace asio {

tora.asio.XMLHttpRequest = function() {
	if (window.XMLHttpRequest)
		this.impl_ = new XMLHttpRequest();
	else if (window.ActiveXObject)
		this.impl_ = new ActiveXObject("Microsoft.XMLHTTP");
}

tora.asio.XMLHttpRequest.ReadyStates = {
	/* const */ UNINITIALIZED : 0,
	/* const */ LOADING : 1,
	/* const */ LOADED : 2,
	/* const */ INTERACTIVE : 3,
	/* const */ COMPLETE : 4
};

tora.asio.XMLHttpRequest.Statuses = {
	/* const */ OK : 200,
	/* const */ UNAUTHORIZED : 401,
	/* const */ FORBIDDEN : 403,
	/* const */ NOT_FOUND : 404,
	/* const */ INTERNAL_SERVER_ERROR : 500
};

tora.asio.XMLHttpRequest.prototype = {

	open : function(method, url, async /* = true */) {
		if (async == undefined)
			async = true;
		this.impl_.open(method, url, async);
	},

	onReadyStateChange : function(f) {
		this.impl_.onreadystatechange = f;
	},

	readyState : function() {
		return this.impl_.readyState;
	},

	status : function() {
		return this.impl_.status;
	},

	statusText : function() {
		var status = tora.asio.XMLHttpRequest.Statuses;
		switch (this.status()) {
		case status.OK:
			return "OK";
		case status.UNAUTHORIZED:
			return "Unauthorized";
		case status.FORBIDDEN:
			return "Forbidden";
		case status.NOT_FOUND:
			return "Not Found";
		case status.INTERNAL_SERVER_ERROR:
			return "Internal Server Error";
		default:
			return "";
		}
	},

	responseText : function() {
		return this.impl_.responseText;
	},

	send : function (data /* = "" */) {
		if (data == undefined)
			data = "";
		this.impl_.send(data);
	},

	abort : function () {
		this.impl_.abort();
	},

	responseXML : function () {
		return this.impl_.responseXML;
	}

};

// } } // tora.asio


