var xmlHttp
var globalSelect;
var globalAutoSelectSingleEntry;

function ClearOptions() {
   // Always clear an option list from the last entry to the first
   for (x = document.getElementById(globalSelect).length; x >= 0; x--) {
      document.getElementById(globalSelect)[x] = null;
   }
}


function AddToOptionList(OptionValue, OptionText) {
   // Add option to the bottom of the list
   document.getElementById(globalSelect)[document.getElementById(globalSelect).length] = new Option(OptionText, OptionValue);
}

function useWord(str)
{
	document.getElementById('searchtext').value = str;
	document.getElementById("txtHint").innerHTML="";
	document.getElementById('txtHint').style.display = "none";
	document.searchForm.submit();
}
function showHint(str, selectfield, code, autoSelectSingleEntry, optionalValue)
{
globalSelect = selectfield;
globalAutoSelectSingleEntry = autoSelectSingleEntry;

//document.getElementById(selectTR).style.display = "none";
if (str.length==0)
  { 
	//document.getElementById(selectTR).innerHTML="";
	return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="gethint.asp";
url=url+"?q="+str+"&selectfield="+selectfield+"&code="+code+"&optionalValue="+optionalValue;
url=url+"&sid="+Math.random();

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
	if (xmlHttp.responseText != "")
	{		
		ClearOptions();
		AddToOptionList('', selectNames[getLocation(globalSelect)][1]);
		
		var parseString = xmlHttp.responseText;
		var fieldID, fieldName;

		while(parseString.indexOf('@') > -1)
		{
		fieldID = parseString.substr(0, parseString.indexOf('@'));
		parseString = parseString.substr(parseString.indexOf('@')+1);
		fieldName = parseString.substr(0, parseString.indexOf('@'));
		parseString = parseString.substr(parseString.indexOf('@')+1);

		AddToOptionList(fieldID, fieldName);
		}

		if((document.getElementById(globalSelect).length == 2) && (globalAutoSelectSingleEntry))
		{
		document.getElementById(globalSelect)[1].selected = true;
		}

		//document.getElementById(globalSelectTR).style.display = "";
		//document.getElementById(globalSelectTR).innerHTML=xmlHttp.responseText;
	}
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}