text: (function(a){a.fn.autoSuggest=function(b,c){var d={allowAdd:true,allowAddMessage:"Please choose an existing tag",asHtmlID:false,startText:"Enter Name Here",emptyText:"No Results Found",preFill:{},limitText:"No More Selections Are Allowed",selectedItemProp:"value",selectedValuesProp:"value",searchObjProps:"value",queryParam:"q",retrieveLimit:false,extraParams:"",matchCase:false,minChars:1,keyDelay:400,resultsHighlight:true,neverSubmit:true,selectionLimit:false,showResultList:true,start:function(){},selectionClick:function(a){},selectionAdded:function(a){},selectionRemoved:function(a){a.remove()},formatList:false,beforeRetrieve:function(a){return a},retrieveComplete:function(a){return a},resultClick:function(a){},resultsComplete:function(){}};var e=a.extend(d,c);var f="object";var g=0;if(typeof b=="string"){f="string";var h=b}else{var i=b;for(k in b)if(b.hasOwnProperty(k))g++}if(f=="object"&&g>0||f=="string"){return this.each(function(b){function F(b){if(a(":visible",n).length>0){var c=a("li",n);if(b=="down"){var d=c.eq(0)}else{var d=c.filter(":last")}var e=a("li.active:first",n);if(e.length>0){if(b=="down"){d=e.next()}else{d=e.prev()}}c.removeClass("active");d.addClass("active")}}function E(b,c){p.val(p.val()+b[e.selectedValuesProp]+",");var f=a('<li class="as-selection-item" id="as-selection-'+c+'"></li>').click(function(){e.selectionClick.call(this,a(this));l.children().removeClass("selected");a(this).addClass("selected")}).mousedown(function(){j=false});var g=a('<a class="as-close">×</a>').click(function(){p.val(p.val().replace(","+b[e.selectedValuesProp]+",",","));e.selectionRemoved.call(this,f);j=true;d.focus();return false});m.before(f.html(b[e.selectedItemProp]).prepend(g));e.selectionAdded.call(this,m.prev())}function D(b,c){if(!e.matchCase){c=c.toLowerCase()}var f=0;n.html(o.html("")).hide();for(var h=0;h<g;h++){var i=h;C++;var k=false;if(e.searchObjProps=="value"){var m=b[i].value}else{var m="";var q=e.searchObjProps.split(",");for(var r=0;r<q.length;r++){var s=a.trim(q[r]);m=m+b[i][s]+" "}}if(m){if(!e.matchCase){m=m.toLowerCase()}if(m.search(c)!=-1&&p.val().search(","+b[i][e.selectedValuesProp]+",")==-1){k=true}}if(k){var t=a('<li class="as-result-item" id="as-result-item-'+i+'"></li>').click(function(){var b=a(this).data("data");var c=b.num;if(a("#as-selection-"+c,l).length<=0&&!A){var f=b.attributes;d.val("").focus();y="";E(f,c);e.resultClick.call(this,b);n.hide()}A=false}).mousedown(function(){j=false}).mouseover(function(){a("li",o).removeClass("active");a(this).addClass("active")}).data("data",{attributes:b[i],num:C});var u=a.extend({},b[i]);if(!e.matchCase){var v=new RegExp("(?![^&;]+;)(?!<[^<>]*)("+c+")(?![^<>]*>)(?![^&;]+;)","gi")}else{var v=new RegExp("(?![^&;]+;)(?!<[^<>]*)("+c+")(?![^<>]*>)(?![^&;]+;)","g")}if(e.resultsHighlight){u[e.selectedItemProp]=u[e.selectedItemProp].replace(v,"<em>$1</em>")}if(!e.formatList){t=t.html(u[e.selectedItemProp])}else{t=e.formatList.call(this,u,t)}o.append(t);delete u;f++;if(e.retrieveLimit&&e.retrieveLimit==f){break}}}l.removeClass("loading");if(f<=0){o.html('<li class="as-message">'+e.emptyText+"</li>")}o.css("width",l.outerWidth());n.show();e.resultsComplete.call(this)}function B(){if(lastKeyPressCode==46||lastKeyPressCode>8&&lastKeyPressCode<32){return n.hide()}var b=d.val().replace(/[\\]+|[\/]+/g,"");if(b==y)return;y=b;if(b.length>=e.minChars){l.addClass("loading");if(f=="string"){var c="";if(e.retrieveLimit){c="&limit="+encodeURIComponent(e.retrieveLimit)}if(e.beforeRetrieve){b=e.beforeRetrieve.call(this,b)}a.getJSON(h+"?"+e.queryParam+"="+encodeURIComponent(b)+c+e.extraParams,function(a){g=0;var c=e.retrieveComplete.call(this,a);for(k in c)if(c.hasOwnProperty(k))g++;D(c,b)})}else{if(e.beforeRetrieve){b=e.beforeRetrieve.call(this,b)}D(i,b)}}else{l.removeClass("loading");n.hide()}}if(!e.asHtmlID){var c="as-input-"+b}else{b=e.asHtmlID;var c=b}e.start.call(this);var d=a(this);d.attr("autocomplete","off").addClass("as-input").attr("id",c).val(e.startText);var j=false;d.wrap('<ul class="as-selections" id="as-selections-'+b+'"></ul>').wrap('<li class="as-original" id="as-original-'+b+'"></li>');var l=a("#as-selections-"+b);var m=a("#as-original-"+b);var n=a('<div class="as-results" id="as-results-'+b+'"></div>').hide();var o=a('<ul class="as-list"></ul>');var p=a('<input type="hidden" class="tags" name="tags" id="tags" />');var q="";if(typeof e.preFill=="string"){var r=e.preFill.split(",");for(var s=0;s<r.length;s++){var t={};t[e.selectedValuesProp]=r[s];if(r[s]!=""){E(t,"000"+s)}}q=e.preFill}else{q="";var u=0;for(k in e.preFill)if(e.preFill.hasOwnProperty(k))u++;if(u>0){for(var s=0;s<u;s++){var v=e.preFill[s][e.selectedValuesProp];if(v==undefined){v=""}q=q+v+",";if(v!=""){E(e.preFill[s],"000"+s)}}}}if(q!=""){d.val("");var w=q.substring(q.length-1);if(w!=","){q=q+","}p.val(","+q);a("li.as-selection-item",l).addClass("blur").removeClass("selected")}d.after(p);l.click(function(){j=true;d.focus()}).mousedown(function(){j=false}).after(n);var x=null;var y="";var z=0;var A=false;d.focus(function(){if(a(this).val()==e.startText&&p.val()==""){a(this).val("")}else if(j){a("li.as-selection-item",l).removeClass("blur");if(a(this).val()!=""){o.css("width",l.outerWidth());n.show()}}j=true;return true}).blur(function(){if(a(this).val()==""&&p.val()==""&&q==""){a(this).val(e.startText)}else if(j){a("li.as-selection-item",l).addClass("blur").removeClass("selected");n.hide();d.val("")}}).keydown(function(b){lastKeyPressCode=b.keyCode;first_focus=false;switch(b.keyCode){case 38:b.preventDefault();F("up");break;case 40:b.preventDefault();F("down");break;case 8:if(d.val()==""){var c=a("li.as-selection-item:last").clone();c.find("a").remove();var f=c.text();l.children().not(m.prev()).removeClass("selected");if(m.prev().hasClass("selected")){p.val(p.val().replace(","+f+",",","));e.selectionRemoved.call(this,m.prev())}else{e.selectionClick.call(this,m.prev());m.prev().addClass("selected")}}if(d.val().length==1){n.hide();y=""}if(a(":visible",n).length>0){if(x){clearTimeout(x)}x=setTimeout(function(){B()},e.keyDelay)}break;case 9:case 188:case 13:A=true;var g=d.val().replace(/(,)/g,"");var h=g!=""&&p.val().search(","+g+",")<0&&g.length>=e.minChars&&a("li.active:first",n).length==0;if(h&&e.allowAdd&&confirm("The Tag '"+g+"' does not exist.\nDo you want to create it?")){b.preventDefault();var i={};i[e.selectedItemProp]=g;i[e.selectedValuesProp]=g;var j=a("li",l).length;E(i,"00"+(j+1));d.val("")}else if(h&&!e.allowAdd){alert(e.allowAddMessage)}else{d.val("")};case 13:A=false;var k=a("li.active:first",n);if(k.length>0){k.click();n.hide()}if(e.neverSubmit||k.length>0){b.preventDefault()}break;default:if(e.showResultList){if(e.selectionLimit&&a("li.as-selection-item",l).length>=e.selectionLimit){o.html('<li class="as-message">'+e.limitText+"</li>");n.show()}else{if(x){clearTimeout(x)}x=setTimeout(function(){B()},e.keyDelay)}}break}});var C=0})}}})(django.jQuery)