
var isOpera=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
var strLastValue = "";
var bMadeRequest;
var theTextBox;
var bNoResults = false;
var aktimeout;
var paramHersteller = 0;


function SetProperties(xElem){
	var props = {
		elem: xElem
	};
	AddHandler(xElem);
	return props;
}

function AddHandler(objText){
	objText.onkeyup = GiveOptions;
	objText.onkeypress = FilterKeys;
	if (isOpera) objText.onkeypress = GiveOptions;
}

function FilterKeys(e)
{
  var keyCode=(e)? e.which : event.keyCode;
  if (keyCode==13) return false;
}

function GiveOptions(e){
	var intKey=-1;
	if(window.event){
		intKey = event.keyCode;
		theTextBox = event.srcElement;
	}
	else{
		intKey = e;
		theTextBox = e.target;
	}
	if (theTextBox.value.length==0 && !isOpera){
		if (aktimeout) { window.clearTimeout(aktimeout); }
		//Ergebnis zeigen
		document.getElementById("dsErgebnis").innerHTML = "";
		strLastValue = "";
		return false;
	}
	if (theTextBox.value != strLastValue) {
		bMadeRequest=true;
		if (aktimeout) { window.clearTimeout(aktimeout); }
		if (intKey==13) {
			TypeAhead();		
			return false;		
		}
		aktimeout = window.setTimeout("TypeAhead()", 500);
	}
	strLastValue = theTextBox.value;
}

function TypeAhead(){
	ShowProgress();
	var loader = new HMAjax();
	loader.url = "searchprinter.ashx";
	loader.params = "q=" + escape(theTextBox.value) + "&hersteller=" + paramHersteller;
	loader.onSuccess = function(){ BuildChoices(loader); };
	loader.doRequest();
	aktimeout=false;
}

function BuildChoices(MyAjax){
	var strText = MyAjax.response;
	document.getElementById("dsErgebnis").innerHTML = strText;	
	HideProgress();
}

function ShowProgress(){
	document.getElementById("LoadPic").style.visibility = "visible";
}

function HideProgress(){
	document.getElementById("LoadPic").style.visibility = "hidden";
}
