Cwo.RegisterNamespace("Cwo.Search.FindAnAgent");Cwo.Search.FindAnAgent=new function(){var a=this;this.LocationString="";this.BranchTypeID=0;this.CurrentPage=0;this.TotalResults=0;this.PagingTotal=0;this.PageSize=0;this.FullyQualifiedPlaceName="";this.ResultsSummaryHtml="";this.TotalSalesBranches=0;this.TotalLettingBranches=0;this.Template;this.DidYouMeanExpanded=false;this.ControlIDs={};this.GetPagingTotal=function(){return a.PagingTotal};this.GetPageSize=function(){return a.PageSize};this.GetCurrentPage=function(){return a.CurrentPage};this.Criteria=new function(){this.BranchTypeID=0;this.SearchString="";this.CurrentPage=0;this.Radius=0;this.PageSize=0};this.Submit=function(b){Cwo.Search.FindAnAgent.Criteria.BranchTypeID=parseInt($("input.agentType:checked").val(),10);Cwo.Search.FindAnAgent.Criteria.SearchString=$("#SearchPredictiveText").val();Cwo.Search.FindAnAgent.Criteria.CurrentPage=b;Cwo.Search.FindAnAgent.Criteria.Radius=$("#"+a.ControlIDs.Radius).val();Cwo.Search.FindAnAgent.Criteria.PageSize=a.PageSize;Cwo.Search.FindAnAgent.QueryWebService();return false};this.SearchResult=function(b){this.ID=b.BranchId;this.BranchType=b.BranchType;this.BrandName=b.BrandName;this.Latitude=b.Latitude;this.Longitude=b.Longitude;var c=a.Template;if(b.IsRooftopLatLongAvailable=="True"){this.IsRooftopLatLongAvailable=true}else{this.IsRooftopLatLongAvailable=false}$.each(b,function(e,d){c=a.ReplaceTemplateContext("\\$"+e+"\\$",d,c)});this.GetListHTML=function(){return c}};this.ReplaceTemplateContext=function(d,e,c){var b=new RegExp(d,"g");c=c.replace(b,e);return c};this.DeserializeBranchListing=function(b){return new a.SearchResult(b)};this.QueryWebService=function(){var b=Cwo.Page.AjajCalls.CreateRequest("BranchSearch");$("#Loading").css("display","block");$("#"+a.ControlIDs.ResultsList).addClass("Hidden");$("#"+a.ControlIDs.NoResults).addClass("Hidden");$("#"+a.ControlIDs.NoPlace).addClass("Hidden");Cwo.AjaxCall("/webservices/branchsearch.asmx/GetBranches",JSON.stringify(a.Criteria),function(c,e){if(Cwo.Page.AjajCalls.IsCurrentSequenceIndex("BranchSearch",b)){a.LocationString=a.Criteria.SearchString;a.CurrentPage=a.Criteria.CurrentPage;if(c.d.ContentContainer!==null){a.TotalResults=c.d.ContentContainer.TotalRecordsAvailable;a.PagingTotal=c.d.ContentContainer.PagingTotal;a.FullyQualifiedPlaceName=c.d.ContentContainer.FullyQualifiedPlaceName;a.ResultsSummaryHtml=c.d.ContentContainer.ResultsSummaryHtml;a.TotalSalesBranches=c.d.ContentContainer.TotalSalesAvailable;a.TotalLettingBranches=c.d.ContentContainer.TotalLettingAvailable}a.BranchTypeID=a.Criteria.BranchTypeID;if(c.d.ErrorMessage===null){var d=c.d.ContentContainer.NearbyPlacesHtml;if(d!==null&&d.length>0){$("#NearbyPlacesContainer").html(d)}a.SetHashURL(c.d.ContentContainer.SearchURL);var h=c.d.ContentContainer.SearchResults;var g=new Array();for(var f=0;f<h.length;f++){g[g.length]=a.DeserializeBranchListing(h[f])}a.RenderListingCollection(g);$("#"+a.ControlIDs.ResultsList).removeClass("Hidden")}else{if(c.d.ErrorMessage==="NoResults"){$("#"+a.ControlIDs.NoResults).removeClass("Hidden")}else{if(c.d.ErrorMessage==="LocationNotFound"){$("#FindAnAgentTwoColumnResultsContainer").removeClass("OneColumn").addClass("TwoColumn");$("#LocationNotFoundText").val(a.Criteria.SearchString);$("#location").text(a.Criteria.SearchString);$("#litLocation").hide();$("#"+a.ControlIDs.NoPlace).removeClass("Hidden")}}}}Cwo.Page.EventController.FireEvent("FindAnAgentResults.PostResultSetChange");a.ShowHeaderAndFooterSummary();$("#Loading").css("display","none")},function(e,c,d){$("#Loading").css("display","none");new Cwo.Error.Popup("Problem fetching list of agents.","Sorry, we could not retrieve any results for your search - this could be a problem with your internet connection, or a problem with our website.<br><br>If you attempt to search again and receive the same error, please wait a few minutes and try again.")})};this.ShowHeaderAndFooterSummary=function(){var c=$("#SearchPredictiveText").val();var e=$("#"+a.ControlIDs.Radius+" option:selected").text();var b="Agent";var d="";switch(a.BranchTypeID){case 1:d="Sales";break;case 2:d="Lettings";break}if(a.TotalResults!==1){b+="s"}$(".LitAgentResultsMiles").html(e);$(".LitAgentPlace").html(a.FullyQualifiedPlaceName);$("#"+a.ControlIDs.ResultsListTopSummary).html(a.ResultsSummaryHtml);$("#"+a.ControlIDs.ResultsListBottomSummary).html(a.ResultsSummaryHtml)};this.RenderListingCollection=function(d){a.RenderBranchCollection(d,"Sales");a.RenderBranchCollection(d,"Lettings");var b=d.length;for(var c=0;c<b;c++){a.BindMiniMapClicks(d[c]);a.BindContactAgentClicks(d[c]);a.BindContactAgentTwoClicks(d[c]);a.BindBranchLogoClicks(d[c]);a.BindBranchLogoTwoClicks(d[c]);a.BindBrandNameClicks(d[c]);a.BindBrandNameTwoClicks(d[c])}};this.RenderBranchCollection=function(c,b){var d="";var e=c.length;var f=0;var h=0;for(var g=0;g<e;g++){if(c[g].BranchType===b){d+=c[g].GetListHTML()}if(c[g].BranchType==="Sales"){h++}if(c[g].BranchType==="Lettings"){f++}}var j;if(b==="Sales"){j=$("#"+a.ControlIDs.ResultsListSales+" ul")}else{j=$("#"+a.ControlIDs.ResultsListLettings+" ul")}if(d.length>0){j.html(d).removeClass("Hidden");if(b===1){$("#EstateNoResults").attr("class","Hidden")}else{$("#LettingsNoResults").attr("class","Hidden")}}else{j.html("").addClass("Hidden");if(b===1){if(a.TotalSalesBranches<1){$("#EstateNoResults").attr("class","")}}else{if(a.TotalLettingBranches<1){$("#LettingsNoResults").attr("class","")}}}};this.BindContactAgentClicks=function(b){new Cwo.Form("ContactAgent"+b.ID,23,false,null,"BranchID:"+b.ID)};this.BindContactAgentTwoClicks=function(b){new Cwo.Form("ContactAgentTwo"+b.ID,23,false,null,"BranchID:"+b.ID)};this.BindBranchLogoClicks=function(b){new Cwo.Form("BranchLogo"+b.ID,23,false,null,"BranchID:"+b.ID)};this.BindBranchLogoTwoClicks=function(b){new Cwo.Form("BranchLogoTwo"+b.ID,23,false,null,"BranchID:"+b.ID)};this.BindBrandNameClicks=function(b){new Cwo.Form("BrandName"+b.ID,23,false,null,"BranchID:"+b.ID)};this.BindBrandNameTwoClicks=function(b){new Cwo.Form("BrandNameTwo"+b.ID,23,false,null,"BranchID:"+b.ID)};this.BindMiniMapClicks=function(b){new Cwo.Maps.Mini(a.ControlIDs.ResultsList,"BranchListingButtons"+b.ID,b.Latitude,b.Longitude,"Map"+b.ID,"ShowMiniMap"+b.ID,"HideMiniMap"+b.ID,null,b.IsRooftopLatLongAvailable)};this.BindClicks=function(){var b=$("#"+a.ControlIDs.SalesButtonID);var e=$("#"+a.ControlIDs.LettingsButtonID);var f=$("#"+a.ControlIDs.SalesAndLettingsButtonID);var c=$("#"+a.ControlIDs.HideColumnSalesButtonID);var d=$("#"+a.ControlIDs.HideColumnLettingsButtonID);b.bind("click",function(){a.ChangeViewTypeAndSubmit(1)});e.bind("click",function(){a.ChangeViewTypeAndSubmit(2)});f.bind("click",function(){a.ChangeViewTypeAndSubmit(3)});c.bind("click",function(){a.ChangeViewTypeAndSubmit(2)});d.bind("click",function(){a.ChangeViewTypeAndSubmit(1)})};this.ChangeViewTypeAndSubmit=function(b){a.ChangeViewType(b);a.Submit(1)};this.ChangeViewType=function(b){var c=$("#"+a.ControlIDs.ContainerID);c.removeClass("OneColumn");c.removeClass("Sales");c.removeClass("Lettings");c.removeClass("TwoColumn");switch(b){case 1:a.ChangeViewTypeSales();break;case 2:a.ChangeViewTypeLettings();break;case 3:a.ChangeViewTypeSalesAndLettings();break;default:a.ChangeViewTypeSales();break}};this.ChangeViewTypeSales=function(){var c=$("#"+a.ControlIDs.ContainerID);var b=$("#"+a.ControlIDs.SalesButtonID);c.addClass("OneColumn");c.addClass("Sales");b.attr("checked","checked")};this.ChangeViewTypeLettings=function(){var c=$("#"+a.ControlIDs.ContainerID);var b=$("#"+a.ControlIDs.LettingsButtonID);c.addClass("OneColumn");c.addClass("Lettings");b.attr("checked","checked")};this.ChangeViewTypeSalesAndLettings=function(){var c=$("#"+a.ControlIDs.ContainerID);var b=$("#"+a.ControlIDs.SalesAndLettingsButtonID);c.addClass("TwoColumn");b.attr("checked","checked")};this.SetHashURL=function(b){window.location.hash="#"+b};this.EnforceHashURL=function(){if(window.location.hash.length>14){if(window.location.hash.substr(0,14)==="#/findanagent/"){if(window.location.hash!==("#"+window.location.pathname)){var c=$("<div>").append($("#Loading").eq(0).clone()).html();$("#body").html(c);$("#body").css("background-position","0px -40px");$("#Loading").css("display","block");var b=window.location;b.href=b.protocol+"//"+b.host+b.hash.substring(1);return true}}}};this.DidYouMeanCollapse=function(){a.DidYouMeanExpanded=false;window.setTimeout('$("#" + ctrls.DidYouMeanButton).removeClass("Selected");',300);$("#"+Cwo.Search.FindAnAgent.ControlIDs.DidYouMeanWrapper).slideUp(400);window.setTimeout('$("#" + Cwo.Search.FindAnAgent.ControlIDs.DidYouMeanButton).removeClass("DidYouMeanButtonSelected");',300)};this.DidYouMeanExpand=function(){a.DidYouMeanExpanded=true;$("#"+Cwo.Search.FindAnAgent.ControlIDs.DidYouMeanButton).addClass("DidYouMeanButtonSelected");$("#"+Cwo.Search.FindAnAgent.ControlIDs.DidYouMeanWrapper).css("display","none").removeClass("Hidden").slideDown(400);$("#"+Cwo.Search.FindAnAgent.ControlIDs.DidYouMeanButton).addClass("Selected")};this.DidYouMeanClick=function(){if(a.DidYouMeanExpanded){a.DidYouMeanCollapse()}else{a.DidYouMeanExpand()}}};$(document).ready(function(){Cwo.Search.FindAnAgent.OnStart=function(){$("html").bind("click",function(c){(c.target.id==="SearchPredictiveText")?$("#SearchPredictive").css("display","block"):$("#SearchPredictive").css("display","none")});if(!Cwo.Search.FindAnAgent.EnforceHashURL()){$("select.submits-branchsearch").bind("change",function(c){Cwo.Search.FindAnAgent.Submit(1)});$("a.CorrectTypoError").bind("click",function(c){var f={};f.SearchString=Cwo.Search.ForSale.Criteria.SearchString;f.CorrectedPlaceName=$(this).attr("title");Cwo.AjaxCall("/webservices/TypoCorrectionAudit.asmx/AuditItem",JSON.stringify(f),function(d,e){})});$("#"+Cwo.Search.FindAnAgent.ControlIDs.DidYouMeanButton).bind("click",function(c){Cwo.Search.FindAnAgent.DidYouMeanClick()});$("#DidYouMeanHideButton").bind("click",function(c){Cwo.Search.FindAnAgent.DidYouMeanCollapse()});var b=new Array();b[0]=Cwo.Search.FindAnAgent.ControlIDs.ResultsListPagingTop;b[1]=Cwo.Search.FindAnAgent.ControlIDs.ResultsListPagingBottom;Cwo.Search.FindAnAgent.PagingController=new Cwo.Search.PagingController(Cwo.Search.FindAnAgent.GetCurrentPage,b,Cwo.Search.FindAnAgent.Submit,Cwo.Search.FindAnAgent.GetPagingTotal,Cwo.Search.FindAnAgent.GetPageSize,"FindAnAgentResults.PostResultSetChange");Cwo.Search.FindAnAgent.PagingController.RenderButtons();Cwo.Search.FindAnAgent.ChangeViewType(Cwo.Search.FindAnAgent.BranchTypeID)}};if(navigator.userAgent.indexOf("MSIE")>-1){Cwo.Search.FindAnAgent.OnStart();return}try{Cwo.Search.FindAnAgent.OnStart()}catch(a){Cwo.Error.TrackError(a)}});
