function FFSuggest() {
	
	var pRequest;
	var pLayer;
	var pDebug					= false;
	var pInstanceName			= "";
	var pSearchURL				= "";
	var pQueryParamName			= "";
	var pFormname 				= "";
	var pLayerName				= "";
	var pQueryInput;
	var pSuggest				= new Array();
	var pLastQuery;
	var pCurrentSelection		= 0;
	var pCellSpacing			= 3;
	var pHighlightBgColor 		= "#CCCCCC";
	var pHighlightTextColor 	= "#FFFFFF";	
	var pStandardBgColor 		= "#FFFFFF";
	var pStandardTextColor 		= "#000000";
	var pSuggestQueryStyle 		= "font-size:12px; font-weight: normal; padding: 0 0 0 10px; color:#696969; cursor:pointer; line-height:18px;";
	var pSuggestTypeStyle 		= "padding: 0 0 0 10px;";
	var submitted				= false;
	var hasFocus =false;
	
	this.init = function(searchURL, formname, queryParamName, divLayername, instanceName, debugMode) {
		
		pSearchURL		= searchURL;
		pFormname		= formname;
		pQueryParamName	= queryParamName;
		pLayerName		= divLayername;
		pInstanceName	= instanceName;
 		//pDebug			= debugMode;
 		pDebug			= true;
		
		if (pSearchURL == "") {		
			if (pDebug) alert("no searchurl defined");
			return null;
		} else if (pInstanceName == "") {
			if (pDebug) alert("no instancename defined");
			return null;
		} else if (pFormname == "") {
			if (pDebug) alert("no formname defined");
			return null;
		} else if (pQueryParamName == "") {
			if (pDebug) alert("no queryparamname defined");
			return null;
		} else if (pLayerName == "") {
			if (pDebug) alert("need a layer for output");
		}
		pQueryInput = document[pFormname][pQueryParamName];
		pQueryInput.onkeyup	= handleKeyPress;
		pQueryInput.onfocus	= showSuggest;
		pQueryInput.onblur	= hideSuggest;
		//document[pFormname].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(typeof suggestItems != 'undefined')
	    if (suggestItems[pCurrentSelection] != undefined) {
  	    hasFocus = false;
  	    $('queryField').value = suggestItems[pCurrentSelection]['-query'].replace("Wies?n", "Wies\'n");
    	  startSearch(suggestItems[pCurrentSelection]['-query'].replace("Wies?n", "Wies\'n"));
    	  hideSuggest();
    	}
  }
	
	/*
	function handleSubmit() {
		submitted = true;
		if (suggestItems[pCurrentSelection] != undefined) {
			if (suggestItems[pCurrentSelection].split('###')[1] == "Kategorie") {
				document[pFormname]["filterkategorie"].value = "__" + suggestItems[pCurrentSelection].split('###')[0] + "__";
				document[pFormname][pQueryParamName].value = "";
			}
			else {
				document[pFormname][pQueryParamName].value = suggestItems[pCurrentSelection].split('###')[0];
			}
		}
	}
	*/
	this.handleClick = function() {
		handleSubmit();
	}
	
	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
		}
	}
	
	function handleKeyPress(evt) {
		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 == "") {
				hideSuggest();
				if (pLayer != null) pLayer.innerHTML = "";
				return null;
			}
			if (keyCode == 13 || keyCode == 10) {
				handleSubmit();
				hideSuggest();
			}
			else{
				//if (pLastQuery != pQueryInput.value)
				startAjax();
				//pLastQuery = pQueryInput.value;
				showSuggest();

			}
		}
	}
	
	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() {
		try{
		var query = pQueryInput.value;
		//var ourPerl = "http://www.falke-shop.com/cgi-bin/SuggestSearch.pl"
		var ourPerl = "http://www.falke-shop.de/FalkeTest/Suggest.ff";
		
		var requestURL = encodeURI(pSearchURL + "?" + pQueryParamName + "=" + escape(query));
		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", ourPerl+"?xml=1&query="+escape(query), true );
					pRequest.onreadystatechange = callbackAjax;
					pRequest.send( null );
				} else {
					hideSuggest();
				}
			} else {
				if (pDebug) alert( "no layer for output found" );
			}
		} catch( ex ) {
			hideSuggest();
			if (ex == undefined) {
				if (pDebug) alert( "Error: " + ex.getmessage );
			} else {
				if (pDebug) alert( "Error: " + ex );
			}
		}
	}catch(e){}
	}
	
	function hideSuggest() {
		if(!hasFocus){
			pQueryInput.style.backgroundImage = 'url(../Shop_Relaunch/Img/Header/de/searchbar_bg.gif)';
			pQueryInput.style.color = '#CCCCCC';
		}
		if (pLayer != null) {
			pLayer.style.display = "none";
		}
	}
	
	this.hideLayerOutsideCall = function() {
		if (pLayer != null) {
			pLayer.style.display = "none";
		}
	}
	
	function showSuggest() {
		hasFocus =true;
		pQueryInput.style.backgroundImage = 'none';
		pQueryInput.style.color = '#000000';
		if(pQueryInput.value == 'Produkt suchen') pQueryInput.value = '';
		if(typeof suggestItems != 'undefined')
			if (pLayer != null && suggestItems != null && suggestItems.length >= 1) {
			
				var myOffsetTop = $('queryField').offsetTop;
				var myOffsetLeft = $('queryField').offsetLeft;
				
				if((Prototype.Browser.IE)){
				myOffsetTop = $('queryField').offsetTop + 
					$('queryField').parentElement.offsetTop + 
					$('queryField').parentElement.parentElement.offsetTop + 
					$('queryField').parentElement.parentElement.parentElement.offsetTop + 
					$('queryField').parentElement.parentElement.parentElement.parentElement.offsetTop + 
					$('queryField').parentElement.parentElement.parentElement.parentElement.parentElement.offsetTop + 
					$('queryField').parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.offsetTop 
					- 17;
				myOffsetLeft = $('queryField').offsetLeft + 
					$('queryField').parentElement.offsetLeft + 
					$('queryField').parentElement.parentElement.offsetLeft + 
					$('queryField').parentElement.parentElement.parentElement.offsetLeft + 
					$('queryField').parentElement.parentElement.parentElement.parentElement.offsetLeft + 
					$('queryField').parentElement.parentElement.parentElement.parentElement.parentElement.offsetLeft + 
					$('queryField').parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.offsetLeft;
				}
				
				
//				var myOffsetElement = (Prototype.Browser.IE) ? $('queryField').parentElement.parentElement.parentElement.parentElement.parentElement.parentElement : $('queryField');
				
				
				pLayer.style.top  = myOffsetTop  + 22 + 'px';
				pLayer.style.left = myOffsetLeft + 'px';
				pLayer.style.display	= "block";
			}
	}
	
	function callbackAjax() {
		if (submitted == false) {
		
			if (pRequest.readyState == 4) {
				if (pRequest.status != 200) {
					hideSuggest();
					if (pDebug) alert( "Error (" + pRequest.status + "): " + pRequest.statusText );
				} else {
					handleResponse(pRequest.responseText);
				}
			}
		}
  }
	
	function handleResponse(text) {
		
		try{
   	suggestItems = new XML.ObjTree();
   	suggestItems.forceArray = ['suggest'];
   	suggestItems = suggestItems.parseXML(text);
		if(typeof suggestItems != 'undefined'){
			if(typeof suggestItems.ff != 'undefined'){
				if(typeof suggestItems.ff.suggest != 'undefined'){
					suggestItems = suggestItems.ff.suggest;
  			}else{
					suggestItems = undefined;
					hideSuggest();
					return;
  			}
  		}
  	}
		if(typeof suggestItems == 'undefined')
			return;
	
		pCurrentSelection = -1;

		var outputText = '<table id="SuggestTable" cellpadding="' + pCellSpacing + '" cellspacing="0" class="' + pLayerName + '" border="0" onMouseDown="' + pInstanceName + '.handleClick();">';
		
		var pNewSuggest = new Array();
		var query = pQueryInput.value;

		for (var i= 0; i<suggestItems.length; i++) {


		outputText += '<tr  id="' + pLayerName + '_' + i + '" style="background-color: ' + pStandardBgColor + '; color: ' + pStandardTextColor + '; padding: 2 2 2 0px;" onMouseOver="' + pInstanceName + '.handleMouseOver(' + i + ');" onMouseOut="' + pInstanceName + '.handleMouseOut(' + i + ');"  onmouseup="handleSubmit()">'
								+ '<td nowrap align="left" style="'+ pSuggestQueryStyle +';">' + suggestItems[i]['-query'].replace("Wies?n", "Wies\'n").replace(new RegExp("("+query+")","ig"),'<span class="suggestContent">$1</span>') + '</td>'
						+'</tr>';
		}
		outputText += '<!--<tr><td colspan="2" style="height:25px; background-color: ' + pStandardBgColor + '; color: ' + pStandardTextColor + '; border-top:solid 1px #5C637D; font-size:9px;" align="right">powered by <a onMouseup="window.open(\'http://www.fact-finder.de\', \'_blank\');"><img src="http://www.falke-shop.de/FalkeTest/images/result/logo_fact-finder_suggest.gif" style="border-width:0px;"/></a> &nbsp;&nbsp;&nbsp;&nbsp;   </td></tr>--></table>';
		
		
		if (suggestItems.length >= 1) {
			pLayer.innerHTML		= outputText;
			if(Prototype.Browser.IE){
				if($('SuggestTable').offsetWidth < 231)
					$('SuggestTable').style.width = "231px";
			}else{
				if($('SuggestTable').offsetWidth < 229)
					$('SuggestTable').style.width = "229px";
				
			}
			showSuggest();
		} else {
			hideSuggest();
			pLayer.innerHTML		= "";
		}
	}catch(e){}
	}
	
	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 suggestItems) {
			tblCell = getTableCell(i);
			if (tblCell != null) {
				unmarkSuggest(tblCell);
			}
		}
	}
	
	function getTableCell(pos) {
		var tblCell;
		tblCell = document.getElementById(pLayerName + "_" + pos);
		return tblCell;
	}
}