function onChangeLocation(n,t,i){var r,u;if(n!=undefined&&n.val()!=undefined&&n.val().trim()!=""){if(contractPattern.test(n.val()))return!0;if(r=t.val().substring(t.val().length-n.val().length,t.val().length),r!=n.val())return i.data("kendoAutoComplete").search(n.val()),!1}return $("#SearchedRealFullLocation")!=undefined&&$("#SearchedRealFullLocation").val()!=""&&(u=$("#MySite").val()=="True"?"localsSuggestionPanelCookie_"+$("#MySiteSEOId").val()+"_"+$("#MasterId").val()+"_lastOne":"localsSuggestionPanelCookie_lastOne",setCookie(u,locationDiacritics($("#SearchedRealFullLocation").val())+"|"+encodeURI($("#SearchedRealFullLocation").val()),1)),!0}function formatValue(n,t){var i=new RegExp(t,"ig");return n.FullLocation.replace(i,function(n){return"<span style='color:#2366b2'>"+n+"<\/span>"})}function getCookie(n){for(var r=n+"=",u=document.cookie.split(";"),t,i=0;i<u.length;i++){for(t=u[i];t.charAt(0)==" ";)t=t.substring(1);if(t.indexOf(r)==0)return t.substring(r.length,t.length)}return""}function visibilityLocalsSuggestion(n,t){t==1&&$("#searchedLocationInput").val().length>2||(n=="show"&&$("#localsSuggestionPanel").find("li").length>0?$("#localsSuggestionPanel").show():$("#localsSuggestionPanel").hide())}function setLocalSuggestion(n,t,i){var f=$("#MySiteHomePageIndexLink")!=null&&$("#MySiteHomePageIndexLink")!=undefined&&$("#MySiteHomePageIndexLink").val()!=undefined?$("#MySiteHomePageIndexLink").val():"",r=GetbusinessTypeUrl(i),u=f+r+"?b="+i+"&q="+locationDiacritics(t)+"&ord="+defaultSort,e;seoversion==2&&(e=setbusinessTypeSEOAlias($("#businessType").data("kendoDropDownList").value()),r=e.toLowerCase()+"/"+clearDescription(seoAllPropertyType)+"/"+locationDiacritics(t.split(", ")[2]+"/"),u=f+r+"?q="+locationDiacritics(t)+"&ord="+defaultSort);$("#SearchedRealFullLocation").val(t);$("#SearchedLocal").val(n);$("#searchedLocationInput").val(n);$("#home-search-button").attr("href",u);$("#home-search-button-allproperties")!=null&&$("#home-search-button-allproperties")!=undefined&&$("#home-search-button-allproperties").attr("href",u);visibilityLocalsSuggestion("hide")}function GetbusinessTypeUrl(n){var t="";switch(n){case"1":t=ur_searchPropertiesForRentPageURL;break;case"2":t=ur_searchPropertiesForBuyPageURL;break;case"3":t=ur_searchPropertiesForBusinessSalePageURL;break;default:t=ur_searchPropertiesForBuyPageURL}return t}var jsversion="96d0d5d9-78a2-475c-ab79-2ff43375cdf6",contractPattern=new RegExp("(MAR-)|(MLS-ES-)|[0-9]{4,6}","ig");$(document).ready(function(){var r=getCookie("LastBusinessTypeSearch"),t=r!=null&&r!=""?r:2,i=GetbusinessTypeUrl(t),e=$("#businessType")[0].length,f,n,u;e==1&&($("#businessTypeSelector").hide(),t=$("#businessType")[0].value);$("#businessType").kendoDropDownList();r!=null&&$("#businessType").data("kendoDropDownList").select(function(n){return n.value==t});seoversion==2&&(f=setbusinessTypeSEOAlias($("#businessType").data("kendoDropDownList").value()),i=f.toLowerCase()+"/"+clearDescription(seoAllPropertyType)+"/"+clearDescription(seolocation1_ALL)+"/");n=$("#MySiteHomePageIndexLink")!=null&&$("#MySiteHomePageIndexLink")!=undefined&&$("#MySiteHomePageIndexLink").val()!=undefined?$("#MySiteHomePageIndexLink").val():"";u=n+i+"?b="+t+"&ord="+defaultSort;seoversion==2&&(u=n+i+"?ord="+defaultSort);$("#home-search-button").attr("href",u);$("#home-search-button-allproperties")!=null&&$("#home-search-button-allproperties")!=undefined&&$("#home-search-button-allproperties").attr("href",u);businessTypeDropDownList=$("#businessType").kendoDropDownList({change:function(){var u=this.value(),i;if(t=u,i=GetbusinessTypeUrl(t),seoversion==2){var r=$("#home-search-button").attr("href"),f=r.split("/"),e=clearDescription(f[0]);i=r.replace(new RegExp(e+"/"),clearDescription(setbusinessTypeSEOAlias($("#businessType").data("kendoDropDownList").value())+"/"));$("#home-search-button").attr("href",n+i);$("#home-search-button-allproperties")!=null&&$("#home-search-button-allproperties")!=undefined&&$("#home-search-button-allproperties").attr("href",n+i)}document.cookie="LastBusinessTypeSearch="+this.value();seoversion==2||($("#home-search-button").attr("href",n+i+"?b="+t+"&ord="+defaultSort),$("#home-search-button-allproperties")!=null&&$("#home-search-button-allproperties")!=undefined&&$("#home-search-button-allproperties").attr("href",n+i+"?b="+t+"&ord="+defaultSort))}});autoComplete=$("#searchedLocationInput").kendoAutoComplete({filtering:function(){visibilityLocalsSuggestion("hide");$("#SearchedLocal").val(this.value())},select:function(n){var t=this.dataItem(n.item.index());$("#SearchedRealFullLocation").val(t.RealFullLocation)},change:function(){var r="",u;this.value().trim()==""?$("#SearchedRealFullLocation").val(""):contractPattern.test(this.value().trim())?(r=this.value(),$("#SearchedRealFullLocation").val(""),$("#SearchedLocal").val("")):$("#SearchedLocal").val(this.value());seoversion==2?(fieldName=reEscape(i.split("/")[2]),u=$("#SearchedRealFullLocation").val()!=""&&$("#SearchedRealFullLocation").val().split(", ").length>1?locationDiacritics($("#SearchedRealFullLocation").val().split(", ")[2]):reEscape(seolocation1_ALL),i=i.replace(new RegExp("/"+fieldName+"/"),"/"+clearDescription(u)+"/"),$("#home-search-button").attr("href",n+i+"?q="+locationDiacritics($("#SearchedRealFullLocation").val())+"&ord="+defaultSort+"&r="+r),$("#home-search-button-allproperties")!=null&&$("#home-search-button-allproperties")!=undefined&&$("#home-search-button-allproperties").attr("href",n+i+"?q="+$("#SearchedRealFullLocation").val().split(" ").join("+")+"&ord="+defaultSort+"&r="+r)):($("#home-search-button").attr("href",n+i+"?b="+t+"&q="+locationDiacritics($("#SearchedRealFullLocation").val())+"&ord="+defaultSort+"&r="+r),$("#home-search-button-allproperties")!=null&&$("#home-search-button-allproperties")!=undefined&&$("#home-search-button-allproperties").attr("href",n+i+"?b="+t+"&q="+locationDiacritics($("#SearchedRealFullLocation").val())+"&ord="+defaultSort+"&r="+r));document.cookie="LastBusinessTypeSearch="+$("#businessType").val()},dataTextField:"FullLocation",dataValueField:"RealFullLocation",noDataTemplate:ur_noDataTemplate,filter:"contains",autoBind:!1,minLength:3,suggest:!0,highlightFirst:!0,ignoreCase:!0,template:kendo.template($("#KendoTemplatePropertySearchInput").html())});locationDataSource=new kendo.data.DataSource({serverFiltering:!0,transport:{read:{url:"/umbraco/Surface/C21AddressLocationSurface/getlocations",data:function(){return{searchText:autoComplete.val(),nodeID:document.getElementById("CurrentNodeID").value,mySite:document.getElementById("MySite").value,masterId:document.getElementById("MasterId").value,agencyId:document.getElementById("MySiteAgencyId")!=null?document.getElementById("MySiteAgencyId").value:null,seoId:document.getElementById("MySiteSEOId")!=null&&document.getElementById("MySiteSEOId")!=undefined?document.getElementById("MySiteSEOId").value:null,language:document.getElementById("SiteLanguage").value}}}}});$("#searchedLocationInput").data("kendoAutoComplete").setDataSource(locationDataSource)})