	var styleOn = 'position: absolute; left:254px; background-color: #FFFFFF; text-align: left; border: 1px solid #000000; border-style:solid;z-index:6;';
	var styleOff = 'position: absolute; left:254px; background-color: #FFFFFF; text-align: left;';
	
	var ajaxMiniSearchObject = getMiniXmlHttpRequestObject();
	//These two varibles are used extensively by the key catching code so uses can arrow up and down to navigate the list
	var elementsInList = 0;
	var selectedElement = -1;
	//lastSuggestion keeps track the length of the query that was last submitted to the ajax action, if the handler 
	//finds that this value is different than what is currently in the form field (i.e. the user has typed very fast 
	//and there is now more text in the field than was originally submitted) then the ajax action is called again 
	//to make the suggestion results accurately reflect what the user has typed in the input box.
	var lastSuggestion = 0; 
	
	function miniTrim(strText) { 
		if (strText != null){
	    while (strText.substring(0,1) == ' ') {
	        strText = strText.substring(1, strText.length);}
	    while (strText.substring(strText.length-1,strText.length) == ' '){
	        strText = strText.substring(0, strText.length-1);}
	        }
	  	 return strText;
	}	
	function miniSearch()
	{
		var check = true;
		var searchValue = document.getElementById('searchValue');
		if(searchValue.value=='')
		{
			alert('Please fill in all search fields');
			check =false;
		}
		if(check==true){		
			document.miniSearchForm.submit();					
			}
	}
	
	function getMiniXmlHttpRequestObject() {
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			alert("Your Browser does not support the search suggestion feature.");
		}
	}
	
	function miniPutSuggestionInTextBox(value)
	{
		value = removeXMLTags(value);
		value = miniTrim(value);		
		document.getElementById("searchValue").value = value;	
	}
	
	//Set function (used for clicking or hitting enter)
	function miniSetSearch(myDiv) {	
		var value = myDiv.innerHTML;
		var sms = 'search_mini_suggest';
		miniPutSuggestionInTextBox(value);
		var sms = document.getElementById(sms);
		sms.innerHTML = '';
		sms.setAttribute("style", "");
		var browser=navigator.appName;
		if (browser == 'Microsoft Internet Explorer')		
		{
			sms.style.setAttribute('cssText', styleOff, 0);
		}
		document.getElementById('exactSearch').value = true;
		
		document.getElementById('miniSearchHiddenId').value = FetchHiddenTagValue(value);
		miniSearch();		
	} 	
	document.onclick=closeMiniSearch;

	function keyPress(e){
		//escape
		if (e.keyCode == 27)
		{
			closeMiniSearch();
		}
		//enter
		else if (e.keyCode == 13)
		{
			
			var thisDiv = document.getElementById(selectedElement);
			miniSetSearch(thisDiv);
		}
		//backspace or delete (we don't want to keep the suggestion box open if 
		//the user backspaces their whole query)
		else if ((e.keyCode == 8) || (e.keyCode == 46))
		{	
			if (document.getElementById('searchValue').value.length < 2)
			{
				closeMiniSearch();
			}
			else //still a valid length, we'll query the db
			{
				queryDB();
			}
		}
		//left or up
		else if ((e.keyCode == 37) || (e.keyCode == 38))
		{
			if ((selectedElement < 0) && (elementsInList > 0))
			{
				var myDiv = document.getElementById((elementsInList - 1));					
				selectedElement = (elementsInList - 1);
				miniSuggestOver(myDiv, false);
			}
			else if ((selectedElement >= 0) && (elementsInList > 0))
			{
				var myUpOldDiv = document.getElementById(selectedElement);										
				miniSuggestOut(myUpOldDiv);
				selectedElement = (parseInt(selectedElement) - 1);
				if (selectedElement < 0)
				{
					selectedElement = (elementsInList - 1);
				}
				
				var myUpNewDiv = document.getElementById(selectedElement);					
				miniSuggestOver(myUpNewDiv, false);
			}				
		}
		//down or right
		else if ((e.keyCode == 39) || (e.keyCode == 40))
		{
			if ((selectedElement < 0) && (elementsInList > 0))
			{
				var myDiv = document.getElementById(0);
				selectedElement = 0;					
				miniSuggestOver(myDiv, false);
			}
			else if ((selectedElement >= 0) && (elementsInList > 0))
			{
				var myDownOldDiv = document.getElementById(selectedElement);										
				miniSuggestOut(myDownOldDiv);					
				selectedElement = (parseInt(selectedElement) + 1);
				if (selectedElement >= elementsInList)
					{selectedElement = 0;
				}
				var myDownNewDiv = document.getElementById(selectedElement);					
				miniSuggestOver(myDownNewDiv, false);
			}								
		}
		//The key pressed was not an arrow, lets make a suggestion
		else
		{
			queryDB();
		}			
	}

	//Basic ajax function, it can be called 2 ways 1) A key was pressed, 2) The handler returned results, but more stuff was typed in 
	//the mean time and those results are out of date, and it needs to be called again.
	function queryDB(){
		var searchValue = escape(document.getElementById('searchValue').value);
		//alert(searchValue);
		if (searchValue.length >= 2){
			if (ajaxMiniSearchObject.readyState == 4 || ajaxMiniSearchObject.readyState == 0) {
				var searchIn = escape(document.getElementById('moduleSearch').value);
				elementsInList = 0;
				selectedElement = -1;
				//lastSuggestion needs to be unescaped to avoid inconsitency with the handler
				lastSuggestion = document.getElementById('searchValue').value.length;				
				ajaxMiniSearchObject.open("GET", '/common/AjaxMiniBarSearchSuggest.do?searchIn=' + searchIn + '&searchValue=' + searchValue, true);
				ajaxMiniSearchObject.onreadystatechange = handleMiniSearchSuggest 
				ajaxMiniSearchObject.send(null);
			}		
		}
	}	
	
	//Called either from they key press action on the minibar text box, or from hodelMiniSearchSuggest if it sees that the results are 
	//out of date.
	function searchMiniSuggest(e) {
		if (e != null){	
			keyPress(e);	
		}					
		else{
			queryDB();
		}	
	}
	
	//Called when the AJAX response is returned.
	function handleMiniSearchSuggest() {
			if (ajaxMiniSearchObject.readyState == 4) {
			if (ajaxMiniSearchObject.responseText != ''){
				var miniStr = ajaxMiniSearchObject.responseText.split("\n");
				var sms = document.getElementById('search_mini_suggest');
				var browser=navigator.appName;
				//Stupid fix for a stupid browser, maybe one of these days MS will make a standards complaint browser
				if (browser == 'Microsoft Internet Explorer')				
					sms.style.setAttribute('cssText', styleOn, 0);
				sms.setAttribute("style", styleOn);		
				sms.innerHTML = '';
				for(i=0; i < (miniStr.length -1); i++) {
					//Build our element string.  This is cleaner using the DOM, but
					//IE doesn't support dynamically added attributes.
					var suggestion = miniStr[i];
					if ((suggestion.indexOf('results not displayed') < 0) && (suggestion.indexOf('No results found') < 0)){
						var miniSuggest = '<div onmouseover="javascript:miniSuggestOver(this, true);selectedElement=this.id;" ';
						miniSuggest += 'onmouseout="javascript:miniSuggestOut(this);" ';
						miniSuggest += 'onclick="javascript:miniSetSearch(this);" ';
						miniSuggest += 'class="suggest_link" id='+ elementsInList +'>' + suggestion + '</div>';
						sms.innerHTML += miniSuggest;
						elementsInList++;
					}else
					{					
						var miniSuggest = '<div ';
						miniSuggest += 'class="suggest_link_more">' + suggestion + '</div>';
						sms.innerHTML += miniSuggest;					
					}					
				}
			}					
		}
		//This marks the end of returning suggestions, now we check to see 
		//if what we queryed for, matches what is in the text box (as you can see
		//we only check the length, as it is slighty faster, and still serves the same purpose)
		//If the values don't match, we need to query again.
		if (lastSuggestion != (document.getElementById('searchValue').value.length))
		{
			 searchMiniSuggest(null);
		}
	}
	
function removeXMLTags(text) {
 	var retVal = text.replace(/(<([^>]+)>)/ig,""); 	 	
	return retVal;
}
	
	//Mouse over function
	function miniSuggestOver(div_value, moused) {
		var clearDiv = document.getElementById(selectedElement);										
		miniSuggestOut(clearDiv);			
		if (div_value != null)
		{
			div_value.className = 'suggest_link_over';			
		}
		//This check is added so that if the users mouse is 
		//over the area where the suggestion box will appear
		//it doesn't take first suggestion that appears under
		//the users mouse and requery on that value... again
		//this is consistent with the behavior of google's box
		if ((moused != null) && (!(moused)))
			miniPutSuggestionInTextBox(div_value.innerHTML);
	}
	//Mouse out function
	function miniSuggestOut(div_value) {
		if (div_value != null){
			div_value.className = 'suggest_link';			
		}
	}	
	
	function closeMiniSearch(){
		var sms = 'search_mini_suggest';
		var divBox = document.getElementById(sms);		
		if (divBox != null)
		{
			divBox.innerHTML = '';
			divBox.setAttribute("style", "");
			var browser=navigator.appName;
			if (browser == 'Microsoft Internet Explorer')		
				{
					divBox.style.setAttribute('cssText', styleOff, 0);
				}				
		}
	}
	

