var searchBox={urlSubmit:"/Client/{0}/SearchSubmit",urlDynamicFilter:"/Client/{0}/SearchFilterDynamic",animationDuration:.4,division:null,$container:null,init:function(){searchBox.division=common.division.getCurrentName();searchBox.division==null&&(searchBox.division=common.division.cars);searchBox.$container=$(".module-search-box");searchBox.$container.find(".filter-dynamic").change(searchBox.eventHandlers.filterDynamic);searchBox.$container.find(".advanced-searchbox-fields-toggle").click(searchBox.eventHandlers.toggleMoreFilters);searchBox.$container.find("#searchSubmit").click(searchBox.eventHandlers.submitClick);$("#searchTextForm").submit(searchBox.eventHandlers.searchTextSubmit)},eventHandlers:{toggleMoreFilters:function(){var n=$(this),t=n.parents(".module-search-box").hasClass("show-all-filters")?"See more options":"Hide options";n.text(t);n.parents(".module-search-box").toggleClass("show-all-filters")},submitClick:function(n){n.preventDefault();var t=searchBox.helpers.compileSearchFilters();searchBox.serverRequests.submitSearch(t)},filterDynamic:function(){var n=$(this),t=searchBox.helpers.compileSearchFilters();this.id=="make"&&(t.models=null);n.attr("name")=="industry"&&n.is(":checked")&&(t.industry=n.val());searchBox.serverRequests.dynamicFilter(t)},searchTextSubmit:function(n){n.preventDefault();var t=searchBox.helpers.compileSearchTextFilters();searchBox.serverRequests.submitSearch(t)}},serverRequests:{submitSearch:function(n){var t=common.functions.stringFormat(searchBox.urlSubmit,searchBox.division),i={pageId:common.pageId,providerName:common.providerName,filters:n};$.ajax({type:"POST",url:t,data:JSON.stringify(i),contentType:"application/json; charset=utf-8",traditional:!0,cache:!1,timeout:3e4,success:function(n){n.error?common.functions.fireTrackingEvent("Search","Home Search "+t,common.trackingResult.ERRORFROMRESPONSE):n.isRedirect&&(common.functions.fireTrackingEvent("Search","Home Search "+t,common.trackingResult.SUCCESS),window.location=n.redirectUrl)},error:function(){common.functions.fireTrackingEvent("Search","Home Search "+t,common.trackingResult.ERRORWITHREQUEST)}})},dynamicFilter:function(n){var t=common.functions.stringFormat(searchBox.urlDynamicFilter,searchBox.division),i={filters:n};$.ajax({type:"POST",url:t,data:JSON.stringify(i),contentType:"application/json; charset=utf-8",traditional:!0,cache:!1,timeout:3e4,success:function(n){n.error||searchBox.helpers.postDynamicFilter(n)},error:function(){}})}},helpers:{postDynamicFilter:function(n){searchBox.helpers.updateList("select[name='locations']",n.filters.Locations);switch(searchBox.division){case common.division.cars:searchBox.helpers.updateTypes(n.filters.Types);searchBox.helpers.updateList("select[name='make']",n.filters.Makes);searchBox.helpers.updateList("select[name='models']",n.filters.Models);searchBox.helpers.updateList("select[name='pricefrom']",n.filters.PricesFrom);searchBox.helpers.updateList("select[name='priceto']",n.filters.PricesTo);searchBox.helpers.updateList("select[name='odofrom']",n.filters.OdometersFrom);searchBox.helpers.updateList("select[name='odoto']",n.filters.OdometersTo);searchBox.helpers.updateList("select[name='yearfrom']",n.filters.YearsFrom);searchBox.helpers.updateList("select[name='yearto']",n.filters.YearsTo);searchBox.helpers.updateList("select[name='salemethods']",n.filters.SaleMethods);searchBox.helpers.updateCustom(n.filters.Custom);break;case common.division.trucksAndMachinery:searchBox.helpers.updateIndustries(n.filters.Industrys);searchBox.helpers.updateList("select[name='category']",n.filters.Categorys);searchBox.helpers.updateList("select[name='subcategories']",n.filters.SubCategorys);searchBox.helpers.updateList("select[name='make']",n.filters.Makes);searchBox.helpers.updateList("select[name='models']",n.filters.Models);searchBox.helpers.updateList("select[name='yearfrom']",n.filters.YearsFrom);searchBox.helpers.updateList("select[name='yearto']",n.filters.YearsTo);searchBox.helpers.updateList("select[name='salemethods']",n.filters.SaleMethods);break;case common.division.damagedAndEndOfLife:searchBox.helpers.updateList("select[name='types']",n.filters.Types);searchBox.helpers.updateList("select[name='make']",n.filters.Makes);searchBox.helpers.updateList("select[name='models']",n.filters.Models);searchBox.helpers.updateList("select[name='pricefrom']",n.filters.PricesFrom);searchBox.helpers.updateList("select[name='priceto']",n.filters.PricesTo);searchBox.helpers.updateList("select[name='yearfrom']",n.filters.YearsFrom);searchBox.helpers.updateList("select[name='yearto']",n.filters.YearsTo);searchBox.helpers.updateList("select[name='regstatus']",n.filters.RegStatus);searchBox.helpers.updateCustom(n.filters.Custom);break;case common.division.boatsAndMarine:searchBox.helpers.updateList("select[name='category']",n.filters.Categorys);break;case common.division.generalGoods:searchBox.helpers.updateList("select[name='category']",n.filters.Categorys);searchBox.helpers.updateList("select[name='subcategories']",n.filters.SubCategorys);searchBox.helpers.updateList("select[name='salemethods']",n.filters.SaleMethods)}},updateTypes:function(n){var t=searchBox.$container.find("input[name='types']");t.length>0&&$.each(t,function(t,i){var r=$(i),f=r.parent(),u=!0,e=!1,o=0;$.each(n,function(n,t){if(t.Value==r.val())return u=t.Count<1,e=t.Selected,o=t.Count,!1});r.prop("disabled",u);r.prop("checked",e);r.siblings(".checkbox-wrapper").children(".number").text(common.functions.stringFormat("({0})",o));u==!0?f.addClass("disabled"):f.removeClass("disabled")})},updateIndustries:function(n){var t=searchBox.$container.find("input[name='industry']");t.length>0&&$.each(t,function(t,i){var r=$(i),f=r.parent(),u=!0,e=!1,o=0;$.each(n,function(n,t){if(t.Value==r.val())return u=t.Count<1,e=t.Selected,o=t.Count,!1});r.prop("disabled",u);r.prop("checked",e);r.siblings(".checkbox-wrapper").children(".number").text(common.functions.stringFormat("({0})",o));u==!0?f.addClass("disabled"):f.removeClass("disabled")})},updateList:function(n,t){var r=searchBox.$container.find(n),u;r.length>0&&(r[0].sumo.is_opened||(r.html(""),u=[],$.each(t,function(n,t){var e=t.GroupName!=null,r,f;if(e){for(r=null,i=0;i<u.length;i++)if(f=u[i],f.isGroup==!0&&f.GroupName==t.GroupName){r=f;break}r==null&&(r={isGroup:!0,GroupName:t.GroupName,options:[]},u.push(r));r.options.push(t)}else u.push(t)}),$.each(u,function(n,t){var i,u;t.isGroup==!0?(i=$('<optgroup label="'+t.GroupName+'"><\/optgroup>'),$.each(t.options,function(n,t){var r=t.Selected?'selected="selected"':"";i.append('<option value="'+t.Value+'" '+r+">"+t.Text+"<\/option>")}),r.append(i)):(u=t.Selected?'selected="selected"':"",r.append('<option value="'+t.Value+'" '+u+">"+t.Text+"<\/option>"))}),r[0].sumo.reload()))},updateCustom:function(n){var t=searchBox.$container.find("input[name='custom']");t.length>0&&$.each(t,function(t,i){var r=$(i),f=r.parent(),u=!0,e=!1,o=0;$.each(n,function(n,t){if(t.Value==r.val())return u=t.Count<1,e=t.Selected,o=t.Count,!1});r.prop("disabled",u);r.prop("checked",e);r.siblings(".checkbox-wrapper").children(".number").text(common.functions.stringFormat("({0})",o));u==!0?f.addClass("disabled"):f.removeClass("disabled")})},compileSearchFilters:function(){var n=searchBox.$container.find("input, select");return common.functions.serializeObject(n)},compileSearchTextFilters:function(){var n=$("#searchTextForm").find("input, select");return common.functions.serializeObject(n)}}},searchAutocomplete={urlSearchAutocomplete:"/Client/{0}/SearchAutocomplete",division:null,$searchContainer:null,init:function(){var n,t;searchAutocomplete.division=common.division.getCurrentName();searchAutocomplete.division==null&&(searchAutocomplete.division=common.division.cars);searchAutocomplete.$searchContainer=$(".module-search-box");searchAutocomplete.$searchContainer.hasClass("cars")&&(n=searchAutocomplete.$searchContainer.find(".search-autocomplete").data("suggestiontexts"),n!==""&&(t=n.split(","),$(".search-autocomplete").placeholderTypewriter({text:t})));$(".search-autocomplete-mobile").focus(searchAutocomplete.eventHandlers.scrollToMobileText);$(".search-autocomplete").autocomplete({minLength:2,source:function(n,t){$.ajax({url:common.functions.stringFormat(searchAutocomplete.urlSearchAutocomplete,searchAutocomplete.division),data:{query:n.term},dataType:"json",success:function(n){n?t(n):t({})},error:function(){t([])}})},select:function(n,t){n.preventDefault();$(".search-autocomplete").val(t.item.Text)},focus:function(n,t){n.preventDefault();$(".search-autocomplete").val(t.item.Text)}});$(".search-autocomplete").each(function(){$(this).autocomplete("instance")._renderItem=function(n,t){var i=$("<div>").append(t.Text);return $("<li>").append(i).appendTo(n)}})},eventHandlers:{scrollToMobileText:function(n){n.preventDefault();common.functions.scrollIntoView($(this).closest(".search-text-container"))}},serverRequests:{},helpers:{}},homePage={init:function(){homePage.catalogueList.init.module();searchBox.init();searchAutocomplete.init()},catalogueList:{urlList:"/Client/Catalogue/SmallCatalogueList",urlTurnersLiveOverlay:"/Client/TurnersLive/ViewOverlay",animationDuration:.8,secondaryAnimationDuration:.2,listIsAnimating:!1,listResults:null,listHasResults:!0,cataloguePageId:null,cataloguePageDivisionIndex:null,$listContainer:null,$listFooter:null,$totalResultsLabel:null,$filters:null,$catalogueHomeLinks:null,$loadMoreButton:null,init:{module:function(){homePage.catalogueList.$listContainer=$("#listContainer");homePage.catalogueList.$listFooter=$("#listFooter");homePage.catalogueList.$totalResultsLabel=$("#totalResultsLabel");homePage.catalogueList.$catalogueHomeLinks=$(".catalogue-home-link");homePage.catalogueList.$loadMoreButton=$(".load-more-events-trigger");homePage.catalogueList.init.filterPanel();homePage.catalogueList.init.results();homePage.catalogueList.$loadMoreButton.click(homePage.catalogueList.eventHandlers.loadMoreClick)},filterPanel:function(){homePage.catalogueList.$filters=$(".filter-static");homePage.catalogueList.$filters.change(homePage.catalogueList.eventHandlers.filterChange)},results:function(){homePage.catalogueList.$listContainer.find(".view-live-button").click(homePage.catalogueList.eventHandlers.viewTurnersLiveClick)}},eventHandlers:{filterChange:function(){homePage.catalogueList.serverRequests.catalogueList(1)},loadMoreClick:function(n){n.preventDefault();homePage.catalogueList.serverRequests.catalogueList(2)},viewTurnersLiveClick:function(n){n.preventDefault();var t=$(this);homePage.catalogueList.cataloguePageId=t.data("pageid");homePage.catalogueList.cataloguePageDivisionIndex=t.data("divisionindex");homePage.catalogueList.serverRequests.openTurnersLiveOverlay()}},serverRequests:{catalogueList:function(n){homePage.catalogueList.helpers.preCatalogueList(n);var i=homePage.catalogueList.urlList,t=homePage.catalogueList.helpers.compileFilters();t.pageId=common.pageId;t.providerName=common.providerName;t.pageNumber=n;$.ajax({type:"POST",url:i,data:JSON.stringify(t),contentType:"application/json; charset=utf-8",traditional:!0,cache:!1,timeout:3e4,success:function(t){t.error?alert(t.errorMessage):homePage.catalogueList.helpers.postCatalogueList(t,n)},error:function(n,t,i){alert(i)}})},openTurnersLiveOverlay:function(){var n={pageId:homePage.catalogueList.cataloguePageId,divisionIndex:homePage.catalogueList.cataloguePageDivisionIndex};$.ajax({type:"POST",url:homePage.catalogueList.urlTurnersLiveOverlay,data:n,traditional:!0,cache:!1,timeout:3e4,success:function(n){common.overlay.openContent(n);$(".turners-live-login").click(function(n){n.preventDefault();common.login.overlay.init.module2("TurnersLive",!1,homePage.catalogueList.serverRequests.openTurnersLiveOverlay)})},error:function(){}})}},helpers:{compileFilters:function(){return common.functions.serializeObject(homePage.catalogueList.$filters)},preCatalogueList:function(n){n==1&&(homePage.catalogueList.$listContainer.height(homePage.catalogueList.$listContainer.height()),homePage.catalogueList.listIsAnimating=!0,TweenMax.to(homePage.catalogueList.$listContainer,homePage.catalogueList.animationDuration,{opacity:"0",ease:SlowMo.easeInOut,onComplete:function(){homePage.catalogueList.listIsAnimating=!1;homePage.catalogueList.helpers.completeCatalogueList(n)}}))},postCatalogueList:function(n,t){homePage.catalogueList.listResults=n;homePage.catalogueList.helpers.completeCatalogueList(t)},completeCatalogueList:function(n){if(n==1)homePage.catalogueList.listIsAnimating==!1&&homePage.catalogueList.listResults!==null&&(homePage.catalogueList.$listContainer.html(homePage.catalogueList.listResults.resultsContent),TweenMax.to(homePage.catalogueList.$listContainer,homePage.catalogueList.animationDuration,{height:"100%",opacity:"1",ease:SlowMo.easeInOut}),homePage.catalogueList.$catalogueHomeLinks.attr("href",homePage.catalogueList.listResults.allCataloguesUrl),homePage.catalogueList.listResults.hasMoreResults?(homePage.catalogueList.$listFooter.show(),homePage.catalogueList.$listFooter.removeClass("events-loaded")):homePage.catalogueList.$listFooter.hide(),homePage.catalogueList.listResults=null);else{homePage.catalogueList.$listContainer.append(homePage.catalogueList.listResults.resultsContent);var t=homePage.catalogueList.secondaryAnimationDuration;homePage.catalogueList.$listContainer.find(".animated-event-row").each(function(n){n>0&&(t=t+.1);TweenMax.to(this,t,{display:"block",top:"0",ease:SlowMo.easeInOut});TweenMax.to(this,t+1.5,{opacity:"1",ease:SlowMo.easeInOut})});homePage.catalogueList.listResults.hasMoreResults?(homePage.catalogueList.$listFooter.show(),homePage.catalogueList.$totalResultsLabel.html(common.functions.stringFormat("We have {0} other events",homePage.catalogueList.listResults.totalResults)),homePage.catalogueList.$listFooter.addClass("events-loaded")):homePage.catalogueList.$listFooter.hide()}homePage.catalogueList.init.results()}}}}