
 var xhttp;
 var oldValue;
 var isIEBr    = 0;
 var isTaskOut = 0;

 var wikiSGL   = 0;
 var tValue    = '';


 function submitAjax()
 {
	if( document.getElementById('w_suggestLine') && tValue != '' )
	{
		return false;
	}
 }


 function Browser()
 {
	var ua, s, i;

	this.isIE    = false;  // Internet Explorer
	this.isNS    = false;  // Netscape
	this.version = null;

	ua = navigator.userAgent;

	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isNS = true;
		this.version = 6.1;
		return;
	}
 }


 var browser = new Browser();
 if(browser.isIE)
 {
	document.onmousedown = pageMousedown;
	document.onkeyup     = seitenklick;
 }
 if(browser.isNS)
 {
	document.addEventListener("mousedown", pageMousedown, true);
	document.addEventListener("keyup", seitenklick, true);
 }


 function seitenklick(event)
 {
	if( !event )
	{
		event = window.event;
	}

	if( browser.isIE )
	{
		hotKey = window.event.keyCode;
		isAlt  = window.event.altKey;
	}
	if( browser.isNS )
	{
		hotKey = event.which;
		isAlt  = event.altKey;
	}

	// Wiki-Suggest
	if( document.getElementById('w_suggestLine') )
	{
		if( hotKey == 40 )
		{
			wikiSGL++;
			var wsgl = 'wsl_'+wikiSGL;
			if( document.getElementById(wsgl) )
			{
				document.getElementById(wsgl).style.backgroundColor = '#EFEFEF';
				tValue   = document.getElementById(wsgl).value;
				var oldL = 'wsl_'+(wikiSGL-1);
				if( document.getElementById(oldL) )
				{
					document.getElementById(oldL).style.backgroundColor = '#FFFFFF';
				}
			} else
			  {
				wikiSGL--;
			  }
		}

		if( hotKey == 38 )
		{
			wikiSGL--;
			var wsgl = 'wsl_'+wikiSGL;
			if( document.getElementById(wsgl) )
			{
				document.getElementById(wsgl).style.backgroundColor = '#EFEFEF';
				tValue   = document.getElementById(wsgl).value;
				var oldL = 'wsl_'+(wikiSGL+1);
				if( document.getElementById(oldL) )
				{
					document.getElementById(oldL).style.backgroundColor = '#FFFFFF';
				}
			} else
			  {
				wikiSGL++;
			  }
		}

		if( hotKey == 13 )
		{
			var wsgl = 'wsl_'+wikiSGL;
			if( document.getElementById(wsgl) )
			{
				var fieldValue     = document.getElementById(wsgl).value;
				self.location.href = 'index.php?site=artikel&action=show&begriff='+fieldValue;
			}
		}
	}
 }


 function pageMousedown(event)
 {
	var el;

	// angeklicktes Element finden
	if( browser.isIE )
	{
		el = window.event.srcElement;
	}
	if( browser.isNS )
	{
		el = (event.target.className ? event.target : event.target.parentNode);
	}

	// Wiki-Suggest
	if( document.getElementById('w_suggestLine') )
	{
		if( el.id != 'w_suggestLine' )
		{
			w_ajax_aus();
		}
	}
 }


 function w_ajax_an()
 {
	var subObject = document.getElementById('wikiSuggest');
	subObject.style.visibility = "visible";

	tValue  = '';
	wikiSGL = 0;
 }


 function w_ajax_aus()
 {
	var subObject = document.getElementById('wikiSuggest');
	subObject.style.visibility = "hidden";

	tValue  = '';
	wikiSGL = 0;
 }


 function updateWiki()
 {
	if( !xhttp )
	{
		return;
	}
	var w = document.wikiForm.wikiSuche.value;
	if( w == oldValue )
	{
		return;
	}
	if( w.length < 2 )
	{
		w_ajax_aus();
		return;
	}

	oldValue = w;

	if( isIEBr == 1 )
	{
		xhttp.onreadystatechange = updateWiki_callback;	
	} else
	  {
		xhttp.onload = updateWiki_callback;
	  }

	w           = encodeURIComponent(w);

	var logic   = ( !document.wikiForm.logic.value            ) ? 'und' : document.wikiForm.logic.value;
	var artikel = ( document.wikiForm.artikel.checked == true ) ? 1     : 0;
	var alte    = ( document.wikiForm.alte.checked    == true ) ? 1     : 0;

	xhttp.open('GET', 'includes/ajax.php?w='+w+'&logic='+logic+'&artikel='+artikel+'&alte='+alte, true);

	if( isIEBr == 1 )
	{
		xhttp.onreadystatechange = updateWiki_callback;	
	} else
	  {
		xhttp.onload = updateWiki_callback;
	  }

	xhttp.send(null);
 }


 function updateWiki_callback()
 {
	if( xhttp.readyState != 4 || xhttp.status != 200 )
	{
		return;
	}

	if( xhttp.responseText )
	{
		var wikiErg = xhttp.responseText;
	} else
	  {
		var wikiErg = xhttp.responseText;
	  }

	document.getElementById('wikiSuggest').innerHTML = wikiErg;

	w_ajax_an();
 }


 function init()
 {
	// Ajax
	if( window.ActiveXObject )
	{
		try
		{
			// IE 6.0
			xhttp = new ActiveXObject("Msxml2.XMLHTTP");
			isIEBr = 1;
		} catch(e)
		  {
			// IE 5.x
			try
			{
				xhttp = new ActiveXObject("Microsoft.XMLHTTP");
				isIEBr = 1;
			} catch(e)
			  {
				xhttp = false;
			  }
		  }
	} else
		if( window.XMLHttpRequest )
		{
			// Mozilla, Opera, Safari
			try
			{
				xhttp = new XMLHttpRequest();
			} catch(e)
			  {
				xhttp = false;
			  }
		}
 }
