/*
* AutoSuggest
* Copyright 2009-2010 Drew Wilson
* www.drewwilson.com
* code.drewwilson.com/entry/autosuggest-jquery-plugin
*
* Forked by Wu Yuntao
* github.com/wuyuntao/jquery-autosuggest
*
* Version 1.6.2
*
* This Plug-In will auto-complete or auto-suggest completed search queries
* for you as you type. You can add multiple selections and remove them on
* the fly. It supports keybord navigation (UP + DOWN + RETURN), as well
* as multiple AutoSuggest fields on the same page.
*
* Inspired by the Autocomplete plugin by: Joern Zaefferer
* and the Facelist plugin by: Ian Tearle (iantearle.com)
*
* This AutoSuggest jQuery plug-in is dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function(a){a.fn.autoSuggest=function(h,e){var i={asHtmlID:false,startText:"Enter Name Here",usePlaceholder:false,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:false,selectionLimit:false,showResultList:true,showResultListWhenNoMatch:false,canGenerateNewSelections:true,start:function(){},selectionClick:function(j){},selectionAdded:function(j){},selectionRemoved:function(j){j.remove()},formatList:false,beforeRetrieve:function(j){return j},retrieveComplete:function(j){return j},resultClick:function(j){},resultsComplete:function(){}};var g=a.extend(i,e);function d(j){var l=0;for(k in j){if(j.hasOwnProperty(k)){l++}}return l}function c(){var j=g.extraParams;if(a.isFunction(j)){return j()}return j}var b;var f=null;if(typeof h=="function"){b=h}else{if(typeof h=="string"){b=function(m,l){var j="";if(g.retrieveLimit){j="&limit="+encodeURIComponent(g.retrieveLimit)}f=a.getJSON(h+"?"+g.queryParam+"="+encodeURIComponent(m)+j+c(),function(o){var n=g.retrieveComplete.call(this,o);l(n,m)})}}else{if(typeof h=="object"&&d(h)>0){b=function(l,j){j(h,l)}}}}if(b){return this.each(function(z){if(!g.asHtmlID){z=z+""+Math.floor(Math.random()*100);var m="as-input-"+z}else{z=g.asHtmlID;var m=z}g.start.call(this,{add:function(x){K(x,"u"+a("li",G).length).addClass("blur")},remove:function(x){M.val(M.val().replace(","+x+",",","));G.find('li[data-value = "'+x+'"]').remove()}});var B=a(this);B.attr("autocomplete","off").addClass("as-input").attr("id",m);if(g.usePlaceholder){B.attr("placeholder",g.startText)}else{B.val(g.startText)}var F=false;B.wrap('