function class_recherche()
{
  this.install=function (args)
  {
    this.resdiv=null;
    this.tabres=null;
    this._lastKeyCode=null;
    this._timeoutAdjustment=0;
    this.requette=null;
    this._numResults=0;
    //traitement des arguments
    this._inputField=args['input']; 
    this._url=args['url'];
    this.def_val=this._inputField.value;
    this.resdiv=args['resdiv'];
    this._inputField.setAttribute("autocomplete","off");
    addEvent(this._inputField,'keyup',this.keyUpHandler);
    addEvent(this._inputField,'click',function () {this.select()});
    this._currentInputFieldValue=this._inputField.value;
    this._oldInputFieldValue=this._currentInputFieldValue;
  }
  
  this.test_val=function () { 
  //~ alert(this.value);
  if (this.value==this.def_val)
    this.value='';
  }
  
  this.rech=function () { 
    var basicmatch = /[a-z0-9]/i;
    q=this._inputField.value;
    q = q.replace('\s+', ' ');
    if ((q.length<3) && (q.length!=0))
      {
      return;
      }
    if (!basicmatch.test(q) && (q.length!=0) ) 
      {
      this._inputField.value='';
      return;
      }
    this._inputField.value=q;
    if (this._oldInputFieldValue==q) return;
    if (this.requette)
      if (this.requette.isActive) this.requette.abort();
    this.requette=AjaxRequest.get
    (
      {
        'url':this._url+this.escapeURI(q.replace("'"," ").replace(/[ΘΙΚΛθικλ]/g,"e"))
        ,'onSuccess':function(req)
          { 
          this.resdiv.innerHTML=req.responseText; 
          this.resdiv.init_options();
          this.resdiv.showoptions();
          }
        ,'onLoaded':function() { _timeoutAdjustment=0; }
      }
    );
    this.requette.resdiv=this.resdiv;
    this._currentInputFieldValue=this._inputField.value;
    this._oldInputFieldValue=q;
  }

  this.keyUpHandler=function (event)
  {
    if(!event&&window.event) {
      event=window.event;
    }
    if (event.target) 
      {
      name=event.target.name;
      o=event.target;
      }
	  else if (event.srcElement) 
      {//ie
      name=event.srcElement.name;
      o=this[event.srcElement.name];     
      }
    if (o.onchange) o.onchange();
    if(event) {
      _lastKeyCode=event.keyCode;
    }
    if(event&&event.keyCode){
      switch (event.keyCode) {
        case 3:
          return false;
          break;
        case 13: // enter
          o.choix(o._selectedRes);
          break;
        case 27: // escape
            this.resdiv.hideoptions();
            return false;
            break;
        case 38: // up arrow
            o.gsc_handleup();
            return false;
            break;
        case 40: // down arrow
            o.gsc_handledown();
            return false;
            break;
        default:
            if (o.resdiv) o._timeoutAdjustment++;
            else 
            o._timeoutAdjustment++;
            eval('setTimeout('+name+'.recalculateTimeout,'+name+'._timeoutAdjustment*30)');
            //~ setTimeout(o.recalculateTimeout,o._timeoutAdjustment*30);
     }
    }
  }
  
  this.recalculateTimeout=function (){
    if (this.name==null)
      {
      o=this;
      }
      else
      {//ie
      o=this[this.name]; 
      }
    if(o._oldInputFieldValue!=o._currentInputFieldValue) return;
    if (o._timeoutAdjustment<=0) o.rech();
    else
      {
      o._timeoutAdjustment--;
      setTimeout(o.recalculateTimeout,o._timeoutAdjustment*30);
      }
  }
  
  this.escapeURI=function (La){
    if(encodeURIComponent) {
      return encodeURIComponent(La);
    }
    if(escape) {
      return escape(La)
    }
  }
  
  this.gsc_handleup=function ()
  {
    if (!this.resdiv) return;
    if (this._selectedRes <= 0)
          this._selectedRes = this._numResults - 1;
      else
          this._selectedRes--;
    this.gsc_highlightsel();
  }
  
  this.gsc_handledown=function ()
  {
    if ((!this.resdiv) || (this._selectedRes ==this.tabres.length))  return;
    if ((this._selectedRes== this._numResults - 1) || this._selectedRes<0)
     this._selectedRes=0;
    else 
      this._selectedRes++;
    this.gsc_highlightsel();
  }
}
