// vim:ts=4
function Remote () {
}

Remote.prototype.http = false;
Remote.prototype.error = false;
Remote.prototype.callback = function (data) { };

Remote.prototype.getHTTPObject = function () {
	var http = false;
	if (typeof ActiveXObject != 'undefined') {
		try {
			http = new ActiveXObject ("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http = new ActiveXObject ("Microsoft.XMLHTTP");
			} catch (e) {
				http = false;
			}
		}
	} else if (XMLHttpRequest) {
		try {
			http = new XMLHttpRequest ();
		} catch (e) {
			http = false;
		}
	}
	return http;
};

Remote.prototype.load = function (url, callback) {
	this.init ();
	if (!this.http || !url)
		return;

	this.callback = callback;
	var self = this;
	
	// Get around caching
	var now = "time=" + new Date ().getTime ();
	url += (url.indexOf ("?") + 1) ? "&" : "?";
	//url += now;

	var parameters = null;

	this.http.open ("GET", url, true);

	this.http.onreadystatechange = function () {
		if (!self)
			return;
		var http = self.http;
		if (http.readyState == 4) {
			if (http.status == 200) {
				if (self.callback)
					self.callback (http.responseText);
			} else {
				if (self.error)
					self.error (http.status);
			}
		}
	}
	this.http.send (parameters);
}

Remote.prototype.init = function () {
	this.http = this.getHTTPObject ();
}
