function Lexique(idDico,tableName) 
{
  this.box = $(idDico); 
  
  //ne pas mettre de suat de ligne dans le html ci-dessous
  this.html = '<form action="#" method="post" class="forms normForms" onsubmit="return false;"><fieldset><div class="contForm"><h3>Vous recherchez une définition</h3> 									<p id="listeLettres" class="listLettres"> 										</p>									<p> 										<label for="motCle">Saisissez un terme</label> 										<input style="padding-left:3px" name="motCle"  id="motCle" value="" type="text"> 										&nbsp;&nbsp;&nbsp;<span class="button"><input id="ok"  src="img/bt_ok.png" alt="ok" class="format_png" type="image"></span> 									</p> 								</div> 							</fieldset> 						</form> ';
  this.setStructure();
  this.getAlphabet();
  //this.setStyle();
  //this.setOnClick();
  
}

/** INITIALISER LA STRUCTURE HTML */

Lexique.prototype = { 
  setStructure: function () {
    el = document.createElement('div');
    el.id = 'alphabet';
    el.innerHTML = this.html;
    this.box.appendChild(el);
    el = document.createElement('div');
    el.id = 'listeDefinitions';
    
    this.box.appendChild(el);
    $('ok').onclick = Lexique.prototype.getDefinitionsByMot;
  },
  getAlphabet: function(){
    var url = 'lexique_ajax.php';
    var pars = 'act=getAlphabet';  
    var myAjax = new Ajax.Request(url, 
                                  {
                                   method: 'get', 
                                   parameters: pars,
                                   onComplete: Lexique.prototype.getAlphabetCallback
                                  } 
                                  );
  },
  
  chargementEnCours: function() {
    $('listeDefinitions').innerHTML = 'Chargement en cours';
  },
  
  getAlphabetCallback: function(XMLreponse) {
    //alert('ici');
    
    var resultat = XMLreponse.responseText.parseJSON();
    //alert(resultat.length);
   
    //alert(Lexique.prototype.getDefinitions);
    for (var i=0; i<resultat.length ; i++) {
     
      el = document.createElement('a');
      el.id = resultat[i];
      el.href = '';
      el.onclick = Lexique.prototype.getDefinitions;
      el.innerHTML = resultat[i];
      $('listeLettres').appendChild(el);
    }
  },
  getDefinitions: function(){
    //alert('ci');
    if (this.tagName == 'STRONG') {
      return false; 
    }
    //alert($('listeLettres').childNodes.length);
    var nbNodes = $('listeLettres').childNodes.length;
    for (var i=0; i<nbNodes;i++) {
      
      if ($('listeLettres').childNodes[i].tagName == 'STRONG') {
        //console.log($('listeLettres').childNodes[i].tagName);
        var el = $('listeLettres').childNodes[i];
        
        var lettre = el.id;  
        var tempId = lettre + '_';
        //console.log(lettre);
        //console.log(tempId);
        new Insertion.After(lettre,'<a id="' + tempId + '">fds</a>');
        new Element.remove(lettre);
        new Insertion.After(tempId,'<a id="' + lettre + '">' + lettre + '</a>');
        new Element.remove(tempId);
        $(lettre).onclick = Lexique.prototype.getDefinitions;
      }
      
    }
    
    
    var url = 'lexique_ajax.php';
    var pars = 'act=getDefinitions&lettre=' + this.id;
    var lettre = this.id;  
    var tempId = lettre + '_';
    
    
    
    //console.log(lettre);
    //console.log(tempId);
    new Insertion.After(this.id,'<strong id="' + tempId + '">fds</strong>');
    new Element.remove(this.id);
    new Insertion.After(tempId,'<strong id="' + lettre + '">' + lettre + '</strong>');
    new Element.remove(tempId);
    var myAjax = new Ajax.Updater('listeDefinitions', url, {method: 'get',
                                                            onLoading: Lexique.prototype.chargementEnCours,
                                                            parameters: pars}
                                  );
    return false;
  },
  getDefinitionsByMot: function(){
    //alert('ci');
    
    var tmpString = $('motCle').value;
    if (tmpString.length < 3 ) {
       $('listeDefinitions').innerHTML = 'Vous devez saisir au moins 3 caractères.';
       return false;
    }   
    
    var url = 'lexique_ajax.php';
    var pars = 'act=getDefinitionsByMot&mot=' + $('motCle').value;  
    
    var myAjax = new Ajax.Updater('listeDefinitions', url, {method: 'get', 
                                                            onLoading: Lexique.prototype.chargementEnCours,
                                                            parameters: pars});
    return false;
  }

 
  

  
  
}
