//Debut du onload JQuery -----------------------------------------------------------------------------------

jQuery(document).ready(function(){


//Formulaire de live search -----------------------------------------------------------------------------------
    var myArr = [];
  
    $.ajax({
      type: "GET",
      url: "typo3conf/ext/ressources/xml/livesearch.xml", // change to full path of file on server
      dataType: "xml",
      success: parseXml,
      complete: setupAC,
      failure: function(data) {
        alert("XML File could not be found");
      }
    });
  
    function parseXml(xml){
      //find every query value
      $(xml).find("Ressource").each(function(){
        var nomid = $(this).find("HistoriqueId").text();
        var nom = $(this).find("Nom").text();
        myArr.push({"leid": nomid, value: nom});
      });  
    }
    
    function setupAC() {
      $("input#searchBox").autocomplete({
          source: myArr,
          minLength: 3,
          select: function(event, ui) {
            $("input#searchBox").val(ui.item.value);            
            window.location.href = "/chercher-une-adresse/ressource-detaillee/?hist="+ui.item.leid ;
          }
      });
    }
	
//Fin du onload JQuery -----------------------------------------------------------------------------------
});
