
function ajax_javascript_detect()
{
    $.ajax({
                type: "POST",
                url: "/SiteEvents.asmx/AjaxJavascriptDetect",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json"
                
            });
}

AutoSuggestControl = function(oTextbox, oProvider)
{
    this.cur = -1;
    this.layer = null;
    this.searchlayer = null;
    this.messageLayer = null;
    this.megalayer = null;
    this.megaBrowseID = null;
    this.megaDropDownButton = null;
    this.megaBrowseLayers = [];
    //this.MegaDropDownHideCount = 0;
    this.provider = oProvider;
    this.textbox = oTextbox;
    this.last = '';
    this.lastSelectedNode = null;
    this.navigateDone = false;
    this.titleText = $(oTextbox).attr('title');
    if (this.textbox.value == '' || this.textbox.value == this.titleText)
    {
        $(oTextbox).val(this.titleText).addClass('blur');
    }
    this.init();
};

AutoSuggestControl.prototype =
{
    init: function()
    {
        var oThis = this;

        this.textbox.onkeyup = function(oEvent)
        {
            if (!oEvent)
            {
                oEvent = window.event;
            }
            oThis.handleKeyUp(oEvent);
        };

        this.textbox.onkeydown = function(oEvent)
        {
            if (!oEvent)
            {
                oEvent = window.event;
            }
            return oThis.handleKeyDown(oEvent);
        };

        this.textbox.onblur = function()
        {
            oThis.closeSuggestions();
        };

        this.textbox.onfocus = function()
        {
            oThis.navigateDone = false;
            $(oThis.messageLayer).hide();
            $(oThis.textbox).removeClass('blur');
            if (oThis.textbox.value == oThis.titleText)
            {
                $(oThis.textbox).val('');
                oThis.last = '';
            }
            else
            {
                oThis.last = oThis.textbox.value;
                oThis.selectRange(0, oThis.textbox.value.length);
            }

        };




        this.createSuggestions();
        if (this.provider.megaDropDown)
        {
            this.createMegaDropDown();

        }
        this.createSuggestionMessage();
        this.createMessage();
        //        $(window).bind('resize', function()
        //        {

        //            oThis.positionMegaDropDownButton();
        //            oThis.hideSuggestions();
        //            oThis.hideMegaDropDown();

        //        });
        this.winWidth = $(window).width();
        this.winHeight = $(window).height();
        var resizeTimeout;
        this.resizeEventCount = 0;
        $(window).resize(function()
        {

            onResize = function()
            {

                var winNewWidth = $(window).width(), winNewHeight = $(window).height();
                if (oThis.winWidth != winNewWidth)//|| winHeight != winNewHeight)
                {
                    oThis.positionMegaDropDownButton();
                    //oThis.hideSuggestions();
                    //oThis.hideMegaDropDown();
                    if (oThis.layer.style.visibility == "visible")
                    {
                        oThis.positionSuggestions();
                    }
                    if (oThis.megalayer != null && oThis.megalayer.style.visibility == "visible")
                    {
                        oThis.positionMegaDropDown();
                    }
                    oThis.winWidth = winNewWidth;
                    oThis.winHeight = winNewHeight;
                }

            }

            var winNewWidth = $(window).width(), winNewHeight = $(window).height();

            if (oThis.winWidth != winNewWidth)//|| winHeight != winNewHeight)
            {
                window.clearTimeout(resizeTimeout);
                resizeTimeout = window.setTimeout(onResize, 10);
            }
        });

    },



    autosuggest: function(aSuggestions, bTypeAhead)
    {
        if (aSuggestions.length > 0 && this.textbox.value.length > 0)
        {
            if (bTypeAhead)
            {
                this.typeAhead(aSuggestions[0][0]);
            }
            this.showSuggestions(aSuggestions, this.textbox.value);
            this.hideMegaDropDown();
            this.hideMessage();
        }
        else if (this.textbox.value.length > 0 && !this.provider.keywords)
        {
            this.showSuggestionMessage('Looking up: ' + this.textbox.value + ' please wait...');
        }
        else if (this.textbox.value.length > 0 && this.provider.allowSearch)
        {
            this.showSuggestionMessage('Search for: ' + this.textbox.value);
        }
        else
        {
            this.hideSuggestions();
            this.hideSuggestionMessage();
        }
    },

    handleKeyUp: function(oEvent)
    {
        var iKeyCode = oEvent.keyCode;
        if (this.textbox.value.length == 0)
        {
            this.hideSuggestions();
            this.hideMegaDropDown();
            this.hideSuggestionMessage();
        }
        else if (iKeyCode == 8 || iKeyCode == 46)
        {
            this.provider.requestSuggestions(this, false);
        }
        else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123))
        {
            //ignore
        }
        else
        {
            this.hideMegaDropDown();
            this.provider.requestSuggestions(this, false);
        }
    },

    handleKeyDown: function(oEvent)
    {
        switch (oEvent.keyCode)
        {
            case 38: //up arrow
                this.previousSuggestion();
                return true;
            case 40: //down arrow 
                this.nextSuggestion();
                return true;
            case 9: //tab
                this.navigateSuggestion(true);
                return false;
            case 13: //enter
                this.navigateSuggestion(true);
                this.navigateDone = true;
                return false;
            case 27: //escape
                this.hideSuggestions();
                this.navigateDone = true;
                $(this.textbox).val(this.last).blur();
                return false;
        }
    },

    closeSuggestions: function()
    {
        this.hideSuggestions();
        if (this.textbox.value === '')
        {
            $(this.textbox).val(this.titleText).addClass('blur');
        }
        else if (this.navigateDone = false)
        {
            this.navigateSuggestion(false);
        }
        this.navigateDone = false;
    },

    createSuggestions: function()
    {
        this.layer = document.createElement("div");
        this.layer.className = "suggestions";
        this.layer.style.visibility = "hidden";
        this.layer.style.zIndex = 100;
        document.body.appendChild(this.layer);
        var oThis = this;
        this.layer.onmousedown = this.layer.onmouseup =
        this.layer.onmouseover = function(oEvent)
        {
            oEvent = oEvent || window.event;
            oTarget = oEvent.target || oEvent.srcElement;
            if (oEvent.layerY)
            {
                iLayerYPos = oEvent.layerY; // || oEvent.offsetY;
                iLayerYPos = Math.max(iLayerYPos - 1, 0);
            }
            else
            {
                iLayerYPos = oEvent.clientY + document.documentElement.scrollTop - oThis.layer.offsetTop;
                if (navigator.appName == 'Microsoft Internet Explorer')
                {
                    var ua = navigator.userAgent;
                    var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
                    if (re.exec(ua) != null)
                    {
                        rv = parseFloat(RegExp.$1);
                    }
                    if (rv >= 8)
                    {
                        iLayerYPos = Math.max(iLayerYPos - 1, 0);
                    }
                    else
                    {
                        iLayerYPos = Math.max(iLayerYPos - 3, 0);
                    }
                }
                else
                {
                    iLayerYPos = Math.max(iLayerYPos - 1, 0);
                }

            }

            iIndex = Math.min(Math.floor(iLayerYPos / oThis.layer.childNodes[0].clientHeight), oThis.layer.childNodes.length - 1);
            //document.title = iLayerYPos + ": " + iIndex;
            oTarget = oThis.layer.childNodes[iIndex];

            if (oEvent.type == "mousedown")
            {
                if (!oTarget._name)
                {
                    oThis.closeSuggestions();
                }
                else
                {
                    oThis.selectSuggestion(oTarget._name);
                    oThis.navigateSuggestion(true);
                }
            }
            else if (oEvent.type == "mouseover")
            {
                oThis.cur = oTarget._index;
                oThis.highlightSuggestion(oTarget);
            }
            else
            {
                oThis.textbox.focus();
            }
        };
    },

    showSuggestions: function(aSuggestions, keyword)
    {
        this.hideSuggestionMessage();
        this.lastSelectedNode = null;
        var oDiv = null;
        this.layer.innerHTML = "";
        for (var i = 0; i < aSuggestions.length; i++)
        {
            oDiv = document.createElement("div");
            $(oDiv).html(this.markKeyword(aSuggestions[i][0], keyword));
            oDiv._data = aSuggestions[i][1];
            oDiv._index = i;
            oDiv._name = this.provider.getName(aSuggestions[i][0]);
            this.layer.appendChild(oDiv);
        }
        this.positionSuggestions();
        this.layer.style.visibility = "visible";
        this.firstSuggestion();
        var oThis = this;
        //        this.SuggestionsHideCount = 0;
        //        $(window).bind('resize', function()
        //        {
        //            if (oThis.SuggestionsHideCount > 0)
        //            {
        //                oThis.hideSuggestions();
        //                oThis.SuggestionsHideCount = 0;
        //            }
        //            else
        //            {
        //                oThis.SuggestionsHideCount++;
        //            }

        //        });
        this.resizeEventCount = 0;
    },

    positionSuggestions: function()
    {
        this.layer.style.left = this.getLeft() + "px";
        this.layer.style.top = (this.getTop() + this.textbox.offsetHeight) + "px";
    },

    hideSuggestions: function()
    {
        this.cur = -1;
        this.layer.style.visibility = "hidden";
        this.layer.innerHTML = "";
        this.resizeEventCount = 0;
    },

    highlightSuggestion: function(oSuggestionNode)
    {
        for (var i = 0; i < this.layer.childNodes.length; i++)
        {
            var oNode = this.layer.childNodes[i];
            if (oNode == oSuggestionNode)
            {
                oNode.className = "current";
                this.lastSelectedNode = oSuggestionNode;
            }
            else if (oNode.className == "current")
            {
                oNode.className = "";
            }
        }
    },

    firstSuggestion: function()
    {
        this.cur = 0;
        var cSuggestionNodes = this.layer.childNodes;
        if (cSuggestionNodes.length > 0 && this.cur < cSuggestionNodes.length)
        {
            var oNode = cSuggestionNodes[this.cur];
            this.highlightSuggestion(oNode);

        }
    },

    nextSuggestion: function()
    {
        var cSuggestionNodes = this.layer.childNodes;
        if (cSuggestionNodes.length > 0 && this.cur < cSuggestionNodes.length - 1)
        {
            var oNode = cSuggestionNodes[++this.cur];
            this.highlightSuggestion(oNode);
            this.selectSuggestion(oNode._name);
        }
    },

    previousSuggestion: function()
    {
        var cSuggestionNodes = this.layer.childNodes;

        if (cSuggestionNodes.length > 0 && this.cur > 0)
        {
            var oNode = cSuggestionNodes[--this.cur];
            this.highlightSuggestion(oNode);
            this.selectSuggestion(oNode._name);
        }
    },

    selectSuggestion: function(sSelectedText)
    {
        this.textbox.value = sSelectedText;
        this.selectRange(0, this.textbox.value.length);
    },

    navigateSuggestion: function(doAction)
    {
        var cSuggestionNodes = this.layer.childNodes;
        this.layer.style.visibility = "hidden";
        if (cSuggestionNodes.length > 0 && this.cur >= 0)
        {
            var oNode = cSuggestionNodes[this.cur];
            return this.doNavigateSuggestion(oNode, doAction);
        }
        else if (cSuggestionNodes.length > 0 && this.cur == -1)
        {
            var oNode = cSuggestionNodes[0];
            return this.doNavigateSuggestion(oNode, doAction);
        }
        else
        {
            var _data = this.provider.isSuggestion(this.textbox.value);
            if (_data >= 0)
            {
                this.cur = -1;
                if (doAction)
                {
                    return this.provider.doAction(_data);
                }
                else
                {
                    return false;
                }
            }
            else if (this.textbox.value != this.last)
            {
                this.cur = -1;
                if (this.provider.allowSearch)
                {
                    if (this.titleText == this.textbox.value || this.textbox.value == "")
                    {
                        this.showMessage('Please type a category!');
                    }
                    else
                    {
                        this.provider.doSearch(this.textbox.value);
                    }
                }
                else if (!this.provider.allowUnlisted)
                {
                    if (this.titleText == this.textbox.value || this.textbox.value == "")
                    {
                        this.showMessage('Please type a category!');
                    }
                    else
                    {
                        this.showMessage('Cannot find: ' + this.textbox.value);
                    }
                    $(this.textbox).val(this.titleText).addClass('blur');
                    this.selectRange(0, oThis.textbox.value.length);
                }
                else
                {
                    if (doAction)
                    {
                        this.provider.doAction();
                        this.showMessage('New catergory: ' + this.textbox.value);
                    }
                }
                return false;
            }
        }
    },

    navigateLastSuggestion: function(doAction)
    {
        if (this.lastSelectedNode != null)
        {
            return this.doNavigateSuggestion(this.lastSelectedNode, doAction);
        }
        else
        {
            if (this.titleText == this.textbox.value || this.textbox.value == "")
            {
                this.showMessage('Please type a category!');
            }
            else
            {
                this.showMessage('Cannot find: ' + this.textbox.value);
            }
            $(this.textbox).val(this.titleText).addClass('blur');
            this.selectRange(0, oThis.textbox.value.length);
        }
    },

    createMegaDropDown: function()
    {

        this.megacontent = document.createElement("div");
        this.megacontent.className = "MegaContent";
        this.megalayer = this.createMegaMenuPane(this.megacontent);
        document.body.appendChild(this.megalayer);



        this.megaDropDownButton = document.createElement("img");
        this.megaDropDownButton.className = "MegaDropDownArrow";
        this.megaDropDownButton.style.visibility = "visible";
        this.megaDropDownButton.setAttribute('src', '/images/mega_drop_arrow.png');
        this.megaDropDownButton.setAttribute('alt', 'Show category options');

        this.megaDropDownButton.style.zIndex = 110;
        document.body.appendChild(this.megaDropDownButton);
        this.positionMegaDropDownButton();
        var oThis = this;
        this.megalayer.style.visibility = "hidden";
        this.megaDropDownButton.onmouseup = function(oEvent)
        {

            if (oThis.megalayer.style.visibility == "visible")
            {
                oThis.hideMegaDropDown();
            }
            else
            {
                oThis.showMegaDropDown();
            }

        };
        this.resizeEventCount = 0;
    },

    positionMegaDropDownButton: function()
    {
        if (this.provider.megaDropDown)
        {
            this.megaDropDownButton.style.left = (this.getLeft() + this.textbox.offsetWidth - 20) + "px";
            this.megaDropDownButton.style.top = (this.getTop() + 2) + "px";
        }
    },



    createMegaMenuPane: function(oContent)
    {
        oPaneDiv = document.createElement("div");
        oPaneDiv.className = "MegaDropDown";
        oPaneDiv.style.visibility = "hidden";
        oPaneDiv.style.zIndex = 120;


        var oDiv = null;

        oDiv = document.createElement("div");
        oDiv.className = "MegaHead";
        oPaneDiv.appendChild(oDiv);

        var oBodyDiv = document.createElement("div");
        oBodyDiv.className = "MegaBody";

        oBodyDiv.appendChild(oContent);

        oPaneDiv.appendChild(oBodyDiv);

        oDiv = document.createElement("div");
        oDiv.className = "MegaFooter";
        oPaneDiv.appendChild(oDiv);

        return oPaneDiv
    },


    showMegaDropDown: function()
    {
        //this.MegaDropDownHideCount = 0;
        this.hideSuggestionMessage();
        this.hideSuggestions();
        var oDiv = null;
        this.megaBrowseID = null;
        this.megaBrowseLayers = [];
        this.addMegaDropDownItems();

        this.positionMegaDropDown();

        this.megalayer.style.visibility = "visible";
        var oThis = this;
        //        this.MegaDropDownHideCount = 1;
        //        $(window).bind('resize', function()
        //        {
        //            if (oThis.MegaDropDownHideCount > 2)
        //            {
        //                oThis.hideMegaDropDown();

        //            }
        //            else (oThis.MegaDropDownHideCount > 0)
        //            {
        //                oThis.MegaDropDownHideCount++;
        //            }
        //        });
        this.resizeEventCount = 0;
    },

    positionMegaDropDown: function()
    {

        this.megalayer.style.left = this.getLeft() + "px";
        this.megalayer.style.top = (this.getTop() + this.textbox.offsetHeight) + "px";
        for (var iLevel = 0; iLevel < this.megaBrowseLayers.length; iLevel++)
        {
            this.megaBrowseLayers[iLevel].style.left = (this.getLeft() + (iLevel + 1) * 250) + "px";
            this.megaBrowseLayers[iLevel].style.top = (this.getTop() + this.textbox.offsetHeight) + "px";

        }
    },

    browseMegaDropDown: function(browse_id, iLevel)
    {
        this.megaBrowseID = browse_id;
        this.provider.getMegaBrowseItems(this, browse_id, iLevel);
    },

    showBrowseMegaDropDown: function(oItems, iLevel)
    {
        //this.MegaDropDownHideCount = 0;
        while (this.megaBrowseLayers.length > iLevel + 1)
        {
            document.body.removeChild(this.megaBrowseLayers.pop());

        }
        oBrowseLevelDiv = document.createElement("div");
        var oUL = document.createElement("ul");
        var oGoA = null;
        var oThis = this;
        for (var li = 0; li < oItems.length; li++)
        {
            var oLI = document.createElement("li");
            var oA = document.createElement("a");
            oA._data = oItems[li][0];
            oA._level = this.megaBrowseLayers.length;
            oA._text = oItems[li][1];
            if (oItems[li][2])
            {
                oGoA = null;
                oA.onmouseup = function(oEvent)
                {
                    oEvent = oEvent || window.event;
                    oTarget = oEvent.target || oEvent.srcElement;
                    oThis.megaDropDownAction(oTarget._text, oTarget._data);

                };
            }
            else
            {
                oA.onmouseup = function(oEvent)
                {
                    oEvent = oEvent || window.event;
                    oTarget = oEvent.target || oEvent.srcElement;
                    oThis.browseMegaDropDown(oTarget._data, oTarget._level);
                };
                oGoA = document.createElement("a");
                oGoA._data = oItems[li][0];

                oGoA._text = oItems[li][1];

                oGoA.onmouseup = function(oEvent)
                {
                    oEvent = oEvent || window.event;
                    oTarget = oEvent.target || oEvent.srcElement;
                    oThis.megaDropDownAction(oTarget._text, oTarget._data);
                };
                var GoLinkText = document.createTextNode("Go >");
                oGoA.appendChild(GoLinkText);
            }
            var LinkText = document.createTextNode(oItems[li][1] + " ");
            oA.appendChild(LinkText);
            oLI.appendChild(oA);
            if (oGoA != null)
            {
                oLI.appendChild(oGoA);
            }
            oUL.appendChild(oLI);
        }
        oBrowseLevelDiv.appendChild(oUL);
        oMegaContentPageDiv = document.createElement("div");
        oMegaContentPageDiv.className = "MegaContentPage";
        oMegaContentPageDiv.appendChild(oBrowseLevelDiv);

        var oBrowse = this.createMegaMenuPane(oMegaContentPageDiv);

        document.body.appendChild(oBrowse);
        if (this.megaBrowseLayers.length > 0)
        {
            oBrowse.style.left = (this.getObjectLeft(this.megaBrowseLayers[this.megaBrowseLayers.length - 1]) + this.megaBrowseLayers[this.megaBrowseLayers.length - 1].offsetWidth) + "px";
        }
        else
        {
            oBrowse.style.left = (this.getObjectLeft(this.megalayer) + this.megalayer.offsetWidth) + "px";
        }
        oBrowse.style.top = (this.getTop() + this.textbox.offsetHeight) + "px";
        this.megaBrowseLayers.push(oBrowse);
        oBrowse.style.visibility = "visible";

        $(oBrowse).animate({ width: "0%" }, { queue: true, duration: 0 }).animate({ width: "250px" }, { queue: true, duration: 500 });
        
    },

    megaDropDownAction: function(sText, iData)
    {
        $(this.textbox).val(sText);
        $(this.textbox).removeClass('blur');
        this.hideMegaDropDown();
        this.provider.doAction(iData);

    },

    addMegaDropDownItems: function()
    {
        this.megacontent.innerHTML = "";
        var oMegaItems = this.provider.getMegaItems(this);
        oMegaContentPageDiv = document.createElement("div");
        oMegaContentPageDiv.className = "MegaContentPage";
        if (this.provider.megaBrowse)
        {
            oDiv = document.createElement("div");

            oDiv.className = "MegaContentItem";
            var oA = document.createElement("a");

            var LinkText = document.createTextNode("Browse All...");
            oA.appendChild(LinkText);
            oDiv.appendChild(oA);
            oMegaContentPageDiv.appendChild(oDiv);
            var oThis = this;
            oA.onmouseup = function(oEvent)
            {
                oThis.browseMegaDropDown(0, -1);
            };
        }

        for (var i = 0; i < oMegaItems.length; i++)
        {
            oDiv = document.createElement("div");
            oDiv.className = oMegaItems[i][0] + " MegaContentItem";
            var oH = document.createElement("h3");
            oH.innerHTML = oMegaItems[i][1];
            oDiv.appendChild(oH);
            var ListItmes = oMegaItems[i][2];
            if (ListItmes.length == 1 && ListItmes[0][1] == "")
            {
                var oP = document.createElement("p");
                oP.innerHTML = ListItmes[0][0];
                oDiv.appendChild(oP);
            }
            else
            {

                var oUL = document.createElement("ul");


                for (var li = 0; li < ListItmes.length; li++)
                {
                    if (ListItmes[li][1] != "")
                    {
                        var oLI = document.createElement("li");
                        var oA = document.createElement("a");
                        oA._data = ListItmes[li][1];
                        oA._text = ListItmes[li][0];
                        oA.onmouseup = function(oEvent)
                        {
                            oEvent = oEvent || window.event;
                            oTarget = oEvent.target || oEvent.srcElement;
                            oThis.megaDropDownAction(oTarget._text, oTarget._data);
                        };
                        var LinkText = document.createTextNode(ListItmes[li][0] + " ");
                        oA.appendChild(LinkText);
                        oLI.appendChild(oA);

                        if (oMegaItems[i][0] == "MegaFavourite" || oMegaItems[i][0] == "MegaRecent")
                        {
                            oA = document.createElement("a");
                            if (oMegaItems[i][0] == "MegaFavourite")
                            {
                                LinkText = document.createTextNode("(Del)");
                            }
                            else if (oMegaItems[i][0] == "MegaRecent")
                            {
                                LinkText = document.createTextNode("(Add)");
                            }
                            oA.appendChild(LinkText);
                            oA._data = ListItmes[li][1];
                            oA._list = oMegaItems[i][0];
                            var oThis = this;
                            oA.onmouseup = function(oEvent)
                            {
                                oEvent = oEvent || window.event;
                                oTarget = oEvent.target || oEvent.srcElement;
                                var oData = oTarget._data;
                                var oListName = oTarget._list;
                                oThis.provider.doMegaDropDownEvent(oListName, oData);
                            };

                            oLI.appendChild(oA);
                        }
                    }
                    else
                    {
                        var oLI = document.createElement("li");
                        oLI.innerHTML = ListItmes[li][0];
                    }

                    oUL.appendChild(oLI);
                }
                oDiv.appendChild(oUL);
            }


            oMegaContentPageDiv.appendChild(oDiv);

        }
        this.megacontent.appendChild(oMegaContentPageDiv);
    },

    hideMegaDropDown: function()
    {
        if (this.provider.megaDropDown)
        {
            while (this.megaBrowseLayers.length > 0)
            {
                document.body.removeChild(this.megaBrowseLayers.pop());

            }

            this.megalayer.style.visibility = "hidden";
            this.megacontent.innerHTML = "";
            this.resizeEventCount = 0;
        }

    },

    createSuggestionMessage: function()
    {
        this.searchlayer = document.createElement("div");
        this.searchlayer.className = "suggestions";
        this.searchlayer.style.visibility = "hidden";
        this.searchlayer.style.zIndex = 150;
        document.body.appendChild(this.searchlayer);
    },

    showSuggestionMessage: function(sSuggestionMessage)
    {
        this.hideSuggestions();
        var oDiv = null;
        this.searchlayer.innerHTML = "";

        oDiv = document.createElement("div");
        $(oDiv).html(sSuggestionMessage);
        this.searchlayer.appendChild(oDiv);

        this.searchlayer.style.left = this.getLeft() + "px";
        this.searchlayer.style.top = (this.getTop() + this.textbox.offsetHeight) + "px";
        this.searchlayer.style.visibility = "visible";
        
    },

    hideSuggestionMessage: function()
    {

        this.searchlayer.style.visibility = "hidden";
        this.searchlayer.innerHTML = "";
    },

    createMessage: function()
    {
        this.messageLayer = document.createElement("div");
        this.messageLayer.className = "suggestions_message";

        $(this.messageLayer).hide();
        this.messageLayer.style.zIndex = 150;
        var oThis = this;
        this.messageLayer.onmousedown = function(oEvent)
        {
            oEvent = oEvent || window.event;
            $(oThis.messageLayer).hide();
        }

        document.body.appendChild(this.messageLayer);

    },

    showMessage: function(sMessage, iTime)
    {
        var oDiv = null;
        if (iTime == null)
        {
            iTime = 1000;
        }
        this.messageLayer.innerHTML = "";
        oDiv = document.createElement("div");
        $(oDiv).html('<p>' + sMessage + '</p>');
        this.messageLayer.appendChild(oDiv);

        this.messageLayer.style.left = this.getLeft() + "px";
        this.messageLayer.style.top = (this.getTop() + this.textbox.offsetHeight - 50) + "px";
        
        $(this.messageLayer).fadeIn(500).animate({ opacity: 1.0 }, iTime).fadeOut(2000);
    },

    hideMessage: function()
    {
        $(this.messageLayer).hide();
    },

    selectRange: function(iStart, iLength)
    {
        if (this.textbox.createTextRange)
        {
            var oRange = this.textbox.createTextRange();
            oRange.moveStart("character", iStart);
            oRange.moveEnd("character", iLength - this.textbox.value.length);
            oRange.select();
        }
        else if (this.textbox.setSelectionRange)
        {
            this.textbox.setSelectionRange(iStart, iLength);
        }
        this.textbox.focus();
    },

    typeAhead: function(sSuggestion)
    {
        if (this.textbox.createTextRange || this.textbox.setSelectionRange)
        {
            var iLen = this.textbox.value.length;
            this.textbox.value = this.textbox.value + sSuggestion.substr(iLen, sSuggestion.length - iLen);
            this.selectRange(iLen, sSuggestion.length);
        }
    },

    getLeft: function()
    {
        var oNode = this.textbox;
        var iLeft = 0;
        while (oNode.tagName != "BODY")
        {
            iLeft += oNode.offsetLeft;
            oNode = oNode.offsetParent;
        }
        return iLeft;
    },

    getObjectLeft: function(oNode)
    {

        var iLeft = 0;
        while (oNode.tagName != "BODY")
        {
            iLeft += oNode.offsetLeft;
            oNode = oNode.offsetParent;
        }
        return iLeft;
    },

    getTop: function()
    {
        var oNode = this.textbox;
        var iTop = 0;
        while (oNode.tagName != "BODY")
        {
            iTop += oNode.offsetTop;
            oNode = oNode.offsetParent;
        }
        return iTop;
    },

    markKeyword: function(textToMark, keyphrase)
    {
        var mCurrentKeyWords = this.provider.getKeywords(textToMark, " ");
        var iStartOffset = 0;
        var sNewText = "";
        var bFoundAWord = false;
        mSearchWords = keyphrase.toLowerCase().split(" ");

        var iKeyWordStart = textToMark.indexOf("(");
        var addSpace;
        for (var KeyWordIndex = 0; KeyWordIndex < mCurrentKeyWords.length; KeyWordIndex++)
        {
            addSpace = true;
            if (mCurrentKeyWords[KeyWordIndex].length > 0)
            {
                bFoundAWord = false;
                if (mSearchWords.length > 1) // try and match whole phrase first!
                {
                    if (mCurrentKeyWords[KeyWordIndex].toLowerCase().indexOf(keyphrase) == 0)
                    {
                        sNewText += "<strong>" + textToMark.substr(iStartOffset, keyphrase.length) + "</strong>" + textToMark.substr(iStartOffset + keyphrase.length, mCurrentKeyWords[KeyWordIndex].length - keyphrase.length);
                        iStartOffset += mCurrentKeyWords[KeyWordIndex].length;
                        bFoundAWord = true;
                    }
                }
                if (bFoundAWord == false)
                {
                    for (var SearchWordIndex = 0; SearchWordIndex < mSearchWords.length; SearchWordIndex++)
                    {
                        keyword = mSearchWords[SearchWordIndex];
                        if (keyword.length > 0 && mCurrentKeyWords[KeyWordIndex].toLowerCase().indexOf(keyword) == 0)
                        {
                            sNewText += "<strong>" + textToMark.substr(iStartOffset, keyword.length) + "</strong>" + textToMark.substr(iStartOffset + keyword.length, mCurrentKeyWords[KeyWordIndex].length - keyword.length);
                            iStartOffset += mCurrentKeyWords[KeyWordIndex].length;
                            bFoundAWord = true;
                            break;
                        }
                    }
                }
                if (!bFoundAWord)
                {
                    if (iKeyWordStart < 0 || iStartOffset < iKeyWordStart)
                    {
                        sNewText += textToMark.substr(iStartOffset, mCurrentKeyWords[KeyWordIndex].length);
                        iStartOffset += mCurrentKeyWords[KeyWordIndex].length;
                    }
                    else
                    {
                        iStartOffset += mCurrentKeyWords[KeyWordIndex].length + 2;
                        addSpace = false;
                    }


                }
            }
            if (addSpace)
            {
                if (iKeyWordStart >= 0 && iStartOffset > iKeyWordStart)
                {
                    sNewText += textToMark.substr(iStartOffset, 2);
                    iStartOffset += 2;
                }
                else
                {
                    sNewText += textToMark.substr(iStartOffset, 1);
                    iStartOffset += 1;
                }
            }
        }
        sNewText = sNewText.replace(/^\s+|\s+$/g, '')
        sNewText = sNewText.replace(/[(,]+$/g, '');
        if (sNewText.indexOf("(") >= 0 && sNewText.indexOf(")") < 0)
        {
            sNewText += ")";
        }
        return sNewText;
    },

    doNavigateSuggestion: function(oNode, doAction)
    {
        this.cur = -1;
        this.selectSuggestion(oNode._name);
        if (doAction)
        {
            return this.provider.doAction(oNode._data);
        }
        else
        {
            return false;
        }
    }
};

function SuggestionProvider() 
{
    //any initializations needed go here
};

SuggestionProvider.prototype.requestSuggestions = function (oAutoSuggestControl) 
{
    var aSuggestions = new Array();
    oAutoSuggestControl.autosuggest(aSuggestions);
};

// ********** CategorySelector ***********************

CatSelectorSuggestions = function(sNavigateURL, sSearchURL)
{
    this.allowUnlisted = false;
    this.allowSearch = true;
    this.megaDropDown = false;
    this.megaBrowse = false;
    if (this.forumOnly == null)
    {
        this.forumOnly = false;
    }
    this.navigateURL = sNavigateURL;
    this.searchURL = sSearchURL;
    this.init();
    this.autoSuggestControl = null;
    this.refreshSuggestions = false;
    this.drawMega = false;
    this.megaItemCatURL = "/members/recommendations/?cat_id=";
};

CatSelectorSuggestions.prototype =
{
    init: function()
    {
        var oThis = this;
        Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "GetCategoriesSuggestions",
            false,
            { "bForumOnly": oThis.forumOnly },
            Function.createDelegate(this, this.getCategoriesSuggestionsComplete),
            null);
        Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "GetRecentFavouritCategories",
            false,
            { "bForumOnly": oThis.forumOnly },
            Function.createDelegate(this, this.getRecentFavouritCategoriesComplete),
            null);
    },

    getCategoriesSuggestionsComplete: function(result)
    {
        this.keywords = result;
        if (this.refreshSuggestions == true)
        {
            this.refreshSuggestions = false;
            this.requestSuggestions(this.autoSuggestControl, false);

        }
    },

    getRecentFavouritCategoriesComplete: function(result)
    {
        this.favourite = result[0];
        this.recent = result[1];
        if (this.drawMega == true)
        {
            this.drawMega = false;
            this.autoSuggestControl.addMegaDropDownItems();

        }

    },

    doMegaDropDownEvent: function(list, data)
    {
        if (list == "MegaRecent")
        {
            Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "AddFavourite",
            false,
            { "iCategoryID": data },
            Function.createDelegate(this, this.doMegaDropDownEventComplete),
            null);

            this.recent = null;

            this.drawMega = true;
        }
        else if (list == "MegaFavourite")
        {
            Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "RemoveFavourite",
            false,
            { "iCategoryID": data },
            Function.createDelegate(this, this.doMegaDropDownEventComplete),
            null);
            this.recent = null;
            this.favourite = null;
            this.drawMega = true;
        }

    },

    doMegaDropDownEventComplete: function(result)
    {
        if (this.drawMega == true)
        {
            this.drawMega = false;
            this.autoSuggestControl.addMegaDropDownItems();

        }
        Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "GetRecentFavouritCategories",
            false,
            { "bForumOnly": false },
            Function.createDelegate(this, this.getRecentFavouritCategoriesComplete),
            null);
    },

    getMegaBrowseItems: function(oAutoSuggestControl, iBaseID, iLevel)
    {
        this.autoSuggestControl = oAutoSuggestControl;
        this.megaBrowseItemsLevel = iLevel;
        Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "GetChildCategories",
            false,
            {"iParentCat": iBaseID, "bForumOnly": false },
            Function.createDelegate(this, this.resultsMegaBrowseItems),
            null);
    },

    resultsMegaBrowseItems: function(result)
    {
//        oItems = []
//        for (var i = 0; i < 6; i++)
//        {
//            oItems.push([i, "Base_" + BaseID + "_Item_" + i, false]);
//        }
        this.autoSuggestControl.showBrowseMegaDropDown(result, this.megaBrowseItemsLevel);
    },

    getKeywords: function(keywordText, replaceString)
    {
        var mCurrentKeyWords = [];
        var sNameKeyWords = "";
        var sOtherKeyWords = "";
        mKeyWordSets = keywordText.split("(");
        mNameKeyWords = mKeyWordSets[0].split(" ");
        for (var i = 0; i < mNameKeyWords.length; i++)
        {
            mCurrentKeyWords.push(mNameKeyWords[i].replace(/^\s+|\s+$/g, ''));
        }
        if (mKeyWordSets.length > 1)
        {
            sOtherKeyWords = mKeyWordSets[1];
            sOtherKeyWords = sOtherKeyWords.replace(/[)]+/, replaceString);
            mOtherKeyWords = sOtherKeyWords.split(",");
            for (var i = 0; i < mOtherKeyWords.length; i++)
            {
                mCurrentKeyWords.push(mOtherKeyWords[i].replace(/^\s+|\s+$/g, ''));
            }

        }
        return mCurrentKeyWords;
    },

    getName: function(sCatKeywords)
    {
        var iKeyStart = sCatKeywords.indexOf("(");
        if (iKeyStart > 0)
        {
            return sCatKeywords.substr(0, iKeyStart - 1);
        }
        else
        {
            return sCatKeywords;
        }
    },

    doAction: function(sCatID)
    {
        //        if (!sCatID)
        //        {
        //            return false;
        //        }
        //        else
        //        {
        location.href = this.navigateURL + sCatID;
        return true;
        //        }
    },

    doSearch: function(sTextboxValue)
    {
        if (!sTextboxValue)
        {
            return false;
        }
        else
        {
            location.href = this.searchURL.replace("<SearchTerm>", sTextboxValue);
            return true;
        }
    },

    isSuggestion: function(sTextboxValue)
    {
        var sTextboxValue = sTextboxValue.toLowerCase();
        if (sTextboxValue.length > 0)
        {
            if (!this.keywords)
            {
                this.refreshSuggestions = true;
                return -1;
            }
            else
            {
                var mCurrentSearchWords = sTextboxValue.split(" ");
                var mCurrentKeyWords = [];
                var mFoundAllWords = true;
                var mFoundAWord = true;
                var mWholePhrase;
                for (var i = 0; i < this.keywords.length; i++)
                {
                    mFoundAllWords = true;
                    mWholePhrase = false;
                    mCurrentKeyWords = this.getKeywords(this.keywords[i][0].toLowerCase(), "");
                    if (mCurrentSearchWords.length > 1)
                    {
                        for (var KeyWordIndex = 0; KeyWordIndex < mCurrentKeyWords.length; KeyWordIndex++)
                        {
                            if (mCurrentKeyWords[KeyWordIndex].indexOf(sTextboxValue) == 0)
                            {
                                mWholePhrase = true;
                                break;
                            }
                        }
                    }
                    if (!mWholePhrase)
                    {
                        for (var currentSearchWord = 0; currentSearchWord < mCurrentSearchWords.length; currentSearchWord++)
                        {
                            mFoundAWord = false;
                            for (var KeyWordIndex = 0; KeyWordIndex < mCurrentKeyWords.length; KeyWordIndex++)
                            {
                                if (mCurrentKeyWords[KeyWordIndex].indexOf(mCurrentSearchWords[currentSearchWord]) == 0)
                                {
                                    mFoundAWord = true;
                                    break;
                                }
                            }
                            if (!mFoundAWord)
                            {
                                mFoundAllWords = false;
                                break;
                            }
                        }
                    }
                    if (mFoundAllWords)
                    {
                        return this.keywords[i][1];
                    }
                }
                return -1;
            }
        }
        else
        {
            return -1;
        }
    },

    requestSuggestions: function(oAutoSuggestControl, bTypeAhead)
    {
        this.autoSuggestControl = oAutoSuggestControl;
        var aSuggestions = [];
        var mSecondSuggestions = [];
        var sTextboxValue = oAutoSuggestControl.textbox.value.toLowerCase();

        if (sTextboxValue.length > 0)
        {
            if (!this.keywords)
            {
                this.refreshSuggestions = true;
            }
            else
            {
                var mCurrentSearchWords = sTextboxValue.split(" ");
                var mCurrentKeyWords = [];
                var mFoundAllWords = true;
                var mWholePhrase;
                var mFoundAWord = true;
                var sCurrentKeywordSet = "";
                for (var i = 0; i < this.keywords.length; i++)
                {
                    mWholePhrase = false;
                    mFoundAllWords = true;
                    bAllTitleWords = true;
                    sCurrentKeywordSet = this.keywords[i][0].toLowerCase();
                    mCurrentKeyWords = this.getKeywords(sCurrentKeywordSet, "");
                    KeyWordStart = sCurrentKeywordSet.indexOf("(");

                    if (mCurrentSearchWords.length > 1)
                    {
                        for (var KeyWordIndex = 0; KeyWordIndex < mCurrentKeyWords.length; KeyWordIndex++)
                        {
                            if (mCurrentKeyWords[KeyWordIndex].indexOf(sTextboxValue) == 0)
                            {
                                if (sCurrentKeywordSet.indexOf(sTextboxValue) > KeyWordStart)
                                {
                                    bAllTitleWords = false;
                                }
                                mWholePhrase = true;

                                break;
                            }
                        }
                    }
                    if (!mWholePhrase)
                    {
                        for (var currentSearchWord = 0; currentSearchWord < mCurrentSearchWords.length; currentSearchWord++)
                        {
                            mFoundAWord = false;


                            for (var KeyWordIndex = 0; KeyWordIndex < mCurrentKeyWords.length; KeyWordIndex++)
                            {

                                if (mCurrentKeyWords[KeyWordIndex].indexOf(mCurrentSearchWords[currentSearchWord]) == 0)
                                {
                                    if (sCurrentKeywordSet.indexOf(mCurrentKeyWords[KeyWordIndex]) > KeyWordStart)
                                    {
                                        bAllTitleWords = false;
                                    }

                                    mFoundAWord = true;
                                    break;
                                }
                            }

                            if (!mFoundAWord)
                            {
                                mFoundAllWords = false;
                                break;
                            }
                        }
                    }
                    if (mFoundAllWords)
                    {
                        if (bAllTitleWords)
                        {
                            aSuggestions.push(this.keywords[i]);
                        }
                        else
                        {
                            mSecondSuggestions.push(this.keywords[i]);
                        }
                    }
                }
            }
            for (var i = 0; i < mSecondSuggestions.length; i++)
            {
                aSuggestions.push(mSecondSuggestions[i]);
            }

            oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
        }
        else
        {
            oAutoSuggestControl.hideSuggestions();
        }
    },

    getMegaItems: function(oAutoSuggestControl)
    {
        this.autoSuggestControl = oAutoSuggestControl;

        var MegaGroups = [];

        var MegaGroupItems = ["MegaFavourite", "Favourite"];
        var MegaItems = [];

        if (!this.favourite)
        {
            this.drawMega = true;
            MegaItems.push(["Please wait...", ""]);
        }
        else if (this.favourite.length == 0)
        {
            MegaItems.push(["No items", ""]);
        }
        else
        {

            for (var j = 0; j < this.favourite.length; j++)
            {
                MegaItems.push([this.favourite[j][0], this.favourite[j][1]]);
            }


        }
        MegaGroupItems.push(MegaItems);
        MegaGroups.push(MegaGroupItems);

        var MegaGroupItems = ["MegaRecent", "Recent"];
        var MegaItems = [];

        if (!this.recent)
        {
            this.drawMega = true;
            MegaItems.push(["Please wait...", ""]);
        }
        else if (this.recent.length == 0)
        {
            MegaItems.push(["No items", ""]);
        }
        else
        {

            for (var j = 0; j < this.recent.length; j++)
            {
                MegaItems.push([this.recent[j][0], this.recent[j][1]]);
            }


        }
        MegaGroupItems.push(MegaItems);
        MegaGroups.push(MegaGroupItems);
        return MegaGroups;
    }



};

CatSelectorSuggestions.registerClass("CatSelectorSuggestions");


// ********** RTCategorySelector ***********************

RTCategorySelectorSuggestions = function(sNavigateURL, sSearchURL)
{

    RTCategorySelectorSuggestions.initializeBase(this, [sNavigateURL, sSearchURL]);
    var lastTextBoxValue;
};

RTCategorySelectorSuggestions.prototype =
{
    init: function()
    {
        var oThis = this;

        Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "GetRecentFavouritCategories",
            false,
            { "bForumOnly": oThis.forumOnly },
            Function.createDelegate(this, this.getRecentFavouritCategoriesComplete),
            null);


    },

    isSuggestion: function(sTextboxValue)
    {

        var oThis = this;
        this.lastTextBoxValue = sTextboxValue;

        Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "RTGetCategoriesSuggestions",
            false,
            { "sSearchPhrase": sTextboxValue, "bForumOnly": oThis.forumOnly  },
            Function.createDelegate(this, this.getCategoriesIsSuggestionsComplete),
            null);


    },

    getCategoriesIsSuggestionsComplete: function(result)
    {
        this.keywords = result;
        CatSelectorSuggestions.prototype.isSuggestion.call(this, lastTextBoxValue);
    },

    requestSuggestions: function(oAutoSuggestControl, bTypeAhead)
    {

        this.autoSuggestControl = oAutoSuggestControl;

        var oThis = this;
        sTextboxValue = oAutoSuggestControl.textbox.value.toLowerCase();

        Sys.Net.WebServiceProxy.invoke(
            "/Controls/Common/CategorySelectorService.asmx",
            "RTGetCategoriesSuggestions",
            false,
            { "sSearchPhrase": sTextboxValue, "bForumOnly": oThis.forumOnly },
            Function.createDelegate(this, this.getCategoriesRequestSuggestionsComplete),
            null);

    },

    getCategoriesRequestSuggestionsComplete: function(result)
    {
        this.keywords = result;
        CatSelectorSuggestions.prototype.requestSuggestions.call(this, this.autoSuggestControl, false);
    }
};



RTCategorySelectorSuggestions.registerClass("RTCategorySelectorSuggestions", CatSelectorSuggestions);

// ********** WizCategorySelector ***********************

WizCatSelectorSuggestions = function(oCatIDObject, oTextBoxObject, bEventMode, sPostBackControlID)
{

    
    this.allowUnlisted = true;
    this.allowSearch = false;
//    this.megaDropDown = true;
//    this.megaBrowse = true;
    this.forumOnly = false;
    this.catIDObject = oCatIDObject;
    this.textBoxObject = oTextBoxObject;
    this.eventMode = bEventMode;
    this._PostBackControlID = sPostBackControlID;
    WizCatSelectorSuggestions.initializeBase(this, ["", ""]);

};

WizCatSelectorSuggestions.prototype =
{

    doAction: function(sCatID)
    {
        if (!sCatID)
        {
            this.catIDObject.value = '-1';

        }
        else
        {
            this.catIDObject.value = sCatID;
        }
        if (this.eventMode)
        {
            __doPostBack(this._PostBackControlID, this.catIDObject.value + "%" + this.textBoxObject.value);
        }
        else
        {
            this.textBoxObject.form[(this.findTabIndex(this.textBoxObject) + 1) % this.textBoxObject.form.length].focus();
        }
        return false;
    },

    findTabIndex: function(input)
    {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input) index = i;
        else i++;
        return index;
    }
};

WizCatSelectorSuggestions.registerClass("WizCatSelectorSuggestions", CatSelectorSuggestions);


// ********** ForumCategorySelector ***********************


ForumCatSelectorSuggestions = function(sNavigateURL, sSearchURL)
{

    
    this.megaItemCatURL = "/members/forum/?cat_id=";
    this.forumOnly = true;
    ForumCatSelectorSuggestions.initializeBase(this, [sNavigateURL, sSearchURL]);
};

ForumCatSelectorSuggestions.prototype =
{
//    init: function()
//    {
//        var oThis = this;
//        Sys.Net.WebServiceProxy.invoke(
//            "/Controls/Common/CategorySelectorService.asmx",
//            "GetCategoriesSuggestions",
//            false,
//            { "bForumOnly": true },
//            Function.createDelegate(this, this.getCategoriesSuggestionsComplete),
//            null);
//         Sys.Net.WebServiceProxy.invoke(
//            "/Controls/Common/CategorySelectorService.asmx",
//            "GetRecentFavouritCategories",
//            false,
//            { "bForumOnly": true },
//            Function.createDelegate(this, this.getRecentFavouritCategoriesComplete),
//            null);
//    },
//    
//    getMegaBrowseItems: function(oAutoSuggestControl, iBaseID, iLevel)
//    {
//        this.autoSuggestControl = oAutoSuggestControl;
//        this.megaBrowseItemsLevel = iLevel;
//        Sys.Net.WebServiceProxy.invoke(
//            "/Controls/Common/CategorySelectorService.asmx",
//            "GetChildCategories",
//            false,
//            {"iParentCat": iBaseID, "bForumOnly": true },
//            Function.createDelegate(this, this.resultsMegaBrowseItems),
//            null);
//    }
};

ForumCatSelectorSuggestions.registerClass("ForumCatSelectorSuggestions", CatSelectorSuggestions);

NewThreadCatSelectorSuggestions = function(oCatIDObject, oTextBoxObject, bEventMode, sPostBackControlID)
{

    
    this.allowUnlisted = false;
    this.allowSearch = false;
//    this.megaDropDown = true;
//    this.megaBrowse = true;
    this.catIDObject = oCatIDObject;
    this.textBoxObject = oTextBoxObject;
    this.eventMode = bEventMode;
    this._PostBackControlID = sPostBackControlID;
    this.forumOnly = true;
    NewThreadCatSelectorSuggestions.initializeBase(this, ["", ""]);

};

NewThreadCatSelectorSuggestions.prototype =
{
//    init: function()
//    {
//        var oThis = this;
//        Sys.Net.WebServiceProxy.invoke(
//            "/Controls/Common/CategorySelectorService.asmx",
//            "GetCategoriesSuggestions",
//            false,
//            { "bForumOnly": true },
//            Function.createDelegate(this, this.getCategoriesSuggestionsComplete),
//            null);
//    },

//    getMegaBrowseItems: function(oAutoSuggestControl, iBaseID, iLevel)
//    {
//        this.autoSuggestControl = oAutoSuggestControl;
//        this.megaBrowseItemsLevel = iLevel;
//        Sys.Net.WebServiceProxy.invoke(
//            "/Controls/Common/CategorySelectorService.asmx",
//            "GetChildCategories",
//            false,
//            { "iParentCat": iBaseID, "bForumOnly": true },
//            Function.createDelegate(this, this.resultsMegaBrowseItems),
//            null);
//    },

    doAction: function(sCatID)
    {
        if (!sCatID)
        {
            return false;

        }
        else
        {
            this.catIDObject.value = sCatID;
        }
        if (this.eventMode)
        {
            __doPostBack(this._PostBackControlID, this.catIDObject.value + "%" + this.textBoxObject.value);
        }
        else
        {
            this.textBoxObject.form[(this.findTabIndex(this.textBoxObject) + 1) % this.textBoxObject.form.length].focus();
        }
        return false;
    },

    findTabIndex: function(input)
    {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input) index = i;
        else i++;
        return index;
    }
};

NewThreadCatSelectorSuggestions.registerClass("NewThreadCatSelectorSuggestions", CatSelectorSuggestions);
// **********