
	
	/////////////////////////////////////////////////////////////////////////////////////////
	//Globales OnLoad Objekt das smtliche Funktionen nach dem Laden des Dokumentes ausfhrt,
	//die dem Objekt mittels add bergeben wurden
	/////////////////////////////////////////////////////////////////////////////////////////
	windowOnLoad = new Object();
	windowOnLoad.func = new Array();
	windowOnLoad.add = function(str) {
		this.func.push(str);
	}
	windowOnLoad.exec = function() {
		for(var i = 0; i < this.func.length; i++) {
			window.setTimeout(this.func[i], 0);
		}
	}
	
	
	window.onload = function() {
		windowOnLoad.exec();
	}
	
	
	
	windowOnLoad.add("Index.init()");
	
	var Index = {
		init: function() {
			//////////////////////////
			// DOCUMENT.BODY ERWEITERN
			//////////////////////////
			Element.extend(document.body);
			
			document.body.startWait = function() {
				document.body.setStyle({
					cursor: "wait"
				});
			}
			
			document.body.stopWait = function() {
				document.body.setStyle({
					cursor: ""
				});
			}
			
			document.body.fade = function() {				
				var div = Builder.node("div", {id: "fade"});
				Element.extend(div);
				
				div.setStyle({
					position: "absolute",
					top: "0px",
					left: "0px",
					height: ($("content").getHeight () > document.body.getHeight () ? $("content").getHeight() : document.body.getHeight()) + 20 + "px",
					width:  document.body.getDimensions().width + "px",
					backgroundColor: "#223F81",
					opacity: 0.0
				});
				
				document.body.appendChild(div);
				new Effect.Opacity("fade", {duration:0.3, from:0.0, to: 0.8});
			}
			
			document.body.appear = function() {
				new Effect.Opacity("fade", {duration: 0.3, from: 0.8, to: 0.0, afterFinish: function(e) {
					$("fade").remove();
				}});
			}
		},
		
		popup: function(src, width, height) {
			window.open(src, "_blank", "width=" + width + "px, height=" + height + "px");
		}
	}
	
	
	
	////////////////////////////
	// MESSAGE CODES VERARBEITEN
	////////////////////////////
	windowOnLoad.add("Message.init()");
	
	var Message = {
		rcodes: new Array(),
		codes: new Object(),
		prefix: new Array(),
		
		init: function() {	
			if(Global.message[0] != false) {
				this.codes = Global.message;
				Object.keys(Global.message).each(function(code) {
					Message.post(code);
				});
			}
			
			this.request();
		},
		
		load: function(code, prefix) {
			if(!prefix) {
				prefix = "";
			}
			else {
				this.prefix.push(prefix);
			}
			
			var nCodes = code.split(",");
			
			nCodes = nCodes.collect(function(c) {
				return prefix + c.strip();
			});
			
			this.rcodes = this.rcodes.concat(nCodes);
		},
		
		request: function() {
			this.rcodes = this.rcodes.uniq();
			for(var i = 0; i < this.rcodes.length; i++) {
				this.rcodes[i] = "code[]=" + this.rcodes[i];
			}
			
			if(this.rcodes.length == 0) {
				return false;
			}
			
			new Ajax.Request("/ajax/ajax.index.php", {
				postBody: this.rcodes.join("&"),
				
				onSuccess: function(r) {
					
					Message.codes = Object.extend(Message.codes, r.responseText.evalJSON());
				}
			});
		},
		
		get: function(code, par) {			
			if(!par) {
				par = {};
			}
			
			
			if(this.codes[code]) {
				var str = this.codes[code];
			}
			else {
				for(var i = 0; i < this.prefix.length; i++) {
					var tCode = this.prefix[i] + code;
					
					if(this.codes[tCode]) {
						 var str = this.codes[tCode];
						 break;
					}
				}
			}
			
			
			if(!str) {
				return "Message not found";
			}
			
			
			var syntax = /(^|.|\r|\n)({\$(\w+)})/;
			var tpl = new Template(str, syntax);
			
			return tpl.evaluate(par);
		},
		
		post: function(code, par) {
			var str = this.get(code, par);
			alert(str);
		},
		
		onLoad: function(str) {
			alert(str);
		}
	}
	
	
	
	/////////////////////
	// MENPUNKT ANWHLEN
	/////////////////////
	windowOnLoad.add("selectNavi()");
	
	function selectNavi() {
		$$(".langControl a").each(function(a) {
			if(a.lang == LANG) {
				a.down("img").addClassName("selected");
			}
		});
		
		$$(".navi a.menu").each(function(a) {
			if(window.location.href.include(a.href)) {
				a.up("li").id = "naktiv";
			}
		});
	}
	
	
	windowOnLoad.add("langA.init()");
	
	var langA = {
		init: function() {
			/*
			$$("a[lang='de']").each(function(a) {
				if(a.href.include("lang=de")) {
					return false;
				}
				
				
				var qry = a.search;
				a.href += a.href.include("?") ? "" : "?";
				a.href += a.href.endsWith("?") ? "" : "&";
				a.href += "lang=" + a.lang;
			});
			*/
		}
	}
	
	
	/////////////////////
	// FORMULAR AUSFLLEN
	/////////////////////
	function fillForm(data) {
		
		var inps = new Array();
		
		for(m in data) {			
			if(data[m] == null) {
				continue;
			}
		
			switch(typeof data[m]) {
				default:
					var elem = $$('[name="' + m + '"]');
					
					if(elem.length == 0) {
						var elem = $$('[name="' + m + '[]"]');
					}
					
					elem.each(function(e) {
						inps.push(new Array(e, data[m]));
					});
					break;
					
				case "object":
					Object.keys(data[m]).each(function(key) {
						if(typeof data[m][key] == "function") {
							return;
						}
						
						switch(typeof data[m][key]) {
							default:
								$$('[name="' + m + '[' + key + ']"]').each(function(e) {
									inps.push(new Array(e, data[m][key]));
								});
								
								$$('[name="' + m + '[]"]').each(function(e) {
									inps.push(new Array(e, data[m][key]));
								});
								break;
								
							case "object":
								Object.keys(data[m][key]).each(function(key2) {
									$$('[name="' + m + '[' + key + '][' + key2 + ']"]').each(function(e) {
										inps.push(new Array(e, data[m][key][key2]));
									});
								});
								break;
						}
					});
					break;
			}
		}
		
		
		
		for(var j = 0; j < inps.length; j++) {			
			switch(inps[j][0].tagName) {
				case "INPUT": 
					switch(inps[j][0].type) {
						case "hidden":
						case "password":
						case "text":
							inps[j][0].value = inps[j][1];
							break;
							
						case "checkbox":
						case "radio":
							if(inps[j][1] == inps[j][0].value) {
								inps[j][0].checked = true;
								if(inps[j][0].onclick) {
									inps[j][0].onclick();
								}
								
								if(inps[j][0].onchange) {
									inps[j][0].onchange();
								}
							}
							break;
					}					
					break;
					
				case "SELECT":
					inps[j][0].value = inps[j][1];				
					break;
					
				case "TEXTAREA":
					inps[j][0].value = inps[j][1];
					break;
			}
		}
	}
	
	
	////////
	// DEBUG
	////////
	windowOnLoad.add("Debug.init()");
	
	var Debug = {
		init: function() {
			if(!$("debugInfo")) {
				return false;
			}
			
			//////////////////
			// LINKS ERWEITERN
			//////////////////
			$$("a").each(function(a) {
				var href = a.href;
				
				if(href.include("?")) {
					href += "&debug";
				}
				else {
					href += "?debug";
				}
				
				a.href = href;
			});
		}
	}
