/*  Le Phare JavaScript library - (c) 2007
/*--------------------------------------------------------------------------*/
var prem = true;
/*  Le Phare JavaScript library - (c) 2007
/*--------------------------------------------------------------------------*/
var prem = true;

var Loader = Class.create({
   initialize: function(element) {
      if($(element)) {
         this.idBody = element;
         this.registerGenerics(); // call generics f°
         this.registerSpecifics(); // call specificsf°
      }
      else {
         alert('ATTENTION\nLa balise body n\'a pas d\'id !');
      }
   },

   registerGenerics: function() {

   },

   registerSpecifics: function() {
         switch (this.idBody) {
            case 'pageAccueil':
               loadPetrins();
               loadMelangeurs();
             
               var myLightWindow = null;
               myLightWindow = new lightwindow();
               myLightWindow.activateWindow({
      	        href: '/fr/images/layer_Europain.jpg',
                width: '640',
                height: '315',
                title: 'Vmi lève le voile à Europain'});   
                           
            break;

            case 'pageContacts':
                initForm();
            break;
            case 'pageCatalogue':
               initRecherche();
            break;
         }
   }
});


// load
Event.observe(window, 'load', function() {
   var loader = new Loader(document.body.id);
});


/*--------------------------------------------------------------------------*/


function loadPetrins() {
   if($('petrins')) {
      Event.observe('petrins','mouseover',function(event){
         $('petrins').hide();
         $('rubriquesPetrins').show();
         Event.stop(event);
      });

      Event.observe('rubriquesPetrins','mouseout',function(event){
         $('petrins').show();
         Event.stop(event);
      });

      $$('#rubriquesPetrins li').each(function(s, index) {
         Event.observe(s,'mouseover',function() {
            $('petrins').hide();
         });
      });
   }
}

function loadMelangeurs() {
   if($('melangeurs')) {
      Event.observe('melangeurs','mouseover',function(event){
         $('melangeurs').hide();
         $('rubriquesMelangeurs').show();
         Event.stop(event);
      });

      Event.observe('rubriquesMelangeurs','mouseout',function(event){
         $('melangeurs').show();
         Event.stop(event);
      });

      $$('#rubriquesMelangeurs li').each(function(s, index) {
         Event.observe(s,'mouseover',function() {
            $('melangeurs').hide();
         });
      });
   }
}


function initForm()
{
         var zeForm = new Validation('zeForm', {
            useTitles:true, stopOnFirst:true, onFormValidate: function() {$('todo').value = "submit_quest";}
         });

         if($('searchSubmitter')) {
            Event.observe('searchSubmitter', 'click', function() {$('searchTodo').value = "email-subscribe"; $('searchEmailForm').submit();});
         }

         if($('errMsg')) {
            if($('errMsg').innerHTML  != '') {
               Element.show('errMsg'); Effect.BlindUp('errMsg', {delay:3});
            }
         }
}

function initRecherche()
{
   Event.observe('searchProd','click',initSearchProd); 
   
   var urlAuto1 = '../../ml/s00_commun/_getProd.php?lg=fr';

   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 initSearchProd()
{
   if(prem)
   {
      $('searchProd').value = "";
      prem = false;
   }  
      
}

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/s06p02_pageGamme.php?prod=" + myId;
      else
         document.location.href = "/fr/s06_catalogue/s06p02_pageGamme.php?prod=" + myId;
   }
}