if( navigator.userAgent.indexOf("Opera") != -1)	document.onkeydown = Tastendruck;
else document.onkeyup = Tastendruck;
document.onclick = mouseClick;

if (navigator.userAgent.indexOf("Windows") != -1) var IExplorer = true;
else var IExplorer = false;
	/* color wieder herstellen */
var save_color;
  /* browser enter event umgehen */
var Cur_Opt_Link;

function mouseClick (Ereignis) {
	if (document.getElementById("ac_results")) {
		document.suchfeld.suchwort.focus();
		getSuchwort('output.php?suchwort=""');
		Cur_Opt_Link ='';
		//evtl. removeAttribute ??
	}
}

function Tastendruck (Ereignis) {
	var Taste;
	if(!Ereignis) Ereignis = window.event;
  if (Ereignis.keyCode) Taste = Ereignis.keyCode;  //IE 
	else if (Ereignis.which) Taste = Ereignis.which; //andere Browser
	//key up event
  if (Taste == 38) {
  	Cur_Opt = document.getElementById("ac_results_selected");
  	if (!Cur_Opt) Cur_Opt = document.getElementById("ac_results").firstChild.lastChild;
  	else if (Cur_Opt != document.getElementById("ac_results").firstChild.firstChild) {
  		Cur_Opt.removeAttribute("id");
  		Cur_Opt.style.backgroundColor = save_color;
  		//Element davor
  		Cur_Opt = Cur_Opt.previousSibling;
  		save_color = Cur_Opt.style.backgroundColor;
  	}
  	if (Cur_Opt ) {
  		Cur_Opt.setAttribute("id","ac_results_selected");
  		Cur_Opt_Link = Cur_Opt.firstChild.href;
  		Cur_Opt.style.backgroundColor = "#FE7500";
  		ChangeSuchwort(Cur_Opt);
  	}
	}
	//key down event
	else if (Taste == 40) {
		Cur_Opt = document.getElementById("ac_results_selected");
		if (!Cur_Opt) {
			Cur_Opt = document.getElementById("ac_results").firstChild.firstChild;
			save_color = Cur_Opt.style.backgroundColor;
		}
		else if (Cur_Opt != document.getElementById("ac_results").firstChild.lastChild) {
			Cur_Opt.removeAttribute("id");
			Cur_Opt.style.backgroundColor = save_color;
			//naechstes Element
			Cur_Opt = Cur_Opt.nextSibling;
			save_color = Cur_Opt.style.backgroundColor;
		}
		if (Cur_Opt){
			Cur_Opt.setAttribute("id","ac_results_selected");
			Cur_Opt_Link = Cur_Opt.firstChild.href;
			Cur_Opt.style.backgroundColor = "#FE7500";
			ChangeSuchwort(Cur_Opt);
		}
	}
	//key ESC event
	else if (Taste == 27) {
		document.suchfeld.suchwort.focus();
		getSuchwort('output.php?suchwort=""');
		Cur_Opt_Link ='';
		//evtl. removeAttribute ??
	}
	//key enter
	else if (Taste == 13) {
		if (Cur_Opt_Link) window.location.href = Cur_Opt_Link;
	}
	//suchwort eingeben event
	else if (Taste != 38 && Taste != 40 ){
		var Param = document.getElementById('suchwort').value;
		getSuchwort('output.php?suchwort=' + Param);
	}
	if (!IExplorer) { Ereignis.preventDefault(); }
}

function ChangeSuchwort(Cur_Opt) {
		suchwort = Cur_Opt.getAttribute("name");
		document.getElementById('suchwort').value = suchwort;
		//document.getElementById('ac_results_selected').scrollIntoView(true);
		document.getElementById('hintdiv').scrollTop = document.getElementById('ac_results_selected').offsetTop;
		/* verhindert scrollen der Broserseite*/
		document.suchfeld.suchwort.focus();
	  document.getElementById('suchwort').focus();
}

function getSuchwort(strURL)
{
  try {
    req = new XMLHttpRequest();
  }
  catch (e) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (failed) {
        req = null;
      }
    }
  }
  if (req) {
    req.onreadystatechange = function() {
      if (req.readyState == 4) {
        if (req.status == 200) document.getElementById('hintdiv').innerHTML=req.responseText;
      }
    }
    req.open("GET", strURL, true);
    req.send(null);
  }
}

function ShowCode(gscode)
{
	var gscode = document.getElementById('gscode').value;
	document.getElementById('facts').innerHTML='Ihr Gutscheincode:<br /><br /><font size="4"><center>'+gscode+'</center></font>';
	
}