function inoAutocompleteTextbox(variableName, uniqueId, textboxId, panelId, keyTimeout, maxPanelHeight)
{
    this.Id = variableName;
	this.UniqueId = uniqueId;
	this.Textbox = document.getElementById(textboxId);
	this.Panel = document.getElementById(panelId);
	this.MaxPanelHeight = maxPanelHeight;

	this.UpdateItems = updateItems;
	this.TextChange = textChange;
	this.DoCallback = doCallback;
	this.LoseFocus = loseFocus;
	this.PanelMouseOver = panelMouseOver;
	this.PanelMouseOut = panelMouseOut;
	this.ShowPanel = showPanel;
	this.HidePanel = hidePanel;
	this.SetText = setText;
	
	this.LastText = null;
	this.IsOverPanel = false;
	this.Timer = null;
	this.needsIframe = document.all ? true : false;
	this.IFrame = null;
	
	function textChange()
	{
	    if (this.LastText == this.Textbox.value)
	    {
	        return;
	    }
	    else
	    {
	        this.LastText = this.Textbox.value;
	    }

	    clearTimeout(this.Timer);

	    this.Timer = setTimeout(this.Id+".DoCallback()", keyTimeout);
	}
	
	function showPanel()
	{
        if (this.needsIframe && this.IFrame == null) 
	    {
            this.IFrame = document.createElement("iframe");
            this.IFrame.id = this.Id +"_iframe";
            this.IFrame.style.position = "absolute";
            this.IFrame.style.top = "0";
            this.IFrame.style.left = "0";
            this.IFrame.style.width = "0px";
            this.IFrame.style.height = "0px";
            this.IFrame.style.zIndex = "199";
            this.IFrame.style.display = "none";
            
            this.Panel.parentNode.insertBefore(this.IFrame, this.Panel);
        }	
        
        this.Panel.style.display = 'block';
        this.Panel.style.width = this.Textbox.offsetWidth;
        
        if (this.MaxPanelHeight != 0)
        {
            if (this.Panel.offsetHeight >= this.MaxPanelHeight)
            {
                this.Panel.style.height = this.MaxPanelHeight;
                this.Panel.style.overflow = "scroll";
                this.Panel.style.overflowX = "hidden";
            }
            else
            {
                this.Panel.style.overflow = "hidden";
                this.Panel.style.height = "";
            }
        }
        
        if (this.needsIframe && this.IFrame != null)
        {
            this.IFrame.style.display = 'block';
            this.IFrame.style.width = this.Panel.offsetWidth;
            this.IFrame.style.height = this.Panel.offsetHeight;
            this.IFrame.style.left = this.Panel.offsetLeft;
            this.IFrame.style.top = this.Panel.offsetTop;
        }
	}
	
	function hidePanel()
	{
	    this.Panel.style.display = 'none';
	    
        if (this.needsIframe && this.IFrame != null)
        {
            this.IFrame.style.display = 'none';
        }
	}

	function doCallback()
	{
        if (this.Textbox.value.length < 1)
	    {
	        this.HidePanel();
	        return;
	    }

    	var message = "ItemsRequested:" + this.Textbox.value;
        var context = this.Id;

        WebForm_DoCallback(this.UniqueId, message, this.UpdateItems, context, null, true);
	}

	function loseFocus()
	{
	    if (!this.IsOverPanel)
	    {
	        this.HidePanel();
	    }
	}

	function panelMouseOver()
	{
	    this.IsOverPanel = true;
	}

    function panelMouseOut()
	{
	    this.IsOverPanel = false;
	    this.Textbox.focus();
	}

	function updateItems(callBackResult, context)
    {
        var instance;
        eval("instance = " + context + ";");

        if (callBackResult == "")
        {
            instance.HidePanel();
            return;
        }
        
        instance.Panel.style.height = "";

        instance.Panel.style.top = inoFindPosY(instance.Textbox) + instance.Textbox.offsetHeight;
        instance.Panel.style.left = inoFindPosX(instance.Textbox);

        instance.Panel.innerHTML = callBackResult;
        instance.ShowPanel();
    }

    function setText(text)
    {
        this.Textbox.value = text;
        this.HidePanel();
    }
}