		function searchFindValue(li) {
			if( !!li.extra ){
				var sValue = li.extra[0];
			}
			else var sValue = li.selectValue;
			
			if (li.extra[0] == 'title')
				return false;
			else
				redirect(li.extra[0]);
			
			//$('#tqsearch').submit();
		}
	
		function searchSelectItem(li) {
			if (li.extra[0] == 'title')
			{
				$("#tqsinput").val('');
				return false;
			}
			searchFindValue(li);
		}
		
	
		function searchFormatItem(row) {
			if (row[1] == 'title')
				return '<div style="padding: 3px 0 2px 4px; font-size: 7.5pt; background: #f5f5f5; color: #666;">' + row[0] + '</div>';
			else
				return '<div>'+row[2]+'<div class="qs_title">'+doHighlight(row[0],$("#tqsinput").val()) +'</div><div class="qs_desc">'+doHighlight(row[3],$("#tqsinput").val())+'</div><div class="clear">&nbsp;</div></div>';
		}
	
		function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<b>";
    highlightEndTag = "</b>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}

		
		function search_autocompletes_init()
		{
			$("#tqsinput").autocomplete("/autocomplete_search.php", {
				delay:100,
				width:170,
				minChars:2,
				matchSubset:false,
				matchContains:true,
				maxItemsToShow: 15,
				delay:400,
				resultsClass:"quick_search",
				cacheLength:0,
				onItemSelect:searchSelectItem,
				onFindValue:searchFindValue,
				formatItem:searchFormatItem,
				autoFill:false
			});
		}
		
