/*  Le Phare JavaScript library - (c) 2007
/*--------------------------------------------------------------------------*/
var prem = true; 

Event.handler = {
   register: function(element) {
      if($(element)) {
         switch (element) {
            case "pageFicheProduit":
               prodTooltips();
            break;
            case "pageCategories":
               rechProd();
            break;
      break;

         }
      }
      // on init le click sur la recherche pour effacer le moteur de recherche 
      init();
     // menuJS();
   } // register
}

// load
Event.observe(window, 'load', function() {

      Event.handler.register(document.body.id);
});

function rechProd()
{
   Event.observe('data_activite_', 'change', getInfosRech);
	Event.observe('data_produit_', 'change', getInfosRech);
	Event.observe('data_matiere_', 'change', getInfosRech);
}

function getInfosRech(e) {
   	new Ajax.Updater('jsSpanRecherche', '../../fr/s06_catalogue/_getInfosRech.php', {
      parameters: 'activite=' + $F('data_activite_') + '&produit=' + $F('data_produit_') + '&matiere=' + $F('data_matiere_'),
      onComplete:rechProd,
      evalScripts:true});
}

function valid_pdm(id_pdm, msg)
{
	ret = false;
	if($F(id_pdm) == 0 || $F(id_pdm) == "") alert(msg);
	else									ret = true;	
	return ret;
}

function goToProduit()
{
   if ($F('data_produit_') > 0) document.location.href = "../s06_catalogue/s06p04_fiche_produit.php?prod=" + $F('data_produit_');
   else                         document.location.href = "../s06_catalogue/s06p05_resultats_produits.php?activite=" + $F('data_activite_') + "&matiere=" + $F('data_matiere_');
}

function goToLstResults()
{
   document.location.href = "../s06_catalogue/s06p05_resultats_produits.php?activite=" + $F('data_activite_') + "&matiere=" + $F('data_matiere_');
}

function prodTooltips()
{
   if($$('.jsCash'))
   {
      $$('.jsCash').each(function(obj){
      obj.title=cash;
      });

      $$('.jsCash').each(function(obj){
      new Tooltip(obj,
               {
                        backgroundColor: "#004C92", 
                        borderColor: "#333", 
                        textColor: "#fff", 
                        textShadowColor: "#000",
                        delay:.4,
                        opacity:.95,
                        maxWidth:420
               });
      });
   }
   if($$('jsPerso'))
   {
   
      $$('.jsPerso').each(function(obj){
      obj.title=perso;
      });

      $$('.jsPerso').each(function(obj){
      new Tooltip(obj, 
               {
                  backgroundColor: "#189461", 
                  borderColor: "#333", 
                  textColor: "#fff", 
                  textShadowColor: "#fff",
                  delay:.4,
                  opacity:.95,
                  maxWidth:420
               });
      });
      
   }
   if($$('jsNouveau'))
   {
   
      $$('.jsNouveau').each(function(obj){
         obj.title=nouveau;
      });

      $$('.jsNouveau').each(function(obj){

      new Tooltip(obj, {
                           backgroundColor: "#DA3A2E", 
                           borderColor: "#333", 
                           textColor: "#fff", 
                           textShadowColor: "#fff",
                           delay:.4,
                           opacity:.95,
                           maxWidth:420
                        });
            });

   }
           
}

function init()
{
   Event.observe('searchProd','click',initSearchProd); 
   var urlAuto1 = '../../ml/s00_commun/_getProd.php';
   var myAuto1 = new Ajax.Autocompleter (
                          'searchProd',      // ID of the source field
                          'jsLstResultatEntete',  // ID of the DOM element to update
                          urlAuto1, // Remote script URI
                          { 
                           method: 'post', 
                           paramName: 'searchProd',
                           minChars: 3,  
                           indicator: 'wait', 
                           afterUpdateElement:ligneRechercheTab
                          }
                        );
   
  
}
function ligneRechercheTab(text, li)
{
   var myId = li.id.replace('ligne_','');

   if(myId!=0)
   {  
      if(navigator.appName=="Microsoft Internet Explorer")
         document.location.href = "../fr/s06_catalogue/s06p04_fiche_produit.php?prod=" + myId;
      else
         document.location.href = "/fr/s06_catalogue/s06p04_fiche_produit.php?prod=" + myId;
   }
}
function initSearchProd()
{
   if(prem)
   {
      $('searchProd').value = "";
      prem = false;
   }      
}
function menuJS()
{
   $$('#navigation li a').each(
      function(obj){
         Event.observe(obj,'mouseover', 
            function(obj_E){
               $$('.jsSousNav').each(
                  function(unObj)
                  { 
                     unObj.hide();
                  });
            });
         });
   //('jsSousNav')
}