var ResizableTextbox=Class.create({options:$H({min:5,max:500,step:7}),initialize:function(B,A){var C=this;this.options.update(A);this.el=$(B);this.width=this.el.offsetWidth;this.el.observe("keyup",function(){var D=C.options.get("step")*$F(this).length;if(D<=C.options.get("min")){D=C.width;}if(!($F(this).length==this.retrieveData("rt-value")||D<=C.options.min||D>=C.options.max)){}}).observe("keydown",function(){this.cacheData("rt-value",$F(this).length);});}});var TextboxList=Class.create({options:$H({resizable:{},className:"bit",separator:"###",extrainputs:true,startinput:true,hideempty:true,fetchFile:undefined,results:10,wordMatch:false}),initialize:function(B,A){this.options.update(A);this.element=$(B).hide();this.bits=new Hash();this.events=new Hash();this.count=0;this.current=false;this.maininput=this.createInput({"class":"maininput"});this.holder=new Element("ul",{"class":"holder"}).insert(this.maininput);this.element.insert({"before":this.holder});this.holder.observe("click",function(C){C.stop();if(this.maininput!=this.current){this.focus(this.maininput);}}.bind(this));this.makeResizable(this.maininput);this.setEvents();},setEvents:function(){document.observe(Prototype.Browser.IE?"keydown":"keypress",function(A){if(!this.current){return ;}if(this.current.retrieveData("type")=="box"&&A.keyCode==Event.KEY_BACKSPACE){A.stop();}}.bind(this));document.observe("keyup",function(A){A.stop();if(!this.current){return ;}switch(A.keyCode){case Event.KEY_LEFT:return this.move("left");case Event.KEY_RIGHT:return this.move("right");case Event.KEY_DELETE:case Event.KEY_BACKSPACE:return this.moveDispose();}}.bind(this)).observe("click",function(){document.fire("blur");}.bindAsEventListener(this));},update:function(){this.element.value=this.bits.values().join(this.options.get("separator"));return this;},add:function(C,A){var D=this.options.get("className")+"-"+this.count++;var B=this.createBox($pick(A,C),{"id":D});(this.current||this.maininput).insert({"before":B});B.observe("click",function(E){E.stop();this.focus(B);}.bind(this));this.bits.set(D,C.value);if(this.options.get("extrainputs")&&(this.options.get("startinput")||B.previous())){this.addSmallInput(B,"before");}return B;},addSmallInput:function(C,B){var A=this.createInput({"class":"smallinput"});C.insert({}[B]=A);A.cacheData("small",true);this.makeResizable(A);if(this.options.get("hideempty")){A.hide();}return A;},dispose:function(A){this.bits.unset(A.id);if(A.previous()&&A.previous().retrieveData("small")){A.previous().remove();}if(this.current==A){this.focus(A.next());}if(A.retrieveData("type")=="box"){A.onBoxDispose(this);}A.remove();return this;},focus:function(B,A){if(!this.current){B.fire("focus");}else{if(this.current==B){return this;}}this.blur();B.addClassName(this.options.get("className")+"-"+B.retrieveData("type")+"-focus");if(B.retrieveData("small")){B.setStyle({"display":"block"});}if(B.retrieveData("type")=="input"){B.onInputFocus(this);if(!A){this.callEvent(B.retrieveData("input"),"focus");}}else{B.fire("onBoxFocus");}this.current=B;return this;},blur:function(B){if(!this.current){return this;}if(this.current.retrieveData("type")=="input"){var A=this.current.retrieveData("input");if(!B){this.callEvent(A,"blur");}A.onInputBlur(this);}else{this.current.fire("onBoxBlur");}if(this.current.retrieveData("small")&&!A.get("value")&&this.options.get("hideempty")){this.current.hide();}this.current.removeClassName(this.options.get("className")+"-"+this.current.retrieveData("type")+"-focus");this.current=false;return this;},createBox:function(B,A){return new Element("li",A).addClassName(this.options.get("className")+"-box").update(B.caption).cacheData("type","box");},createInput:function(B){var A=new Element("li",{"class":this.options.get("className")+"-input"});var D=new Element("input",Object.extend(B,{"type":"text"}));D.observe("click",function(E){E.stop();}).observe("focus",function(E){if(!this.isSelfEvent("focus")){this.focus(A,true);}}.bind(this)).observe("blur",function(){if(!this.isSelfEvent("blur")){this.blur(true);}}.bind(this)).observe("keydown",function(E){this.cacheData("lastvalue",this.value).cacheData("lastcaret",this.getCaretPosition());});var C=A.cacheData("type","input").cacheData("input",D).insert(D);return C;},callEvent:function(B,A){this.events.set(A,B);B[A]();},isSelfEvent:function(A){return(this.events.get(A))?!!this.events.unset(A):false;},makeResizable:function(A){var B=A.retrieveData("input");B.cacheData("resizable",new ResizableTextbox(B,Object.extend(this.options.get("resizable"),{min:B.offsetWidth,max:(this.element.getWidth()?this.element.getWidth():0)})));return this;},checkInput:function(){var A=this.current.retrieveData("input");return(!A.retrieveData("lastvalue")||(A.getCaretPosition()===0&&A.retrieveData("lastcaret")===0));},move:function(B){var A=this.current[(B=="left"?"previous":"next")]();if(A&&(!this.current.retrieveData("input")||((this.checkInput()||B=="right")))){this.focus(A);}return this;},moveDispose:function(){if(this.current.retrieveData("type")=="box"){return this.dispose(this.current);}if(this.checkInput()&&this.bits.keys().length&&this.current.previous()){return this.focus(this.current.previous());}}});Element.addMethods({getCaretPosition:function(){if(this.createTextRange){var A=document.selection.createRange().duplicate();A.moveEnd("character",this.value.length);if(A.text===""){return this.value.length;}return this.value.lastIndexOf(A.text);}else{return this.selectionStart;}},cacheData:function(B,A,C){if(Object.isUndefined(this[$(B).identify()])||!Object.isHash(this[$(B).identify()])){this[$(B).identify()]=$H();}this[$(B).identify()].set(A,C);return B;},retrieveData:function(B,A){return this[$(B).identify()].get(A);}});function $pick(){for(var D=0,C=arguments.length;D<C;D++){if(!Object.isUndefined(arguments[D])){return arguments[D];}}return null;}