function FFSuggest() {
	
	var pRequest;
	var pLayer;
	var pDebug					= false;
	var pInstanceName			= "";
	var pSearchURL				= "";
	var pQueryParamName			= "";
	var pFormname 				= "";
	var pLayerName				= "";
	var pQueryInput;
	var pQueryForm;
	var pSuggest				= new Array();
	var pMandantId				= "";
	var pLastQuery;
	var pCurrentSelection		= 0;
	var pCellSpacing		= 0;
	var pHighlightBgColor 		= "#fd9900";
	var pHighlightTextColor 	= "#FFFFFF";	
	var pStandardBgColor 		= "#FCFCFC";
	var pStandardTextColor 		= "#173553";
	var pSuggestQueryStyle 		= "font-weight: bold; padding: 2 15 2 10px;";
	var pSuggestTypeStyle 		= "padding: 2 5 2 15px;";
	var submitted				= false;
	var pResults = new Array();
	var pIndex = 0;
	var pSortingField;
	
	this.init = function(searchURL, realForm, inputField, divLayername, instanceName, debugMode, mandantId, indx, sortingField ) {

		pIndex = indx;
		pResults = results;

		pSearchURL		= searchURL;
		//pFormname		= formname;
		//pQueryParamName	= queryParamName;
		pLayerName		= divLayername;
		pInstanceName	= instanceName;
		pMandantId = mandantId;
 		// pDebug			= debugMode;
		pDebug			= false;

		pQueryInput = inputField;
		pQueryInput.onkeyup	= handleKeyPress;
		pQueryInput.onfocus	= showLayer;
		if (pQueryInput.attachEvent) {
			pQueryInput.attachEvent( 'onfocus', showLayer );
		}
		pQueryInput.onblur	= hideLayer;
		
		pQueryForm = realForm;
		pQueryForm.onsubmit = handleSubmit;

		pSortingField = sortingField;
	
		if (pSearchURL == "") {		
			if (pDebug) alert("no searchurl defined");
			return null;
		} else if (pInstanceName == "") {
			if (pDebug) alert("no instancename defined");
			return null;
		} else if (pLayerName == "") {
			if (pDebug) alert("need a layer for output");
		} else if (pMandantId == "") {
			if (pDebug) alert("need a clientDB for output");
		} else if( inputField === undefined ){
			if (pDebug) alert("need an inputField for output");
		} else if( realForm === undefined ){
			if (pDebug) alert("need an realForm for output");
		}

		pQueryInput.onkeyup	= handleKeyPress;
		pQueryInput.onfocus	= showLayer;

		if (pQueryInput.attachEvent) {
			pQueryInput.attachEvent( 'onfocus', showLayer );
		}
		pQueryInput.onblur	= hideLayer;
		pQueryForm.onsubmit = handleSubmit;
	}
	
	this.setHighlightColors = function(highlighBackgroundColor, highlighTextColor) {
		pHighlightBgColor	= highlighBackgroundColor;
		pHighlightTextColor	= highlighTextColor;
	}
	
	this.setStandardColors = function(standardBackgroundColor, standardTextColor) {
		pStandardBgColor	= standardBackgroundColor;
		pStandardTextColor	= standardTextColor;
	}
	
	this.setCellspacing = function(cellspacing) {
		pCellSpacing = cellspacing;
	}
	
	function handleSubmit() {
		submitted = true;
		if (pSuggest[pCurrentSelection] != undefined) {
			if (pSuggest[pCurrentSelection].split('###')[1] == "Kategorie") {
				pQueryForm["filterkategorie"].value = "__" + pSuggest[pCurrentSelection].split('###')[0] + "__";
				pQueryInput.value = "";
			}
			else {
				pQueryInput.value = pSuggest[pCurrentSelection].split('###')[0];
			}
		}
		if( pQueryInput.value == undefined || pQueryInput.value == "" ){
			alert("Ihr Suchfeld ist leer. Bitte geben Sie einen Suchbegriff ein");
			return false;
		}		
	}
	
	this.handleClick = function() {
		if (pSuggest[pCurrentSelection] != undefined) {
			if (pSuggest[pCurrentSelection].split('###')[1] == "Kategorie") {
				pQueryForm["filterkategorie"].value = "__" + pSuggest[pCurrentSelection].split('###')[0] + "__";
				pQueryInput.value = "";
				pQueryForm.submit();
			}
			else {
				pQueryInput.value = pSuggest[pCurrentSelection].split('###')[0];
				pQueryForm.submit();
			}
		}
	}
	
	this.handleMouseOver = function(pos) {
		var tblCell = getTableCell(pos);
		unmarkAll();
		if (tblCell != null) {
			highlightSuggest(tblCell);
			pCurrentSelection = pos;
		}
	}
	
	this.handleMouseOut = function(pos) {
		var tblCell = getTableCell(pos);
		if (tblCell != null) {
			unmarkSuggest(tblCell);
			pCurrentSelection = -1
		}
	}
	this.handleEnterPressed = function( suggestValue ) {
		pQueryInput.value = suggestValue;
		
		//document[pFormname].submit();
	}

	function handleKeyPress(evt) {
		evt = (evt) ? evt : ((window.event) ? window.event : "");
		//evt = (evt) ? evt : ((event) ? event : null);
		var keyCode = evt.keyCode;
		if (keyCode == 38) {
			moveSelection("up")
		} else if (keyCode == 40) {
			moveSelection("down");
		} else {
			if (pQueryInput.value == "") {
				hideLayer();
				if (pLayer != null) pLayer.innerHTML = "";
				return null;
			}
			if (pLastQuery != pQueryInput.value) startAjax();
			pLastQuery = pQueryInput.value;
		}
	}

	function handleKeyPressSuggestTable ( suggestValue, evt ) {
		evt = (evt) ? evt : ((window.event) ? window.event : "");
		var keyCode = evt.keyCode;
		if (keyCode == 13) {
			pQueryInput.value = suggestValue;
			pQueryForm.submit();
		}		
	}

	function submitForm() {
		//wenn true zurückgegene wird, wird das formular gesendet
		if (pCurrentSelection < 0 ) {
			return true;
		}
		pQueryInput.value = pSuggest[pCurrentSelection].split('###')[0];
		return true;
	}

	function moveSelection(direction) {
		var pos = pCurrentSelection;
		if (direction == "up")	pos--;
		else 					pos += 1;
		
		if (pos < 0) {
			unmarkAll();
			pQueryInput.focus();
			pCurrentSelection	= -1;
		} else {
			var tblCell = getTableCell(pos);
			if (tblCell != null) {
				unmarkAll();
				highlightSuggest(tblCell);
				pCurrentSelection = pos;
			}
		}
		
		var query = pQueryInput.value;
		pQueryInput.value = "";
		pQueryInput.focus();
		pQueryInput.value = query; 
	}
	
	function startAjax() {
		var query = pQueryInput.value;
		var requestURL = pSearchURL + "?query=" + escape(query);
		if ( pMandantId != null && pMandantId != "" ) {
			requestURL = requestURL + "&m=" + pMandantId;
		}
		
		try {
			if( window.XMLHttpRequest ) {
				pRequest = new XMLHttpRequest();
			} else if( window.ActiveXObject ) {
				pRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
			} else {
				if (pDebug) alert( "" );
			}
			
			pLayer = document.getElementById(pLayerName);
			if (pLayer != null) {
				if (query != "") {
					pRequest.open( "GET", requestURL, true );
					pRequest.onreadystatechange = callbackAjax;
					pRequest.send( null );
				} else {
					hideLayer();
				}
			} else {
				if (pDebug) alert( "no layer for output found" );
			}
		} catch( ex ) {
			hideLayer();
			if (ex == undefined) {
				if (pDebug) alert( "Error: " + ex.getmessage );
			} else {
				if (pDebug) alert( "Error: " + ex );
			}
		}
	}
	
	function hideLayer() {
		if (pLayer != null) {
			pLayer.style.display = "none";
		}
		if ( pSortingField != null && pSortingField != undefined &&  pSuggest != null && pSuggest.length >= 2 ) {
			pSortingField.style.display	= "inline";
		}
	}
	
	this.hideLayerOutsideCall = function() {
		if (pLayer != null) {
			pLayer.style.display = "none";
		}
	}
	
	function showLayer() {
		if (pLayer != null && pSuggest != null && pSuggest.length >= 1) {
			pLayer.style.display	= "block";
		}
		if ( pSortingField != null && pSortingField != undefined &&  pSuggest != null && pSuggest.length >= 2 ) {
			pSortingField.style.display	= "none";
		}
	}
	
	function callbackAjax() {
		if (submitted == false) {
			if (pRequest.readyState == 4) {
				if (pRequest.status != 200) {
					hideLayer();
					if (pDebug) alert( "Error (" + pRequest.status + "): " + pRequest.statusText );
				} else {
					handleResponse(pRequest.responseText);
				}
			}
		}
  	}
	
	function handleResponse(text) {

		pCurrentSelection = -1;
		pSuggest = new Array();
		pSuggest = text.split("\n");
		var outputText = '<table cellpadding="' + pCellSpacing + '" cellspacing="0" class="suggestLayer" width="100%" border="0" onMouseDown="results['+pIndex+'].handleClick();" onClick="results['+pIndex+'].handleClick();">';
		outputText += '<tr class="suggestHeader" ><td class="suggestHeader" nowrap="nowrap" colspan="3">Vorschläge zu Ihrer Suche...<td></tr>';
		
		var pNewSuggest = new Array();
		for (var i in pSuggest) {
			var firstChar = pSuggest[i].charCodeAt(0);
			if (firstChar != 13 && firstChar != 10 && pSuggest[i].length >= 1) {
				pNewSuggest.push(pSuggest[i]);
			}
		}
		pSuggest = pNewSuggest;
		var query = pQueryInput.value;
		for (var i in pSuggest) {
			pSuggestParts = new Array();
			pSuggestParts = pSuggest[i].split("###");
			var part = pSuggestParts[1];
			var Ausdruck = /(\d.+)\s(\w.+)/;
			Ausdruck.exec(part);
			var teil1 = "";
			var teil2 = "";
			if( part != "" ){
				var teil1 = RegExp.$1;
				var teil2 = RegExp.$2;
			}
			outputText += '<tr id="' + pLayerName + '_' + i + '" style="background-color: ' + pStandardBgColor + '; padding: 2 2 2 0px;" onMouseOver="results['+pIndex+'].handleMouseOver(' + i + ');" onMouseOut="results['+pIndex+'].handleMouseOut(' + i + ');" >'
				+ '<td nowrap="nowrap" style="'+ pSuggestQueryStyle +';" width="280">' + pSuggestParts[0].replace(new RegExp("("+query+")","ig"),'<span style="padding: 0px;" class="suggestContent">$1</span>') + '</td>'
				//+'<td nowrap="nowrap" style="'+ pSuggestTypeStyle +'" width="30%">' + pSuggestParts[2] + '</td>'
				//+'<td nowrap="nowrap" align="right" style="'+ pSuggestTypeStyle +'" width="30%">' + '<span style="color:#990000;">' + teil1 + '</span>&nbsp;' + teil2 + '</td>'
				+'<td nowrap="nowrap" align="right" style="'+ pSuggestTypeStyle +'" width="30%">'  + pSuggestParts[1] + '</td>'
			+'</tr>' + '\n';
		}
		outputText += '</table>';

		
		if (pSuggest.length >= 1) {
			showLayer();
			pLayer.innerHTML		= outputText;
		} else {
			hideLayer();
			pLayer.innerHTML		= "";
		}
	}
	
	function highlightSuggest(tblCell) {
		tblCell.style.backgroundColor	= pHighlightBgColor;
		tblCell.style.color	= pHighlightTextColor;
	}
	
	function unmarkSuggest(tblCell) {
		tblCell.style.backgroundColor	= pStandardBgColor;
		tblCell.style.color				= pStandardTextColor;
	}
	
	function unmarkAll() {
		var tblCell;
		for (var i in pSuggest) {
			tblCell = getTableCell(i);
			if (tblCell != null) {
				unmarkSuggest(tblCell);
			}
		}
	}
	
	function getTableCell(pos) {
		var tblCell;
		tblCell = document.getElementById(pLayerName + "_" + pos);
		return tblCell;
	}
}
