net = new Object();
	
net.addJob = function (func,funcThisObj,params){
	if(!this.jobs)
		this.jobs = new Array();
	
	jobObj = new Object();
	jobObj.func = func;
	jobObj.funcThisObj = funcThisObj
	jobObj.params = params;
	
	this.jobs.push(jobObj);
}

net.workJobs = function (){

	for (var job in this.jobs)
	{
		jobObj = this.jobs[job];
		this.jobs.splice(job, 1);
		
		jobObj.func.call(jobObj.funcThisObj,jobObj.params);
	}
		
}




net.ajaxRequest = function (url,onload,onerror,ongather){

	this.defaultError = function(){
		alert("error fetching data!");
	}
		
	this._constructor = function(url,onload,onerror,ongather){
		this.url = url;
		this.ajax = null;
		this.onload = onload;
		this.ongather = ongather;
		this.onerror = (onerror) ? onerror : this.defaultOnError;
		
		if(isArray(url)||isObject(url)){
			for(key in url)
				this[key] = url[key];
		}
		if(url&&onload)
			this.loadAjaxDoc(url);
	}
	
	if(url&&onload)
		this._constructor(url,onload,onerror,ongather);
	
	this. loadAjaxDoc=function(url){
		if(window.XMLHttpRequest){
			this.ajax = new XMLHttpRequest();
		}else if(window.ActiveXObject){
			this.ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if(this.ajax){
			try{
				var loader=this;
				this.ajax.onreadystatechange = function(){
					loader.onReadyState.call(loader);
				}
				
				if(this.ongather)
					this.ongather.call(this)
				this.open(url);
				if(net.messageMapper){
					this.message = net.messageMapper.addMessage("Lade Daten von "+url,"Datentransfer",null,{duration:null});
				}
				
			}catch(err){
				this.onerror.call(loader);
			}
		}
	}
	this.open = function(url){
		this.ajax.open('GET',url,true);
		this.ajax.send(null);
	}
	this.onReadyState=function(){
		
		var ajax = this.ajax;
		var ready = ajax.readyState;
		if(ready == 4){
			var httpStatus = ajax.status;
			if(httpStatus == 200 || httpStatus == 0){
				if(this.message)
					this.message.destroy();
				this.onload.call(this);
			}else{
				this.onerror.call(this);
			}
		}
	}
	
	this.abort = function(){
		this.ajax.abort();
	}
}


net.postRequest = function(url,onload,post,ongather,onerror){
	this.post = post;
	
	this.open=function (url){
		this.ajax.open('POST',url,true);
		this.ajax.setRequestHeader("Method", "POST "  + url  +  " HTTP/1.1");
  		this.ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.ajax.send(this.post);
	}
			
	this._constructor(url,onload,onerror,ongather);
}

net.postRequest.prototype = new net.ajaxRequest();
/*
##		Command
*/

net.command = new Object();

net.command.object = function(){
	this.isCommand = function(){};
	this.toString = function(){
		var xml = "<command ";
		for(key in this){
			if(!isFunction(this[key]))
				xml += key+"=\""+this[key]+"\" ";
		}
		xml +=" />";
		return xml;
	}
}

net.command.query = function(url,freq,onload,onUpdate){
	this.url = url;
	this.freq = freq;
	this.onload = onload;
	this.onUpdate = onUpdate
	this.commands 	= new Object();
	this.status 	= new Object();
	this.count = 0;
	
	this.addCommand = function(obj){
		if(obj.id && obj.cmdType)
			var id = obj.cmdType+"_"+obj.id;
		else
			var id = this.commands.length;
		obj.cmdId = id;
		
		if(this.commands[id]){
			for(key in obj){
				if(!isFunction(obj[key]))
					this.commands[id][key] = obj[key];
			}
		}else{
		
			this.commands[id] = obj;
		}
		this.status[id]	= 0;
		this.count++;
	}
	
	this.processAnswer = function(){
		var xml = this.ajax.responseXML;
		if(!xml){
			if(net.messageMapper){
				var p = document.createElement("p");
				p.innerHTML = "Kein XML-Document empfangen!<br/><br/>Antwort:";
				p.appendChild(document.createTextNode(this.ajax.responseText));
				bsystem.message.obj.addMessage(p,"Datenfehler",gui.MSG_TYPE_CRIT,null);	
			}else{
				alert("Schwerer Fehler:\r\nKein XML-Document empfangen!\r\nAntwort:"+this.ajax.responseText);
			}
		}else{
			commands = xml.getElementsByTagName("command");
			for(var i=0;i<commands.length;i++){
				id = commands[i].getAttribute("cmdId");
				if(this.query.commands[id])
					if(this.query.commands[id].callback)
						if(this.query.commands[id].callback.call)
							this.query.commands[id].callback.call(this,commands[i]);
				this.query.status[id] = commands[i].getAttribute("cmdStatus");
					
			}
		}
		if(this.query.onload)
			if(this.query.onload.call)
				this.query.onload.call(this);
	}
	
	this.update = function(){
		
		var middlexml = "";
		var commands = 0;
		for(com in this.commands){
			if(this.commands[com].isCommand && ((!this.status[com])||(this.status[com] > 2))){
				middlexml += this.commands[com];
				this.status[com] = 1;
				commands++;
			}
		}
		var xml = "<commands time=\""+(new Date().getTime())+"\" count=\""+commands+"\" >"+middlexml+"</commands>";
		
		
		if(commands > 0)
		{	
			post = "&command=update&xml="+xml;
			req = new net.postRequest(this.url,this.processAnswer,post,null,null);
			req.query = this;
		}
		
	}
	
	var instance = this;
	var update = function(){
		instance.update();
	}
	
	if(!this.freq)
		this.freq = 1000;
	
	this.interval = setInterval(update,this.freq);
}