function GetResults(){gettingResults=!0;$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:listingSearchWebServiceUrl+"ListingSearchResults",data:JSON.stringify(currentSearch),success:function(n){if(n.d!=null){currentSearch.endIndex=currentSearch.startIndex-1+n.d.numResults;currentSearch.totalResults=n.d.totalResults;currentSearch.reachedEnd=currentSearch.endIndex>=currentSearch.totalResults;currentSearch.reachedEnd?$(".load-more").hide():$(".load-more").show();var t=$("#search-results");currentSearch.startIndex>1?(n.d.resultsHtml!=""?(t.append(n.d.resultsHtml),DisableSelectedWatchList()):t.append("<li>No more results.<\/li>"),$("#resultsListMsg span.endindex").text(currentSearch.endIndex)):n.d.resultsHtml!=""?(t.html(n.d.resultsHtml),$("#resultsListMsg span.endindex").text(currentSearch.endIndex),DisableSelectedWatchList()):t.html("<li>Sorry, no results found<\/li>");currentSearch.currentview==="grid"?ViewGallery():currentSearch.currentview==="list"&&ViewList();localStorage.setItem("sortOrder",currentSearch.sortOrder)}},complete:function(){gettingResults=!1;$(".trunc8-7lines").length&&$(".trunc8-7lines").trunk8({lines:7})}})}function GetNextPage(){currentSearch.reachedEnd||(currentSearch.startIndex=currentSearch.endIndex+1,currentSearch.endIndex+=currentSearch.pageSize,GetResults())}function ViewGallery(){$(".btn-gallery-view").addClass("active");$(".btn-list-view").removeClass("active");var n=$("#search-results");n.addClass("grid")}function ViewList(){$(".btn-list-view").addClass("active");$(".btn-gallery-view").removeClass("active");var n=$("#search-results");n.removeClass("grid")}var listingSearchWebServiceUrl="/umbraco/surface/ListingResults/",gettingResults=!1;$(function(){$(".btn-list-view").click(function(n){n.preventDefault();currentSearch.currentview="list";localStorage.setItem("currentview",currentSearch.currentview);ViewList()});$(".btn-gallery-view").click(function(n){n.preventDefault();currentSearch.currentview="grid";localStorage.setItem("currentview",currentSearch.currentview);ViewGallery()});$(".results-sort").change(function(){var n=$(this).val();n!=currentSearch.sortOrder&&(CSTrackEvent(n,"sort_filter"),currentSearch.sortOrder=n,currentSearch.startIndex=1,currentSearch.endIndex=currentSearch.pageSize,GetResults())});$(".load-more").click(function(n){if(n.preventDefault(),!gettingResults){if(currentSearch.reachedEnd){$(this).hide();return}GetNextPage()}});localStorage.getItem("currentview")==="grid"?(currentSearch.currentview="grid",ViewGallery()):localStorage.getItem("currentview")==="list"&&(currentSearch.currentview="list",ViewList());localStorage.getItem("sortOrder")!==$(".results-sort").val()&&$(".results-sort").change();$("#btnAddToFavourites").click(function(n){n.preventDefault();SetOnClickButton("btnAddToFavourites",!1);CSTrackEvent("favouritesearch");driven_google_analystics.sendGaEvent("Search","Subscribe to search");$.ajax({type:"POST",url:userServiceUrl+"/AddToFavourites",data:JSON.stringify(currentSearch),dataType:"json",contentType:"application/json; charset=utf-8",success:function(n){var r,t,i;if(SetOnClickButton("btnAddToFavourites",!0),r="error",n.success&&(r="success"),$("#btnAddToFavourites").notify(n.message,{position:"bottom-left",arrowShow:!0,className:r}),!n.success&&n.showLogin){$("#btnAddToFavourites").siblings(".notifyjs-wrapper").find(".notifyjs-bootstrap-error span").html(n.message+"<br><a href='javascript:GoToLogin()'>Login<\/a> or <a href='/register' class='register-btn'>Register<\/a>.");$("#loginFavouriteUrl").val("1");return}$("#btnAddToFavourites").removeAttr("href");t=$(".favourite-count").html();t=t.replace("(","").replace(")","");i=parseInt(t)?parseInt(t):0;n.success&&n.isAdded?($("#btnAddToFavourites").addClass("added").html("<div title='Added to Saved Searches' class='button-added'><span class='icon icon-check'><\/span> Saved Searches<\/div><div title='Remove from Saved Searches' class='button-remove'><span class='icon icon-remove'><\/span> Saved Searches<\/div>"),i++):n.success&&!n.isAdded&&($("#btnAddToFavourites").removeClass("added").html("<div title='Add to Saved Searches'><span class='icon icon-plus'><\/span> Saved Searches<\/div>"),i--);i>0?$(".favourite-count").html("("+i.toString()+")"):$(".favourite-count").html("")}})});var n=[];$(".addToWatchlistBtn[data-listingid]").each(function(){n.push($(this).data("listingid"))});n.length>0&&$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:listingSearchWebServiceUrl+"LogListingResults",data:JSON.stringify({listingIds:n})})})