var debugLog = new Array();
function logDebug(msg) {
	//alert(msg);
	debugLog.push(msg);
}

var errorLog = new Array();
function logError(msg, file, line) {
	//alert(msg);
	errorLog.push(msg);
}
//window.onerror = logError;

/**
* Setzen eines Cookies
*
* @var string name Name des Cookies
* @var string value Wert des Cookies
* @var int expires Ablaufsdatum in Tagen von jetzt an gerechnet
* @var string path Pfad für das das Cookie gültig ist
* @var string domain Domain für die das Cookie gilt
* @var boolean secure Zeigt an ob das Cookie nur über https gesendet werden soll
*/
function setCookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	// expires in days
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expiresDate = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expiresDate.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

/**
* Liest ein Cookie aus.
*
* @var string name Name des zu lesenden Cookies
* @return string Wert des Cookies
*/
function getCookie(name)
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

//<!--
// Ultimate client-side JavaScript client sniff. Version 3.04
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4,
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection
// Revised 06 Jan 04 to add Opera6 detection
// Revised xx xxx 05 to add Opera7 detection
// Revised xx xxx 05 to add Konquerer5 detection
// Revised 02 Sept 06 to add JavaScript Version det

	// convert all characters to lowercase to simplify testing
	var agt=navigator.userAgent.toLowerCase();

	// *** BROWSER VERSION ***
	// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);

	// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
	// If you want to allow spoofing, take out the tests for opera and webtv.
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var is_nav2 = (is_nav && (is_major == 2));
	var is_nav3 = (is_nav && (is_major == 3));
	var is_nav4 = (is_nav && (is_major == 4));
	var is_nav4up = (is_nav && (is_major >= 4));
	var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
	var is_nav6 = (is_nav && (is_major == 5));
	var is_nav6up = (is_nav && (is_major >= 5));
	var is_gecko = (agt.indexOf('gecko') != -1);
	var is_ff2 = (agt.indexOf('firefox/2') != -1);
	var is_ff3 = (agt.indexOf('firefox/3') != -1);
	//var is_ff36 = (agt.indexOf('firefox/36') != -1);

	// IE
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3    = (is_ie && (is_major < 4));
	var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	var is_ie4up  = (is_ie && (is_major >= 4));
	var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0") !=-1));
	var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
	var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
	var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
	var is_ie7up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5  && !is_ie6);
	var is_ie8    = (is_ie && (is_major == 4) && (agt.indexOf("msie 8.")!=-1) );
	var is_ie8up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5  && !is_ie6 && !is_ie7);

	// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
	// or if this is the first browser window opened.  Thus the
	// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
	var is_aol   = (agt.indexOf("aol") != -1);
	/*var is_aol3  = (is_aol && is_ie3);
	var is_aol4  = (is_aol && is_ie4);
	var is_aol5  = (agt.indexOf("aol 5") != -1);
	var is_aol6  = (agt.indexOf("aol 6") != -1);*/

	// Opera
	var is_opera = (agt.indexOf("opera") != -1);
	var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
	var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
	var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
	var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
	var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
	var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
	var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5);
	var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
	var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6);
	var is_opera8 = (agt.indexOf("opera 8") != -1 || agt.indexOf("opera/8") != -1);
	var is_opera8up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6 && !is_opera7);
	var is_opera9 = (agt.indexOf("opera 9") != -1 || agt.indexOf("opera/9") != -1) && agt.indexOf("opera/9.8") == -1;
	var is_opera9up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6 && !is_opera7 && !is_opera8);
	var is_opera10 = (agt.indexOf("opera/9.80") != -1 && (agt.indexOf("version/10") != -1));
	var is_opera10up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6 && !is_opera7 && !is_opera8 && !is_opera9);
	
	// Konquerer
	var is_konqueror = (agt.indexOf("konqueror") != -1);
	/*var is_konqueror1 = (agt.indexOf("konqueror 1") != -1 || agt.indexOf("konqueror/1") != -1);
	var is_konqueror2 = (agt.indexOf("konqueror 2") != -1 || agt.indexOf("konqueror/2") != -1);
	var is_konqueror3 = (agt.indexOf("konqueror 3") != -1 || agt.indexOf("konqueror/3") != -1);
	var is_konqueror3up = (is_konqueror && !is_konqueror2 && !is_konqueror1);
	/*var is_konqueror4 = (agt.indexOf("konqueror 4") != -1 || agt.indexOf("konqueror/4"));
	var is_konqueror5 = (agt.indexOf("konqueror 5") != -1 || agt.indexOf("konqueror/5"));
	var is_konqueror5up = (is_konqueror && !is_konqueror5 && !is_konqueror4 && !is_konqueror3 && !is_konqueror2 && !is_konqueror1);*/
	
	// Chrome
	var is_chrome = (agt.indexOf("chrome") != -1);
	// Safari
	var is_safari = (agt.indexOf("safari") != -1) && !is_chrome;
	
	
	var is_webkit = is_safari || is_chrome;
	
	
	// Mobile Devices
	var is_android = (agt.indexOf("android") != -1);
	var is_android_2up = (agt.indexOf("android 2") != -1);
	var is_iphone = (agt.indexOf("iphone") != -1) || (agt.indexOf("ipod") != -1);
	var is_symbian = (agt.indexOf("series60") != -1) || (agt.search("symbian") != -1);
	var is_wince = (agt.indexOf("windows ce") != -1);
	var is_winp7 = (agt.indexOf("windows phone os") != -1);
	var is_bb = (agt.indexOf("blackberry") != -1);
	
	
	// Sonstige
	//var is_webtv = (agt.indexOf("webtv") != -1);

	/*var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
	var is_AOLTV = is_TVNavigator;

	var is_hotjava = (agt.indexOf("hotjava") != -1);
	var is_hotjava3 = (is_hotjava && (is_major == 3));
	var is_hotjava3up = (is_hotjava && (is_major >= 3));*/

	// *** JAVASCRIPT VERSION CHECK ***
	/*var is_js;
	if (is_nav2 || is_ie3) is_js = 1.0;
	else if (is_nav3) is_js = 1.1;
	else if (is_opera5up) is_js = 1.3;
	else if (is_opera) is_js = 1.1;
	else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
	else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
	else if (is_hotjava3up) is_js = 1.4;
	else if (is_nav6 || is_gecko) is_js = 1.5;
	// NOTE: In the future, update this code when newer versions of JS
	// are released. For now, we try to provide some upward compatibility
	// so that future versions of Nav and IE will show they are at
	// *least* JS 1.x capable. Always check for JS version compatibility
	// with > or >=.
	else if (is_nav6up) is_js = 1.5;
	// NOTE: ie5up on mac is 1.4
	else if (is_ie5up) is_js = 1.3

	// HACK: no idea for other browsers; always check for JS version with > or >=
	else is_js = 0.0;*/


	/**
	* OS Check
	* 
	*/
	var is_win  = (agt.indexOf('win')!=-1);
	var is_mac  = (agt.indexOf('mac')!=-1);
	
	
	/**
	* Ermittelt die benutzer Browser Engine
	*/
	var xsltOutput = "html";
	var browserEngine;
	if (is_safari) {
		browserEngine = "webkit";
	}
	else if (is_konqueror) {
		browserEngine = "khtml";
	}
	else if (is_opera) {
		browserEngine = "presto";
		if (!is_opera9up) {
			xsltOutput = "xml";
		}
	}
	else if (is_gecko) {
		browserEngine = "gecko";
	}
	else if (is_nav) {
		browserEngine = "gecko";
	}
	else if (is_ie) {
		browserEngine = "trident";
		xsltOutput = "xml";
	}
	else  {
		browserEngine = "unknown";
	}
	
	var tmp = getCookie("browserEngine");
	if (!(tmp && tmp != "" && tmp != "unknown")) {
		setCookie("browserEngine", browserEngine);
	}
	

	/**
	 * Redirekt auf die entsprechende dict Seite (pda, IPhone, ...)
	 * je nach mobilem Endgerät
	 */
	if (!pda && !getCookie("redirect") && application == "dict") {
		if(is_iphone) {
			window.location = "http://pda.leo.org/iphone/?lp="+lp;
		}
		else if(is_android) {
			window.location = "http://pda.leo.org/?redirect=1&lp="+lp;
		}
		else if (is_symbian) {
			window.location = "http://pda.leo.org/?redirect=1&lp="+lp;
		}
		else if (is_wince || is_winp7) {
			window.location = "http://pda.leo.org/?redirect=1&lp="+lp;
		}
		else if (is_bb) {
			window.location = "http://pda.leo.org/?redirect=1&lp="+lp;
		}
	}
	
	/**
	* Browserabhängige CSS werden eingebunden
	* Unterscheidlich für PDA und Default Plattform
	*/
	if (!pda) {
		if (is_ie || is_aol) {
			// Warum soltle das auskommentiert sein?
			document.write('<link rel="stylesheet" type="text/css" href="/css/ie.css">');
			if (!is_ie8up || is_aol) {
				document.write('<link rel="stylesheet" type="text/css" href="/css/ie5-6-7.css">');
			}
			if (!is_ie7up || is_aol) {
				document.write('<link rel="stylesheet" type="text/css" href="/css/ie5-6.css">');
			}
		}
		if (is_safari) {
			document.write('<link rel="stylesheet" type="text/css" href="/css/safari.css">');
		}
		if (is_chrome) {
			document.write('<link rel="stylesheet" type="text/css" href="/css/chrome.css">');
		}
		if (is_opera) {
			document.write('<link rel="stylesheet" type="text/css" href="/css/geckoWin.css">');
		}
		if (is_gecko && is_ff2) {
			document.write('<link rel="stylesheet" type="text/css" href="/css/ff2.css">');
		}
		
	}
	else {
		if (application == "forum") {
			if (is_android) {	
				document.write('<link rel="stylesheet" type="text/css" href="css/android.css"/>');
			}
			else if (is_gecko){
				document.write('<link rel="stylesheet" type="text/css" href="css/gecko.css"/>');
			}
			else if (is_opera){
				document.write('<link rel="stylesheet" type="text/css" href="css/opera.css"/>');
			}
		}
	}
	
	/**
	* Browserabhängige JS werden eingebunden
	* Js wird erweitert
	*/
	if (is_gecko ) {
		Node.prototype.outerHTML = function(){
			var el = document.createElement('div');
			el.appendChild(this.cloneNode(true));
			return el.innerHTML;
		}
	}
	if (typeof XSLTProcessor == 'undefined' || typeof document.evaluate  == 'undefined' || is_safari) {
		try {
			// Test ob der IE alle benötigten ActiveXObject erstellen kann.
			var tmp = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
			tmp = new ActiveXObject("MSXML2.XSLTemplate");
			tmp = new ActiveXObject("Microsoft.XMLDOM");
		}
		catch(e) {
			// Browser unterstützt kein XSLT oder XPath
			document.write('<script language="javascript" type="text/javascript" src="/js/top-dom.js" type="text/javascript"></script>');
		}
	}

	/**
	* Dynamische CSS Anpassung
	* Wird nur im dict verwendet, könnte man vmtl irgendwo auslagern?
	*/
	var innerHeight = 0;
	var innerWidth = 0;
	function setCss() {
		if (document.getElementById("fp")) {
			document.getElementById("fp").value = hash;
		}
		if (document.getElementById("testResult") && typeof startTest != 'undefined') {
			startTest();
		}
		var diff = 350;
		//var diff = 300;

		var innerHeight = 0;
		if (window.innerHeight) {
			// alle Browser auser IE
			innerHeight = window.innerHeight;
			innerWidth = window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			// IE 6 Strict Mode
			innerHeight = document.documentElement.clientHeight;
			innerWidth = document.documentElement.clientWidth;
		}
		else if (document.body) {
			// andere IEs
			innerHeight = document.body.clientHeight;
			innerWidth = document.body.clientWidth;
		}
		var height = innerHeight -  diff;
		if (height < 380) {
			height = 380;
		}
		else if (height > 540) {
			height = 540;
		}
		
		var width = innerWidth - 178;
		if (width < 816) {
			width = 815;
		}
		else if ( width > 1025) {
			width = 1025;
		}
		
		// Für alle Browser
		if ( document.styleSheets[0].cssRules) {
			for (var i = 0; i < document.styleSheets[0].cssRules.length; i++) {
				if (document.styleSheets[0].cssRules[i].selectorText == "div.container .content") {
					document.styleSheets[0].cssRules[i].style.height = height + "px";
					document.styleSheets[0].cssRules[i].style.width = width + "px";
				}
				if (document.styleSheets[0].cssRules[i].selectorText == ".content tbody.overflow") {
					document.styleSheets[0].cssRules[i].style.height = (height-22) + "px";
				}
				if (document.styleSheets[0].cssRules[i].selectorText == "div.container .content .left"
					|| document.styleSheets[0].cssRules[i].selectorText == "div.container .content .right") {
					//document.styleSheets[0].cssRules[i].style.height = (height-26) + "px";
					document.styleSheets[0].cssRules[i].style.height = height + "px";
				}
				
				
			}
// 			for (var i = 0; i < document.styleSheets[2].cssRules.length; i++)
// 			{
// 				if (document.styleSheets[2].cssRules[i].selectorText == ".container")
// 				{
// 					document.styleSheets[2].cssRules[i].style.height = (height) + "px";
// 				}
// 			}
		}
		else
		{
			// IE Hack
			if ( document.styleSheets[0].rules) {
				for (var i = 0; i < document.styleSheets[0].rules.length; i++) {
// 					if (document.styleSheets[0].rules[i].selectorText == ".container .content")
// 					{
// 						document.styleSheets[0].rules[i].style.height = height + "px";
// 					}
					
					if (document.styleSheets[0].rules[i].selectorText.toLowerCase() == "div.container .content") {
						document.styleSheets[0].rules[i].style.height = height + "px";
						document.styleSheets[0].rules[i].style.width = width + "px";
					}
					if (document.styleSheets[0].rules[i].selectorText.toLowerCase() == ".content tbody.overflow") {
						document.styleSheets[0].rules[i].style.height = (height-22) + "px";
					}
					if (document.styleSheets[0].rules[i].selectorText.toLowerCase() == "div.container .content .left"
						|| document.styleSheets[0].rules[i].selectorText.toLowerCase() == "div.container .content .right") {
						//document.styleSheets[0].cssRules[i].style.height = (height-26) + "px";
						document.styleSheets[0].rules[i].style.height = height + "px";
					}
				}
			}
		}
		
		/*loader = new Loader(document.getElementById("async"), "/api/help.php");*/
		if (typeof onForumLoad != "undefined") {
			onForumLoad();
		}
		onLoad();
	}

	//setCss();

// -->


