// This is the search autocomplete
// e = event
// div = location for the autocomplete results
// content = search letters
// type = type of search (used by PHP script)
// target = where the selected result gets posted when user clicks it 
function autoComplete(e,div,content,type,target){
	// Check if enter key pressed to submit form, if not proceed with autocomplete.  This keeps the autocomplete from popping up every time you hit enter.
	if( !submitEnter(e, type) ) {
	  return;
		}
		
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp1==null) {
 		alert ("Browser does not support HTTP Request");
 		return;
  } 
	
	content = document.getElementById(content).value;
	
	script = "scripts/search.php?content=" + escape(content);
	script = script + "&type=" + type;
	script = script + "&target=" + target;
	script = script + "&sid=" + Math.random();
	xmlHttp1.onreadystatechange = function() {stateChanged(div, xmlHttp1);}
	xmlHttp1.open("GET", script, true);
	xmlHttp1.send(null);

	// Must be a mininum of 2 characters before it starts to auto-suggest items
	if(content.length>1) {
		box('1');
	}
	else {
		box('0');
	}
}	

// Function display & box are used for autocomplete
function display(word, target) {
	document.getElementById(target).value = word;
	document.getElementById('box').style.display = 'none';
	document.getElementById(target).focus();
}

// Show / Hide the auto suggest drop down box
function box(act)	{
  if(act=='0') {
	  document.getElementById('box').style.display = 'none';
	  }
  else {
		document.getElementById('box').style.display = 'inline';
	  }
}