function DOMElementBase (id) {
	this.id = id;
	this.focus = false;
	this.focusStack = [];
	this.blurStack = [];
	
	this.__defineSetter__("onfocus",function (value) { 
		var self = this; 
		this.focusStack.push(value);
		this.addEvent("click",function (e) { 
			if (!self.focus) {
				self.focus = true;
				for (var i = 0; i < self.focusStack.length; i++) {
					self.focusStack[i](e);
				}
				global.onblurStack = self;
			}
		},true);
	});
	this.__defineSetter__("onblur",function (value) { this.blurStack.push(value); });
	this.__defineGetter__("onblur",function () { global.onblurStack = null; this.focus = false; return this.blurStack; });
}


function Element (id,className,tag,insertPlace,insertBeforePlace) {
	var self = this;
	this.constructor(id);
	this.id = id + tag;
	this.tag = tag.toLowerCase();
	
	this.object = document.createElement(this.tag);
	if (id) {
		this.object.id = id + tag;
	}
	if (typeof(className) != "undefined" && className != "")
		this.object.className = className;
	if (typeof(insertPlace) != "undefined") {
		if (typeof(insertBeforePlace) != "undefined") {
			this.insert(insertPlace,insertBeforePlace);
		}
		else {
			this.insert(insertPlace);
		}
	}
	
	//this.onfocus = function () { if (this.commands) alert("ABC"); };
}

Element.prototype = new DOMElementBase();

DOMElementBase.prototype.addAttribute = function (property,value) {
	if (typeof(property) == "undefined" || typeof(property) == "undefined")
		throw "Parserfehler: Property und / oder value ist / sind nicht definiert.";

	this.object.setAttribute(property,value);
	if (this.getAttribute(property) == value)
		return true;
	return "DOM-Fehler: Das Attribut konnte nicht gesetzt werden. Möglicherweise existiert es im W3C-Standard nicht.";
}

DOMElementBase.prototype.getAttribute = function (property) {
	if (!property)
		return "Parserfehler: Property ist nicht definiert";
	
	return this.object.getAttribute(property);
}

DOMElementBase.prototype.removeAttribute = function (property) {
	if (typeof(property) == "undefined")
		throw "Parserfehler: Property ist nicht definiert";
	
	this.object.removeAttribute(property);
	return true;
}

DOMElementBase.prototype.addStyle = function (property,value,returnobject) {
	if (returnobject == true) {
		returnobject = this;
	}
	else
		returnobject = true;
	
	if (typeof(property) == "undefined" || typeof(value) == "undefined")
		throw "Parserfehler: Property und / oder value ist / sind nicht definiert. Folgende Werte wurden übergeben: Property: " + property + " value: " + value;
	
	if (typeof(property) == "object" && typeof(value) == "object") {
		if (property.length != value.length)
			throw "Parserfehler: Anzahl der Argumente stimmt nicht überein";
		
		for (var i = 0; i < property.length; i++)
			addStyle.call(this,property[i],value[i]);
		
		return returnobject;
	} else {
		addStyle.call(this,property,value);
		return returnobject;
	}
	
	
	function addStyle (property,value) {
		if (this.object.style.setProperty) {
			this.object.style.setProperty(property,value,null);
				return true;
		}
		if (this.object.style.setAttribute) {
			self.object.style.setAttribute(property,value,false);
			return true;
		}
			
		throw "DOM-Fehler: Das Stilattribut konnte nicht hinzugefügt werden. Überprüfen Sie, ob property und value korrekt sind und dem W3C-Standard entsprechen";
	}
}

DOMElementBase.prototype.getStyle = function (property) {
	if (property == "margin-left") {
		property = "marginLeft";
	} else if (property == "margin-top") {
		property = "marginTop";
	} else if (property == "margin-right") {
		property = "marginRight";
	} else if (property == "margin-bottom") {
		property = "marginBottom";
	} else if (property == "padding-left") {
		property = "paddingLeft";
	} else if (property == "padding-right") {
		property = "paddingRight";
	} else if (property == "border-left-width") {
		property = "borderLeftWidth";
	} else if (property == "border-right-width") {
		property = "borderRightWidth";
	}
	
	if (window.getComputedStyle)
		return window.getComputedStyle(this.object,null)[property];
	if (this.object.currentStyle)
		return this.object.currentStyle(property);
	throw "DOM-Fehler: Das Stilattribut konnte nicht ausgelesen werden. Überprüfen Sie, ob property korrekt ist und dem W3C-Standard entspricht."; 
}

DOMElementBase.prototype.getDeclaredStyle = function (property) {
	// 0E024
	
	if (property == "margin-left") {
		property = "marginLeft";
	} else if (property == "margin-top") {
		property = "marginTop";
	} else if (property == "margin-right") {
		property = "marginRight";
	} else if (property == "margin-bottom") {
		property = "marginBottom";
	} else if (property == "padding-left") {
		property = "paddingLeft";
	} else if (property == "padding-right") {
		property = "paddingRight";
	} else if (property == "border-left-width") {
		property = "borderLeftWidth";
	} else if (property == "border-right-width") {
		property = "borderRightWidth";
	}
	
	return this.object.style[property];
}

DOMElementBase.prototype.removeStyle = function (property) {
	if (this.object.style.removeProperty) {
		this.object.style.removeProperty(property);
		return true;
	}
	if (this.object.style.removeAttribute) {
		this.object.style.removeAttribute(property);
		return true;
	}
	throw "DOM-Fehler: Das Stilattribut konnte nicht entfernt werden. Überprüfen Sie, ob property korrekt ist und dem W3C-Standard entspricht.";
}
DOMElementBase.prototype.addEvent = function (type,eventFunction,capture) {
	if (typeof(type) == "undefined")
		throw "Parserfehler: Event ist nicht definiert.";
	if (typeof(eventFunction) != "function")
		throw "Parserfehler: EventFunction ist keine Funktion.";
	
	type = type.toLowerCase();
	var possible = false;
	var allowedEvents = new Array("click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","keydown","keyup","keypress","load","unload","abort","error","select","change","submit","reset","focus","blur","resize","scroll","beforeunload");
	for (var i = 0; i < allowedEvents.length; i++) {
		if (type == allowedEvents[i]) {
			if (type != "focus" && type != "blur" && type != "reset" && type != "submit" && type != "change" && type != "select" && type != "abort" && type != "error" && type != "unload" && type != "beforeunload")
				possible = true;
			else if ((type == "focus" || type == "blur") && (this.tag == "label" || this.tag == "input" || this.tag == "select" || this.tag == "textarea" || this.tag == "button"))
				possible = true;
			else if ((type == "reset" || type == "submit") && this.tag == "form")
				possible = true;
			else if (type == "change" && (this.tag == "input" || this.tag == "select" || this.tag == "textarea"))
				possible = true;
			else if (type == "select" && (this.tag == "input" || this.tag == "textarea"))
				possible = true;
			else if (type == "abort" && this.tag == "object")
				possible = true;
			else if (type == "error" && (this.tag == "object" || this.tag == "body"))
				possible = true;
			else if ((type == "unload" || type == "beforeunload") && this.tag == "body")
				possible = true;
			break;
		}
	}
	
	if (possible == true) {
		try {
			capture = capture ? capture : false;
			this.object.addEventListener(type,eventFunction,capture);
			return true;
		}
		catch (e) {
			try {
				this.object.attachEvent("on" + type,eventFunction);
				return true;
			}
			catch (e) {
				return "DOM-Fehler:" + e;
			}
		}
	}
	return "DOM-Fehler: Das Event existiert nicht im Standard des W3C oder es wurde auf einem nicht erlaubten HTML-Element platziert.";
}

Element.prototype.removeEvent = function (event,eventfunction) {
	// 0E026
	if (typeof(event) == "undefined" && typeof(eventfunction) != "function") 
		return "Parserfehler: Event und / oder eventfunction ist nicht definiert.";
	try {
		this.object.removeEventListener(event,eventfunction,false);
		return true;
	}
	catch (e) {
		try {
			this.object.detachEvent(event,eventfunction);
			return true;
		}
		catch (e) {
			return "DOM-Fehler:" + e;
		}
	}
}

DOMElementBase.prototype.addLabel = function (referenceObject) {
	if (typeof(referenceObject) == "object") {
		this.label = referenceObject;
		return true;
	}
	else
		return "Parserfehler: referenceObject ist nicht definiert oder ist kein Objekt";
}
DOMElementBase.prototype.removeLabel = function () {
	if (this.label != null)
		this.label = null;
	return true;
}
DOMElementBase.prototype.text = function (text,reset) {
	if (typeof(text) == "undefined")
		return this.object.innerHTML;
	
	if (text == "clear")
		this.object.innerHTML = "";
	else if (text == "++")
		this.object.innerHTML = (parseInt(this.object.innerHTML) + 1);
	else if (this.object.childNodes.length == 0 || reset == true)
		this.object.innerHTML = text;
	else {
		var textnode = document.createTextNode(text);
		this.object.appendChild(textnode);
	}
	
	return this;
}
DOMElementBase.prototype.insert = function (insertPlace,insertBeforePlace) {
	// Input-Erweiterung in 0E028
	if (typeof(insertPlace) == "undefined")
		throw "Parserfehler: Place ist nicht definiert.";
	
	if (typeof(insertBeforePlace) == "object") {
		try {
			if (insertPlace.style) {
				if (insertBeforePlace.style)
					insertPlace.insertBefore(this.object,insertBeforePlace);
				else
					insertPlace.insertBefore(this.object,insertBeforePlace.object);
			} else {
				if (insertBeforePlace.style)
					insertPlace.object.insertBefore(this.object,insertBeforePlace);
				else
					insertPlace.object.insertBefore(this.object,insertBeforePlace.object);
			}
			
			return true;
		} catch (e) {
			console.error("DOM-Fehler: Das Objekt mit der ID \""+ this.object.id +"\" konnte nicht eingefügt werden." + e);
		}
	}
	
	try {
		if (insertPlace instanceof Input && insertPlace.object.tagName !== "SELECT") {
			var container = insertPlace.container;
			container.object.appendChild(this.object);
			this.addStyle("margin-left","20px");
			return true;
		}
		
		
		if (typeof(insertPlace.style) == "undefined")
			insertPlace.object.appendChild(this.object);
		else
			insertPlace.appendChild(this.object);
		
		return true;
	} catch (e) {
		throw "DOM-Fehler:" + e;
	}
}

DOMElementBase.prototype.remove = function () {
	this.object.parentNode.removeChild(this.object);
}

DOMElementBase.prototype.makeDragable = function (fireElement,maxPositions,float,magneticLinesEnabled,magneticObjects) {
	var self = this;
	if (typeof(fireElement.style) != "undefined")
		fireElement = dodb(fireElement);
	
	fireElement.addEvent("mousedown",function draginit (event) {
						 event = event ? event : window.event;
						 drag.init(self,event.pageX,event.pageY,maxPositions,float,magneticLinesEnabled,magneticObjects);
						 if (event && event.preventDefault) event.preventDefault();
						 });
}

DOMElementBase.prototype.makeResizable = function (fireElement,maxSize,minSize,direction,proportion,magneticLinesEnabled,magneticObjects) {
	// Achtung geändert in 0E024
	var self = this;
	
	this.resizeProperties = {
		maxSize : maxSize,
		minSize : minSize,
		direction : direction,
		proportion : proportion,
		magneticLinesEnabled : magneticLinesEnabled,
		magneticObjects : magneticObjects
	}
	
	if (fireElement instanceof Array) {
		for (var i = 0; i < fireElement.length; i++) {
			addFireEvent(fireElement[i]);
		}
	} else
		addFireEvent(fireElement);
	
	function addFireEvent (object) {
		if (typeof(object.resizer) != "object")
			throw "Parserfehler: FireElement ist kein Resize-Objekt.";
		
		fireElementObject = object.resizer;
		if (object.type == "hud") {
			fireElementObject.addStyle(["left","top"],[parseInt(self.getStyle("width")) - 15 + "px",parseInt(self.getStyle("height")) - 15 + "px"]);
			fireElementObject.insert(self);
		} else if (object.type == "media") {
			if (object.position == "bottom right" || object.position == "top left")
				fireElementObject.addStyle("cursor","nwse-resize");
			else if (object.position == "top right" || object.position == "bottom left")
				fireElementObject.addStyle("cursor","nesw-resize");
			else if (object.position == "top center" || object.position == "bottom center")
				fireElementObject.addStyle("cursor","ns-resize");
			else if (object.position == "middle left" || object.position == "middle right")
				fireElementObject.addStyle("cursor","ew-resize");
		}
		
		fireElementObject.addEvent("mousedown",function resizeinit (event) {
								   event = event ? event : window.event;
								   proportion = event.altKey == 1 ? true : false;
								   proportion = event.shiftKey == 1 ? true : false;
								   resize.init(object,self,event.pageX,event.pageY);
								   if (event && event.preventDefault) event.preventDefault();
								   });
	}
}

DOMElementBase.prototype.setResizeProperty = function (property,value) {
	// 0E024
	this.resizeProperties[property] = value;
}

DOMElementBase.prototype.getPosition = function (whichPosition,viewpoint) {
	var object = this.object;
	if (whichPosition == "left") {
		var x = object.getBoundingClientRect().left;
		if (viewpoint === "document") {
			x += window.pageXOffset;
		}
		return x;
	}
	
	if (whichPosition == "top") {
		var y = object.getBoundingClientRect().top;
		if (viewpoint === "document") {
			y += window.pageYOffset;
		}
		return y;
	}
	
	var x = parseInt(object.offsetLeft);
	var y = parseInt(object.offsetTop);
	while (object.offsetParent.tagName.toLowerCase() != "body") {
		object = object.offsetParent;
		x += object.offsetLeft;
		y += object.offsetTop;
	}
	return [x,y];
}

DOMElementBase.prototype.getContentPosition = function (whichPosition) {
	// 0E023
	var object = this.object;
	if (whichPosition == "left") {
		var x = parseInt(object.offsetLeft);
		return x;
	}
	
	if (whichPosition == "top") {
		var y = parseInt(object.offsetTop);
		return y;
	}
	
	var x = parseInt(object.offsetLeft);
	var y = parseInt(object.offsetTop);
	return [x,y];
}

DOMElementBase.prototype.getRelativePosition = function (whichPosition,element) {
	// 0E024
	if (whichPosition === "left") {
		return this.getPosition("left") - element.getPosition("left");
	} else if (whichPosition === "top") {
		return this.getPosition("top") - element.getPosition("top");
	} else {
		return [this.getPosition("left") - element.getPosition("left"),this.getPosition("top") - element.getPosition("top")];
	}
}

DOMElementBase.prototype.getAvailibleWidth = function () {
	if (this.getStyle("box-sizing") === "border-box" || this.getStyle("-webkit-box-sizing") === "border-box" || this.getStyle("-moz-box-sizing") === "border-box") {
		return parseInt(this.getStyle("width"));
	} else {
		var width = parseInt(this.getStyle("width"));
		width -= parseInt(this.getStyle("padding-left")) + parseInt(this.getStyle("padding-right")) + parseInt(this.getStyle("border-left-width")) + parseInt(this.getStyle("border-right-width"));
		return width;
	}
}

DOMElementBase.prototype.whichElementChildren = function () {
	// 0E023
	var count = 0;
	var object = this.object.previousElementSibling;
	while (object) {
		count++;
		object = object.previousElementSibling;
	}
	
	return count;
}

DOMElementBase.prototype.focus = function () {
	this.object.focus();
}

DOMElementBase.prototype.blur = function () {
	this.object.blur();
}

DOMElementBase.prototype.isChildOf = function (element) {
	// 0E028
	var element = element.style ? element : element.object;
	var object = this.object;
	
	while (object.parentNode !== null) {
		if (object === element) {
			return true;
		}
		
		object = object.parentNode;
	}
	
	return false;
}




function Input (id,className,name,type,value,labeltext,labelclass,labelalign,functionNames,autoCache,insertPlace,insertBeforePlace) {
	if (type != "file" && type != "checkbox" && autoCache) {
		var objectForArray = [this,"input",global.activeWindow];
		global.usedObjects.push(objectForArray);
	}
	
	var self = this;
	
	this.constructor(id);
	this.type = type.toLowerCase();
	if (value instanceof Array) {
		this.infoValue = value[1];
		this.value = value[0];
	} else {
		this.infoValue = false;
		this.value = value;
	}
		
	if (Cache.get(global.activeWindow + ";input;" + this.id) && this.type != "select") {
		this.infoValue = this.value == Cache.get(global.activeWindow + ";input;" + this.id) ? false : true;
		this.value = Cache.get(global.activeWindow + ";input;" + this.id);
	}
	
	if (this.type == "textarea") {
		this.tag = "textarea";
		this.object = document.createElement(this.tag);
		this.addValue(this.value);
	} else if (this.type == "search") {
		this.tag = "input";
		this.object = document.createElement(this.tag);
		this.addAttribute("type","text");
		this.addValue(this.value);	
		
		if (typeof(className) != "undefined" && className != "")
			className = "search " + className;
		else
			className = "search";
	} else if (this.type === "search-with-options") {
		// 0E028
		this.tag = "input";
		this.object = document.createElement(this.tag);
		this.addAttribute("type","text");
		this.addValue(this.value);	
		
		if (typeof(className) != "undefined" && className != "")
			className = "searchwithoptions " + className;
		else
			className = "searchwithoptions";
			
		var optionspicker = new Element(false,"dbinputoptionspicker","div");
		this.optionspicker = new Element(false,"dboptionspicker","div",global.window);
		var optionsarrow = new Element(false,"arrow","img",this.optionspicker);
		optionsarrow.addAttribute("src","../../media/dbflexx/images/options_arrow.png");
		
		this.options = [];
		this.activeOptions = [];
		
		optionspicker.onfocus = function () {
			self.optionspicker.addStyle("display","block");
		}
		
		optionspicker.onblur = function (e) {
			if (!dodb(e).isChildOf(self.optionspicker)) {
				self.optionspicker.addStyle("display","none");
			}
		}
		
		this.optionspicker.onfocus = function () {}
		
		this.optionspicker.onblur = function (e) {
			if (!dodb(e).isChildOf(self.optionspicker)) {
				self.optionspicker.addStyle("display","none");
			}
		}
		
	} else if (this.type == "select") {
		this.tag = "select";
		this.object = document.createElement(this.tag);
		this.addValue(this.value,this.infoValue);
	} else if (this.type == "checkbox") {
		this.tag = "input";
		this.object = document.createElement(this.tag);
		this.addAttribute("type","checkbox");
		this.addValue(this.value);
	} else {
		this.tag = "input";
		this.object = document.createElement(this.tag);
		this.addAttribute("type",type);
		this.addValue(this.value);
	}
	
	
	this.addAttribute("name",name);
	
	this.reset();
	
	this.addEvent("keyup", function (event) {
				  event = event ? event : window.event;
				  if (event.which == 27)
				  self.clearAll.call(self);
				  });
	this.addEvent("blur", function () {
				  if (this.value == "") {
				  self.reset.call(self);
				  }});
	
	if (functionNames instanceof Array) {
		if (functionNames[1] == "letter") {
			// Verändert in 0E028
			this.addEvent("keyup", function (event) {
				var event = event ? event : window.event;
				if (typeof(functionNames[2] == "object")) 
					functionNames[0].call(functionNames[2],event,this.value,self.activeOptions);
				else
					functionNames[0](event,this.value,self.activeOptions);
			});
		} else if (functionNames[1] == "blur") {
			this.addEvent("keydown", function (event) {
						  event = event ? event : window.event;
						  if (event.which == 9) {
						  if (typeof(functionNames[2] == "object")) 
						  functionNames[0].call(functionNames[2],event,this.value);
						  else
						  functionNames[0](event,this.value);
						  }
						  });
			this.addEvent("keyup", function (event) {
						  event = event ? event : window.event;
						  if (event.which == 13) {
						  if (typeof(functionNames[2] == "object")) 
						  functionNames[0].call(functionNames[2],false,this.value);
						  else
						  functionNames[0](false,this.value);
						  this.blur();
						  }
						  });
		} else if (functionNames[1] == "enter") {
			this.addEvent("keyup", function (event) {
						  event = event ? event : window.event;
						  if (event.which == 13) {
						  if (typeof(functionNames[2] == "object")) 
						  functionNames[0].call(functionNames[2],false,this.value);
						  else
						  functionNames[0](false,this.value);
						  this.blur();
						  }
						  });
		} else if (functionNames[0] instanceof Function) {
			this.addEvent("change",function (event) {
						  event = event ? event : window.event;
						  functionNames[0](event,this.value);
						  });
		}
	}
	
	this.object.id = id + this.tag;
	if (this.tag == "select") {
		this.object.className = "dbselect";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbselect " + className;
	} else {
		this.object.className = "dbinput";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbinput " + className;
	}
	
	
	var inputContainer = new Element(id + "container","dbinputcontainer","div");
	this.container = inputContainer;
	if (typeof(labeltext) != "undefined" && labeltext != "") {
		this.labelalign = labelalign;
		var label = new Element(id,labelclass + " " + labelalign,"label");
		label.addAttribute("for",this.id);
		label.addStyle("display","block");
		
		if (labelalign == "left") {
			label.addStyle("float","left");
		} else if (labelalign == "right") {
			this.addStyle(["float","margin-right"],["left","5px"]);
		}
		
		label.text(labeltext);
		this.addLabel(label);
		
		if (typeof(insertPlace) != "undefined") {
			if (labelalign == "above" || labelalign == "left")
				label.insert(inputContainer);
			
			this.insert(inputContainer);
			inputContainer.insert(insertPlace,insertBeforePlace);
			
			if (labelalign == "right" || labelalign == "below")
				label.insert(inputContainer);
		}
	} else {
		if (typeof(insertPlace) != "undefined") {
			this.container.insert(insertPlace,insertBeforePlace);
			this.insert(this.container);
		}
	}
	
	if (optionspicker) {
		this.container.addStyle("text-align","right"); // SPEZIFISCH, MUSS DRINGEND GEÄNDERT WERDEN
		
		optionspicker.insert(this.container);
		var position = optionspicker.getRelativePosition("both",global.window);
		this.optionspicker.addStyle(["right","top"],["10px",position[1] + 30 + "px"]);
	}
	
}

Input.prototype = new DOMElementBase();

Input.prototype.clearAll = function () {
	this.object.value = "";
}

Input.prototype.reset = function () {
	var self = this;
	if (!this.infoValue) {
		this.addStyle("color","#808080");
		this.object.value = this.value;
		this.addEvent("focus",function () { 
					  if (this.value == self.value)
					  clearInput.call(self); 
					  });
	} else {
		this.addStyle("color","#000");
		this.addAttribute("value",this.value);
	}
	
	function clearInput () {
		this.object.value = "";
		self.addStyle("color","#000");
	}
}

Input.prototype.addValue = function (value,optionalValue) {
	if (this.type == "textarea")
		this.text(value);
	else if (this.type == "select") {
		if (value instanceof Array) {
			for (var i = 0; i < value.length; i++) {
				var option = document.createElement("option");
				option.value = optionalValue[i];
				option.innerHTML = value[i];
				dodb(option).insert(this);
			}
		}
	} else if (this.type == "checkbox") {
		this.object.checked = this.value;
	} else
		this.object.value = this.value;
}

Input.prototype.getValue = function () {
	if (this.type == "textarea")
		return this.text();
	else
		return this.object.value;
}

if ("defineProperty" in Object) {
	Object.defineProperty(Input.prototype,"disabled",{
		set : function (value) {
			this.object.disabled = value ? true : false;
		},
		get : function () {
			return this.object.disabled;
		}
	});
} else {
	Input.prototype.__defineSetter__("disabled",function (value) {
		this.object.disabled = value ? true : false;
	});
	Input.prototype.__defineGetter__("disabled",function () {
		return this.object.disabled;
	});
}

Input.prototype.addOptions = function (options,details) {
	// 0E028
	if (!(this.options instanceof Array)) {
		console.log("Dieser Input-Typ unterstützt keine Optionen");
		return;
	}
	
	var self = this;
	var list = new Element(false,false,"ul",this.optionspicker);
		
	options.forEach(function (value) {
		if (value instanceof Array) {
			var selectable = value[2];
			var defaultValue = value[1];
			value = value[0];
		}
		
		var listelement = new Element(false,false,"li",list).text(value);
		if (defaultValue === true) {
			listelement.addAttribute("class","active");
			self.activeOptions.push(value);
		}
		self.options.push(value);
		
		if (selectable !== false) {
			listelement.object.onclick = function (e) {
				if (e.altKey) {
					if (e.target.className.indexOf("active") === -1) {
						activateAll();
						e.target.className = "";
						self.activeOptions.in_array(value,true);
					} else {
						deactivateAll();
						e.target.className = "active";
						self.activeOptions.push(value);
					}
				} else {
					if (e.target.className.indexOf("active") === -1) {
						e.target.className = "active";
						self.activeOptions.push(value);
					} else {
						e.target.className = "";
						self.activeOptions.in_array(value,true);
					}
				}
								
				if (self.onOptionChange instanceof Function) {
					self.onOptionChange({ data : self.activeOptions });
				} else if (self.onOptionChange instanceof Array && self.onOptionChange.length === 2) {
					self.onOptionChange[0].call(self.onOptionChange[1],{ data : self.activeOptions });
				}
			}
		}
	});
	
	
	
	function activateAll () {
		var children = list.object.childNodes,
			i = 0;
		
		for (i; i < children.length; i++) {
			children[i].className = "active";
			self.activeOptions.push(children[i].firstChild.data);
		}
		
		self.activeOptions = self.activeOptions.unique();
	}
	
	function deactivateAll () {
		var children = list.object.childNodes,
			i = 0;
		
		for (i; i < children.length; i++) {
			children[i].className = "";
			self.activeOptions.in_array(children[i].firstChild.data,true);
		}
	}

	
	return this;
}




function Button (id,className,type,value,mode,firstHandler,secondHandler,insertPlace,insertBeforePlace) {
	var objectForArray = [this,"button",global.activeWindow];
	global.usedObjects.push(objectForArray);
	
	var self = this;
	
	this.constructor(id);
	this.type = type.toLowerCase();
	this.mode = mode;
	this.active = false;
	this.availible = true;
	if (firstHandler instanceof Array) {
		this.firstHandler = firstHandler[0];
		this.context = firstHandler[1];
	} else
		this.firstHandler = firstHandler;
	if (secondHandler instanceof Array) {
		this.secondHandler = secondHandler[0];
		this.context = secondHandler[1];
	} else
		this.secondHandler = secondHandler;
	
	if (this.type == "actionbar") {
		this.object = document.createElement("div");
		this.object.id = id + this.type;
		this.object.className = "dbactionbarbutton dbdarkbutton";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbactionbarbutton dbdarkbutton " + className;
		
		if (typeof(insertPlace) != "undefined")
			this.insert(insertPlace,insertBeforePlace);
		
		var label = new Element(id,"dbactionbarbuttonlabel","img",this.object);
		value = value.indexOf(global.dbimages) !== -1 ? value : global.dbimages + value.replace(/\.\.\//g,"").replace(/media\/dbflexx\/images\//,"");
		label.addAttribute("src",value);
		
		this.className = this.object.className;
	}
	
	if (this.type == "media") {
		var self = this;
		
		this.object = document.createElement("div");
		this.object.id = id + this.type;
		this.object.className = "dbmediabutton dbdarkbutton";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbmediabutton dbdarkbutton " + className;
		
		if (typeof(insertPlace) != "undefined")
			this.insert(insertPlace,insertBeforePlace);
		
		var label = new Element(id,"dbmediabuttonlabel","img",this.object);
		value = value.indexOf(global.dbimages) !== -1 ? value : global.dbimages + value.replace(/\.\.\//g,"").replace(/media\/dbflexx\/images\//,"");
		label.addAttribute("src",value);
		
		this.className = this.object.className;
	}
	
	if (this.type == "mediatext") {
		var self = this;
		
		//Benötigte Breite ermitteln
		var widthel = new Element("dbbuttonwidth","","span",document.body);
		widthel.text(value);
		widthel.addStyle("height","0px");
		var width = widthel.object.offsetWidth;
		document.body.removeChild(widthel.object);
		
		this.object = document.createElement("div");
		this.object.id = id + this.type;
		this.object.className = "dbnormaltextbutton dbdarkbutton";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbnormaltextbutton dbdarkbutton " + className;
		
		if (typeof(insertPlace) != "undefined")
			this.insert(insertPlace,insertBeforePlace);
		
		this.addStyle("width",width + 10 + "px");
		this.text(value);
		
		this.className = this.object.className;
	}
	
	if (this.type == "normaltext") {
		var self = this;
		
		//Benötigte Breite ermitteln
		var widthel = new Element("dbbuttonwidth","","span",document.body);
		widthel.text(value);
		widthel.addStyle("height","0px");
		var width = widthel.object.offsetWidth;
		document.body.removeChild(widthel.object);
		
		this.object = document.createElement("div");
		this.object.id = id + this.type;
		this.object.className = "dbnormaltextbutton dbbrightbutton";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbnormaltextbutton dbbrightbutton " + className;
		
		if (typeof(insertPlace) != "undefined")
			this.insert(insertPlace,insertBeforePlace);
		
		this.addStyle("width",width + 10 + "px");
		this.text(value);
		
		this.className = this.object.className;
	}
	
	if (this.type == "normal") {
		var self = this;
		
		this.object = document.createElement("div");
		this.object.id = id + this.type;
		this.object.className = "dbnormalbutton dbbrightbutton";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbnormalbutton dbbrightbutton " + className;
		
		if (typeof(insertPlace) != "undefined")
			this.insert(insertPlace,insertBeforePlace);
		
		var label = new Element(id,"dbmediabuttonlabel","img",this.object);
		value = value.indexOf(global.dbimages) !== -1 ? value : global.dbimages + value.replace(/\.\.\//g,"").replace(/media\/dbflexx\/images\//,"");
		label.addAttribute("src",value);
		
		this.className = this.object.className;
	}
	
	if (this.type == "taskbar") {
		var self = this;
		
		this.object = document.createElement("div");
		this.object.id = id + this.type;
		this.object.className = "dbtaskbar";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbtaskbar " + className;
		
		if (typeof(insertPlace) != "undefined")
			this.insert(insertPlace,insertBeforePlace);
				
		var label = new Element(id,"dbmediabuttonlabel","img",this.object);
		value = value.indexOf(global.dbimages) !== -1 ? value : global.dbimages + value.replace(/\.\.\//g,"").replace(/media\/dbflexx\/images\//,"");
		label.addAttribute("src",value);
		
		this.className = this.object.className;
	}
	
	if (this.type == "image") {
		this.object = document.createElement("div");
		this.object.id = id + this.type;
		
		this.object.className = "dbimagebutton";
		if (typeof(className) != "undefined" && className != "")
			this.object.className = "dbimagebutton " + className;
		
		if (typeof(insertPlace) != "undefined")
			this.insert(insertPlace,insertBeforePlace);
		
		this.addStyle("background-image","url(www.rt85.de/media/dbflexx/images/" + value + ")");
		this.addStyle(["width","height"],["22px","22px"]);
		this.className = this.object.className;
	}
	
	if (Cache.get(global.activeWindow + ";button;" + this.id)) {
		if (Cache.get(global.activeWindow + ";button;" + this.id) == "true") {
			global.functionStack.push([global.activeWindow,this.activate,this]);
		}
	}
	
	this.addEvent("click",function (event) { event = event ? event : window.event; self.activate.call(self,event); });	
}

Button.prototype = new DOMElementBase();

Button.prototype.activate = function (event) {
	if (this.availible == true) {
		if (this.mode == true) {
			if (this.active == true) {
				this.addAttribute("class",this.className);
				this.active = false;
				if (typeof(this.grouped) != "undefined")
					this.grouped.active = false;
				
				if (this.secondHandler instanceof Function) {
					if (typeof(this.context) != "undefined")
						this.secondHandler.call(this.context,event);
					else
						this.secondHandler(event);
				}
			} else {
				if (typeof(this.grouped) != "undefined") {
					if (typeof(this.grouped.active) == "object" && this.grouped.active != this)
						this.grouped.active.activate(event,true);
					this.grouped.active = this;
				}
				this.addAttribute("class",this.className + " active");
				this.active = true;
				
				if (typeof(this.context) != "undefined")
					this.firstHandler.call(this.context,event);
				else
					this.firstHandler(event);
			}
		} else {
			if (typeof(this.context) != "undefined")
				this.firstHandler.call(this.context,event);
			else
				this.firstHandler(event);
		}
	}
}

Button.prototype.makeAvailible = function () {
	this.availible = true;
	if (this.type == "image") {
		this.addStyle("opacity","1");
	}
}

Button.prototype.makeUnAvailible = function () {
	this.availible = false;
	if (this.type == "image") {
		this.addStyle("opacity","0.5");
	}
}

ButtonGroup = function (buttons,style) {
	if (buttons instanceof Array) {
		this.constructor(buttons[0].id);
		if (style == "left") {
			this.object = document.createElement("div");
			this.object.id = buttons[0].id + "containerdiv";
			this.object.className = "dbbutton groupedleft";
			
			this.addStyle(["height"],["20px"]);
			
			if (buttons[0].object.parentNode != null)
				this.insert(buttons[0].object.parentNode,buttons[0].object);
			
			for (var i = 0; i < buttons.length; i++) {
				if (buttons[i].active == true) {
					this.active = buttons[i];
				}
				if (buttons[i].object.parentNode != null)
					buttons[i].object.parentNode.removeChild(buttons[i].object);
				buttons[i].insert(this);
				buttons[i].grouped = this;
			}
			if (typeof(this.active) != "object")
				this.active = false;
		}
	}
}

ButtonGroup.prototype = new DOMElementBase();

function Table (id,className,columns,handler,insertPlace,insertBeforePlace) {
	this.constructor(id);
	this.className = className == "" ? false : className;
	
	this.handler = handler;
	
	this.object = document.createElement("table");
	this.object.id = id;
	if (typeof this.className != "undefined") 
		this.object.className = "dbflexx " + this.className;
	else
		this.object.className = "dbflexx";
	
	if (columns instanceof Array) {
		this.columnslength = columns[0];
		this.columnsname = columns[1];
		this.columnslabel = columns[2];
		
		if (columns[3] instanceof Array) {
			this.columnswidth = columns[3];
		} else {
			this.columnswidth = false;
			this.addStyle("table-layout","auto");
		}
		
		this.columnsminwidth = typeof columns[4] == "undefined" ? false : columns[4];
		this.columnsresizable = typeof columns[5] == "undefined" ? true : columns[5];
	} else {
		console.error("Verarbeitungsfehler: columns ist kein Array!");
		return;
	}
	
	this.insert(insertPlace,insertBeforePlace);
	
	var colgroup = new Element(this.id + "colgroup",this.className + "colgroup dbflexx","colgroup",this.object);
	colgroup.addAttribute("span",this.columnslength);
		
	this.columns = [];
	this.rows = [];
	this.header = new Element(this.id + "header",this.className + "header dbflexx","tr",this.object);
	
	this.columns.header = [];
	
	for (var i = 0; i < this.columnslength; i++) {
		var colreference = new Element(false,false,"col",colgroup);
		this.columns["header"][this.columnsname[i]] = new Element(this.id + this.columnsname[i],this.className + this.columnsname[i] + " dbflexx","th",this.header);
		this.columns["header"][i] = this.columns["header"][this.columnsname[i]];
		this.columns["header"][i].colreference = colreference;
		
		this.columns["header"][i].text(this.columnslabel[i]);
		if (this.columnswidth) {
			colreference.addStyle("width",this.columnswidth[i] * 100 + "%");
		}
	}
	
	for (var i = 0; i < this.columnslength - 1; i++) {
		var self = this;
		
		this.columns["header"][i].resizeElement = new Element("",this.className + " resizeelement dbflexx","div",this);
		
		var left = this.getContentPosition("left");
		for (var j = 0; j <= i; j++) {
			left += this.columns["header"][j].object.offsetWidth;
		}
		
		this.columns["header"][i].resizeElement.addStyle(["height","left","top"],[this.object.offsetHeight + "px",left - 5 + "px",this.getContentPosition("top") + "px"]);
		
		this.columns["header"][i].colreference.onresizestart = function () { 
		
			var columnsWidths = [];
		
			for (var n = 0; n < self.columnslength; n++) {
				columnsWidths.push(self.columns["header"][n].object.offsetWidth);
			}
			self.addStyle("table-layout","fixed");
			
			for (var n = 0; n < self.columnslength; n++) { 
				self.columns["header"][n].colreference.addStyle("width",columnsWidths[n] + "px"); 
			}
		};
		
		this.columns["header"][i].colreference.onresize = function (event) {
			if (event.hasResized) {
				event.object.object.nextElementSibling.style.width = parseInt(event.object.object.nextElementSibling.style.width) - event.x + "px";
			}
			//console.log(event.object.object.nextElementSibling);
			//console.log(self.columns["header"][i].object.previousSibling);
		}
		
		this.columns["header"][i].colreference.onresizestop = function () { 
			for (var z = 0; z < self.columnslength - 1; z++) {			
				var left = self.getContentPosition("left");
				for (var x = 0; x <= z; x++) {
					left += self.columns["header"][x].object.offsetWidth;
				}
				
				self.columns["header"][z].resizeElement.addStyle(["height","left"],[self.object.offsetHeight + "px",left - 5 + "px"]);
			}
		};
				
		this.columns["header"][i].colreference.makeResizable(new ResizeObject(this.columns["header"][i].resizeElement),[this.columns["header"][i + 1].object.offsetWidth - 10,0],[10,0],"horizontal",false,false,false);
	}
}

Table.prototype = new DOMElementBase();

Table.prototype.addRow = function (data,internlabel) {
	var self = this;
	if (data instanceof Array && data.length == this.columnslength) {
		var pushedElement = this.rows.push(new Element(this.id + "row" + (this.rows.length + 1),this.className + "row","tr",this.object));
		this.rows[pushedElement - 1].onfocus = function () { if (self.handler instanceof Function) self.handler(internlabel); self.rows[pushedElement - 1].addStyle(["background","background","background"],["#F3D153","-webkit-gradient(linear, left top, left bottom,from(#FFF1B7), to(#F3D153))","-moz-linear-gradient(top, #FFF1B7,#F3D153)"]); };
		this.rows[pushedElement - 1].onblur = function () { global.windowobject.commandBar.clear(); self.rows[pushedElement - 1].addStyle("background","none"); };
		
		this.columns["rows" + pushedElement] = [];
		
		for (var i = 0; i < this.columnslength; i++) {
			this.columns["rows" + pushedElement][this.columnsname[i]] = new Element(this.id + this.columnsname[i],this.className + this.columnsname[i] + " dbflexx","td",this.rows[pushedElement - 1]);
			this.columns["rows" + pushedElement][i] = this.columns["rows" + pushedElement][this.columnsname[i]];
			
			this.columns["rows" + pushedElement][i].text(data[i]);
		}
		
		for (var i = 0; i < this.columnslength - 1; i++) {			
			var left = this.getContentPosition("left");
			for (var j = 0; j <= i; j++) {
				left += this.columns["header"][j].object.offsetWidth;
			}
			
			this.columns["header"][i].resizeElement.addStyle(["height","left"],[this.object.offsetHeight + "px",left - 5 + "px"]);
			this.columns["header"][i].colreference.setResizeProperty("maxSize",[this.columns["header"][i].object.offsetWidth + this.columns["header"][i + 1].object.offsetWidth - 10,0]);
		}
		
		
	} else {
		console.error(print("Verarbeitungsfehler: Die in data enthaltenen Inhalte stimmen nicht mit der Spaltenzahl der Tabelle überein!"));
		return "Error 301";
	}
}

Table.prototype.clear = function () {
	for (var i = 0; i < this.rows.length; i++) {
		this.rows[i].remove();
		this.rows[i] = null;
	}
	this.rows = [];
}

function Columns (id,className,amount,width,maxwidth,minwidth,resizeable,insertPlace,insertBeforePlace) {
	/* Bei widersprüchlichen Angaben bezüglich maxwidth / minwidth und resizeable über console.warn() informieren! */
	
	this.constructor(id);
	
	this.object = document.createElement("div");
	this.object.id = id;
	
	if (typeof this.className != "undefined") 
		this.object.className = "dbflexx multicolumns " + this.className;
	else
		this.object.className = "dbflexx multicolumns";
	
	if (typeof insertPlace != "undefined")
		this.insert(insertPlace,insertBeforePlace);
	
	this.columns = [];
	
	for (var i = 0; i < amount; i++) {
		this.columns[i] = new Element(id + "column" + i,false,"div",this);
		if (i < amount - 1) {
			this.columns[i].addStyle("float","left");
			this.columns[i].addStyle("width",width[i]);
		}
	}
	
}

Columns.prototype = new DOMElementBase();

function Sidebar (id,className,width,maxwidth,insertPlace,insertBeforePlace) {
	this.constructor(id);
	
	this.object = document.createElement("div");
	this.object.id = id;
	
	if (typeof this.className != "undefined") 
		this.object.className = "dbflexx multicolumns sidebar " + this.className;
	else
		this.object.className = "dbflexx multicolumns sidebar";
	
	if (typeof insertPlace != "undefined")
		this.insert(insertPlace,insertBeforePlace);
	
	var sidebar = new Columns(id + "sidebar",className,2,width,maxwidth,["30px","30px"],[true,true]);
	
	this.columns = [];
	this.selectedItem = null;
	
	for (var i = 0; i < sidebar.columns.length; i++) {
		this.columns[i] = sidebar.columns[i];
		this.columns[i].insert(this);
	}
	this.columns[0].addStyle("background","rgb(210,210,210)");
	this.columns[0].items = [];
	this.columns[0].itemcontainer = new Element(id + "sidebaritemcontainer",false,"ul",this.columns[0]);
}

Sidebar.prototype = new DOMElementBase();

Sidebar.prototype.addItem = function (type,id,label,value,firstHandler,secondHandler) {
	var self = this;
	if (type == "normal") {
		var newItem = new Element(id + "sidebaritem",false,"li",this.columns[0].itemcontainer);
		newItem.text(value);
		newItem.internlabel = label;
		newItem.object.internlabel = label;
		newItem.onfocus = function () { newItem.addStyle(["background","background","background"],["#F3D153","-webkit-gradient(linear, left top, left bottom,from(#FFF1B7), to(#F3D153))","-moz-linear-gradient(top, #FFF1B7,#F3D153)"]); firstHandler(newItem.internlabel); self.selectedItem = newItem.internlabel };
		newItem.onblur = function () { self.selectedItem = null; newItem.addStyle("background","none"); secondHandler(); };
		this.columns[0].items.push(newItem);
		
		return newItem;
	}
	
	if (type == "input") {
		var newItemContainer = new Element(id + "sidebaritem",false,"li",this.columns[0].itemcontainer);
		var newItem = new Input(id + "sidebaritem",false,id + "sidebaritem","text",value,false,false,false,[firstHandler,"enter"],true,newItemContainer);
		newItem.internlabel = label;
		
		this.columns[0].items.push(newItemContainer);
		return newItemContainer;
	}
}

Sidebar.prototype.removeItem = function (item) {
	for (var i = 0; i < this.columns[0].items.length; i++) {
		if (this.columns[0].items[i] == item) {
			if (this.selectedItem == this.columns[0].items[i].internlabel)
				this.selectedItem = null;
			this.columns[0].items[i].remove();
			this.columns[0].items[i] = null;
		}
	}
}

Sidebar.prototype.clear = function () {
	for (var i = 0; i < this.columns[0].items.length; i++) {
		if (this.columns[0].items[i] != null)
			this.columns[0].items[i].remove();
	}
	this.columns[0].items = [];
	this.selectedItem = null;
}

function dodb (object) {
	if ((typeof(object) == "object" && object.style) || typeof(object) == "string") {
		if (typeof(object) == "string")
			object = document.getElementById(object);
		var element = new Element(object.id,object.className,object.tagName);
		element.object = object;
		return element;
	}
	return "Parserfehler: Object ist nicht definiert oder kein HTML-Objekt";
}

function print (string) {
	return string;
}

Array.prototype.in_array = function (value,remove) {
	var found = false,
		i = 0;
			
	for (i; i < this.length; i++) {
		if (this[i] instanceof Array) {
			found = this[i].in_array(value);
		} else if (this[i] instanceof Object && value instanceof Object) {
			found = this[i].equal(value);
		} else if (this[i] === value) {
			found = true;
		}
		
		if (found) {
			if (remove === true) {
				this.splice(i,1);
			}
			return true;
		}
	}
	
	return false;
}

Array.prototype.merge = function (array) {
	var newArray = [],
		oldArray = array.slice();
		i = 0, length = this.length;
	
	for (i; i < length; i++) {
		if (oldArray.in_array(this[i],true)) {
			newArray.push(this[i]);
		}
	}
	
	return newArray;
}

Array.prototype.unify = function (array) {
	var newArray = this.slice(),
		i = 0, length = array.length;
	
	for (i; i < length; i++) {
		if (!this.in_array(array[i])) {
			newArray.push(array[i]);
		}
	}
	
	return newArray;
}

Object.prototype.equal = function (object) {
	var keys = Object.keys(this),
		i = 0;
	
	for (i; i < keys.length; i++) {
		if (object[keys[i]] === "undefined") {
			return false;
		}
		
		if (this[keys[i]] instanceof Object) {
			tempResult = this[keys[i]].equal(object[keys[i]]);
			if (!tempresult) {
				return false;
			}
		} else if (!(this[keys[i]] instanceof Function)) {
			if (object[keys[i]] !== this[keys[i]]) {
				return false;
			}
		}
	}
	
	return true;
}

Array.prototype.getArrays = function () {
	var items = [[],[]],
		i = 0;
		
	for (i; i < this.length; i++) {
		if (this[i] instanceof Array) {
			items[0].push(this[i]);
			items[1].push(i);
		}
	}
	
	return items;
}

Array.prototype.mjoin = function (join) {
	// multidimensional join
	
	for (var i = 0; i < this.length; i++) {
		if (this[i] instanceof Array) {
			this[i] = this[i].mjoin(join);
		}
	}
	
	return this.join(join);
}

Array.prototype.unique = function () {
	// 0E028
	
	var length = this.length,
		returnArray = [];
	
	this.forEach(function (value) {
		if (!returnArray.in_array(value)) {
			returnArray.push(value);
		}
	});
	
	return returnArray;
}
