var RechercheClass=new Class({options:{popupfx:{transition:Fx.Transitions.Quint.easeOut,duration:400},classes:{container:"container",popup:"popup",item:"item"},size:{width:100,height:24},maxcatch:5,form:"form",showtimeout:15000,triggertimeout:1000},initialize:function(panel,options){if($defined(options)){this.setOptions(options);}this.form=document.forms[this.options.form];if(!Browser.Engine.trident){this.form.recherche.addEvent("keypress",function(event){if(event.code==event.event.DOM_VK_RETURN){this.doAction("recherche");return(false);}if(!this.delaytrigger){var f=function(){this.doAction("trigger");this.delaytrigger=false;};this.delaytrigger=f.delay(this.options.triggertimeout,this);}return(true);}.bind(this));pos=this.form.recherche.getCoordinates();this.container=new Element("div").addClass(this.options.classes.container);this.popup=new Element("div").addClass(this.options.classes.popup);this.mintop=-((this.options.size.height*this.options.maxcatch)+this.popup.getStyle("padding-bottom").toInt()+this.popup.getStyle("padding-top").toInt());this.popup.setStyles({height:-this.mintop,top:this.mintop,visibility:"visible",width:this.options.size.width,left:"0px"});this.popup.setStyles({height:(this.options.size.height*this.options.maxcatch),top:this.mintop,visibility:"visible",width:this.options.size.width,left:"0px"});this.container.setStyles({visibility:"hidden",top:pos.top+pos.height,left:pos.left,width:this.options.size.width,height:-this.mintop});this.container.injectInside(document.body);this.popup.injectInside(this.container);this.popup.fxshow=new Fx.Morph(this.popup,{duration:this.options.popupfx.duration,transition:this.options.popupfx.transition});this.popup.fxhide=new Fx.Morph(this.popup,{duration:this.options.popupfx.duration,transition:this.options.popupfx.transition,onComplete:function(){this.container.setStyles({visibility:"hidden"});}.bind(this)});}this.tmprecherche="";this.delaytrigger=false;this.delaypopout=false;this.liste=[];this.step="attente";this.getRechercheStr=function(){tmp=this.form.recherche.value.replace(/([^\w\déèçàùâêîûôëïüö])/g," ");tmp=tmp.replace(/\s+/g," ").trim();return($defined(tmp.match(/[\wéèçàùâêîûôëïüö]{3,}/))?tmp:null);};},doAction:function(action,index){switch(this.step){case"attente":switch(action){case"trigger":tmp=this.getRechercheStr();if(tmp==null){break;}this.tmprecherche=tmp;JSearchHelper.Search("webtv",tmp,this.options.maxcatch,{callback:function(data){this.doAction("resultat",data);}.bind(this),errorHandler:function(data){this.doAction("error",data);}.bind(this)});break;case"popout":if(!$defined(this.container)){break;}try{aa=this.delaypopout;this.delaypopout=false;$clear(aa);}catch(ex){}try{aa=this.delaytrigger;this.delaytrigger=false;$clear(aa);}catch(ex){}if(this.container.getStyle("visibility")!="visible"){break;}this.popup.fxhide.start({top:this.mintop});break;case"recherche":this.doAction("popout");this.step="preparerecherche";if(!$defined(index)){a=this.getRechercheStr();if(a==null){this.step="attente";break;}this.doAction("push",this.getRechercheStr());break;}this.doAction("ok");break;case"click":this.form.recherche.value=this.liste[index];this.doAction("recherche",true);break;case"error":break;case"resultat":this.popup.empty();this.liste=index;if(this.liste.length==0){this.doAction("popout");break;}this.liste.forEach(function(l,i){d=new Element("div").injectInside(this.popup);a=new Element("a").setProperty("href","#").addClass(this.options.classes.item);a.set("html",l.replace(this.tmprecherche,"<b>"+this.tmprecherche+"</b>"));a.addEvent("click",function(){this.doAction("click",i);}.bind(this));a.injectInside(d);}.bind(this));if(this.container.getStyle("visibility")!="visible"){this.container.setStyles({visibility:"visible"});this.popup.fxshow.start({top:0});}try{$clear(this.delaypopout);}catch(ex){}var f2=function(){this.doAction("popout");};this.delaypopout=f2.delay(this.options.showtimeout,this);break;default:}break;case"preparerecherche":switch(action){case"push":if(index!=null){JSearchHelper.AddRecord("webtv",index,{callback:function(data){this.doAction("ok",data);}.bind(this),errorHandler:function(data){this.doAction("error",data);}.bind(this)});break;}case"error":case"ok":try{resultatobj.pushRequest(this.getRechercheStr());this.step="attente";}catch(e){this.step="theend";this.form.recherche.value=this.getRechercheStr();this.form.submit();}break;}break;}}});RechercheClass.implement(new Events,new Options);