var _autocomplete_key = "";var _autocomplete_cache = null;var _maxResults = 25;$.widget("custom.catcomplete", $.ui.autocomplete, {_create: function () {this._super();this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)");},_renderMenu: function (ul, items) {var that = this, currentCategory = "";$.each(items, function (index, item) {var li;if (item.category != currentCategory) {ul.append("" + item.category + "");currentCategory = item.category;}li = that._renderItemData(ul, item);if (item.category) {li.attr("aria-label", item.category + " : " + item.label);}});}});$(function () {$(".searchbox").catcomplete({source: function (request, response) {if ($(".searchbox").val().substring(0, 3) === _autocomplete_key && _autocomplete_key != null) {var results = $.ui.autocomplete.filter(_autocomplete_cache, $(".searchbox").val());response(results.slice(0, _maxResults));return true;}var param = { keyword: $(".searchbox").val() };_autocomplete_key = "";_autocomplete_cache = null;$.ajax({url: "/WebMethods/WebMethods.aspx/AutocompleteList",data: JSON.stringify(param),dataType: "json",type: "POST",contentType: "application/json; charset=utf-8",dataFilter: function (data) { return data; },success: function (data) {_autocomplete_key = $(".searchbox").val().substring(0, 3);_autocomplete_cache = $.map(data.d, function (item) {return {value: item[0],label: item[1],category: item[2]}});var resultsItems = $.ui.autocomplete.filter(_autocomplete_cache, $(".searchbox").val());response(resultsItems.slice(0, _maxResults));},error: function (XMLHttpRequest, textStatus, errorThrown) {}});},minLength: 3,select: function (event, ui) {$(".searchbox").val(ui.item.value);//if (ui.item.category != "Manufacturer") { $(".searchbox").val("Manufacturer-" + ui.item.label); }//else { $(".searchbox").val(ui.item.value); }document.getElementById('Search2_searchsubmit').click();return false;}});});