Number.prototype.format = function(places,seperator,fixed){
	var temp = (fixed ? this.toFixed(fixed) : this).toString();
	start = temp.lastIndexOf(".");
	start -= 3;
	
	temp = temp.replace(/\./g, seperator);
	
	while(start > 0){
		temp = temp.substr(0,start)+places+temp.substr(start);
		start -= 3;
	}
	return temp;
}

var gui = new Object();
gui.document = new Object();
gui.document.old = new Object();
gui.windows = new Array();
gui.guiObjects = new Array();

gui.effectQueues = 0;

gui.WND_TYPE_DLG = 1;
gui.WND_TYPE_MODAL = 3;
gui.WND_OK = 4;

gui.WND_SPEC_DEFAULT = {titlebar:true,
				resize:true,
				minimize:true,
				drag:true
				}

			
			
			

if(typeof homePath == "undefined")
	homePath = "";

gui.MSG_TYPE_PRIO_LOW = {icon:homePath+"/layout/images/gui/message_notify.gif",duration:10};
gui.MSG_TYPE_PRIO_DEFAULT = {icon:homePath+"/layout/images/gui/message_default.gif"};
gui.MSG_TYPE_PRIO_HIGHT =  {icon:homePath+"/layout/images/gui/message_error.gif"};
gui.MSG_TYPE_PRIO_CRITICAL =  {icon:homePath+"/layout/images/gui/message_critical.gif"};

gui.MSG_TYPE_NOTIFY = gui.MSG_TYPE_PRIO_LOW;
gui.MSG_TYPE_WARNING = gui.MSG_TYPE_PRIO_DEFAULT;
gui.MSG_TYPE_ERROR = gui.MSG_TYPE_PRIO_HIGHT;
gui.MSG_TYPE_CRIT = gui.MSG_TYPE_PRIO_CRITICAL;

gui.addGuiObject = function(obj){
	gui.guiObjects.push(obj);
}

gui.render = function(){
	
	var time = new Date().getTime();
	for(var z = 0; z < gui.windows.length;z++){
		gui.windows[z].render();
	}
	
	for(var z = 0; z < gui.guiObjects.length;z++){
		if(gui.guiObjects[z].render)
			gui.guiObjects[z].render();
	}
	
	
}

gui.removeWindow = function(window){
	for(var i =0;i < gui.windows.length;i++)
		if(gui.windows[i] == window)
			gui.windows.splice(i,1);
}

//Knotenkopie samt event handlern
gui.cloneNodeXl = function(node){
	if(!node.cloneNode)
		return;
	var copynode = node.cloneNode(false);
	for(var attr in node){
		if(attr.indexOf("on") == 0)
			copynode[attr] = node[attr];
	}
	for(var i = 0; i < node.childNodes.length; i++){
		copynode.appendChild(gui.cloneNodeXl(node.childNodes[i]));
	}
	return copynode;
}

gui.cloneNodeTo = function(node,parent,replace){
	if(!node.cloneNode)
		return;
	var copynode = node.cloneNode(false);
	for(var attr in node){
		if(attr.indexOf("on") == 0)
			copynode[attr] = node[attr];
	}
	for(var i = 0; i < node.childNodes.length; i++){
		copynode.appendChild(gui.cloneNodeXl(node.childNodes[i]));
	}
	
	if(parent&&copynode)
		if(!replace)
			parent.appendChild(copynode);
		else if(replace.parentNode == parent)
			gui.replaceNode(copynode,replace);
	return copynode;
}

gui.deleteNode = function (node){
	
	while(node.childNodes.length)
		gui.deleteNode(node.lastChild);
	
	//Eventhandler unhooken... liste machen =(
	if(node.onclick)
		node.onclick = null;
	if(node.onmousedown)
		node.onmousedown = null;
	if(node.onmouseup)
		node.onmouseup = null;
	if(node.onmouseover)
		node.onmouseover = null;
	if(node.onmousemove)
		node.onmousemove = null;
	if(node.onkeydown)
		node.onkeydown = null;
	if(node.onkeyup)
		node.onkeyup = null;
	
	if(!node.parentNode)
		return;

	node.parentNode.removeChild(node);
}

gui.replaceNode = function(newnode,node){
	var time = new Date().getTime();
	while(node.childNodes.length){
		gui.deleteNode(node.lastChild);
		
	}
	if(!node.parentNode)
		return;
	
	node.parentNode.replaceChild(newnode,node);
}

gui.removeChilds =function (node){
	if(!node)
		return;
	
	while(node.childNodes.length)
		if(node.lastChild)
			gui.deleteNode(node.lastChild);
}

gui.createElementTo = function(ele,parent,replace,before){
	var element = document.createElement(ele);
	replace = (replace)? replace : "";
	before = (before)? before : "";
	if(parent&&element)
		if(before.parentNode == parent)
			parent.insertBefore(element,before);
		else if(replace.parentNode == parent)
			gui.replaceNode(element,replace);
		else
			parent.appendChild(element);
		
	return element;
}

gui.createTextNodeTo = function(str,parent,replace){
	var element = document.createTextNode(str);
	if(parent&&element)
		if(!replace)
			parent.appendChild(element);
		else if(replace.parentNode == parent)
			gui.replaceNode(element,replace);

	return element;
}

gui.document.disableSelect = function(){

	if(document.onselectstart)
		this.old.onselectstart = document.onselectstart;
	document.onselectstart = new Function ("return false")
			
	if (window.sidebar){
			if(document.onmousedown)
				this.old.onmousedown = document.onmousedown;
			document.onmousedown = function(e){return false};
		}
}
	
gui.document.enableSelect = function(){
		document.onselectstart=this.old.onselectstart;
			
		if (window.sidebar){
				document.onmousedown=this.old.onmousedown
			}
	}
	

gui.focus = function(element){
	parent = element.parentNode;
	if(!element.style.zIndex)
		element.style.zIndex = 1;

	if(parent)
	for(var i = 0; i < parent.childNodes.length; i++){
		if(!parent.childNodes[i].style)
			continue;
		if(( parent.childNodes[i].style.zIndex*1 >= element.style.zIndex*1) && (element != parent.childNodes[i])){
			element.style.zIndex = parent.childNodes[i].style.zIndex*1 +1;

		}
	}
	
	if(element.style.zIndex < 1000)
	element.style.zIndex = 1000;
}
	
gui.cWindow = function (content,parent,title,before,spec){
	/*
	##		Model
	*/
	this.autoSpec = function(){
		var defaultSpec = {
			titlebar:true,
			resize:true,
			minimize:true,
			drag:true
		};
		
		return defaultSpec;
	}
	
	this.getDocument = function(){
		return doc;	
	}
	
	this.getWindow = function(){
		return win;	
	}
	
	this.destroy = function(){
		gui.removeWindow(this);
		gui.deleteNode(win);

		if(modal){
			gui.deleteNode(modal);
		}
		if(modalbg){
			gui.deleteNode(modalbg);
		}
		
		win = null;
		titlebar = null;
		closeButton = null;
		doc = null;
		controlbar = null;
		
		corner = null;
		borderRight = null;
		borderBottom = null;
	}
	
	/*
	##		Präsentation
	*/
	this.appendTo = function(parent){
		parent.appendChild(win);
	}
	this.insertTo = function(parent,before){
	
		if(parent == win.parentNode)
			return;
			
		if(!before)
			before = parent.firstChild;
		parent.insertBefore(win,before);
		this.parent = parent;
	}
	
	this.show = function(){
		if(!win)
			return false;
		if(!this.before)
			this.before = parent.firstChild;
		if(this.parent)
		if(this.before == -1)
			this.parent.appendChild(win);
		else
			this.parent.insertBefore(win,this.before);
	}
	
	this.focus = function(){
		gui.focus(win);
	}
	
	this.hide = function(){
		win.style.display = "none";
	}
	this.close = function(){
		win.parentNode.removeChild(win);
		if(modal){
			if(modal.parentNode)
				modal.parentNode.removeChild(modal);
			modal.appendChild(win);
		}
		if(modalbg){
			if(modalbg.parentNode)
				modalbg.parentNode.removeChild(modalbg)
		}
		
		if(this.onclose)
			this.onclose();
	}
	this.setTitle = function(title){
		if(title.nodeName)
			titlebar.replaceChild(title,titlebar.firstChild);
		else
			titlebar.replaceChild(document.createTextNode(title),titlebar.firstChild);
	}
	
	this.addMenue = function(menue,parent){
		var ul = document.createElement("ul");
		win.insertBefore(ul,doc);
		ul.className = "controlbar";
		for(item in menue){
			var li = null;
			//Wenn es ein normaler Menüpunkt ist
			if(isFunction(menue[item])){
				li = document.createElement("li");
				li.className = "menueItem";
				
				var a = document.createElement("a");
				a.className = "menueItemButton";
				a.onclick = menue[item];
				a.appendChild(document.createTextNode(item));
				
				li.appendChild(a);
				
			}
			//Menüpunkt mit unterpunkten
			if(isObject(menue[item])||isArray(menue[item])){
				
			}
			//ein html element, das in die leiste soll (buttonleiste z.b.)
			if(menue[item].tagName){
				
			}
			if(li)
				if(li.tagName)
					ul.appendChild(li);
		}
		this.menueCount++;
		
		this.render();
	}
	
	this.appendGuiChild = function(element){
		element.element = document.createElement("div");
		doc.appendChild(element.element);
		
		if(element.render)
			element.render();
		
		guiChilds.push(element);
	}
	
	
	this.render = function(){
		for(var i = 0; i < guiChilds.length;i++){
			if(guiChilds[i].render) 
				guiChilds[i].render();
		}
		win.style.paddingBottom = (5 + (25*(this.spec['titlebar'] ? 1 : 0)) + (5*(this.spec['resize'] ? 1 : 0)) + (20*this.menueCount))+"px";
	}
	
	
	this.setHeight = function(height){
		win.style.height = height;
	}
	
	this.getHeight = function(){
		return win.style.height;
	}
	
	this.setWidth = function(width){
		win.style.width = width;
	}
	
	this.getWidth = function(){
		return win.style.width;
	}
	
	this.setPosition = function(x,y){
		win.style.left = x;
		win.style.top = y;
	}
	/*
	##		Steuerung
	*/
	
	this.mouseOver = function(e){

	}

	this.mouseOut = function(e){
	}
	

	
	this.startSize= function(e,direction){
		var e = e || window.event;
		var x = e.pageX || e.clientX;
		var y = e.pageY || e.clientY;
		
		this.sizeing = new Object();
		this.sizeing.width = win.offsetWidth;
		this.sizeing.height= win.offsetHeight;
		this.sizeing.mouseX 	= x;
		this.sizeing.mouseY 	= y;
		this.sizeing.layerX	= e.layerX || e.offsetX;
		this.sizeing.layerY	= e.layerY || e.offsetY;
		this.sizeing.direction  = direction;
		
		if(window.onmousemove)
			this.sizeing.oldMouseMove = window.mousemove;
		
		if(window.onmouseup)
			this.sizeing.oldMouseUp = window.mouseup;
		
		window.onmousemove 	= function(e){instance.size(e,this);};
		window.onmouseup 		= function(e){instance.stopSize(e,this);};
	}
	
	this.stopSize = function(e,oldthis){
		var e = e || window.event;
		
		window.onmousemove = this.sizeing.oldMouseMove;
		window.onmouseup = this.sizeing.oldMouseUp;
		
		if(window.onmouseup)
			window.onmouseup.call(oldthis);
		
		this.dragging = null;
	}
	
	this.size = function(e,oldthis){
		var e = e || window.event;
		var x = e.pageX || e.clientX;
		var y = e.pageY || e.clientY;
		
		if(!this.sizeing)
			return;
		if((((y - this.sizeing.mouseY ) > 0)&&(this.sizeing.direction&4))
		 ||(((y - this.sizeing.mouseY ) < 0)&&(this.sizeing.direction&1)))
			win.style.height = this.sizeing.height +(y - this.sizeing.mouseY )- parseInt(win.style.paddingBottom)-2 +"px" ;

		if((((x - this.sizeing.mouseX ) > 0)&&(this.sizeing.direction&2))
		 ||(((x - this.sizeing.mouseX ) < 0)&&(this.sizeing.direction&8)))
		win.style.width = this.sizeing.width +(x - this.sizeing.mouseX ) +"px" ;
		
		if(this.sizeing.oldMouseMove)
			this.sizeing.oldMouseMove.call(oldthis);
	}
	
	this.startDrag = function(e){
		var e = e || window.event;
		var x = e.pageX || e.clientX;
		var y = e.pageY || e.clientY;
		
		this.dragging = new Object();
		this.dragging.mouseX 	= x;
		this.dragging.mouseY 	= y;
		this.dragging.layerX	= e.layerX || e.offsetX;
		this.dragging.layerY	= e.layerY || e.offsetY;
		this.dragging.top		= win.offsetTop;
		this.dragging.left	= win.offsetLeft;
		
		if(window.onmousemove)
			this.dragging.oldMouseMove = window.mousemove;
		
		if(window.onmouseup)
			this.dragging.oldMouseUp = window.mouseup;
		
		window.onmousemove 	= function(e){instance.drag(e,this);};
		window.onmouseup 		= function(e){instance.stopDrag(e,this);};
		
	}
	
	this.stopDrag = function(e,oldthis){
		var e = e || window.event;
		
		window.onmousemove = this.dragging.oldMouseMove;
		window.onmouseup = this.dragging.oldMouseUp;
		
		if(window.onmouseup)
			window.onmouseup.call(oldthis);
		
		this.dragging = null;
	}
	
	this.drag = function(e,oldthis){
		var e = e || window.event;
		var x = e.pageX || e.clientX;
		var y = e.pageY || e.clientY;
		
		if((!this.dragging)||(!this.spec.drag))
			return;
		
		if(win.style.position != "absolute")
			win.style.position ="absolute";
		if(win.style.margin !== 0)
		win.style.margin = 0;
		
		win.style.top = ( y  - this.dragging.layerY) +"px" ;
		win.style.left = ( x - this.dragging.layerX) +"px" ;
		
		if(this.dragging.oldMouseMove)
			this.dragging.oldMouseMove.call(oldthis);
	}
	
	
	/*
	##		Constuction
	*/
	
	this.title = title;
	this.content = content;
	this.parent = parent ? parent : document;
	this.before = before;
	this.spec = spec ? copyObject(spec) : this.autoSpec();
	
	this.menueCount = 0;
	
	var guiChilds = new Array();
	
	var win = document.createElement("div");
	var titlebar = document.createElement("div");
	var closeButton = document.createElement("a");
	var doc = document.createElement("div");
	var controlbar = document.createElement("div");
	
	var corner = document.createElement("div");
	var borderRight = document.createElement("div");
	var borderBottom = document.createElement("div");
	var instance = this;
	
	win.onclick = function(e){instance.focus()};
	
	titlebar.className = "titlebar";
	var dragObject = titlebar;
	if(!this.spec.titlebar && this.spec.drag)
		dragObject = win;
	
	dragObject.onmousedown = function(e){instance.startDrag(e)};
	dragObject.onmouseover = function(e){ gui.document.disableSelect.call(gui.document,e)};
	dragObject.onmouseout  = function(e){ gui.document.enableSelect.call(gui.document,e)};
	
	
	
	controlbar.className = "controlbar";
	
	closeButton.className = "closebutton";
	closeButton.appendChild(document.createTextNode("x"));
	closeButton.onclick = function(){instance.close()};
	
	doc.className = "document";
	corner.className = "corner";
	borderRight.className = "rightBorder";
	borderBottom.className = "bottomBorder";


	corner.onmousedown = function(e){instance.startSize(e,15)};
	borderRight.onmousedown = function(e){instance.startSize(e,10)};
	borderBottom.onmousedown = function(e){instance.startSize(e,5)};
	
	
	
	if(!before)
		before = parent.firstChild;
	if(parent)
		if(before == -1)
			parent.appendChild(win);
		else
			parent.insertBefore(win,before);
	
	win.appendChild(closeButton);
	if(this.spec.titlebar)
		win.appendChild(titlebar);
	//win.appendChild(controlbar);
	if(content)
	if(content.nodeName)
		doc.appendChild(content);
	else 
		doc.appendChild(document.createTextNode(content));
	
	if(!title)
		title = " ";
	if(title.nodeName)
		titlebar.appendChild(title);
	else
		titlebar.appendChild(document.createTextNode(title));
	
		
	win.appendChild(doc);
	if(this.spec.resize){
		win.insertBefore(borderRight,doc);
		win.appendChild(corner);
		win.appendChild(borderBottom);
	}
	
	win.className = "window";

	if(this.spec.type & gui.WND_TYPE_DLG){
		win.className += " dialog";
	}
	
	if((this.spec.type & gui.WND_TYPE_MODAL) == gui.WND_TYPE_MODAL){
		//win.className += " dialog";
		var modal = document.createElement("div");
		modal.style.position = "fixed";
		modal.style.top = "0px";
		modal.style.left = "0px";
		modal.style.width = "100%";
		modal.style.height = "100%";
		modal.style.zIndex = "10000";
		
		var modalbg = modal.cloneNode(true);
		modalbg.style.backgroundColor = "#222222";
		modalbg.style.zIndex = "9999";
		modalbg.style.width = document.body.offsetWidth+"px";
		modalbg.style.height = document.body.offsetHeight+"px";
		
		var transpEffect = new Effect.Opacity(modalbg, {duration:0.0,  to:0.5});
		
		document.body.appendChild(modalbg);
		document.body.appendChild(modal);
		modal.appendChild(win);
		
	}
	
	if(this.spec.type & gui.WND_OK){ 
		var button_ok = document.createElement("input");
		button_ok.type = "button";
		button_ok.value = "OK";
		button_ok.onclick = function(){if(instance.onok)instance.onok()};

		
		if(win.lastChild != doc){
			win.insertBefore(button_ok,doc.nextSibling);
		}else{
			doc.appendChild(button_ok);
		}
		
		//Per enter ok aufrufen
		win.onkeydown = function(e){
			if (!e) {e = window.event;}
			if (e.which) {key = e.which;}
			else if (e.keyCode) {key = e.keyCode;}
			if (key == 13) {
				button_ok.onclick();
			}
			
		};
	}
	
	//weitere classNames einfügen
	if(this.spec.style)
		if(this.spec.style.win)
			win.className += " "+this.spec.style.win;
			
	// Spezifische specs weiter verarbeiten
	for(var key in this.spec){
		switch (key){
			case "width":
				win.style.width = this.spec.width;
			break;
			case "height":
				win.style.height = this.spec.height;
			break;
			
		}
	}
	
	this.render();
	
	gui.windows.push(this);
	
}

gui.objectViewer = function(obj,specs,rendermode){
	this.obj = obj;
	this.specs = copyArray(specs);
	this.rendermode = rendermode ? rendermode : 0;

	var defaultHlType = {duration:3000,type:"Pulsate",spec:{queue:'begin'}};
	
	for(var i = 0; i < this.obj.length; i++){
		if(this.obj[i].registerObjView)
			this.obj[i].registerObjView(this);
	}
	
	this.table = function(styles){
		if(this.element)
			parent = this.element.parentNode;
		var table = gui.createElementTo("table",parent,this.element);
		for(var i = 0; i < this.specs.length; i++){
			var spec = this.specs[i];
			var tr = document.createElement("tr");
			var keytd = document.createElement("td");
			var keydiv = document.createElement("div");
			var valuetd = document.createElement("td");
			var valuediv = document.createElement("div");
			
			var keytext = document.createTextNode(spec.name);
			var valuetext = null;

			
			
			table.appendChild(tr);
			
			tr.appendChild(keytd);
			tr.appendChild(valuetd);
			
			keytd.appendChild(keydiv);
			keydiv.appendChild(keytext);
			
			valuetd.appendChild(valuediv);
			
			//if(valuetext)
			//	valuediv.appendChild(valuetext);
			
			this.showValue(spec,valuediv);

			
			if(spec.edit){
				instance = this;
				valuediv.onclick = function(e){instance.edit(e,this);};

				valuediv.style.width = "100%";
				valuediv.style.height = valuediv.parentNode.offsetHeight-2+"px";

			}
			
			
			
			
		}
		this.element = table;
		return table;
	}

	this.row = function(){
		if(this.element)
			parent = this.element.parentNode;
		var row = gui.createElementTo("tr",parent,this.element);

		
		this.element = row;
		for(var i = 0; i < this.specs.length; i++){
			var spec = this.specs[i];
			var valuetd = document.createElement("td");
			var valuediv = document.createElement("div");
			var valuetext = null;

			this.showValue(spec,valuediv);
			valuetd.appendChild(valuediv);
			
			
			
			if(spec.edit){
				instance = this;
				valuediv.onclick = function(e){instance.edit(e,this);};
				valuediv.style.width = "100%";
				valuediv.style.height = valuediv.parentNode.offsetHeight-2+"px";
			}
			
			
			row.appendChild(valuetd);
			
			
		}

		return row;
	}
	
	this.showValue= function(spec,element,replace){
		switch(spec.type){
				case "int":
					if(replace)
						if(this.obj[spec.obj][spec.key] == replace.data)
							break;
					var valuetext = gui.createTextNodeTo(this.obj[spec.obj][spec.key],element,replace);
					break;
				case "string":
					if(replace)
							if(this.obj[spec.obj][spec.key] == replace.data)
								break;
					var valuetext = gui.createTextNodeTo(this.obj[spec.obj][spec.key],element,replace);

					break;
				case "multistr":
					var rows = spec.key.split(",");
					var valuetext = gui.createElementTo("div",element,replace);

					for(var x = 0; x < rows.length;x++){
						var ids = rows[x].split("+");
						for(var y = 0; y < ids.length;y++){
							var span = document.createElement("span");
							var text = this.obj[spec.obj][ids[y]];
							if(y < ids.length-1)
								text += spec.glue;
							span.appendChild(document.createTextNode(text));
							valuetext.appendChild(span);
						}
						
						if(x < rows.length-1)
							valuetext.appendChild(document.createElement("br"));
					}
					break;
				case "multiline":
					var valuetext = gui.createElementTo("div",element,replace);
					if(element)
						element.appendChild(valuetext);
					for(x = 0; x < this.obj[spec.obj][spec.key].length;x++)
					{
						valuetext.appendChild(document.createTextNode(this.obj[spec.obj][spec.key][x]));
						if(x < this.obj[spec.obj][spec.key].length-1)
							valuetext.appendChild(document.createElement("br"));
					}
					break;
				case "static":
					if(spec.data)
						if(spec.data.tagName){
							valuetext = gui.cloneNodeTo(spec.data,element,replace);

												
						}
						else
							valuetext = gui.createTextNodeTo(spec.data,element,replace);
				break;
				default:
					value = this.obj[spec.obj][spec.key];
					if(spec.type)
					if(spec.type.call)
						value = spec.type.call(this,value,spec.key);
					if(replace)
						if(value == replace.data)
							break;
					var valuetext = gui.createTextNodeTo(value,element,replace);
					//if(element)
					//	element.appendChild(valuetext);
					break;
			}
			
			if(element)
			if(spec.hl){
				if(!spec.hlqueue)
					spec.hlqueue = ++gui.effectQueues;
				if(Effect[spec.hl.type]){
					spec.hl.spec.queue = {position:"end",scope:"queue"+spec.hlqueue};
					
					var effect = new Effect[spec.hl.type](element,spec.hl.spec);
					var clearEffect = new Effect.Opacity(element, {duration:0.0,  to:1.0,queue:spec.hl.spec.queue});
				}else{	//Standarteffect
					var effect = new Effect.Pulsate(element,spec.hl);
				}
				spec.hl = null;
				
			}
			
			return valuetext;
	}
	
	this.div = function(styles){
		
	}
	
	this.renderTable =function(){
		if(this.element)
			if(this.element.childNodes.length != this.specs.length)
				return this.table();	//Das erste mal Rendern
			else{
				for(var i=0; i<this.specs.length;i++){
					var spec = this.specs[i];
					
					if(this.element.childNodes[i].firstChild.firstChild.firstChild.data == spec.name)
						this.showValue(spec,this.element.childNodes[i].firstChild.nextSibling.firstChild,
									  this.element.childNodes[i].firstChild.nextSibling.firstChild.firstChild);
				}
			}
	}
	
	this.renderRow = function(){
		if(this.element)
			if(this.element.childNodes.length != this.specs.length)
				return this.table();	//Das erste mal Rendern
			else{
				for(var i=0; i<this.specs.length;i++){
					var spec = this.specs[i];
					
					//if(this.element.childNodes[i].firstChild.firstChild.data == spec.name)
						this.showValue(spec,this.element.childNodes[i].firstChild,
								this.element.childNodes[i].firstChild.firstChild);
				}
			}
	}
	
	this.render = function(){
		if(!this.element)
			return;
		element = this.element;
		switch(this.rendermode){
			case 1:
				this.renderRow();
			break;
			case 0:
			default:
				this.renderTable();
			break;
		}
		
		if(this.element)
			if(element.parentNode)
				element.parentNode.replaceChild(this.element,element);
	}
	
	this.setItemHl = function(obj,key,type){
		
		for(var i = 0; i < this.specs.length; i++){
			if((this.obj[this.specs[i].obj] == obj)&&(this.specs[i].key == key)){
				if(!type)
					type = defaultHlType;
				
				this.specs[i].hl = type;
			}
		}
	}
	
	this.edit = function(e,child){
		var name = child.parentNode.previousSibling.firstChild.firstChild.data;
		var spec = null;
		for(var i = 0; i < this.specs.length; i++){
			if(this.specs[i].name == name){
				spec = this.specs[i];
				break;
			}
		}
		
		if(!spec)
			return ;
			
		instance = this;	
		
		if(isFunction(spec.edit["edit"])){
			spec.edit["edit"].call(this,e,child);
		}
		
		switch(spec.type){
			case "date":
				var key = spec.key;
				var input = document.createElement("input");
				
				child.parentNode.replaceChild(input,child);
				
				var calendarOption = gui.createElementTo("span",input.parentNode)
				
				var calendarButton = gui.createElementTo("a",calendarOption);
				calendarButton.className = "cCalendarButton";
				
				var value = this.obj[spec.obj][spec.key];

				var calendar = new gui.cCalendar(calendarButton.parentNode,value.split(".")[1]*1,value.split(".")[2]);
				
				calendarButton.onclick = function() {calendar.show()};
				
				input.onblur = function(e){instance.notify(e,this,spec);gui.deleteNode(calendarOption)};
				input.onkeydown = function(e){
					e = e ? e : window.event;
					var keyCode = e.keyCode ? e.keyCode : e.which;
					if(keyCode == 13)
						this.blur();
				};
				input.value = child.firstChild.data;
				input.name = key;
				
				
			break;
			case "string":
			case "int":
				var key = spec.key;
				var input = document.createElement("input");
				
				input.onblur = function(e){instance.notify(e,this,spec)};
				input.onkeydown = function(e){
					e = e ? e : window.event;
					var keyCode = e.keyCode ? e.keyCode : e.which;
					if(keyCode == 13)
						this.blur();
				};
				input.value = child.firstChild.data;
				input.name = key;
				
				child.parentNode.replaceChild(input,child);
				input.focus();
			break;
			case "multistr":
				var rows = spec.key.split(",");
				var div = gui.createElementTo("div",child.parentNode,child);

				for(var x = 0; x < rows.length;x++){
					var ids = rows[x].split("+");
					for(var y = 0; y < ids.length;y++){
						var span = gui.createElementTo("span",div);
						var input = gui.createElementTo("input",div);
						var value = this.obj[spec.obj][ids[y]];
						var text = ids[y];
						
						input.value = value;
						input.name = text;
						
						span.style.cssFloat = "left";
						input.style.cssFloat = "right";
						span.style.clear = "both";
						
						input.onblur = function(e){instance.notify(e,this,spec)};
						input.onkeydown = function(e){
							e = e ? e : window.event;
							var keyCode = e.keyCode ? e.keyCode : e.which;
							if(keyCode == 13){
								this.blur();
							}
						};
						
						gui.createTextNodeTo(text,span);
						//gui.createElementTo("br",div);
					}
					
					if(x < rows.length-1)
						valuetext.appendChild(document.createElement("br"));
				}
				break;


			default:
				var key = spec.key;
				if(isArray(spec.edit)){
					
					var input = gui.createElementTo("select",child.parentNode,child);
					
					input.onchange = function(e){instance.notify(e,this,spec)};
					input.onblur = function(){this.onchange();};
					for(var i= 0; i<spec.edit.length;i++){
						if(!spec.edit[i])
							continue;
						var option = gui.createElementTo("option",input);
						gui.createTextNodeTo(spec.edit[i],option);
						option.value = i;
						
						if(i == this.obj[spec.obj][spec.key])
							option.selected = true;
					}
					
					input.name = key;
					input.focus();
				}
				break;
				
		}
		
		
		
		
		
	}
	
	this.notify = function(e,child,spec){
		switch(spec.type){
			case "int":
				if(!(child.value*1)){
					var msg = document.createElement("p");
					msg.innerHTML = "F&uuml;r das Feld '"+spec.name+"' sind nur numerische Werte erlaubt.<br/>"
							+"Ihre Eingabe: "+child.value;
					bsystem.message.obj.addMessage(msg,"Eingabefehler",gui.MSG_TYPE_ERROR);
					break;
				}else{
					child.value = child.value*1;
				}
			case "date":
			case "string":
				var key = spec.key;
				if(isFunction(this.edit["notify"])){
					this.edit["notify"].call(this,e,child,spec);
				}else{
					if(isFunction(this.obj[spec.obj].setProperty)){
						this.obj[spec.obj].setProperty(key,child.value);
					}
				}
			break;
			case "multistr":
				if(child != child.parentNode.lastChild){
					if(child.nextSibling.nextSibling.focus){
						child.nextSibling.nextSibling.focus();
						if(child.nextSibling.nextSibling.select)
						child.nextSibling.nextSibling.select();
						return;
					}
						
				}
				if(isFunction(this.edit["notify"])){
					this.edit["notify"].call(this,e,child,spec);
				}else{
					if(isFunction(this.obj[spec.obj].setProperty)){
						var inputs = child.parentNode.getElementsByTagName("input");
						for(var i = 0; i < inputs.length; i++)
							this.obj[spec.obj].setProperty(inputs[i].name,inputs[i].value);
					}
				}
				child = child.parentNode;
				
				break;
			case "date":
				
			break;
			default: 
				if(isFunction(this.edit["notify"])){
					this.edit["notify"].call(this,e,child,spec);
				}else{
					if(typeof(child.value) != "undefined" ){
						if(this.obj[spec.obj].setProperty)
							this.obj[spec.obj].setProperty(spec.key,child.value);
					}
				}
			break;
		}
		var div = gui.createElementTo("div",child.parentNode,child);
		div.onclick = function(e){instance.edit(e,this);};
		div.style.width = "100%";
		div.style.height = div.parentNode.offsetHeight-2+"px";
		this.render();
		
	}
}

gui.objectTableViewer = function(obj,specs,element){
	this.obj = obj;
	
	this.objects = new Array();
	
	for(var i=0; i < obj.length;i++)
		this.objects.push({object:obj[i],viewer:null});
	
	
	this.specs = specs;
	this.element = element;
	
	this.search = new Array();
	
	var instance = this;
	
	this.renderFull = function(){
		var table = this.element;
		var rowth = document.createElement("tr");
		
		table.appendChild(rowth);
		for(var i = 0; i < this.specs.length; i++){
			var spec = this.specs[i];
			var th = document.createElement("th");
			var a = document.createElement("a");
			
			var instance = this;
			
			if(spec.key.indexOf(this.sortKey) > -1)
				a.className = "curSort";
			a.onclick = function(e){instance.sort(e,this)};
			
			rowth.appendChild(th);
			th.appendChild(a);
			a.appendChild(document.createTextNode(spec.name));
			
			if(spec.search)
				this.addSearch(i);
		}
		
		if(this.search.length > 0){
			if(!this.searchEle){
				this.searchEle = document.createElement("fieldset");
				table.parentNode.insertBefore(this.searchEle,table);
				
				var legend = gui.createElementTo("legend",this.searchEle);
				gui.createTextNodeTo("Search",legend);
				this.searchEle.className = "objTableViewerSearch";
				legend.onclick = function(){
					if(this.nextSibling.style.display == "block")
					this.nextSibling.style.display = 'none';
					else
					this.nextSibling.style.display = 'block';
				};
				
			}
						
			var searchOptions = gui.createElementTo("ul",this.searchEle);
			searchOptions.style.display = "none";
			for(var i = 0; i < this.search.length;i++){
				if(!this.search[i])
					continue;
				var spec = this.specs[i];
				var option = gui.createElementTo("li",searchOptions);
				var optionName = gui.createElementTo("label",option);
				gui.createTextNodeTo(spec.name,optionName);
				var input = gui.createElementTo("input",option);
				input.name = i;
			
			}
			var option = gui.createElementTo("li",searchOptions);
			var go = gui.createElementTo("a",option);
			gui.createTextNodeTo("Go",go);

			go.onclick = function(e){instance.setSearchCriterias(this.parentNode.parentNode)};
			
			this.fullRendered = true;
		}
		
		
		for(var i = 0; i < this.obj.length;i++){
			var viewer = new gui.objectViewer(this.objects[i].object,this.specs,1);
			var row = document.createElement("tr");
			viewer.element = row;
			table.appendChild(row);
			viewer.row();
			this.objects[i].viewer = viewer;

		}
		
		table.appendChild(gui.cloneNodeXl(rowth));
	
		return table;
	}
	
	this.renderSimple =function(){

		for(var i = 0; i < this.objects.length;i++){
			this.element.insertBefore(this.objects[i].viewer.element,this.element.lastChild);
			this.objects[i].viewer.render();
			if(this.filter)
				for(var x in this.filter){
					if(isString(this.filter[x]))
					{
						if(this.objects[i].viewer.element.childNodes[x].firstChild.innerHTML.indexOf(this.filter[x]) == -1)
							this.element.removeChild(this.objects[i].viewer.element);
					}
				}
		}
	}
	
	this.render = function(){
		if(!this.sortKey){
			return this.sort(null,this.specs[0]);
		}
/*
		var table = (this.element.getElementsByTagName("tr").length != this.objects.length+2) ? gui.createElementTo("table",this.element.parentNode,this.element) : this.element;
		table.border = 1;		// Verschiebebug! :S ='(
		if(table == this.element){
			this.element = table;
			this.renderSimple();
		}else{
			this.element = table;
			this.renderFull();
		}*/
		if(this.fullRendered){
			this.renderSimple();
		}else{
			this.element = gui.createElementTo("table",this.element.parentNode,this.element)
			this.renderFull();
		}
		this.element.border = 1;	
		

		return this.element;

	}
	
	this.sort = function(e,child){
		type = "string";
		for(var i = 0; i < this.specs.length;i++){
			if(child.firstChild)
			if(this.specs[i].name == child.firstChild.data)
				var spec = this.specs[i]
			if(this.specs[i] == child)
				var spec = child;
		}
		type = spec.type;
		key = spec.key;
		obj = spec.obj;
		while((key.indexOf("+") > -1)||(key.indexOf(",")>-1)){
			key = key.split(",")[0].split("+")[0];
		}
		
		switch(type){
			case "int":
				var func = function(a,b){return a - b};
			break;
			case "date":
				var func = function(a,b){return (new Date(a.split(".")[2],a.split(".")[1],a.split(".")[0]).getTime())-(new Date(b.split(".")[2],b.split(".")[1],b.split(".")[0]).getTime());}
			break;
			case "string":
			default:
			break;
		}
		
		var sortFunc = function(a,b){
			var tempArr = new Array(a[obj][key],b[obj][key]);
			if(func)
				tempArr.sort(func);
			else
				tempArr.sort();
			if(tempArr[0] == a[obj][key])
				return -1;
			else
				return 1;
		}
		
		var sortFunc2 = function(a,b){
			var tempArr = new Array(a.object[obj][key],b.object[obj][key]);
			if(func)
				tempArr.sort(func);
			else
				tempArr.sort();
			if(tempArr[0] == a.object[obj][key])
				return -1;
			else
				return 1;
		}
		
		this.obj.sort(sortFunc);
		this.objects.sort(sortFunc2);
		
		if((this.sortKey == key)&&(!this.reverseSort)){
			this.obj.reverse();
			this.objects.reverse();
			this.reverseSort = true;
		}else{
			this.reverseSort = false;
		}
		
		this.sortKey = key;
		
		return this.render();
	}
	
	this.addSearch = function(specNr){
		this.search[specNr] = true;
	}
	
	this.setSearchCriterias = function(obj){
		var inputs = obj.getElementsByTagName("input");
		this.filter = new Array();
		for(var i =0; i < inputs.length;i++){
			if(inputs[i].value){
				this.filter[inputs[i].name] = inputs[i].value;
			}
		}
		
		this.renderSimple();
	}
}

gui.cMessage	= function(text,title,type,spec,iconParent,windowParent,onok,oncancel,onclose){
	
	this.autoSpec =function(type,addspec){
		var spec = type ? copyObject(type) : gui.MSG_TYPE_NOTIFY;
		for(var prop in addspec){
			spec[prop] = addspec[prop];
		}
		return spec;
	}
	
	this.display = function(){
		clearTimeout(this.timeout);
		if(!this.window){
			var spec = {drag:true,titlebar:true,type:gui.WND_TYPE_DLG|gui.WND_OK};
			if(this.type == gui.MSG_TYPE_CRIT)
				spec = {drag:true,titlebar:true,type:gui.WND_TYPE_MODAL|gui.WND_OK};

			this.win = new gui.cWindow(this.text,this.windowParent,this.title,null,spec);
			this.win.onok = this.onok;
			this.win.onclose = this.onok;
		}else{
			this.win.appendTo(this.windowParent);
		}
	}
	
	this.renderIcon = function() {
		if(!this.icon){
			this.icon = document.createElement("a");
			this.icon.className = "msgIcon";
			this.icon.style.backgroundImage = "url('"+this.spec.icon+"')";
			this.icon.onclick = function(){instance.display()};
		}
		this.iconParent.appendChild(this.icon);
	}
	
	this.destroy = function(){
		gui.deleteNode(this.icon);
		this.icon = null;
		if(this.win)
			this.win.destroy();
		this.window = null;

	}

	this.text = text;
	this.title= title;
	this.type = type;
	this.spec = this.autoSpec(type,spec);
	this.iconParent = iconParent;
	this.windowParent = windowParent ? windowParent : document.body;
	this.onok = onok;
	this.oncancel = oncancel;
	this.onclose = onclose;
	
	var instance = this;
	
	if(this.type == gui.MSG_TYPE_CRIT)
		this.display();
	
	if(this.spec.duration){
		this.timeout = setTimeout(function(){instance.destroy()},this.spec.duration*1000);
	}
}

gui.cMessageMapper = function(element,spec){
	this.element = element;
	this.spec = spec;
	
	this.messages = new Array();
	
	this.addMessage = function(text,title,type,spec){
		var message = new gui.cMessage(text,title,type,spec,this.element,null,function(){message.destroy();});
		var id = this.messages.push(message);
		//message.onok = function(){alert("?");message.destroy();};
		message.renderIcon();
		return message;
	}
	
	this.clear = function(){
		for(var i = 0; i < this.messages.length; i++){
			this.messages[i].destroy();
			delete this.messages[i];
		}
		
		this.messages = new Array();
	}
}
// /style=(["|'])^\n]*\1/

gui.cCalendar = function(parent,month,year,onchange,cssClass){
	
	if(year < 1900)
		year = "20"+year;
	
	var monatstage = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var monate= new Array("Januar","Februar","M�rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
	var instance = this;
	
	this.year = year;
	this.month = month;
	
	if(parent){
		var calendar = gui.createElementTo("div",parent);
	}else{
		var calendar = document.createElement("div");
	}
	
	if(!cssClass){
		cssClass = "cCalendar";
	}
	
	calendar.className = "cCalendar";
	
	var head = gui.createElementTo("div",calendar);
	head.className = "head";
	
	var previousMonth = gui.createElementTo("a",head);
	gui.createTextNodeTo("<<",previousMonth);
	previousMonth.onclick = function(){instance.previousMonth();};
	previousMonth.style.cssFloat = "left";
	
	var nextMonth = gui.createElementTo("a",head);
	gui.createTextNodeTo(">>",nextMonth);
	nextMonth.onclick = function(){instance.nextMonth();};
	nextMonth.style.cssFloat = "right";
	
	
	var titleMonth =  gui.createElementTo("span",head);
	
	
	
	
	var body = gui.createElementTo("div",calendar);
	
	this.changeDate = function(month,year){
		gui.removeChilds(body);
		
		if(year >1900)
			this.year = year;
		
		this.month = month;
		
		while(this.month < 1){
			this.year--;
			this.month += 12;
		}
		
			
		this.date = new Date(this.year,this.month-1,1);

		titleMonth.innerHTML = monate[this.date.getMonth()]+" "+this.date.getFullYear();
			
		var days = monatstage[this.date.getMonth()];
		if((days == 28) &&(this.year % 4 == 0))
			days = 29;
		
			
		var firstday = this.date.getDay();
		if(firstday == 0)
			firstday = 7
		for(var i = 1; i < firstday;i++){
			var day = gui.createElementTo("a",body);
			day.className = "day";
		}
			
		for(var i = 1; i <= days; i++){
			var day = gui.createElementTo("a",body);
			day.className = "day";
			var daytext = gui.createTextNodeTo(i+".",day);
			
		}
	}
	
	this.nextMonth = function(){
		this.changeDate(this.month+1);
	}
	
	this.previousMonth = function(){
		this.changeDate(this.month-1);
	}
	
	this.changeDate(this.month,this.year);
}

gui.progressbar = function(){
	
	var bar;
	var abortCallback;
	var bartype;
	var statustext;
	var backref = this;
	
	this.create = function(type){
		
	}
	
	this.setObject = function(obj,type){
		bar = obj;
		bartype = type;
	}
	
	this.init = function(){
		if(bartype && 1){
			if(!bar.getElementsByTagName("a")[0]){
				var cancel = gui.createElementTo("a",bar);
				cancel.className = "cancelsmall";
				cancel.onclick = function(){backref.onAbort()};
			}
		}
		if(!bar.getElementsByTagName("span")[0]){
			statustext = gui.createElementTo("span",bar);
		}else
			statustext = gbar.getElementsByTagName("span")[0];
		
	}
	
	this.status = function(text){
		statustext.innerHTML = text;
	}
	
	this.progress = function(progress,text){
		
	}
	
	this.setAbort = function(callback){
		abortCallback = callback;
	}
	
	this.onAbort = function(){
		statustext.innerHTML = "User Interupted";
		bar.firstChild.style.display = "none";
		bar.style.backgroundImage = "url('"+homePath+"/layout/images/system/progress_done.jpg')";
		if(abortCallback)
			abortCallback(this);
	}
	
	this.finish = function(text){
		statustext.innerHTML = text;
		bar.style.backgroundImage = "url('"+homePath+"/layout/images/system/progress_done.jpg')";
		bar.firstChild.style.display = "none";
	}
	
	this.loading = function(text){
		
		bar.style.visibility = "visible";
		bar.style.backgroundImage = "url('"+homePath+"/layout/images/system/progress.gif')";
		
		bar.firstChild.style.display = "block";
		if(text)
			this.status(text);
	}
	
	this.getBar = function(){
		return bar;
	}
	
	return this;
}


gui.console = new Object();
gui.console.window = new Object();
gui.console.control = new Object();
gui.console.system = new Object();


gui.console.window.hwnd = false;

gui.console.window.open = function(){
	if(!gui.console.window.hwnd)
		gui.console.window.init();
	gui.console.window.show();
}

gui.console.window.init = function(){
	gui.console.window.hwnd = gui.createElementTo("div",document.body);
	gui.console.window.hwnd.className = "console";
	//gui.console.window.hwnd.style.height = "0px";
	
	gui.console.window.output = gui.createElementTo("ul",gui.console.window.hwnd);
	gui.console.window.input = gui.createElementTo("input",gui.console.window.hwnd);
	gui.console.window.input.onkeypress = gui.console.window.typing;
	gui.console.window.output.className = "output";
}

gui.console.window.show = function(){
	gui.console.window.hwnd.style.display = "block";
}

gui.console.window.close = function(){
	gui.console.window.hwnd.style.display = "none";
}

gui.console.window.clear = function(){
	gui.removeChilds(gui.console.window.output);
}

gui.console.window.typing = function(e){
	var e = e || window.event;
	var code = e.witch ? e.witch : e.keyCode;
	switch(code){
		case 13:
			gui.console.control.command(this.value);
			this.value = "";
		break;
		case 38: //up arrow
			
			gui.console.system.history.pointer++;
			var cmds = gui.console.system.history.cmds;
			
			if(gui.console.system.history.pointer > cmds.length)
				gui.console.system.history.pointer = 1;
				
			if(cmds.length == 0)
				break;
				
			this.value = cmds[cmds.length-gui.console.system.history.pointer];
	            break;
	    case 40: //down arrow
			gui.console.system.history.pointer--;
			var cmds = gui.console.system.history.cmds;
			
			if(gui.console.system.history.pointer < 1)
				gui.console.system.history.pointer = cmds.length;
				
			if(cmds.length == 0)
				break;
				
			this.value = cmds[cmds.length-gui.console.system.history.pointer];
	            break;
	}
}




gui.console.control.workingDir = "";
gui.console.control.user = new Object();
gui.console.control.user.user = "coni";

gui.console.control.output = function(output){
	
	var scroll = true;
	if(gui.console.window.output.scrollTop&&
	((gui.console.window.output.scrollTop+gui.console.window.output.offsetHeight) < gui.console.window.output.scrollHeight))
		scroll = false;
	
	
	var line = gui.createElementTo("li",gui.console.window.output);
	var user = gui.createElementTo("span",line);
	var out  = gui.createElementTo("div",line);

	var dir = gui.console.control.workingDir;
	if(gui.console.control.user)
		var username = gui.console.control.user.user;
	else
		var username = "";
	gui.createTextNodeTo(dir+" : "+username+" > ",user);
		user.scrollLeft = user.scrollWidth;
	var cmd;
	var obj;

	if(isObject(output)){
		obj = output;
		cmd = output.request;
		output = output.output;
	}
	
	//gui.createTextNodeTo(output,out);
	if(cmd)
		out.innerHTML = cmd;

	if(output)
		if(isArray(output)){
			var outputUL = gui.createElementTo("ul",out);
			for(var i = 0; i < output.length; i++){
				var li = gui.createElementTo("li",outputUL);
				gui.createTextNodeTo(output[i],li);
			}
		}else{
			if(cmd)
				out.innerHTML += "<br>"+output;
			else
				out.innerHTML = output;
		}
	if(obj)
	if(obj.error){
		out.innerHTML += "<p class='error'>"+obj.error+"</p>";
	}
	
	if(scroll)
		gui.console.window.output.scrollTop = gui.console.window.output.scrollHeight;
	
	return line;
}

gui.console.control.command = function(cmd){
	gui.console.system.history.cmds.push(cmd);
	gui.console.system.history.pointer = 0;
	if(cmd == "exit"){
		gui.console.window.hwnd.style.display = "none";return;
	}
	
	if(cmd == "clear"){
		gui.console.window.clear();return;
	}
	
	var request = new Object();
	request.cmd = cmd;
	request.workingDir = gui.console.control.workingDir;

	//gui.console.control.output(cmd);
	gui.console.control.request(request);
}

gui.console.control.request = function(request){
	url = "https://"+window.location.hostname+homePath+"/module/cms/console/console.ajax.php";
	url = "http://"+window.location.hostname+homePath+"/module/cms/console/console.ajax.php";
	
	onload = gui.console.control.progress;
	

	post = "&request="+Object.toJSON(request);//request.toJSONString();
		
	var ongather = null;
	var onerror = function(){
		gui.console.control.output("error fetching data! Status:"+this.ajax.status);
		gui.console.control.output(this.ajax.responseText);
	};
	
	req = new net.postRequest(url,onload,post,ongather,onerror);
}

gui.console.control.progress = function(){
	try {
		
		var answer = eval("("+this.ajax.responseText+")");
		
	} catch(error) {
		//debug(this.ajax.responseText);
		gui.console.control.output("error using data! Return:"+this.ajax.responseText);
	} finally {
		
		/*if(!answer.user)
			return;*/
			
		//Die Arbeitsvariablen setzen
		gui.console.control.user = answer.user;
		gui.console.control.workingDir = answer.workingDir;
		
		switch(answer.cmd){
			case "access":
				if(answer.access == 1)
					gui.console.window.open();
			break;
			default:
				gui.console.control.output(answer);
				//gui.console.control.output(this.ajax.responseText);
			break;
		}	
	}
	

	
}

gui.console.control.open = function(){
	var request = new Object();
	request.cmd = "access";

	gui.console.control.request(request);
	
}
gui.console.system.history = new Object();
gui.console.system.history.cmds = new Array();
gui.console.system.history.pointer = 0;

gui.console.system.onWindowKeyPress = function(e){
	//which ;
	var e = e || window.event;
	var code = e.which ? e.which : e.keyCode;

	str = String.fromCharCode(code);

	if(e.ctrlKey && e.altKey && (code == 48))
		gui.console.control.open();
		
	if(gui.console.system.oldOnWindowKeyDown)
		gui.console.system.oldOnWindowKeyDown(e);
}

var system = new Object();

system.setCookie = function(name,value){
	var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*365);
	document.cookie = name+'='+value+'; expires='+a.toGMTString()+';'; 	
}

system.readCookie = function(name){
	var variables = new Object();
	
	a = document.cookie;
	res = '';
	while(a != '')
	{
		cookiename = a.substring(0,a.search('='));
		cookiewert = a.substring(a.search('=')+1,a.search(';'));
		if(cookiewert == '')
		{
			cookiewert = a.substring(a.search('=')+1,a.length);
		}
		
		if(name == cookiename){
			res = cookiewert;
		}
		
		i = a.search(';')+1;
		if(i == 0){i = a.length}
			a = a.substring(i,a.length);
	}
	return(res)
}

system.deleteCookie = function(name){
	document.cookie = name+'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

/*
	Hooking some Events
*/

gui.console.system.oldOnWindowKeyPress = window.onkeypress;
window.onkeypress = gui.console.system.onWindowKeyPress;