function handleSearchWithOptions(n,t,i){function u(n){n?t.attr("data-auction-id",n):t.removeAttr("data-auction-id")}function r(){var t=searchFunctions.GetSearchOption()!==GapSearchOptionsEnum.LotNumber,r=searchFunctions.GetSearchOption()===GapSearchOptionsEnum.ThisAuction?i:null;u(r),n.enable(t)}typeof initializeSearchFunctions=="function"&&(initializeSearchFunctions(),r(),searchFunctions.change(r))}var GapRecentlySearched=function(n){function t(t,i){typeof i=="undefined"&&(i=20),typeof t=="undefined"&&(t="gap-recent-searches"),this.maxItems=i,this.storage=n.localStorage,this.name=t}function i(i,r,u){function y(n){return n===f.recent?at:n===f.suggested?lt:null}function b(n){typeof n!="undefined"&&n!=null&&n.toggle()}function et(){e!=null&&(e.removeClass(v),e=null)}function h(n){n!==s&&(s===f.none&&(e=null),b(y(s)),b(y(n)),et(),s=n)}function k(n){h(f.none);var t=htmlUnescape(searchStrip(o.val()));c.data("mode",f.none),n&&n.hasClass("recentSearch")&&c.data("mode",f.recent),n&&n.hasClass("suggestedSearch")&&c.data("mode",f.suggested),typeof t!="undefined"&&t!=null&&t!==""&&t!==" "&&(a.add(t),typeof r!="undefined"&&r())}function d(t,i,r){var u=n.validator.format('<li class="'+i+'">{0}</li>');t.empty(),n(r).each(function(n,i){t.append(u(htmlEscape(i)))}),t.children().click(function(){o.val(htmlUnescape(n(this).html())),k(n(this))})}function g(){d(c.find(".recent-search-select"),"suggestion recentSearch",a.getItems())}function ht(n){d(c.find(".suggested-search-select"),"suggestion suggestedSearch",n)}function nt(){e.addClass(v),o.val(e.html())}function st(){if(e!==null){var n=y(s);n!=null&&(e=e.removeClass(v).prev(),e.length===0&&(e=n.find(".suggestion:last")),nt())}}function ot(){var n=y(s);n!=null&&(e===null?e=n.find(".suggestion:first"):(e=e.removeClass(v).next(),e.length===0&&(e=n.find(".suggestion:first"))),nt())}function vt(n){switch(n.which){case 13:return n.preventDefault(),k(),!1;case 38:return st(),!0;case 40:return ot(),!0}return!1}function ft(n){n.length>0?(ht(n),h(f.suggested)):h(f.none)}function tt(t){n.ajax({type:"GET",url:o.data("gap-ac-url"),data:{term:t,auctionId:o.attr("data-auction-id")},contentType:"application/json; charset=utf-8",success:function(n){ft(n)}})}function rt(n){if(!vt(n)){var t=htmlUnescape(searchStrip(o.val()));t.length>0&&s===f.recent&&h(f.none),clearTimeout(w),t.length>=3?w=setTimeout(function(){tt(t)},300):h(s===f.suggested?f.none:s)}}function it(){var i=n(this),u=i.val(),r;return u===""?(r=s===f.none&&a.hasData()?f.recent:f.none,h(r),!0):(setTimeout(function(){var n=i.val();n===""&&h(f.none)},1),!0)}function ut(){c.find(".clear-all").click(function(){h(f.none),a.removeAll(),g()})}function p(n){n?(o.keydown(rt),o.mouseup(it)):(h(f.none),o.unbind("keyup"),o.unbind("mouseup"))}function ct(){n(document).on("mouseup",function(t){return s!==f.none&&(n(t.target).prop("id")===o.prop("id")||n(t.target).closest(".search-panel").length||h(f.none)),!0})}function yt(){g(),p(l),ut(),ct()}if(typeof i=="undefined")throw"A container must be defined for search";typeof u=="undefined"&&(u=new t);var c=n(i),a=u,o=c.find("input:first"),at=c.find(".recent-search.search-panel"),lt=c.find(".suggested-search.search-panel"),f={none:0,recent:1,suggested:2},s=f.none,e=null,v="selected",l=!0,w;this.enable=function(n){return typeof n!="undefined"&&l!==n&&(l=n,p(l)),l},this.storeTerm=function(){a.add(htmlUnescape(searchStrip(o.val())))},yt()}return t.prototype.removeAll=function(){this.storage.remove(this.name)},t.prototype.getItems=function(){var n;return n=this.storage.isSet(this.name)?this.storage.get(this.name):[],this.length=n.length,n},t.prototype.hasData=function(){return typeof this.length=="undefined"?!1:this.length>0},t.prototype.add=function(t){if(typeof t!="undefined"&&t!==null&&t!==""){var i=this.getItems();i=n(i).not([t]).get(),i.unshift(t),i.splice(this.maxItems),this.storage.set(this.name,i)}},i}(jQuery)