	function lookup(inputString,inputCompany) {
                inputCompany=$('#comp').val();
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("/sixcms/detail.php?template=suchworte_rpc_local_2", {queryString: ""+inputString+"",queryCompany: ""+inputCompany+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup

	function fill(thisValue) {
		$('#inputString').val(thisValue);
		//setTimeout("$('#suggestions').hide();", 200);
                if (currentSelection>-1){
                  document.suche.submit();
                }
	}

function hide20() {
//  setTimeout("$('#suggestions').hide();", 2000);
}

function li_over(thisLi) {
   $("#autoSuggestionsList ul li").removeClass("itemhover");
  $(thisLi).addClass('itemhover');
          $("#autoSuggestionsList ul li").each(function(index) {
              if ($(this).attr('class') == 'itemhover') {
                //alert(index);
                currentSelection=index;
              } else {
              //alert(index + ": " +$(this).text() + ": " +$(this).attr('class'));
              }
          }
          );
}
function li_out(thisLi) {
 // $(thisLi).removeClass('itemhover');
}
var currentSelection = -1;

    $(document).keydown(function (e) {
      var keyCode = e.keyCode || e.which,
          arrow = {left: 37, up: 38, right: 39, down: 40, ret: 13 };

      switch (keyCode) {
        case arrow.ret:
               setInputSelected(currentSelection); 
               e.keyCode=0;
	       e.which=0;
        break;
        case arrow.left:
        break;
        case arrow.up:
              navigate('up');
        break;
        case arrow.right:
        break;
        case arrow.down:
              navigate('down');
        break;
        default:
        break;
      }
    });

    $(document).keyup(function (e) {
      var keyCode = e.keyCode || e.which,
          arrow = {left: 37, up: 38, right: 39, down: 40, ret: 13  };

      switch (keyCode) {
        case arrow.left:
        break;
        case arrow.up:
     //    alert(currentSelection);
        break;
        case arrow.right:
        break;
        case arrow.down:
        break;
        default:
           lookup($('#inputString').val(),'mr');
        break;
      }
    });

function navigate(direction) {
   if($("#autoSuggestionsList ul li.itemhover").size() == 0) {
      currentSelection = -1;
   } else {
          $("#autoSuggestionsList ul li").each(function(index) {
              if ($(this).attr('class') == 'itemhover') {
                //alert(index);
                currentSelection=index;
              }          }
          );
          //alert($("#autoSuggestionsList ul").index(myli));
   }

   if(direction == 'up' && currentSelection != -1) {
      if(currentSelection != 0) {
         currentSelection--;
      }
   } else if (direction == 'down') {
      if(currentSelection != $("#autoSuggestionsList ul li").size() -1) {
         currentSelection++;
      }
   }
   setSelected(currentSelection);
}
function setSelected(menuitem) {
   $("#autoSuggestionsList ul li").removeClass("itemhover");
   $("#autoSuggestionsList ul li").eq(menuitem).addClass("itemhover");
}

function setInputSelected(menuitem) {
   Click2=$("#autoSuggestionsList ul li").eq(menuitem).attr("onclick");
   eval(Click2); 
}

