
(function($){$.fn.extend({textlist:function(_2,_3){var _4=typeof _2=="string";_3=$.extend({},$.Autocompleter.defaults,{url:_4?_2:null,data:_4?null:_2,delay:_4?$.Autocompleter.defaults.delay:10,max:_3&&!_3.scroll?10:150},_3);_3.highlight=_3.highlight||function(_5){return _5;};_3.formatMatch=_3.formatMatch||_3.formatItem;return this.each(function(){new $.TextList(this,_3);});},result:function(_6){return this.bind("result",_6);},search:function(_7){return this.trigger("search",[_7]);},flushCache:function(){return this.trigger("flushCache");},showList:function(){return this.trigger("show");},setOptions:function(_8){return this.trigger("setOptions",[_8]);},untextlist:function(){return this.trigger("untextlist");}});$.TextList=function(_9,_a){var _b={UP:38,DOWN:40,DEL:46,TAB:9,RETURN:13,ESC:27,COMMA:188,PAGEUP:33,PAGEDOWN:34,BACKSPACE:8};var _c=$(_9).attr("autocomplete","off").addClass(_a.inputClass);var _d;var _e="";var _f=$.Autocompleter.Cache(_a);var _10=0;var _11;var _12={mouseDownOnSelect:false};var _13=$.Autocompleter.Select(_a,_9,selectCurrent,_12);_13.needsInit=true;var _14;$.browser.opera&&$(_9.form).bind("submit.textlist",function(){if(_14){_14=false;return false;}});_c.unbind(($.browser.opera?"keypress":"keydown")+".textlist").unbind(($.browser.opera?"keypress":"keydown")+".autocomplete").unbind("search").unbind("flushCache").unbind("setOptions").unbind("unautocomplete");_c.bind(($.browser.opera?"keypress":"keydown")+".textlist",function(_15){_11=_15.keyCode;switch(_15.keyCode){case _b.UP:_15.preventDefault();if(_13.visible()){_13.prev();}
break;case _b.DOWN:_15.preventDefault();if(_13.visible()){_13.next();}
break;case _b.PAGEUP:_15.preventDefault();if(_13.visible()){_13.pageUp();}
break;case _b.PAGEDOWN:_15.preventDefault();if(_13.visible()){_13.pageDown();}
break;case _b.TAB:case _b.RETURN:if(selectCurrent()){_15.preventDefault();_14=true;return false;}
break;case _b.ESC:_13.hide();break;default:clearTimeout(_d);_d=setTimeout(onChange,_a.delay);break;}}).focus(function(){_10++;}).blur(function(){_10=0;if(!_12.mouseDownOnSelect){hideResultsNow();}}).click(function(){_10++;if(!_13.visible()){onChange(0,true);}}).bind("search",function(){var fn=(arguments.length>1)?arguments[1]:null;function findValueCallback(q,_18){var _19;if(_18&&_18.length){for(var i=0;i<_18.length;i++){if(_18[i].result.toLowerCase()==q.toLowerCase()){_19=_18[i];break;}}}
if(typeof fn=="function"){fn(_19);}else{_c.trigger("result",_19&&[_19.data,_19.value]);}}
$.each(trimWords(_c.val()),function(i,_1c){request(_1c,findValueCallback,findValueCallback);});}).bind("flushCache",function(){_f.flush();}).bind("show",function(){if(!_13.visible()){onChange(0,true);}}).bind("setOptions",function(){$.extend(_a,arguments[1]);if("data"in arguments[1]){_f.populate();}}).bind("untextlist",function(){debug("unbind textlist");_13.unbind();_c.unbind(($.browser.opera?"keypress":"keydown")+".textlist").unbind(($.browser.opera?"keypress":"keydown")+".autocomplete").unbind("search").unbind("flushCache").unbind("show").unbind("setOptions").unbind("untextlist").unbind("unautocomplete");$(_9.form).unbind(".textlist");});function selectCurrent(){var _1d=_13.selected();if(!_1d){return false;}
var v=_1d.result;_e=v;if(_a.multiple){var _1f=trimWords(_c.val());if(_1f.length>1){v=_1f.slice(0,_1f.length-1).join(_a.multipleSeparator)+_a.multipleSeparator+v;}
v+=_a.multipleSeparator;}
_c.val(v);hideResultsNow();_c.trigger("result",[_1d.data,_1d.value]);return true;}
function onChange(_20,_21){if(_11==_b.DEL){_13.hide();return;}
var _22=_c.val();if(!_21&&_22==_e){return;}
_e=_22;_22=lastWord(_22);_c.addClass(_a.loadingClass);if(!_a.matchCase){_22=_22.toLowerCase();}
request(_22,receiveData,hideResultsNow);}
function trimWords(_23){if(!_23){return[""];}
var _24=_23.split(_a.multipleSeparator);var _25=[];$.each(_24,function(i,_27){if($.trim(_27)){_25[i]=$.trim(_27);}});return _25;}
function lastWord(_28){if(!_a.multiple){return _28;}
var _29=trimWords(_28);return _29[_29.length-1];}
function autoFill(q,_2b){if(_a.autoFill&&(lastWord(_c.val()).toLowerCase()==q.toLowerCase())&&_11!=_b.BACKSPACE){_c.val(_c.val()+_2b.substring(lastWord(_e).length));$.Autocompleter.Selection(_9,_e.length,_e.length+_2b.length);}}
function hideResults(){clearTimeout(_d);_d=setTimeout(hideResultsNow,200);}
function hideResultsNow(){var _2c=_13.visible();_13.hide();clearTimeout(_d);stopLoading();if(_a.mustMatch){_c.search(function(_2d){if(!_2d){if(_a.multiple){var _2e=trimWords(_c.val()).slice(0,-1);_c.val(_2e.join(_a.multipleSeparator)+(_2e.length?_a.multipleSeparator:""));}else{_c.val("");}}});}
if(_2c){$.Autocompleter.Selection(_9,_9.value.length,_9.value.length);}
_13.hide();}
function receiveData(q,_30){if(_30&&_30.length&&_10){stopLoading();_13.display(_30,q);autoFill(q,_30[0].value);_13.show();}else{hideResultsNow();}}
function request(_31,_32,_33){if(!_a.matchCase){_31=_31.toLowerCase();}
var _34=_f.load(_31);if(_34&&_34.length){_32(_31,_34);}else{if((typeof _a.url=="string")&&(_a.url.length>0)){var _35={timestamp:+new Date()};$.each(_a.extraParams,function(key,_37){_35[key]=typeof _37=="function"?_37():_37;});$.ajax({mode:"abort",port:"textlist"+_9.name,dataType:_a.dataType,url:_a.url,data:$.extend({q:lastWord(_31),limit:_a.max},_35),success:function(_38){var _39=_a.parse&&_a.parse(_38)||parse(_38);_f.add(_31,_39);_32(_31,_39);}});}else{_13.emptyList();_33(_31);}}}
function parse(_3a){var _3b=[];var _3c=_3a.split("\n");for(var i=0;i<_3c.length;i++){var row=$.trim(_3c[i]);if(row){row=row.split("|");_3b[_3b.length]={data:row,value:row[0],result:_a.formatResult&&_a.formatResult(row,row[0])||row[0]};}}
return _3b;}
function stopLoading(){_c.removeClass(_a.loadingClass);}};})(jQuery);
