function ConditionAndDrugAutoCompleter(inTextFieldElementId, inResultAreaElementId, inErrorIndicatorElementId, inTableName, inUrlMappingTableName, isPartialSearch, inMinCharactersToStartSearch, inMaximumChoices)
{
	var itsTextFieldElementId = inTextFieldElementId;
    var itsResultAreaElementId = inResultAreaElementId;
	var itsErrorIndicatorElementId = inErrorIndicatorElementId;
    var itsTableName = inTableName;
    var itsMinCharactersToStartSearch = inMinCharactersToStartSearch;
    var itsMaximumChoices = inMaximumChoices;
    var itsIsPartialSearch = isPartialSearch;
    var itsUrlMappingTableName = inUrlMappingTableName;
    var itsAutoCompleter;


    function isUndefined(inValue)
	{
		return (inValue == null && inValue !== null);
	}

	this.showError = function()
	{
		var theErrorIndicatorElement = document.getElementById(itsErrorIndicatorElementId);
		if(theErrorIndicatorElement)
			theErrorIndicatorElement.style.display = "block";

	}

	this.hideError = function()
	{
		var theErrorIndicatorElement = document.getElementById(itsErrorIndicatorElementId);
		if(theErrorIndicatorElement)
			theErrorIndicatorElement.style.display = "none";
	}

	this.redirectToUrl = function()
	{
		var theTextFieldValue = document.getElementById(itsTextFieldElementId).value;
		var theUrl = "";
		for (var key in itsUrlMappingTableName) {
		      if(key.toLowerCase() == theTextFieldValue.toLowerCase())
			  {
			    theUrl = itsUrlMappingTableName[key];
                break;
			  }
		}
		if(theUrl == "")
			this.showError();
		else
			window.location.href = theUrl;
	};

    this.clearQueryField = function()
    {
        var theErrorIndicatorElement = document.getElementById(itsErrorIndicatorElementId);
        var theTextFieldElement = document.getElementById(itsTextFieldElementId);

        if(theErrorIndicatorElement)
            theErrorIndicatorElement.style.display = 'none';

        if(theTextFieldElement.value==theTextFieldElement.defaultValue)
            theTextFieldElement.value='';
    };
    
    /* Deprecated - dont use this method */
	this.init = function()
	{
		var theAutoCompleterParameters = "{choices:" + itsMaximumChoices + ", partialSearch:" + itsIsPartialSearch + ", minChars:" + itsMinCharactersToStartSearch + "}";        
        itsAutoCompleter = new Autocompleter.Local(itsTextFieldElementId, itsResultAreaElementId, itsTableName, eval('(' + theAutoCompleterParameters + ')'));        
    }

}
