(function(E){var C={method:"GET",contentType:"json",queryParam:"q",searchDelay:300,minChars:1,propertyToSearch:"name",jsonContainer:null,hintText:"Type in a search term",waterMarker:"",noResultsText:"No results",searchingText:"Searching...",deleteText:"&times;",animateDropdown:true,tokenLimit:null,tokenDelimiter:",",tokenValue:"name",prePopulate:null,processPrePopulate:false,idPrefix:"token-input-",inputTabIndex:null,resultsFormatter:function(G){return"<li>"+G[this.propertyToSearch]+"</li>"},tokenFormatter:function(G){return"<li><p>"+G[this.propertyToSearch]+"</p></li>"},onResult:null,onAdd:null,onClearRecent:null,onBatchAdd:null,onDelete:null,onReady:null};var F={tokenList:"token-input-list",emptyTokenList:"empty",token:"token-input-token",tokenDelete:"token-input-delete-token",selectedToken:"token-input-selected-token",highlightedToken:"token-input-highlighted-token",dropdown:"token-input-dropdown",dropdownItem:"token-input-dropdown-item",dropdownItem2:"token-input-dropdown-item2",selectedDropdownItem:"token-input-selected-dropdown-item",inputToken:"token-input-input-token"};var D={BEFORE:0,AFTER:1,END:2};var A={BACKSPACE:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,NUMPAD_ENTER:108,SEMI_COLON_MOZILLA:59,SEMI_COLON:186};var B={init:function(G,H){var I=E.extend({},C,H||{});return this.each(function(){E(this).data("tokenInputObject",new E.TokenList(this,G,I))})},clear:function(){this.data("tokenInputObject").clear();return this},add:function(G){this.data("tokenInputObject").add(G);return this},remove:function(G){this.data("tokenInputObject").remove(G);return this},get:function(){return this.data("tokenInputObject").getTokens()}};E.fn.tokenInput=function(G){if(B[G]){return B[G].apply(this,Array.prototype.slice.call(arguments,1))}else{return B.init.apply(this,arguments)}};E.TokenList=function(H,Y,AB){if(E.type(Y)==="string"||E.type(Y)==="function"){AB.url=Y;var P=d();if(AB.crossDomain===undefined){if(P.indexOf("://")===-1){AB.crossDomain=false}else{AB.crossDomain=(location.href.split(/\/+/g)[1]!==P.split(/\/+/g)[1])}}}else{if(typeof (Y)==="object"){AB.local_data=Y}}if(AB.classes){AB.classes=E.extend({},F,AB.classes)}else{if(AB.theme){AB.classes={};E.each(F,function(AI,AJ){AB.classes[AI]=AJ+"-"+AB.theme})}else{AB.classes=F}}var n=[];var b=0;var X=new E.TokenList.Cache();var z;var w;var AH=AB.inputTabIndex?("tabindex="+AB.inputTabIndex):"";var h=E('<input type="text" autocomplete="off" autocorrect="off" '+AH+">").css({outline:"none"}).attr("id",AB.idPrefix+H.id).focus(function(){if(AB.tokenLimit===null||AB.tokenLimit!==b){O()}}).blur(function(AJ){p();var AK=E.trim(E(this).val());if(AK&&AK.length!==0){var AI=AK.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/"/g,"&quot;").replace(/>/g,"&gt;").replace(/=/g,"&#61;");v({key:AI})}else{E(this).val("")}}).bind("keyup keydown blur update",j).keydown(function(AK){var AM;var AI;if(AK.shiftKey){return }switch(AK.keyCode){case A.LEFT:case A.RIGHT:if(!E(this).val()){AM=T.prev();AI=T.next();if((AM.length&&AM.get(0)===l)||(AI.length&&AI.get(0)===l)){if(AK.keyCode===A.LEFT){t(E(l),D.BEFORE)}else{t(E(l),D.AFTER)}}else{if(AK.keyCode===A.LEFT&&AM.length){AC(E(AM.get(0)))}else{if(AK.keyCode===A.RIGHT&&AI.length){AC(E(AI.get(0)))}}}}break;case A.UP:if(E(this).val()){var AL=E(y).prev();if(AL.hasClass("separator")){AL=AL.prev()}if(AL.length){r(AL)}return false}break;case A.DOWN:if(E(this).val()){var AL=null;if(!y){AL=E("."+AB.classes.dropdown+" li").first()}else{AL=E(y).next()}if(AL.hasClass("separator")){AL=AL.next()}if(AL.length){r(AL)}return false}break;case A.BACKSPACE:AM=T.prev("li");if(!E(this).val().length){if(l){N(E(l));m.change()}else{if(AM.length){AC(E(AM.get(0)))}}return false}else{if(E(this).val().length===1){p()}else{setTimeout(function(){k()},5)}}break;case A.TAB:case A.ENTER:case A.NUMPAD_ENTER:case A.SEMI_COLON:case A.SEMI_COLON_MOZILLA:if(E.trim(E(this).val()).length===0){break}if(y){var AJ=E(y).data("tokeninput");AJ.from="autoSuggest";v(AJ);m.change();return false}else{v({key:E(this).val().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/"/g,"&quot;").replace(/>/g,"&gt;").replace(/=/g,"&#61;")});m.change();return false}break;case A.ESCAPE:p();return true;default:if(String.fromCharCode(AK.which)){setTimeout(function(){k()},5)}break}}).keyup(function(){if((E.trim(E(this).val()).length===0)&&(E(this).parent().siblings("li").length==0)){I.show()}else{I.hide()}});var m=E(H).hide().val("").focus(function(){h.focus()}).blur(function(){h.blur()});var l=null;var q=0;var y=null;var U=E("<ul />").addClass(AB.classes.tokenList).addClass(AB.classes.emptyTokenList).click(function(AJ){var AI=E(AJ.target).closest("li");if(AI&&AI.get(0)&&E.data(AI.get(0),"tokeninput")){AG(AI)}else{if(l){t(E(l),D.END)}h.focus()}}).mouseover(function(AJ){var AI=E(AJ.target).closest("li");if(AI&&l!==this){AI.addClass(AB.classes.highlightedToken)}}).mouseout(function(AJ){var AI=E(AJ.target).closest("li");if(AI&&l!==this){AI.removeClass(AB.classes.highlightedToken)}}).focusout(function(AI){if(E(this).children("li").length===1){E(this).find(I).show()}else{E(this).find(I).hide()}}).insertBefore(m);G();var I=E("<span />").addClass("watermark").html(AB.waterMarker).appendTo(U);var T=E("<li />").addClass(AB.classes.inputToken).appendTo(U).append(h);var AF=E("<div>").addClass(AB.classes.dropdown).appendTo("body").hide();var u=E("<tester/>").insertAfter(h).css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:h.css("fontSize"),fontFamily:h.css("fontFamily"),fontWeight:h.css("fontWeight"),letterSpacing:h.css("letterSpacing"),whiteSpace:"nowrap"});m.val("");var g=AB.prePopulate||m.data("pre");if(AB.processPrePopulate&&E.isFunction(AB.onResult)){g=AB.onResult.call(m,g)}if(g&&g.length){E.each(g,function(AI,AJ){AD(AJ);M()})}if(E.isFunction(AB.onReady)){AB.onReady.call()}e();E(document).keydown(function(AI){if(AI.keyCode===A.BACKSPACE){if(l){AI.preventDefault();N(E(l));m.change()}}});this.clear=function(){U.children("li").each(function(){if(E(this).children("input").length===0){N(E(this))}})};this.add=function(AI){v(AI)};this.remove=function(AI){U.children("li").each(function(){if(E(this).children("input").length===0){var AL=E(this).data("tokeninput");var AJ=true;for(var AK in AI){if(AI[AK]!==AL[AK]){AJ=false;break}}if(AJ){N(E(this))}}})};this.getTokens=function(){return n};function M(){if(AB.tokenLimit!==null&&b>=AB.tokenLimit){h.hide();p()}}function G(){if(U.hasClass(AB.classes.emptyTokenList)){h.width(U.width())}else{h.width(u.width()+10)}}function j(){if(w===(w=h.val())){return }var AI=w.replace(/&/g,"&amp;").replace(/\s/g," ").replace(/</g,"&lt;").replace(/>/g,"&gt;");u.html(AI);G()}function AA(AI){return((AI>=48&&AI<=90)||(AI>=96&&AI<=111)||(AI>=186&&AI<=192)||(AI>=219&&AI<=222))}function s(){return E("<span>"+AB.deleteText+"</span>").addClass(AB.classes.tokenDelete).click(function(){N(E(this).parent());m.change();return false})}function L(AI){return E(AB.tokenFormatter(AI)).addClass(AB.classes.token)}function W(AI){return AI&&E.trim(AI[AB.propertyToSearch]).length>0}function J(AI){if(!W(AI)){return }var AK=L(AI).insertBefore(T);s().appendTo(AK);var AJ={};AJ[AB.propertyToSearch]=AI[AB.propertyToSearch];AJ.from=AI.from;E.data(AK.get(0),"tokeninput",AI);n=n.slice(0,q).concat([AJ]).concat(n.slice(q));q++;c(n,m);b+=1;R(b);if(AB.tokenLimit!==null&&b>=AB.tokenLimit){h.hide();p()}return AK}function AD(AJ,AM){if(!W(AJ)){return }var AL=E.map(AJ[AB.propertyToSearch].split(AB.tokenDelimiter),function(AN){var AO={};AO[AB.propertyToSearch]=E.trim(AN);AO.from=AJ.from;return AO});for(var AI in AL){var AK=AL[AI];J(AK);if(E.isFunction(AM)){AM.call(m,AK)}}return AL}function AE(){h.val("")}function v(AJ){var AL=AB.onAdd,AI=AB.onBatchAdd;AE();j();if(AB.tokenLimit==null||b<AB.tokenLimit){var AK=AD(AJ,AL);if(E.isFunction(AI)){AI.call(m,AK)}M()}e();p()}function AC(AI){AI.addClass(AB.classes.selectedToken);l=AI.get(0);AE();p()}function t(AJ,AI){AJ.removeClass(AB.classes.selectedToken);l=null;if(AI===D.BEFORE){T.insertBefore(AJ);q--}else{if(AI===D.AFTER){T.insertAfter(AJ);q++}else{T.appendTo(U);q=b}}setTimeout(function(){h.focus()},100)}function AG(AJ){var AI=l;if(l){t(E(l),D.END)}if(AI===AJ.get(0)){t(AJ,D.END)}else{AC(AJ)}}function R(AI){if(AI){U.removeClass(AB.classes.emptyTokenList)}else{U.addClass(AB.classes.emptyTokenList)}G()}function N(AJ){var AK=E.data(AJ.get(0),"tokeninput");var AL=AB.onDelete;var AI=AJ.prevAll("."+AB.classes.token).length;if(AI>q){AI--}AJ.remove();l=null;h.focus();n=n.slice(0,AI).concat(n.slice(AI+1));if(AI<q){q--}c(n,m);b-=1;R(b);if(AB.tokenLimit!==null){h.show().val("").focus()}if(E.isFunction(AL)){AL.call(m,AK)}}function c(AK,AI){var AJ=E.map(AK,function(AL){return AL[AB.tokenValue]});AI.val(AJ.join(AB.tokenDelimiter+" "))}function p(){AF.hide().empty();y=null}function V(){y=null;AF.css({position:"absolute",top:E(U).offset().top+E(U).outerHeight(),left:E(U).offset().left,zindex:999}).show()}function S(){if(AB.searchingText){AF.html("<p>"+AB.searchingText+"</p>");V()}}function O(){if(AB.hintText){AF.html("<p>"+AB.hintText+"</p>");V()}}function a(AJ,AI){return AJ.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+AI+")(?![^<>]*>)(?![^&;]+;)","i"),"<b>$1</b>")}function i(AL,AK){var AI=AL.split(AB.tokenDelimiter);var AJ=[];var AM=AI.shift();AJ.push(a(AM,AK));AJ=AJ.concat(AI);return AJ.join(AB.tokenDelimiter)}function K(){AF.find(".separator").nextAll().remove();X.flush()}function o(AI,AK,AJ){var AL=AB.onClearRecent;E.each(AI,function(AN,AO){var AP=AB.resultsFormatter(AO);var AM;if(E(AP).hasClass("separator")){AM=E(AP).html()}else{AM=i(AO[AB.propertyToSearch],AK)}E(AP).addClass("ellipsis").html(AM);E(AP).find("a").click(function(AQ){AQ.preventDefault();if(E.isFunction(AL)){AL()}K()});AP=E(AP).appendTo(AJ);if(AN%2){AP.addClass(AB.classes.dropdownItem)}else{AP.addClass(AB.classes.dropdownItem2)}E.data(AP.get(0),"tokeninput",AO)})}function Q(){var AI=E("<ul>").appendTo(AF).mouseover(function(AK){var AJ=E(AK.target).closest("li");if(AJ.hasClass("separator")){f(E(y));return false}r(AJ)}).mousedown(function(AK){var AJ=E(AK.target).closest("li").data("tokeninput");if(AJ.type==="separator"){f(E(y));return false}AJ.from="autoSuggest";v(AJ);m.change();return false}).hide();return AI}function x(AK,AI){if(AI&&AI.length){AF.empty();var AJ=Q();o(AI,AK,AJ);V();if(AB.animateDropdown){AJ.slideDown("fast")}else{AJ.show()}}else{if(AB.noResultsText){AF.html("<p>"+AB.noResultsText+"</p>");V()}}}function r(AI){if(AI){if(y){f(E(y))}AI.addClass(AB.classes.selectedDropdownItem);y=AI.get(0)}}function f(AI){AI.removeClass(AB.classes.selectedDropdownItem);y=null}function k(){var AI=h.val().toLowerCase();if(AI&&AI.length){if(l){t(E(l),D.AFTER)}if(AI.length>=AB.minChars){S();clearTimeout(z);z=setTimeout(function(){Z(AI)},AB.searchDelay)}else{p()}}}function Z(AO){var AK=AO+d();var AI=X.get(AK);if(AI){x(AO,AI)}else{if(AB.url){var AM=d();var AL={};AL.data={};if(AM.indexOf("?")>-1){var AP=AM.split("?");AL.url=AP[0];var AJ=AP[1].split("&");E.each(AJ,function(AQ,AS){var AR=AS.split("=");AL.data[AR[0]]=AR[1]})}else{AL.url=AM}AL.data[AB.queryParam]=AO;AL.type=AB.method;AL.dataType=AB.contentType;if(AB.crossDomain){AL.dataType="jsonp"}AL.success=function(AQ){if(E.isFunction(AB.onResult)){AQ=AB.onResult.call(m,AQ,{query:AO})}X.add(AK,AB.jsonContainer?AQ[AB.jsonContainer]:AQ);if(h.val().toLowerCase()===AO){x(AO,AB.jsonContainer?AQ[AB.jsonContainer]:AQ)}};E.ajax(AL)}else{if(AB.local_data){var AN=E.grep(AB.local_data,function(AQ){return AQ[AB.propertyToSearch].toLowerCase().indexOf(AO.toLowerCase())>-1});if(E.isFunction(AB.onResult)){AN=AB.onResult.call(m,AN,{query:AO})}X.add(AK,AN);x(AO,AN)}}}}function d(){var AI=AB.url;if(typeof AB.url=="function"){AI=AB.url.call()}return AI}function e(){if(E("."+AB.classes.token).length==0){I.show()}else{I.hide()}}};E.TokenList.Cache=function(H){var J=E.extend({max_size:500},H);var K={};var I=0;var G=function(){K={};I=0};this.add=function(M,L){if(I>J.max_size){G()}if(!K[M]){I+=1}K[M]=L};this.get=function(L){return K[L]};this.flush=function(){G()};this.remove=function(L){delete K[L]}}}($LMI));(function(B){var A={init:function(C){var D=B.extend({},C);return this.each(function(){B(this).data("smartSuggester",new B.Suggestion(this,D));B(this).data("smartSuggester").bindEventHandler()})},suggest:function(C){if(!this.length){return }B(this).data("smartSuggester").suggest(C);return this},get:function(){return B(this).data("smartSuggester").getSuggestions()}};B.fn.smartSuggester=function(C){if(A[C]){return A[C].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof C==="object"||!C){return A.init.apply(this,arguments)}else{B.error("Method "+C+" does not exist on jQuery.smartSuggester")}}};B.Suggestion=function(E,G){var C,D,F={onSelected:function(H){B(document).trigger(B(E).attr("id")+"-ready",H)}};C=[];D=function(H){C=B.map(H,function(I){return{id:I.id,key:I.key,from:"nearbySuburb"}})};this.getSuggestions=function(){return C};this.bindEventHandler=function(){B(E).find("a").live("click",function(){var K,J,H,I=B(this).attr("data-location-id");J=B(this).attr("data-location-name");H=B(this).attr("data-location-from");K=G.onSelected||F.onSelected;K({id:I,key:J,from:H})})};this.hideSuggestion=function(){var H=G.noSuggestion||function(){B("#"+G.suggestionContainer).addClass("hidden")};H()};this.showSuggestion=function(){var H=G.haveSuggestion||function(){B("#"+G.suggestionContainer).removeClass("hidden")};H()};this.buildLocations=function(){if(C.length===0){this.hideSuggestion();return""}this.showSuggestion();var H=B.map(C,function(I){return"<a data-location-id='"+I.id+"' data-location-name='"+I.key+"' data-location-from='"+I.from+"'>"+I.key.replace(",","")+"</a>"}).join("<span>,</span> ");return H};this.buildQueryString=function(I){var H=B.map(I,function(J){return encodeURI(J)}).join(";");return"where="+H};this.suggest=function(J){J=J||[];if(J.length===0){this.hideSuggestion();return }var I=this.buildQueryString(J),H=this;B.ajax({url:G.url+"?"+I,type:"GET",success:function(L){D(L);var K=H.buildLocations();B(E).empty().addClass("loading");setTimeout(function(){B(E).html(K).removeClass("loading").hide().fadeIn(200)},600)},error:function(K){B(E).html(K);H.hideSuggestion()}})}}})($LMI);(function(A){A(document).ready(function(){var E,B,F,C=A("#suggestedLocations").smartSuggester({url:LMI.Data.Urls.smartWhereSuggestion,suggestionContainer:"surroundingLocations"});B=A("#suggestedLocationsBottom").smartSuggester({url:LMI.Data.Urls.smartWhereSuggestion,suggestionContainer:"surroundingLocationsBottom"});function D(G){if(G&&A(G).length){return A.map(A(G).tokenInput("get"),function(H){return H.key||""})}}LMI.SearchLocations=(function(){function M(Q,O){var P=A.grep(A(Q).tokenInput("get"),function(R){return R.from===O});A("input[name="+O+"]").each(function(){this.value=P.length>0})}function N(O){var P=A(O).attr("id");if(P==="where"){C.smartSuggester("suggest",D(O))}else{B.smartSuggester("suggest",D(O))}M(O,"nearbySuburb");M(O,"autoSuggest")}function I(P){var O=[];if(LMI.Data.recentLocations.length>0){O=A.map(LMI.Data.recentLocations,function(Q){return{key:Q.locationValue,type:"recent"}});O=A.grep(O,function(Q){return Q.key.toLowerCase().indexOf(P.query.toLowerCase())===0});if(O.length>0){O.unshift({key:"Recent Locations",type:"separator"})}}return O}function L(){var O=LMI.Data.Urls.removeLocations+";jsessionid="+LMI.Data.state.sessionId+"?noresponse=1";A("<img>").attr("src",O);LMI.Data.recentLocations=[]}function J(P){var Q,O=A("<a>").attr("href","#").html("clear");Q=A("<li>").addClass("separator").text(P.key);O.appendTo(Q);return Q}function G(Q,O){var P=A("#"+Q);return P.tokenInput(O,{queryParam:"query",minChars:3,waterMarker:LMI.Strings.getString("js.example.where"),propertyToSearch:"key",hintText:"",tokenValue:"key",tokenDelimiter:";",inputTabIndex:P.attr("tabindex")||null,resultsFormatter:function(R){if(R.type==="separator"){return J(R)}else{return A("<li>").addClass("menuItem").text(R.key)}},tokenFormatter:function(R){return A("<li>").attr("title",R.key).append(A("<p>").text(R.key))},onClearRecent:function(){L()},onBatchAdd:function(R){N(this)},onDelete:function(S){if(F){clearTimeout(F)}var R=this;F=setTimeout(function(){N(R)},100)},onResult:function(R,S){return A.merge(R,I(S))},prePopulate:(function(){return A.map(A.grep(LMI.Data.searchedWheres,function(R){return R.key.length!==0}),function(R){return{key:R.key}})})()})}var H=G("where",LMI.Data.Urls.whereSuggest),K=G("whereBottom",LMI.Data.Urls.whereSuggest);return{tokenInputWhere:H,tokenInputWhereBottom:K}})();E=LMI.SearchLocations;if(LMI.Data.loadSuggestion){C.smartSuggester("suggest",D(E.tokenInputWhere));B.smartSuggester("suggest",D(E.tokenInputWhereBottom))}A(document).on("suggestedLocations-ready",function(G,H){E.tokenInputWhere.tokenInput("add",H)});A(document).on("suggestedLocationsBottom-ready",function(G,H){E.tokenInputWhereBottom.tokenInput("add",H)})})}($LMI));