Array.prototype.index=function(b){for(var d=0,g=this.length;d0&&m<=5&&f.fadeTo("fast",0.5).fadeTo("fast",1)},E=function(m){if(m.isEmpty())return"none";if(m.total>g&&m.allocations.length>1)return"support";return"ok"},B=function(m){k.attr("class","dashboard "+m)};this.insert=function(m){c.val(m);c.select()};this.fullResultsCallback=function(m){B(E(m));if(m.isEmpty()){z();A(0);o.show();w()}else if(m.total>g&&m.allocations.length>1){z();w();n.show(m);A(m.total)}else if(m.offset==0){z();A(m.total);u.render(m);s.show();w()}else{h.remove(); u.render(m);$.scrollTo("#picky .results div.info:last",{duration:500,offset:-12})}c.focus()};this.liveResultsCallback=function(m){B(E(m));A(m.total)};this.allocationChosen=function(m){m=m.data.query;c.val(m);b.allocationChosen(m)};this.addinationClicked=function(m){b.addinationClicked(x(),m)};(function(){c.keyup(function(m){if(x()==""){D();b.searchTextCleared()}else{b.searchTextEntered(x(),m);w()}});r.click(function(){x()==""||b.searchButtonClicked(x())});e.click(function(){D("");b.clearButtonClicked(); c.focus()})})();c.focus()};var PickyBackend=function(b){var d=function(g,c,e,r){var f=r||{};f=$.extend({query:g,offset:e},r);$.ajax({type:"GET",url:b,data:f,success:function(k){c&&c(new PickyData(k))},dataType:"json"})};this.search=function(g,c,e,r,f){d(g,function(k){c&&c(f,k)},e,r)}},LiveBackend=function(b){var d=new PickyBackend(b);this.search=function(g,c,e,r,f){f=f||{};latestRequestTimestamp=new Date;f.live=latestRequestTimestamp;d.search(g,function(k,s){if(!k.live||k.live==latestRequestTimestamp)c&&c(s)},e,r,f)}},FullBackend= function(b){var d=new PickyBackend(b);this.search=function(g,c,e,r,f){f=f||{};latestRequestTimestamp=new Date;f.full=latestRequestTimestamp;d.search(g,function(k,s){if(!k.full||k.full==latestRequestTimestamp)c&&c(s)},e,r,f)}};var PickyController=function(b){var d=new PickyView(this,b),g=b.backends,c=b.before||function(){},e=b.success||function(){},r=b.after||function(){},f=function(h,n){h=e(h,n)||h;d.fullResultsCallback(h);r(h,n)},k=function(h,n,u){u=u||{};n=n||0;o.stop();$.address&&$.address.parameter("q",h);u=c(u,h,n)||u;var w=g.full;w&&w.search(h,f,n,u)},s=function(h,n){h=e(h,n)||h;d.liveResultsCallback(h);r(h,n)},o=$.timer(180,function(h){var n=d.text();c({});var u=g.live;u&&u.search(n,s,0,void 0);h.stop()});o.stop(); this.insert=function(h,n){d.insert(h);n&&k(h)};this.clearButtonClicked=function(){o.stop()};this.searchTextCleared=function(){o.stop()};this.searchTextEntered=function(h,n){if($.inArray(n.keyCode,[0,8,13,32,46,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90])>-1)n.keyCode==13?k(h):o.reset()};this.searchButtonClicked=function(h){k(h)};this.allocationChosen=function(h){k(h)};this.addinationClicked=function(h,n){k(h,n.data.offset)}};var Localization={location_delimiters:{de:"in",fr:"\u00e0",it:"a",en:"in",ch:"in"},explanation_delimiters:{de:"und",fr:"et",it:"e",en:"and",ch:"und"}},PickyClient=function(b){Localization.qualifiers=b.qualifiers||{};Localization.explanations=b.explanations||{};Localization.explanation_delimiters={de:"und",fr:"et",it:"e",en:"and",ch:"und"};var d=b.backends;if(d){d.live||alert("Both a full and live backend must be provided.");d.full||alert("Both a full and live backend must be provided.")}else b.backends= {live:b.live&&new LiveBackend(b.live)||alert("A live backend path must be provided."),full:b.full&&new FullBackend(b.full)||alert("A live backend path must be provided.")};var g=b.controller&&new b.controller(b)||new PickyController(b);var c=this.insert=function(e,r){g.insert(e,r||true)};this.insertFromURL=function(e){if(e&&e!="")c(e);else $.address&&c($.address.parameter("q"))};$.address&&$.address.externalChange(function(e){(e=e.parameters.q)&&c(e)})};var PickyAddination=function(b,d){this.remove=function(){d.find(".addination").remove()};this.render=function(g){var c=g.total,e=void 0;e=e||0;e=g.offset+20+e;var r=e+20;g=g.total;if(g"+t("results.addination.more")+"");c.bind("click",{offset:g.offset},b.addinationClicked);return c}else return""}};var PickyResultsRenderer=function(b){var d=["street_number","zipcode"],g=function(f){var k=f[f.length-1];f=f.slice(0,f.length-1);if(f==[])f=[f];if(!d.include(k[0]))if(k[1].match(/[^\*~]$/))k[1]+="*";f.push(k);return f},c=function(f){for(var k=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},s=[],o,h=0,n=f.length;h$1"),h[1]].join(" ")});o=o.join(" "+s+" ");return'
'+f+" "+o+"
"},r=function(f,k){var s='
';s+=e(k.type,k.combination);if(f.offset>0)s+='';s+='
';return s};this.render=function(f){var k=$("#picky .results");f.allocations.each(function(s,o){k.append(r(f,o)).append(o.entries.join("")).append(b.render(f))})}};function AllocationRenderer(b){function d(a){var i={},p={},j=[],q;q=0;for(l=a.length;q=0;q--)a.remove(j[q]);return a}function g(a,i){var p=i||false,j=a[0],q=a[1],v=D[j];if(v){if(v.method)q=q[v.method]();if(v.format)q=v.format.replace(/%1\$s/,q)}j=w[j]||j;if(p&&!(v&&v.ignoreSingle))return q+" ("+j+")";return q}function c(a){if(a.length==0)return"";else if(a.length== 1)return g(a[0],true);else{var i=[],p=[];a=d(a);for(var j=0,q=a.length;j0&&i.push(p);return i.join(" ")}}function e(a){return function(i,p){for(var j=0,q=a.length;j0)C=j[j.length-1];else if(p.length>0)C=p[p.length-1];else if(i.length>0)C=i[i.length-1];z.include(C[0])||(C[1]+="...");a=c(i);p=k(p);j=r(j);return[a, p,j]}function o(a){var i=a[0],p=a[1];a=a[2];var j="";j=i!=""?p!=""?[i,p].join(B):i:p;if(a=="")return j;return[j,a].join(m)}function h(a){var i=[],p,j;for(j in a){p=a[j][0];p=u[p]||p;i[j]=p+":"+a[j][1]}return i.join(" ")}var n=PickyI18n.locale,u=Localization.qualifiers&&Localization.qualifiers[n]||{},w=Localization.explanations&&Localization.explanations[n]||{};n=Localization.location_delimiters[n];this.explanation=this.query=this.text="";var z=["street_number","zipcode"];this.contract=d;var D={maiden_name:{format:"(-%1$s)", method:"capitalize",ignoreSingle:true},name:{format:"%1$s",method:"toUpperCase",ignoreSingle:true},first_name:{format:"%1$s",method:"capitalize"}};this.who=c;var x={zipcode:":zipcode ["+w.city+"]",city:":city","city,zipcode":":zipcode :city"};this.where=r;this.what=k;var A=["first_name","name","maiden_name"],E=["zipcode","city"];this.trisect=s;var B=", ",m=" "+n+" ";this.fuse=o;this.querify=h;this.render=function(a){var i=a.combination,p=a.count;a=h(i);i=o(s(i));i=$('
  • '+ i+'
    '+p+"
  • ");i.bind("click",{query:a},b);return i}};var PickyAllocationsCloud=function(b){var d=$("#picky .allocations"),g=d.find(".shown"),c=d.find(".more"),e=d.find(".hidden"),r=function(){d.hide()},f=new AllocationRenderer(function(o){r();b.allocationChosen(o)}),k=function(o){var h=[];o.each(function(n,u){h.push(f.render(u))});return h},s=function(o){if(o.length==0)return $("#search .allocations").hide();g.empty();c.hide();e.empty().hide();if(o.length>3){$.each(o.slice(0,2),function(h,n){g.append(n)});$.each(o.slice(2),function(h,n){e.append(n)}); c.show()}else $.each(o,function(h,n){g.append(n)});return $("#search .allocations").show()};c.click(function(){c.hide();e.show()});this.hide=r;this.show=function(o){s(k(o.allocations));d.show()}};