var vote=function(){var k={informModerator:-1,undoMod:0,upMod:1,downMod:2,offensive:3,favorite:4,deletion:5,undeletion:6,spam:7,remove:8},f=imagePath+"vote-arrow-down.png",c=imagePath+"vote-arrow-down-on.png",x=imagePath+"vote-arrow-up.png",w=imagePath+"vote-arrow-up-on.png",A=imagePath+"vote-favorite-on.png",o=imagePath+"vote-favorite-off.png",bindFlag=function(){var C='<a href="/einloggen?returnurl='+escape(document.location)+'">einloggen oder anmelden</a>';$("div.vote").find("img").unbind("click").click(function(){showErrorMessage($(this),"Du musst Dich "+C+", um Beitr&auml;ge zu bewerten.")});getFlag().unbind("click").click(function(){showErrorMessage($(this),"Du musst Dich "+C+", um Dich &uuml;ber einen Beitrage zu beschweren.")})},initVoteBtns=function(C){if(!C)C="div.vote";$(C).find("img.vote-up").unbind("click").click(function(){vote.up($(this))});$(C).find("img.vote-down").unbind("click").click(function(){vote.down($(this))});$(C).find("img.vote-favorite").unbind("click").click(function(){vote.favorite($(this))})},callSpeechVotes=function(C){$.ajax({type:"GET",url:"/api/speechvotes/"+C,dataType:"json",success:initVoteBtnsWithData,cache:false})},initVoteBtnsWithData=function(C){$.each(C,function(){var D=$("div.vote:has(input[value="+this.Id+"])");switch(this.VoteTypeId){case k.upMod:$("img.vote-up, img.vote-down").unbind();$("img.vote-up").attr("src",w);break;case k.downMod:$("img.vote-up, img.vote-down").unbind();$("img.vote-down").attr("src",c);break;case k.favorite:$("img.vote-favorite").unbind();$("img.vote-favorite").attr("src",A);D.find("div.favoritecount b").addClass("favoritecount-selected");break;default:alert("Vote.js > highlightExisting Votes has no case for "+this.VoteTypeId)}});votesCast=null},getLock=function(){return $("div.post-menu a[id^='lock-post-']")},getFlag=function(){return $("div.post-menu a[id^='flag-post-']")},getRetag=function(){return $("div.post-menu a[id^='retag-post-']")},toggleImgs=function(D,C){D.attr("src")==w&&D.attr("src",x);C.attr("src")==c&&C.attr("src",f)},s=function(C,D){var E=C.siblings("span.vote-count-post");E.text(parseInt(E.text(),10)+D)},updownVote=function(E,D){$("DIV.vote").find("img").unbind("click");var C=$("DIV.vote input").val();submitVote(E,C,D,voteSuccess)},submitVote=function(F,D,C,I,H){closePopup();var G={__RequestVerificationToken:fkey};if(H)for(var E in H)G[E]=H[E];D=D.replace(/-is-owned-by-current-user/i,"");$.ajax({type:"POST",url:"/api/speechvote/"+D+"?type="+C,data:G,dataType:"json",success:function(J){I(F,D,J)},error:function(){showErrorMessage(F,"Es trat ein Fehler auf. - Bitte versuche es noch einmal.")}})},voteSuccess=function(D,C,E){if(E.Success)E.Message&&showSelect(D,E.Message,E.Id);else if(window.console&&window.console.firebug&&(!E.Message||E.Message.length<5))showErrorMessage(D,"Es schein so also ob FireBug aktiviert ist. In einigen Fällen kann es dabei zu Problem mit den Funktionen dieser Seite kommen;<br />Bitte aktualisiere die Seite, um zu sehen, ob Deine Abstimmung korrekt verarbeitet wurde.<br /><br />Fall das Problem weiterhin besteht, vergewissere Dich, dass FireBug für diese Site deaktiviert ist.");else{showErrorMessage(D,E.Message);toggleImgs(D,D);E.LastVoteTypeId&&commentInput(D,E.LastVoteTypeId)}$("span.vote-count-post").text(E.Points);initVoteBtns(D.parent())},commentInput=function(F,D){var E,C;if(D==k.upMod){E="img.vote-up";C=w}else if(D==k.downMod){E="img.vote-down";C=c}E&&F.parent().find(E).attr("src",C)},closePopup=function(){$(".error-notification").fadeOut("fast",function(){$(this).remove()})},showErrorMessage=function(C,D){var E=$('<div class="error-notification popbox W400"><h3>'+D+"</h3>(Zum Schliessen dieses Dialogs bitte hier klicken)</div>");E.click(function(){$(".error-notification").fadeOut("fast",function(){$(this).remove()})});C.parent().append(E);E.fadeIn("fast")},showSelect=function(D,F,K){var G=$('<div class="error-notification popbox W120">'+F+"</div>");D.parent().append(G);G.find("A").click(function(){var FK={__RequestVerificationToken:fkey,points:$(this).text()};$.ajax({type:"POST",url:"/api/savespeechvote/"+K,data:FK,dataType:"json",success:function(){document.location.reload(true)},error:function(){showErrorMessage(D,"Es trat ein Fehler auf. - Bitte versuche es noch einmal.")}});$(this).unbind();closePopup()});G.fadeIn("fast")};return {init:function(C){if(typeof isRegistered!="undefined"&&isRegistered){var newImg=new Image;newImg.src=w;newImg=new Image;newImg.src=c;if(votesCast==null)callSpeechVotes(C);else initVoteBtnsWithData(votesCast);initVoteBtns();getFlag().unbind("click").click(function(){vote.flag($(this))});getRetag().unbind("click").click(function(){vote.retag($(this))})}else bindFlag();$("div.post-menu a[id^='delete-post-']").unbind("click").click(function(){vote.deletion($(this))});$("a[id^='remove-post-']").unbind("click").click(function(){vote.remove($(this))})},up:function(F){var G=F.parent().find("img.vote-up"),E=F.parent().find("img.vote-down"),D=G.attr("src")==w,C=E.attr("src")==c,H=D?-1:C?2:1;toggleImgs(G,E);!D&&G.attr("src",w);updownVote(F,k.upMod)},down:function(F){var G=F.parent().find("img.vote-up"),E=F.parent().find("img.vote-down"),D=E.attr("src")==c,C=G.attr("src")==w,H=D?1:C?-2:-1;toggleImgs(G,E);!D&&E.attr("src",c);updownVote(F,k.downMod)},favorite:function(D){var E=D.parent().find("div.favoritecount b"),C=parseInt("0"+E.text().replace(/^\s+|\s+$/g,""),10);if(!(D.attr("src")==A)){D.attr("src",A);E.addClass("favoritecount-selected").text(++C)}else{D.attr("src",o);E.removeClass("favoritecount-selected").text(C--<=0?"":C)}D.unbind("click");submitVote(D,D.parent().find("input").val(),k.favorite,function(){D.click(function(){vote.favorite($(this))})})},flag:function(E){for(var C=E.attr("id").substring("flag-post-".length),J="form-flag-"+C,M=$("#"+C+"-is-owned-by-current-user").length>0,K=[[k.offensive,"Beschwerde über anstö&szlig;igen, bleidigenden oder falschen Betrag",!M],[k.spam,"Spam",!M],[k.informModerator,"Muss durch einen Moderator gepr&uuml;ft werden",true]],H='<div class="popup flag-menu"><h3>Bitte nutze diese Funktion mit Bedacht:</h3><div class="flag-reasons"><form id="'+J+'">',F=0;F<K.length;F++)if(K[F][2]){var L="flag-radio"+C+"-"+K[F][0];H+='<input type="radio" id="'+L+'" name="flag-'+C+'" value="'+K[F][0]+'" />';H+='<label for="'+L+'">'+K[F][1]+"</label><br />"}H+='<div class="flag-comment">Warum willst Du Dich über diesen Beitrag beschweren?<textarea name="flag-reason" cols="58" rows="4"></textarea><br /><span class="text-counter"></span></div>';H+="</form></div>";H+='<input type="button" class="flag-cancel" value="Abbrechen" /><input type="button" class="flag-submit" value="Beitrag melden" />';H+="</div>";var G=$(H),D=G.find("#"+J),I=D.find("textarea");G.find("#"+J+" input[type='radio']").click(function(){var N=$("div.flag-comment"),O=vote.flagIsInform(J);N.toggle(O);O&&I.focus();vote.flagAllowSubmit(G,I,O)});G.find("#"+J+" textarea").bind("blur focus keyup",function(){comments.updateTextCounter(this,150);vote.flagAllowSubmit(G,$("#"+J+" textarea"),vote.flagIsInform(J))});G.find(".flag-submit").click(function(){if(vote.flagIsInform(J)&&!vote.flagTextValid($("#"+J+" textarea")))return;vote.flagSubmit(E,C,$("#"+J+" input:radio:checked"),$("#"+J+" textarea"))});G.find(".flag-cancel").click(function(){vote.flagClosePopup(E)});E.parent().append(G);G.fadeIn("fast")},flagIsInform:function(C){var D=$("#"+C+" input:radio:checked");if(D.length==0)return false;return D.val()==k.informModerator},flagAllowSubmit:function(D,E,F){var C=F?vote.flagTextValid(E):true;D.find(".flag-submit").toggle(C)},flagTextValid:function(txt){var len=txt.val().length;return len>=10&&len<=150},flagClosePopup:function(C){C.parent().find(".popup").fadeOut("fast",function(){$(this).remove()})},flagSubmit:function(F,D,C,G){vote.flagClosePopup(F);var E=C.val(),D=F.attr("id").substring("flag-post-".length);if(E==k.informModerator)$.ajax({type:"POST",url:"/api/flagspeech/"+D,dataType:"json",data:{msg:G.val(),__RequestVerificationToken:fkey},success:function(H){$U.showAjaxError(F.parent(),H.Message)},error:function(H){$U.showAjaxError(F.parent(),H.responseText&&H.responseText.length<40?H.responseText:"Bei der Übertragung trat ein Fehler auf.")}});else submitVote(F,D,E,vote.flagSubmitCallback,{comment:G.val()})},flagSubmitCallback:function(D,C,F){if(F&&F.Success){if(F.Message);}else{var E=D.parent();if(F&&F.Message)$U.showAjaxError(E,F.Message);else $U.showAjaxError(E,"Es kam zu einem Problem bei der Übertragung dieser Beschwerde")}},retag:function(E){var C=E.attr("id").substring("retag-post-".length),J="form-tag-"+C,M=$("#"+C+"-is-owned-by-current-user").length>0,N="",O=$("div.post-taglist");$.each($("div.post-taglist a"),function(){N=N+$(this).text()+", ";$(this).hide()});var H='<div class="popup retag-menu"><h3>Themen dieses Beitrags überarbeiten</h3><div class="retag-tags"><form id="'+J+'">';H+='<input type="text" name="tags" id="tags" value="'+N+'" /></form></div>';H+='<input type="button" class="retag-cancel" value="Abbrechen" /><input type="button" class="retag-submit" value="Themen speichern" />';H+="</div>";var G=$(H);G.find(".retag-submit").click(function(){vote.retagSubmit(E,C,$("#"+J+" input"));vote.retagClosePopup(G)});G.find(".retag-cancel").click(function(){$.each($("div.post-taglist a"),function(){$(this).show()});vote.retagClosePopup(G)});G.find("#tags").autocomplete({serviceUrl:"/api/tags.json",minChars:2,delimiter:/(,|;)\s*/,maxHeight:400,width:300,deferRequestBy:0});var I=$("#"+J).parent();I.append(G);G.fadeIn("fast");G.find(".retag-submit").toggle(C)},retagSubmit:function(F,D,G){var D=F.attr("id").substring("retag-post-".length);$.ajax({type:"POST",url:"/speech/retag/"+D,dataType:"json",data:{tags:G.val(),__RequestVerificationToken:fkey},success:function(){vote.loadNewTagList(D)},error:function(H){$U.showAjaxError(F.parent(),H.responseText&&H.responseText.length<40?H.responseText:"Bei der Übertragung trat ein Fehler auf.")}})},loadNewTagList:function(r){var l=$("#post-taglist-"+r);$U.appendLoader(l);$.ajax({type:"GET",url:"/Api/SpeechTags/"+r,dataType:"html",success:function(t){$U.removeLoader();l.children().length>0&&l.children().remove();l.append(t)},error:function(t){$U.removeLoader();$.each($("div.post-taglist a"),function(){$(this).show()});$U.showAjaxError("#post-taglist-"+r,t.responseText&&t.responseText.length<100?t.responseText:"Die Themenliste konnte nicht aktualisiert werden.")}})},retagClosePopup:function(C){C.parent().find(".popup").fadeOut("fast",function(){$(this).remove()})},deletion:function(E){var C=E.attr("id").substring("delete-post-".length),D=E.text().indexOf("wiederherstellen")>-1;confirm("Stimmst Du dafür diesen Beitrag "+(D?"wiederherzustellen":"zu löschen")+"?")&&submitVote(E,C,D?k.undeletion:k.deletion,vote.deletionCallback)},deletionCallback:function(F,E,G){var H=F.text().indexOf("undelete")>-1;if(G&&G.Success){F.text(G.Message);if(G.NewScore<0){var D=$("#question:has(a[id='delete-post-"+E+"'])").length>0,C=D?"#question, div.answer":"#answer-"+E;vote.setDeleteStyles($(C),!H)}else showErrorMessage(F,"Dieser Beitrag braucht noch "+G.NewScore+" Stimme(n) von anderen Mitgliedern, um "+(H?"wiederhergestellt":"gelöscht")+" zu werden.")}else{var I=G&&G.Message?G.Message:"Es kam zu einem Problem beim "+(H?"Wiederherstellen":"Löschen")+" auf.";$U.showAjaxError(F.parent(),I)}},remove:function(E){var C=E.attr("id").substring("remove-post-".length);confirm("Soll dieser Beitrag wirklich unwiederbringlich gelöscht werden?")&&submitVote(E,C,k.remove,vote.removeCallback)},removeCallback:function(F,E,G){if(G&&G.Success){alert("Dieser Beitrag wurde erfolgreich gelöscht");document.location.href=G.Message}else $U.showAjaxError(F.parent(),G&&G.Message?G.Message:"Es kam zu einem Problem beim Löschen des Beitrags auf.")},setDeleteStyles:function(D,C){if(C){$("div.question-status:has(span:contains('delete'))").show();D.addClass("deleted-answer").find("a[id^='delete-post-']").addClass("deleted-post").end().find("div[id^='comments-']").addClass("comments-container-deleted").end().find("a[id^='comments-link-']").addClass("comments-link-deleted")}else document.location.reload(true)}}}(),comments=function(){var l=imagePath+"comment-flag.png",f=imagePath+"comment-flag-hover.png",c=imagePath+"comment-up.png",m=imagePath+"comment-up-hover.png",e=imagePath+"comment-del.png",i=imagePath+"comment-del-hover.png",q=500,commentInput=function(s){var r=$("#form-comments-"+s);if(r.length>0){var u='<table><tr><td><textarea name="comment" cols="68" rows="3" maxlength="'+q+'" onblur="comments.updateTextCounter(this)" onfocus="comments.updateTextCounter(this)" onkeyup="comments.updateTextCounter(this)"></textarea>';u+='<input type="submit" value="Kommentar speichern" class="button" /></td></tr><tr><td><span class="text-counter">Noch '+q+' Zeichen übrig</span><span class="form-error"></span></td></tr></table>';r.append(u);r.submit(function(){var w=true,x=function(y){w=y};$U.bindLengthValidation(r.find("textarea"),15,"* bitte mindestens 15 Zeichen eingeben",r.find(".form-error"),x);if(w){$U.disableSubmitButton(r);postComment(s,r)}return false});var t=$("#comments-"+s+" tr.comment:first td.comment-actions").width()||-1;t+=9;r.children("table").css("margin-left",t+"px")}},loadMoreComments=function(r){$("div.post-menu form").parent().parent().parent().hide();$U.appendLoader("#comments-"+r+" div.comments");$.ajax({type:"GET",url:"/Api/SpeechComments/"+r,dataType:"html",success:function(t){addComments(r,t)},error:function(t){$U.removeLoader();$U.showAjaxError("#comments-"+r,t.responseText&&t.responseText.length<100?t.responseText:"Die Kommentare konnten nicht aktualisiert werden.")}})},addComments=function(r,s){var t=$("#comments-"+r).find("div.comments");t.children().length>0&&t.children().remove();t.append(s);unbindComments();initComments();$U.removeLoader()},d=function(t){var r="";if(t&&t>0){var s=t<5?"":t<=15?"warm":t<=30?"hot":"supernova";r+='<span title="Anzahl der \'guten Kommentare\', die aufgewertet wurden" class="'+s+'">'+t+"</span>"}return r},initComments=function(){$("img.comment-up").click(function(){postCommentVote($(this),2,c,m,function(s,r){s.closest("tr").siblings("tr").remove();s.parent().siblings().children().remove();s.parent().siblings().append(d(r.NewScore))})}).hover(function(){$(this).attr("src",m)},function(){$(this).attr("src",c)});$("img.comment-flag").click(function(){confirm("Soll dieser Kommentar wirklich als Spam, zu Aggressiv oder Müll der Spielleitung gemeldet werden??")&&postCommentVote($(this),4,l,f,function(s,r){if(r.NewScore==-1)s.parents("tr.comment").remove();else{s.parents("tr.comment").find("img.comment-up").remove();s.remove()}})}).hover(function(){$(this).attr("src",f)},function(){$(this).attr("src",l)});$("img.comment-delete").click(function(){confirm("Soll dieser Kommentar wirklich gelöscht werden?")&&postCommentVote($(this),10,e,i,function(s){s.parents("tr.comment").remove()})}).hover(function(){$(this).attr("src",i)},function(){$(this).attr("src",e)});$("tr.comment").hover(function(){$(this).find("img.comment-up, img.comment-flag, img.comment-delete").css("visibility","visible").closest("tr.comment").addClass("comment-hover")},function(){$(this).removeClass("comment-hover").find("img.comment-up, img.comment-flag, img.comment-delete").css("visibility","hidden")})},unbindComments=function(){$("tr.comment").unbind("mouseenter mouseleave");$("img.comment-up, img.comment-flag, img.comment-delete").unbind("click mouseenter mouseleave")},postCommentVote=function(y,u,x,v,t){var w=y.parents("tr.comment").attr("id").substr("comment-".length),s=y.attr("class");$("div.error-notification").hide();y.removeClass().unbind("click mouseenter mouseleave").attr("src",v);$U.appendLoader("#comments-"+y.parent()+" div.comments");var r=function(){y.addClass(s).click(function(){postCommentVote(y,u,x,v,t)}).attr("src",x)};$.ajax({type:"POST",url:"/Meldung/Kommentar-Bewerten/"+w+"/"+u,dataType:"json",data:{fkey:fkey},success:function(z){if(z.Success)t(y,z);else{$U.showAjaxError(y.parent(),z.Message);r()}},error:function(z){$U.showAjaxError(y.parent(),z.responseText&&z.responseText.length<100?z.responseText:"Es kam zu einen Problem bei der Bewertung");r()}});$U.removeLoader()},postComment=function(t,s){var r=s.find("textarea");if(r.val()&&r.val().length>q){$U.showAjaxError(s,"Kommentare sind auf "+q+" Zeichen begrenzt");$U.enableSubmitButton(s);return}$U.appendLoader("#comments-"+t+" div.comments");var u=function(){$(".error-notification").fadeOut("fast",function(){$(this).remove()})};$.ajax({type:"POST",url:"/Meldung/Kommentieren/"+t,dataType:"html",data:{comment:r.val(),__RequestVerificationToken:fkey},success:function(v){u();addComments(t,v);r.val("");comments.updateTextCounter(r);$U.enableSubmitButton(s)},error:function(v){$U.removeLoader();u();$U.showAjaxError(s,v.responseText&&v.responseText.length<100?v.responseText:"Es kam zu einem Problem bei der Übertragung des Kommentars");$U.enableSubmitButton(s)}})};return {init:function(){$("a[id^='more-comments-link-']").unbind("click").click(function(){var r=$(this).attr("id").substr("more-comments-link-".length),u=$("#comments-"+r);loadMoreComments(r,u);$(this).hide()});$("a[id^='new-comments-link-']").unbind("click").click(function(){var r=$(this).attr("id").substr("new-comments-link-".length),u=$("#comments-"+r);commentInput(r,u);u.removeClass("none");var s=u.find("form textarea"),t=200+$('form[id^="form-comments-"] > table').length*2;s.attr("tabindex",t++);u.find("form input").attr("tabindex",t);s.focus();$(this).hide()});initComments()},updateTextCounter:function(t,s){if(!s)s=q;var u=t.value?t.value.length:0,r=u>s*.8?"supernova":u>s*.6?"hot":u>s*.4?"warm":"cool";$(t).parents("form").find("span.text-counter").html("Noch "+(s-u)+" Zeichen übrig").removeClass().addClass("text-counter").addClass(r)}}}();(function($){$.fn.autocomplete=function(options){return this.each(function(){return new Autocomplete(this,options)})};var reEscape=new RegExp("(\\"+["/",".","*","+","?","|","(",")","[","]","{","}","\\"].join("|\\")+")","g"),fnFormatResult=function(value,data,currentValue){var pattern="("+currentValue.replace(reEscape,"\\$1")+")";return value.replace(new RegExp(pattern,"gi"),"<strong>$1</strong>")},Autocomplete=function(el,options){this.el=$(el);this.el.attr("autocomplete","off");this.suggestions=[];this.data=[];this.badQueries=[];this.selectedIndex=-1;this.currentValue=this.el.val();this.intervalId=0;this.cachedResponse=[];this.onChangeInterval=null;this.ignoreValueChange=false;this.serviceUrl=options.serviceUrl;this.isLocal=false;this.options={autoSubmit:false,minChars:1,maxHeight:300,deferRequestBy:0,width:0,highlight:true,params:{},fnFormatResult:fnFormatResult,delimiter:null};options&&$.extend(this.options,options);if(this.options.lookup){this.isLocal=true;if($.isArray(this.options.lookup))this.options.lookup={suggestions:this.options.lookup,data:[]}}this.initialize()};Autocomplete.prototype={killerFn:null,initialize:function(){var me,zindex;me=this;zindex=Math.max.apply(null,$.map($("body > *"),function(e){var pos=$(e).css("position");if(pos==="absolute"||pos==="relative")return parseInt($(e).css("z-index"),10)||1}));this.killerFn=function(e){if($(e.target).parents(".autocomplete").size()===0){me.killSuggestions();me.disableKillerFn()}};var uid=(new Date).getTime(),autocompleteElId="Autocomplete_"+uid;if(!this.options.width)this.options.width=this.el.width();this.mainContainerId="AutocompleteContainter_"+uid;$('<div id="'+this.mainContainerId+'" style="position:absolute;z-index:'+zindex+'"><div class="autocomplete-w1"><div class="autocomplete" id="'+autocompleteElId+'" style="display:none; width:'+this.options.width+'px;"></div></div></div>').appendTo("body");this.container=$("#"+autocompleteElId);this.fixPosition();if(window.opera)this.el.keypress(function(e){me.onKeyPress(e)});else this.el.keydown(function(e){me.onKeyPress(e)});this.el.keyup(function(e){me.onKeyUp(e)});this.el.blur(function(){me.enableKillerFn()});this.el.focus(function(){me.fixPosition()});this.container.css({maxHeight:this.options.maxHeight+"px"})},fixPosition:function(){var offset=this.el.offset();$("#"+this.mainContainerId).css({top:offset.top+this.el.innerHeight()+"px",left:offset.left+"px"})},enableKillerFn:function(){var me=this;$(document).bind("click",me.killerFn)},disableKillerFn:function(){var me=this;$(document).unbind("click",me.killerFn)},killSuggestions:function(){var me=this;this.stopKillSuggestions();this.intervalId=window.setInterval(function(){me.hide();me.stopKillSuggestions()},300)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},onKeyPress:function(e){if(!this.enabled)return;switch(e.keyCode){case 27:this.el.val(this.currentValue);this.hide();break;case 9:case 13:if(this.selectedIndex===-1){this.hide();return}this.select(this.selectedIndex);if(e.keyCode===9)return;break;case 38:this.moveUp();break;case 40:this.moveDown();break;default:return}e.stopImmediatePropagation();e.preventDefault()},onKeyUp:function(e){switch(e.keyCode){case 38:case 40:return}clearInterval(this.onChangeInterval);if(this.currentValue!==this.el.val())if(this.options.deferRequestBy>0){var me=this;this.onChangeInterval=setInterval(function(){me.onValueChange()},this.options.deferRequestBy)}else this.onValueChange()},onValueChange:function(){clearInterval(this.onChangeInterval);this.currentValue=this.el.val();var q=this.getQuery(this.currentValue);this.selectedIndex=-1;if(this.ignoreValueChange){this.ignoreValueChange=false;return}if(q===""||q.length<this.options.minChars)this.hide();else this.getSuggestions(q)},getQuery:function(val){var d,arr;d=this.options.delimiter;if(!d)return $.trim(val);arr=val.split(d);return $.trim(arr[arr.length-1])},getSuggestionsLocal:function(q){var ret,arr,len,val;arr=this.options.lookup;len=arr.suggestions.length;ret={suggestions:[],data:[]};for(var i=0;i<len;i++){val=arr.suggestions[i];if(val.toLowerCase().indexOf(q.toLowerCase())===0){ret.suggestions.push(val);ret.data.push(arr.data[i])}}return ret},getSuggestions:function(q){var cr,me,ls;cr=this.isLocal?this.getSuggestionsLocal(q):this.cachedResponse[q];if(cr&&$.isArray(cr.suggestions)){this.suggestions=cr.suggestions;this.data=cr.data;this.suggest()}else if(!this.isBadQuery(q)){me=this;me.options.params.query=q;$.get(this.serviceUrl,me.options.params,function(txt){me.processResponse(txt)},"text")}},isBadQuery:function(q){var i=this.badQueries.length;while(i--)if(q.indexOf(this.badQueries[i])===0)return true;return false},hide:function(){this.enabled=false;this.selectedIndex=-1;this.container.hide()},suggest:function(){if(this.suggestions.length===0){this.hide();return}var me,len,div,f;me=this;len=this.suggestions.length;f=this.options.fnFormatResult;v=this.getQuery(this.currentValue);this.container.hide().empty();for(var i=0;i<len;i++){div=$((me.selectedIndex===i?'<div class="selected"':"<div")+' title="'+this.suggestions[i]+'">'+f(this.suggestions[i],this.data[i],v)+"</div>");div.mouseover(function(xi){return function(){me.activate(xi)}}(i));div.click(function(xi){return function(){me.select(xi)}}(i));this.container.append(div)}this.enabled=true;this.container.show()},processResponse:function(text){var response;try{response=eval("("+text+")")}catch(err){return}if(!$.isArray(response.data))response.data=[];this.cachedResponse[response.query]=response;response.suggestions.length===0&&this.badQueries.push(response.query);if(response.query===this.getQuery(this.currentValue)){this.suggestions=response.suggestions;this.data=response.data;this.suggest()}},activate:function(index){var divs=this.container.children(),activeItem;this.selectedIndex!==-1&&divs.length>this.selectedIndex&&$(divs.get(this.selectedIndex)).attr("class","");this.selectedIndex=index;if(this.selectedIndex!==-1&&divs.length>this.selectedIndex){activeItem=divs.get(this.selectedIndex);$(activeItem).attr("class","selected")}return activeItem},deactivate:function(div,index){div.className="";if(this.selectedIndex===index)this.selectedIndex=-1},select:function(i){var selectedValue=this.suggestions[i];if(selectedValue){this.el.val(selectedValue);if(this.options.autoSubmit){var f=this.el.parents("form");f.length>0&&f.get(0).submit()}this.ignoreValueChange=true;this.hide();this.onSelect(i)}},moveUp:function(){if(this.selectedIndex===-1)return;if(this.selectedIndex===0){this.container.children().get(0).className="";this.selectedIndex=-1;this.el.val(this.currentValue);return}this.adjustScroll(this.selectedIndex-1)},moveDown:function(){if(this.selectedIndex===this.suggestions.length-1)return;this.adjustScroll(this.selectedIndex+1)},adjustScroll:function(i){var activeItem,offsetTop,upperBound,lowerBound;activeItem=this.activate(i);offsetTop=activeItem.offsetTop;upperBound=this.container.scrollTop();lowerBound=upperBound+this.options.maxHeight-25;if(offsetTop<upperBound)this.container.scrollTop(offsetTop);else offsetTop>lowerBound&&this.container.scrollTop(offsetTop-this.options.maxHeight+25)},onSelect:function(i){var me,onSelect,getValue,s,d;me=this;onSelect=me.options.onSelect;getValue=function(value){var del,currVal;del=me.options.delimiter;currVal=me.currentValue;if(!del)return value;var arr=currVal.split(del);if(arr.length===1)return value;return currVal.substr(0,currVal.length-arr[arr.length-1].length)+value};s=me.suggestions[i];d=me.data[i];me.el.val(getValue(s));$.isFunction(onSelect)&&onSelect(s,d)}}})(jQuery)