
//if(typeof (Cnc2)=="undefined"){Cnc2={version:"2008-03-26"}}Cnc2.Dialog=new Class({Implements:[Events,Options,Chain],options:{mask:true,followScroll:true,styles:{},classes:[]},initialize:function(C,B,D,A){this.setOptions(A);this.element=$(C);if(this.options.mask){this.masker=$(document.body).get("mask",this.options)}this.element.setStyle("z-index",this.masker.getZIndex()+1);this.resize=this.adjust.bind(this);this.scroll=this.follow.bind(this);this.element.store("dialog",this);B.addEvent("click",this.show.bind(this));D.addEvent("click",this.hide.bind(this))},getCenterPosition:function(){var B=(window.getWidth()/2)-(this.element.getWidth()/2);var A=(window.getHeight()/2)-(this.element.getHeight()/2);B=(B<0)?0:B+window.getScroll().x;A=(A<0)?0:A+window.getScroll().y;return{left:B,top:A}},adjust:function(){if(this.element.getStyle("display")=="none"){this.element.setStyle("visibility","hidden").setStyle("display","block")}var B=this.getCenterPosition().left;var A=this.getCenterPosition().top;this.element.setStyle("position","absolute").setStyle("left",B).setStyle("top",A)},follow:function(){var B=this.getCenterPosition().left;var A=this.getCenterPosition().top;this.element.get("tween",{link:"chain"});this.element.tween("left",this.element.getStyle("left").toInt(),B);this.element.tween("top",this.element.getStyle("top").toInt(),A)},show:function(){this.adjust();if(this.options.mask){this.masker.mask()}this.element.setStyle("display","block").fade(1);window.addEvent("resize",this.resize);if(this.options.followScroll){window.addEvent("scroll",this.scroll)}},hide:function(){if(this.options.mask){this.masker.unmask()}this.element.fade(0).get("tween").chain(function(){this.element.setStyle("display","none")}.bind(this));window.removeEvent("resize",this.resize);if(this.options.followScroll){window.removeEvent("scroll",this.scroll)}}});Cnc2.Masker=new Class({Implements:[Events,Options,Chain],options:{styles:{opacity:0.6,position:"absolute",display:"none","z-index":99,"background-color":"#fff"},classes:[]},initialize:function(B,A){this.setOptions(A);this.element=$(B);this.cover=$(new Element("div")).addClass("mask");this.cover.setStyles(this.options.styles).setStyle("opacity",0);this.cover.injectInside(this.element);this.adjust();this.resize=this.adjust.bind(this);this.options.classes.each(function(C){this.cover.addClass(C)},this)},getZIndex:function(){return this.cover.getStyle("z-index")},adjust:function(){this.cover.setStyles(this.element.getCoordinates()).setStyle("height",this.element.getScrollSize().y)},mask:function(){this.cover.setStyle("display","block").fade(this.options.styles.opacity);window.addEvent("resize",this.resize);window.addEvent("scroll",this.resize)},unmask:function(){this.cover.fade(0).get("tween").chain(function(){this.cover.setStyle("display","none")}.bind(this));window.removeEvent("resize",this.resize);window.removeEvent("scroll",this.resize)}});Element.Properties.mask={get:function(A){if(A||!this.retrieve("mask")){this.set("mask",A)}return this.retrieve("mask")},set:function(A){return this.store("mask",new Cnc2.Masker(this,A))}};Element.implement({mask:function(A){this.get("mask",A).mask();return this},unmask:function(A){this.get("mask",A).unmask();return this}});Cnc2.Rotator=new Class({Implements:[Chain,Events,Options],initialize:function(D,B,A,C){this.element=D;this.items=$splat(B);this.count=this.items.length;this.order=0;if(A.length==2){this.prevBtn=A[0];this.nextBtn=A[1]}else{if(A.length<2||(A.length>2&&this.controls.length!=this.count)){this.prevBtn=new Element("a").inject(this.element,"after");this.nextBtn=new Element("a").inject(this.element,"after")}else{this.controls=A}}this.setOptions(C);this.scroller=new Fx.Scroll(this.element,this.options);if(A.length>2&&this.controls.length==this.count){this.registerOrdinalRotator()}else{if(this.options.loop&&this.count>=3){this.registerLoopRotator()}else{this.registerRotator()}}if(this.options.timer){$$(this.element,this.prevBtn,this.nextBtn).addEvent("mouseenter",function(){$clear(this.timerId);this.timerId=null}.bind(this));$$(this.element,this.prevBtn,this.nextBtn).addEvent("mouseleave",function(){this.registerTimer()}.bind(this));this.registerTimer()}},registerTimer:function(){if(this.timerId!=null){return }this.timerId=(function(){this.nextBtn.fireEvent("click")}.bind(this)).periodical(this.options.timer)},registerOrdinalRotator:function(){for(ctrlIdx=0;ctrlIdx<this.count;ctrlIdx++){this.controls[ctrlIdx].addEvent("click",function(B,A){this.order=A;this.scroller.toElement(this.items[this.order]);this.nextBtn=this.controls[(this.order+1)%this.count]}.bindWithEvet(this,ctrlIdx))}},registerRotator:function(){this.prevBtn.addEvent("click",function(){this.order=(this.order-1+this.count)%this.count;this.scroller.toElement(this.items[this.order])}.bind(this));this.nextBtn.addEvent("click",function(){this.order=(this.order+1)%this.count;this.scroller.toElement(this.items[this.order])}.bind(this))},registerLoopRotator:function(){this.instantScroller=new Fx.Scroll(this.element,$merge(this.options,{duration:0}));this.fxOrder=0;this.instantScroller.toElement(this.items[1]).chain(function(){this.items[this.count-1].inject(this.items[0],"before")}.bind(this));this.prevBtn.addEvent("click",function(){if(this.fxOrder!=this.order){return }this.mover=this.items[(this.order-2+this.count)%this.count];var A=(this.order+1)%this.count;this.order=(this.order-1+this.count)%this.count;this.element.set("opacity",0.99);this.instantScroller.toElement(this.items[A]).chain(function(){this.mover.inject(this.items[this.order],"before");this.element.set("opacity",1);this.scroller.toElement(this.items[this.order]).chain(function(){this.fxOrder=this.order}.bind(this))}.bind(this))}.bind(this));this.nextBtn.addEvent("click",function(){if(this.fxOrder!=this.order){return }this.mover=this.items[(this.order-1+this.count)%this.count];var A=(this.order-1+this.count)%this.count;this.order=(this.order+1)%this.count;this.element.set("opacity",0.99);this.instantScroller.toElement(this.items[A]).chain(function(){this.mover.inject(this.mover.getParent());this.element.set("opacity",1);this.scroller.toElement(this.items[this.order]).chain(function(){this.fxOrder=this.order}.bind(this))}.bind(this))}.bind(this))}});Cnc2.Tabber=new Class({Implements:[Chain,Events,Options],options:{currentClass:"current",patchIe6Rollover:true},initialize:function(B,C,A){this.tabs=B;this.contents=C;this.setOptions(A);this.order=0;this.fxOrder=0;this.count=this.tabs.length;for(i=0;i<this.count;i++){if(this.tabs[i].hasClass(this.options.currentClass)){this.order=i;this.fxOrder=i}}if(Browser.Engine.trident4&&this.options.patchIe6Rollover){this.tabs.each(function(D){D.addEvent("mouseenter",function(){D.addClass(this.options.currentClass)}.bind(this));D.addEvent("mouseleave",function(E,F){if(F!=this.tabs[this.fxOrder]){F.removeClass(this.options.currentClass)}}.bindWithEvent(this,D))}.bind(this))}this.registerTabChanger();if(this.options.timer){this.tabsBase=this.tabs[0].getParent();this.contentsBase=this.contents[0].getParent();$$(this.tabsBase,this.contentsBase).addEvent("mouseenter",function(){$clear(this.timerId);this.timerId=null}.bind(this));$$(this.tabsBase,this.contentsBase).addEvent("mouseleave",function(){this.registerTimer()}.bind(this));this.registerTimer()}},registerTimer:function(){if(this.timerId!=null){return }this.timerId=(function(){this.tabs[(this.order+1)%this.count].fireEvent("click")}.bind(this)).periodical(this.options.timer)},registerTabChanger:function(){for(tabIdx=0;tabIdx<this.count;tabIdx++){this.contents[tabIdx].set("tween",this.options);if(tabIdx!=this.order){this.contents[tabIdx].fade("hide")}this.tabs[tabIdx].addEvent("click",function(B,A){this.tabs.removeClass(this.options.currentClass);this.tabs[A].addClass(this.options.currentClass);if(this.order!=this.fxOrder){this.contents[this.fxOrder].get("tween").cancel();this.contents[this.fxOrder].fade("hide").removeClass(this.options.currentClass)}this.fxOrder=A;this.contents[this.order].get("tween").cancel().clearChain().chain(function(){this.contents[this.order].removeClass(this.options.currentClass);this.contents[this.order].fade("hide");this.contents[this.fxOrder].addClass(this.options.currentClass);this.contents[this.fxOrder].get("tween").chain(function(){this.order=this.fxOrder}.bind(this));this.contents[this.fxOrder].fade("in")}.bind(this));this.contents[this.order].fade("out")}.bindWithEvent(this,tabIdx))}}});Cnc2.Sticker=new Class({Implements:[Chain,Events,Options],options:{horiAlignFrom:"left",vertAlignFrom:"top",horiAlignTo:"left",vertAlignTo:"top",xOffset:0,yOffset:0},initialize:function(B,C,A){this.element=$(B);this.setTarget(C);this.setOptions(A);this.stick();window.addEvent("resize",function(){this.stick()}.bind(this))},setTarget:function(A){this.target=$(A);return this},stick:function(){var A=this.target.getPosition();var C=A.x+this.options.xOffset;var B=A.y+this.options.yOffset;this.element.setStyle("display","block").setStyle("position","absolute");this.element.setStyle("top",B).setStyle("left",C)}});Element.Properties.sticker={get:function(B,A){if(!this.retrieve("sticker")){this.set("sticker",B,A)}return this.retrieve("sticker").setTarget(B).setOptions(A)},set:function(B,A){return this.store("sticker",new Cnc2.Sticker(this,B,A))}};Element.implement({stick:function(B,A){this.get("sticker",B,A).stick();return this}});
if(typeof (Cnc2)=="undefined"){Cnc2={version:"2008-03-26"}}Cnc2.OverlayFix=new Class({initialize:function(A){if(Browser.Engine.trident){this.element=$(A);this.relative=this.element.getOffsetParent();this.fix=new Element("iframe",{frameborder:"0",scrolling:"no",src:"javascript:false;",styles:{position:"absolute",border:"none",display:"none",filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=0)"}}).inject(this.element,"after")}},show:function(){if(this.fix){var A=this.element.getCoordinates(this.relative);delete A.right;delete A.bottom;this.fix.setStyles($extend(A,{display:"",zIndex:(this.element.getStyle("zIndex")||1)-1}))}return this},hide:function(){if(this.fix){this.fix.setStyle("display","none")}return this},morph:function(A){if(this.fix){this.fix.morph(A)}return this},destroy:function(){this.fix=this.fix.destroy()}});Cnc2.Dialog=new Class({Implements:[Events,Options,Chain],options:{mask:true,followScroll:true,styles:{},classes:[]},initialize:function(D,C,E,B){this.setOptions(B);this.element=$(D);if(this.options.mask){this.masker=$(document.body).get("mask",this.options)}var A=(this.options.mask)?this.masker.getZIndex():this.element.getParent().getStyle("z-index")||99;this.element.setStyle("z-index",A+1);this.resize=this.adjust.bind(this);this.scroll=this.follow.bind(this);this.element.store("dialog",this);this.fix=new Cnc2.OverlayFix(this.element);C.addEvent("click",this.show.bind(this));E.addEvent("click",this.hide.bind(this))},getCenterPosition:function(){var B=(window.getWidth()/2)-(this.element.getWidth()/2);var A=(window.getHeight()/2)-(this.element.getHeight()/2);B=(B<0)?0:B+window.getScroll().x;A=(A<0)?0:A+window.getScroll().y;return{left:B,top:A}},adjust:function(){if(this.element.getStyle("display")=="none"){this.element.setStyle("visibility","hidden").setStyle("display","block")}var B=this.getCenterPosition().left;var A=this.getCenterPosition().top;this.element.setStyle("position","absolute").setStyle("left",B).setStyle("top",A);this.fix.show()},follow:function(){var B=this.getCenterPosition().left;var A=this.getCenterPosition().top;this.element.morph({left:B,top:A});this.fix.morph({left:B,top:A})},show:function(){this.adjust();if(this.options.mask){this.masker.mask()}this.fix.show();this.element.setStyle("display","block").fade(1);window.addEvent("resize",this.resize);if(this.options.followScroll){window.addEvent("scroll",this.scroll)}},hide:function(){if(this.options.mask){this.masker.unmask()}this.element.fade(0).get("tween").chain(function(){this.element.setStyle("display","none");this.fix.hide()}.bind(this));window.removeEvent("resize",this.resize);if(this.options.followScroll){window.removeEvent("scroll",this.scroll)}}});Element.Properties.dialog={get:function(A){if(A||!this.retrieve("dialog")){this.set("dialog",trigger,closer,A)}return this.retrieve("dialog")},set:function(B,C,A){return this.store("dialog",new Cnc2.Dialog(this,B,C,A))}};Cnc2.Masker=new Class({Implements:[Events,Options,Chain],options:{styles:{opacity:0.6,position:"absolute",display:"none","z-index":99,"background-color":"#fff"},classes:[]},initialize:function(B,A){this.setOptions(A);this.element=$(B);this.cover=$(new Element("div")).addClass("mask");this.cover.setStyles(this.options.styles).setStyle("opacity",0);this.cover.injectInside(this.element);this.adjust();this.resize=this.adjust.bind(this);this.fix=new Cnc2.OverlayFix(this.cover);this.options.classes.each(function(C){this.cover.addClass(C)},this)},getZIndex:function(){return this.cover.getStyle("z-index")},adjust:function(){this.cover.setStyles(this.element.getCoordinates()).setStyle("height",this.element.getScrollSize().y)},mask:function(){this.cover.setStyle("display","block").fade(this.options.styles.opacity);this.fix.show();window.addEvent("resize",this.resize);window.addEvent("scroll",this.resize)},unmask:function(){this.cover.fade(0).get("tween").chain(function(){this.cover.setStyle("display","none");this.fix.hide()}.bind(this));window.removeEvent("resize",this.resize);window.removeEvent("scroll",this.resize)}});Element.Properties.mask={get:function(A){if(A||!this.retrieve("mask")){this.set("mask",A)}return this.retrieve("mask")},set:function(A){return this.store("mask",new Cnc2.Masker(this,A))}};Element.implement({mask:function(A){this.get("mask",A).mask();return this},unmask:function(A){this.get("mask",A).unmask();return this}});Cnc2.Rotator=new Class({Implements:[Chain,Events,Options],initialize:function(D,B,A,C){this.element=D;this.items=$splat(B);this.count=this.items.length;this.order=0;if(A.length==2){this.prevBtn=A[0];this.nextBtn=A[1]}else{if(A.length<2||(A.length>2&&this.controls.length!=this.count)){this.prevBtn=new Element("a").inject(this.element,"after");this.nextBtn=new Element("a").inject(this.element,"after")}else{this.controls=A}}this.setOptions(C);this.scroller=new Fx.Scroll(this.element,this.options);if(A.length>2&&this.controls.length==this.count){this.registerOrdinalRotator()}else{if(this.options.loop&&this.count>=3){this.registerLoopRotator()}else{this.registerRotator()}}if(this.options.timer){$$(this.element,this.prevBtn,this.nextBtn).addEvent("mouseenter",function(){$clear(this.timerId);this.timerId=null}.bind(this));$$(this.element,this.prevBtn,this.nextBtn).addEvent("mouseleave",function(){this.registerTimer()}.bind(this));this.registerTimer()}},registerTimer:function(){if(this.timerId!=null){return }this.timerId=(function(){this.nextBtn.fireEvent("click")}.bind(this)).periodical(this.options.timer)},registerOrdinalRotator:function(){for(ctrlIdx=0;ctrlIdx<this.count;ctrlIdx++){this.controls[ctrlIdx].addEvent("click",function(B,A){this.order=A;this.scroller.toElement(this.items[this.order]);this.nextBtn=this.controls[(this.order+1)%this.count]}.bindWithEvet(this,ctrlIdx))}},registerRotator:function(){this.prevBtn.addEvent("click",function(){this.order=(this.order-1+this.count)%this.count;this.scroller.toElement(this.items[this.order])}.bind(this));this.nextBtn.addEvent("click",function(){this.order=(this.order+1)%this.count;this.scroller.toElement(this.items[this.order])}.bind(this))},registerLoopRotator:function(){this.instantScroller=new Fx.Scroll(this.element,$merge(this.options,{duration:0}));this.fxOrder=0;this.instantScroller.toElement(this.items[1]).chain(function(){this.items[this.count-1].inject(this.items[0],"before")}.bind(this));this.prevBtn.addEvent("click",function(){if(this.fxOrder!=this.order){return }this.mover=this.items[(this.order-2+this.count)%this.count];var A=(this.order+1)%this.count;this.order=(this.order-1+this.count)%this.count;this.element.set("opacity",0.99);this.instantScroller.toElement(this.items[A]).chain(function(){this.mover.inject(this.items[this.order],"before");this.element.set("opacity",1);this.scroller.toElement(this.items[this.order]).chain(function(){this.fxOrder=this.order}.bind(this))}.bind(this))}.bind(this));this.nextBtn.addEvent("click",function(){if(this.fxOrder!=this.order){return }this.mover=this.items[(this.order-1+this.count)%this.count];var A=(this.order-1+this.count)%this.count;this.order=(this.order+1)%this.count;this.element.set("opacity",0.99);this.instantScroller.toElement(this.items[A]).chain(function(){this.mover.inject(this.mover.getParent());this.element.set("opacity",1);this.scroller.toElement(this.items[this.order]).chain(function(){this.fxOrder=this.order}.bind(this))}.bind(this))}.bind(this))}});Cnc2.Tabber=new Class({Implements:[Chain,Events,Options],options:{currentClass:"current",patchIe6Rollover:true},initialize:function(B,C,A){this.tabs=B;this.contents=C;this.setOptions(A);this.order=0;this.fxOrder=0;this.count=this.tabs.length;for(i=0;i<this.count;i++){if(this.tabs[i].hasClass(this.options.currentClass)){this.order=i;this.fxOrder=i}}if(Browser.Engine.trident4&&this.options.patchIe6Rollover){this.tabs.each(function(D){D.addEvent("mouseenter",function(){D.addClass(this.options.currentClass)}.bind(this));D.addEvent("mouseleave",function(E,F){if(F!=this.tabs[this.fxOrder]){F.removeClass(this.options.currentClass)}}.bindWithEvent(this,D))}.bind(this))}this.registerTabChanger();if(this.options.timer){this.tabsBase=this.tabs[0].getParent();this.contentsBase=this.contents[0].getParent();$$(this.tabsBase,this.contentsBase).addEvent("mouseenter",function(){$clear(this.timerId);this.timerId=null}.bind(this));$$(this.tabsBase,this.contentsBase).addEvent("mouseleave",function(){this.registerTimer()}.bind(this));this.registerTimer()}},registerTimer:function(){if(this.timerId!=null){return }this.timerId=(function(){this.tabs[(this.order+1)%this.count].fireEvent("click")}.bind(this)).periodical(this.options.timer)},registerTabChanger:function(){for(tabIdx=0;tabIdx<this.count;tabIdx++){this.contents[tabIdx].set("tween",this.options);if(tabIdx!=this.order){this.contents[tabIdx].fade("hide")}this.tabs[tabIdx].addEvent("click",function(B,A){this.tabs.removeClass(this.options.currentClass);this.tabs[A].addClass(this.options.currentClass);if(this.order!=this.fxOrder){this.contents[this.fxOrder].get("tween").cancel();this.contents[this.fxOrder].fade("hide").removeClass(this.options.currentClass)}this.fxOrder=A;this.contents[this.order].get("tween").cancel().clearChain().chain(function(){this.contents[this.order].removeClass(this.options.currentClass);this.contents[this.order].fade("hide");this.contents[this.fxOrder].addClass(this.options.currentClass);this.contents[this.fxOrder].get("tween").chain(function(){this.order=this.fxOrder}.bind(this));this.contents[this.fxOrder].fade("in")}.bind(this));this.contents[this.order].fade("out")}.bindWithEvent(this,tabIdx))}}});Cnc2.Sticker=new Class({Implements:[Chain,Events,Options],options:{horiAlignFrom:"left",vertAlignFrom:"top",horiAlignTo:"left",vertAlignTo:"top",xOffset:0,yOffset:0},initialize:function(B,C,A){this.element=$(B);this.setTarget(C);this.setOptions(A);this.stick();window.addEvent("resize",function(){this.stick()}.bind(this))},setTarget:function(A){this.target=$(A);return this},stick:function(){var A=this.target.getPosition();var C=A.x+this.options.xOffset;var B=A.y+this.options.yOffset;this.element.setStyle("display","block").setStyle("position","absolute");this.element.setStyle("top",B).setStyle("left",C)}});Element.Properties.sticker={get:function(B,A){if(!this.retrieve("sticker")){this.set("sticker",B,A)}return this.retrieve("sticker").setTarget(B).setOptions(A)},set:function(B,A){return this.store("sticker",new Cnc2.Sticker(this,B,A))}};Element.implement({stick:function(B,A){this.get("sticker",B,A).stick();return this}});
var Observer=new Class({Implements:[Options,Events],options:{periodical:false,delay:1000},initialize:function(C,A,B){this.setOptions(B);this.addEvent("onFired",A);this.element=$(C)||$$(C);this.value=this.element.get("value");if(this.options.periodical){this.timer=this.changed.periodical(this.options.periodical,this)}else{this.element.addEvent("keyup",this.changed.bind(this))}},changed:function(){var A=this.element.get("value");if($equals(this.value,A)){return }this.clear();this.value=A;this.timeout=this.onFired.delay(this.options.delay,this)},setValue:function(A){this.value=A;this.element.set("value",A);return this.clear()},onFired:function(){this.fireEvent("onFired",[this.value,this.element])},clear:function(){$clear(this.timeout||null);return this}});var $equals=function(B,A){return(B==A||JSON.encode(B)==JSON.encode(A))};var Autocompleter={};Autocompleter.Base=new Class({options:{minLength:1,markQuery:true,width:"inherit",maxChoices:10,injectChoice:null,customChoices:null,className:"autocompleter-choices",zIndex:42,delay:400,observerOptions:{},fxOptions:{},onOver:$empty,onSelect:$empty,onSelection:$empty,onShow:$empty,onHide:$empty,onBlur:$empty,onFocus:$empty,autoSubmit:false,overflow:false,overflowMargin:25,selectFirst:false,filter:null,filterCase:false,filterSingle:false,filterSubset:true,forceSelect:false,selectMode:true,choicesMatch:null,multiple:false,separator:", ",separatorSplit:/\s*[,;]\s*/,autoTrim:true,allowDupes:false,cache:true,relative:true},initialize:function(B,A){this.element=$(B);this.setOptions(A);this.build();this.observer=new Observer(this.element,this.prefetch.bind(this),$merge({delay:this.options.delay},this.options.observerOptions));this.queryValue=null;if(this.options.filter){this.filter=this.options.filter.bind(this)}var C=this.options.selectMode;this.typeAhead=(C=="type-ahead");this.selectMode=(C===true)?"selection":C;this.cached=[]},build:function(){if($(this.options.customChoices)){this.choices=this.options.customChoices}else{this.choices=new Element("ul",{"class":this.options.className,styles:{zIndex:this.options.zIndex}}).inject(document.body);this.relative=false;if(this.options.relative){this.choices.inject(this.element,"after");this.relative=this.element.getOffsetParent()}this.fix=new OverlayFix(this.choices)}if(!this.options.separator.test(this.options.separatorSplit)){this.options.separatorSplit=this.options.separator}this.fx=(!this.options.fxOptions)?null:new Fx.Tween(this.choices,$merge({property:"opacity",link:"cancel",duration:200},this.options.fxOptions)).addEvent("onStart",Chain.prototype.clearChain).set(0);this.element.setProperty("autocomplete","off").addEvent((Browser.Engine.trident||Browser.Engine.webkit)?"keydown":"keypress",this.onCommand.bind(this)).addEvent("click",this.onCommand.bind(this,[false])).addEvent("focus",this.toggleFocus.create({bind:this,arguments:true,delay:100})).addEvent("blur",this.toggleFocus.create({bind:this,arguments:false,delay:100}))},destroy:function(){if(this.fix){this.fix.destroy()}this.choices=this.selected=this.choices.destroy()},toggleFocus:function(A){this.focussed=A;if(!A){this.hideChoices(true)}this.fireEvent((A)?"onFocus":"onBlur",[this.element])},onCommand:function(B){if(!B&&this.focussed){return this.prefetch()}if(B&&B.key&&!B.shift){switch(B.key){case"enter":if(this.element.value!=this.opted){return true}if(this.selected&&this.visible){this.choiceSelect(this.selected);return !!(this.options.autoSubmit)}break;case"up":case"down":if(!this.prefetch()&&this.queryValue!==null){var A=(B.key=="up");this.choiceOver((this.selected||this.choices)[(this.selected)?((A)?"getPrevious":"getNext"):((A)?"getLast":"getFirst")](this.options.choicesMatch),true)}return false;case"esc":case"tab":this.hideChoices(true);break}}return true},setSelection:function(G){var H=this.selected.inputValue,I=H;var B=this.queryValue.length,D=H.length;if(H.substr(0,B).toLowerCase()!=this.queryValue.toLowerCase()){B=0}if(this.options.multiple){var F=this.options.separatorSplit;I=this.element.value;B+=this.queryIndex;D+=this.queryIndex;var C=I.substr(this.queryIndex).split(F,1)[0];I=I.substr(0,this.queryIndex)+H+I.substr(this.queryIndex+C.length);if(G){var A=/[^\s,]+/;var E=I.split(this.options.separatorSplit).filter(A.test,A);if(!this.options.allowDupes){E=[].combine(E)}var J=this.options.separator;I=E.join(J)+J;D=I.length}}this.observer.setValue(I);this.opted=I;if(G||this.selectMode=="pick"){B=D}this.element.selectRange(B,D);this.fireEvent("onSelection",[this.element,this.selected,I,H])},showChoices:function(){var C=this.options.choicesMatch,G=this.choices.getFirst(C);this.selected=this.selectedValue=null;if(this.fix){var H=this.element.getCoordinates(this.relative),D=this.options.width||"auto";this.choices.setStyles({left:H.left,top:H.bottom,width:(D===true||D=="inherit")?H.width:D})}if(!G){return }if(!this.visible){this.visible=true;this.choices.setStyle("display","");if(this.fx){this.fx.start(1)}this.fireEvent("onShow",[this.element,this.choices])}if(this.options.selectFirst||this.typeAhead||G.inputValue==this.queryValue){this.choiceOver(G,this.typeAhead)}var B=this.choices.getChildren(C),A=this.options.maxChoices;var F={overflowY:"hidden",height:""};this.overflown=false;if(B.length>A){var E=B[A-1];F.overflowY="scroll";F.height=E.getCoordinates(this.choices).bottom;this.overflown=true}this.choices.setStyles(F);this.fix.show()},hideChoices:function(A){if(A){var C=this.element.value;if(this.options.forceSelect){C=this.opted}if(this.options.autoTrim){C=C.split(this.options.separatorSplit).filter($arguments(0)).join(this.options.separator)}this.observer.setValue(C)}if(!this.visible){return }this.visible=false;this.observer.clear();var B=function(){this.choices.setStyle("display","none");this.fix.hide()}.bind(this);if(this.fx){this.fx.start(0).chain(B)}else{B()}this.fireEvent("onHide",[this.element,this.choices])},prefetch:function(){var F=this.element.value,E=F;if(this.options.multiple){var C=this.options.separatorSplit;var A=F.split(C);var B=this.element.getCaretPosition();var G=F.substr(0,B).split(C);var D=G.length-1;B-=G[D].length;E=A[D]}if(E.length<this.options.minLength){this.hideChoices()}else{if(E===this.queryValue||(this.visible&&E==this.selectedValue)){if(this.visible){return false}this.showChoices()}else{this.queryValue=E;this.queryIndex=B;if(!this.fetchCached()){this.query()}}}return true},fetchCached:function(){return false;if(!this.options.cache||!this.cached||!this.cached.length||this.cached.length>=this.options.maxChoices||this.queryValue){return false}this.update(this.filter(this.cached));return true},update:function(A){this.choices.empty();this.cached=A;if(!A||!A.length){this.hideChoices()}else{if(this.options.maxChoices<A.length&&!this.options.overflow){A.length=this.options.maxChoices}A.each(this.options.injectChoice||function(C){var B=new Element("li",{html:this.markQueryValue(C)});B.inputValue=C;this.addChoiceEvents(B).inject(this.choices)},this);this.showChoices()}},choiceOver:function(C,D){if(!C||C==this.selected){return }if(this.selected){this.selected.removeClass("autocompleter-selected")}this.selected=C.addClass("autocompleter-selected");this.fireEvent("onSelect",[this.element,this.selected,D]);if(!D){return }this.selectedValue=this.selected.inputValue;if(this.overflown){var F=this.selected.getCoordinates(this.choices),E=this.options.overflowMargin,G=this.choices.scrollTop,A=this.choices.offsetHeight,B=G+A;if(F.top-E<G&&G){this.choices.scrollTop=Math.max(F.top-E,0)}else{if(F.bottom+E>B){this.choices.scrollTop=Math.min(F.bottom-A+E,B)}}}if(this.selectMode){this.setSelection()}},choiceSelect:function(A){if(A){this.choiceOver(A)}this.setSelection(true);this.queryValue=false;this.hideChoices()},filter:function(B){var A=new RegExp(((this.options.filterSubset)?"":"^")+this.queryValue.escapeRegExp(),(this.options.filterCase)?"":"i");return(B||this.tokens).filter(function(C){return A.test(B||this.tokens)})},markQueryValue:function(A){return(!this.options.markQuery||!this.queryValue)?A:A.replace(new RegExp("("+((this.options.filterSubset)?"":"^")+this.queryValue.escapeRegExp()+")",((this.options.filterCase)?"":"i")+((this.options.filterSingle)?"":"g")),'<span class="autocompleter-queried">$1</span>')},addChoiceEvents:function(A){return A.addEvents({mouseover:this.choiceOver.bind(this,[A]),click:this.choiceSelect.bind(this,[A])})}});Autocompleter.Base.implement(new Events);Autocompleter.Base.implement(new Options);Autocompleter.Local=new Class({Extends:Autocompleter.Base,options:{minLength:0,delay:200},initialize:function(B,C,A){this.parent(B,A);this.tokens=C},query:function(){this.update(this.filter())}});Autocompleter.Ajax={};Autocompleter.Ajax.Base=new Class({Extends:Autocompleter.Base,options:{postVar:"value",postData:{},ajaxOptions:{},onRequest:$empty,onComplete:$empty},initialize:function(C,B){this.parent(C,B);var A=$(this.options.indicator);if(A){this.addEvents({onRequest:A.show.bind(A),onComplete:A.hide.bind(A)},true)}},query:function(){var A=$unlink(this.options.postData);A[this.options.postVar]=this.queryValue;this.fireEvent("onRequest",[this.element,this.request,A,this.queryValue]);this.request.send({data:A})},queryResponse:function(){this.fireEvent("onComplete",[this.element,this.request,this.response])}});Autocompleter.Ajax.Json=new Class({Extends:Autocompleter.Ajax.Base,initialize:function(C,B,A){this.parent(C,A);this.request=new Request.JSON($merge({url:B,link:"cancel"},this.options.ajaxOptions)).addEvent("onComplete",this.queryResponse.bind(this))},queryResponse:function(A){this.parent();this.update(A)}});Autocompleter.Ajax.Xhtml=new Class({Extends:Autocompleter.Ajax.Base,initialize:function(C,B,A){this.parent(C,A);this.request=new Request.HTML($merge({url:B,link:"cancel",update:this.choices},this.options.ajaxOptions)).addEvent("onComplete",this.queryResponse.bind(this))},queryResponse:function(A,B){this.parent();if(!B||!B.length){this.hideChoices()}else{this.choices.getChildren(this.options.choicesMatch).each(this.options.injectChoice||function(C){var D=C.innerHTML;C.inputValue=D;this.addChoiceEvents(C.set("html",this.markQueryValue(D)))},this);this.showChoices()}}});var OverlayFix=new Class({initialize:function(A){if(Browser.Engine.trident){this.element=$(A);this.relative=this.element.getOffsetParent();this.fix=new Element("iframe",{frameborder:"0",scrolling:"no",src:"javascript:false;",styles:{position:"absolute",border:"none",display:"none",filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=0)"}}).inject(this.element,"after")}},show:function(){if(this.fix){var A=this.element.getCoordinates(this.relative);delete A.right;delete A.bottom;this.fix.setStyles($extend(A,{display:"",zIndex:(this.element.getStyle("zIndex")||1)-1}))}return this},hide:function(){if(this.fix){this.fix.setStyle("display","none")}return this},destroy:function(){this.fix=this.fix.destroy()}});Element.implement({getOffsetParent:function(){var A=this.getDocument().body;if(this==A){return null}if(!Browser.Engine.trident){return $(this.offsetParent)}var B=this;while((B=B.parentNode)){if(B==A||Element.getComputedStyle(B,"position")!="static"){return $(B)}}return null},getCaretPosition:function(){if(!Browser.Engine.trident){return this.selectionStart}this.focus();var A=document.selection.createRange();var B=this.createTextRange();A.setEndPoint("StartToStart",B);return A.text.length},selectRange:function(C,A){if(Browser.Engine.trident){var B=this.createTextRange();B.collapse(true);B.moveEnd("character",A);B.moveStart("character",C);B.select()}else{this.focus();this.setSelectionRange(C,A)}return this}});

