function URLGrabber(containerID, dataURL)
{
	this._dataURL = dataURL;
	this._containerID = containerID;
}

URLGrabber.prototype._request = undefined;

URLGrabber.prototype.load = function()
{
	var module = document.getElementById(this._containerID);
	module.body.innerHTML = 'Laddar...';
	this._request = this._getXMLHTTPRequest();
	var _this = this;
	this._request.onreadystatechange = function(){_this._onData()};
	this._request.open("GET", this._generateDataUrl(), true);
	this._request.send(null);
}

URLGrabber.prototype._render = function(data)
{
	var module = document.getElementById(this._containerID);
	module.body.innerHTML = data;
	Modules.sortModules();
}

URLGrabber.prototype._action = function(action, data)
{
	var module = document.getElementById(this._containerID);
	module.fireAction(action, data);
	Modules.sortModules();
}

URLGrabber.prototype._generateDataUrl = function()
{
	return this._dataURL;
}

URLGrabber.prototype._onData = function()
{
	if(this._request.readyState == 4)
	{
		if(this._request.status == "200") {
			var h = this._request.getAllResponseHeaders().split('\n');
			for(var i = 0; i < h.length; i++) {
				var t = h[i].split(':');
				t[0] = trim(t[0]);
				t[1] = trim(t[1]);
				if(t[0] == 'action')
					this._action(t[1], t[2]);
			}
			this._render(this._request.responseText);
		} else {
			this._render('Tj&auml;nsten kunde ej kontaktas, f&ouml;rs&ouml;k igen senare!');
			//this.onError({status:this_request.status, 
			//statusText:this._request.statusText});
		}
		
		delete this._request;
	}
}

URLGrabber.prototype._getXMLHTTPRequest = function()
{
	var xmlHttp;
	try {
		var xmlHttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		// browser doesn't support ajax. handle however you want
	}
	
	return xmlHttp;
}
