/*  Le Phare JavaScript library - (c) 2007
/*--------------------------------------------------------------------------*/
var prem = true;
var premrr = true;

Event.handler = {
   register: function(element) {
   
      if($(element)) {
         switch (element) {
            case 'pageGuideChoixForm':
               gestGuideChoix();
               break;
            case 'pageFicheProduit':
               affLayer();
               findCat();

            break;
            case 'pageFaq':
            
            break;
            case 'jsPageContact':
               initFormContact();
            break;
            case 'jsPageJeux':
               initFormJeux();
            break;
            case 'pageCorpoA':
            case 'pageFamilleProduits':
               funct_gilder();
            break;
            case "pageEmploi":
               if($('formEmploi'))
               {
                  var zeForm2 = new Validation('formEmploi',{useTitles:true,stopOnFirst:true,onFormValidate: function() {$('todo').value = "submit_quest";}});
                  var calDateEndDisp =    Calendar.setup({inputField:"data_date_end_disp_", button:"date_end_disp_trigger", ifFormat:"dd/mm/y", mondayFirst:true, onSelect:setDate, displayArea : "date_end_disp_trigger",align : "Bl"});
               }
            break;
            case "pageCorpoF":
            if($('zoneGoogleMap'))
                  load();
            break;
            case 'pageCorpoE':
               click_Region();
               click_RegionNG();
            break;
            case 'choixDevisExpress':
               initConfigurateur();
            break;
            default:
         }
         
      }
   }// register
}              

// load
Event.observe(window, 'load', function() {
      Event.handler.register(document.body.id);
      // ajout de modif sur tout le site
      
      Event.observe('inscription','click', funct_newsletter);

      Event.observe('recherche','click',function(){ funct_RechRapide();});

});
function funct_newsletter()
{
   if(prem)
   {
      $('inscription').value='';
      prem = false;
   }
}

function funct_RechRapide()
{

   if(premrr)
   {

      $('recherche').value='';
      premrr = false;
   }

}

function funct_gilder()
{
   if($('my_glider'))
   {
      var myGlider = new Glider('my_glider', {duration:0.5});
      
   }   
   if($('btnPrecedent'))
      Event.observe('btnPrecedent','click',function(){if(myGlider)myGlider.previous(); });
      
   if($('btnSuivant'))
      Event.observe('btnSuivant','click',function(){if(myGlider)myGlider.next(); });      
}
function affLayer()
{
   if($('lnkSecurite'))
   {
      Event.observe('lnkSecurite','mouseover', function(){
         $('layerSecu'+ $F('jsEtoile')).show();
      });
      Event.observe('lnkSecurite','mouseout', function(){
         $('layerSecu'+ $F('jsEtoile')).hide();
      });
   }
}

function gestGuideChoix()
{
   $('zeform').reset();
   var valid = new Validation('zeform', {useTitles:true, immediate:true, stopOnFirst:true,  debug:true});
   
   Event.observe('plateforme','click',functPF);
   Event.observe('echafaudage','click',functEchaf);
   // si rafraichissement
   if($('echafaudage').checked)
   {
      $('blocPlateforme').hide();
      $('blocEchafaudage').show();
   }
   else if($('plateforme').checked)
   {
      $('blocPlateforme').show();
      $('blocEchafaudage').hide();
   }
   else
   {
      $('blocPlateforme').hide();
      $('blocEchafaudage').hide();
   }
     
   if($('choixHauteurA'))
   {
      Event.observe('choixHauteurA','click',functChoixA);
      Event.observe('choixHauteurB','click',functChoixB); 
      Event.observe('choixHauteurC','click',functChoixC);
   }     
   
   if($('choixHauteurMaxA'))
   {
      // si  rafraichissement de la page 
            
      if($('besoinEchaB').checked)
         $('largeur_porte').show();
      else
         $('largeur_porte').hide();
         
               
      if($('besoinEchaC').checked)
         $('rentabilite').show();
      else
         $('rentabilite').hide();         
      //-------------------------------------------
      Event.observe('choixHauteurMaxA','click',functChoixMaxA);
      Event.observe('choixHauteurMaxB','click',functChoixMaxB);
      Event.observe('choixHauteurMaxC','click',functChoixMaxC);
      Event.observe('choixHauteurMaxD','click',functChoixMaxD);
      Event.observe('choixHauteurMaxE','click',functChoixMaxE);
      
      Event.observe('besoinEchaB','click',function(){
         if($('besoinEchaB').checked)
            $('largeur_porte').show();
         else
            $('largeur_porte').hide();
      });
      Event.observe('besoinEchaC','click',function(){
         if($('besoinEchaC').checked)
            $('rentabilite').show();
         else
            $('rentabilite').hide();
      });
   }
}
function functChoixMaxA()
{
   $('jsMatiereB').show();
   
   $('jsLongueurPlancherA').show();
   $('jsLongueurPlancherB').hide();
   $('jsLongueurPlancherC').hide();
   $('jsLongueurPlancherD').hide();

   
}
function functChoixMaxB()
{
   $('jsMatiereB').show();
   
   $('jsLongueurPlancherA').show();
   $('jsLongueurPlancherB').show();
   $('jsLongueurPlancherC').show();
   $('jsLongueurPlancherD').show();

   
}
function functChoixMaxC()
{
   $('jsMatiereB').show();
   
   $('jsLongueurPlancherA').show();
   $('jsLongueurPlancherB').show();
   $('jsLongueurPlancherC').show();
   $('jsLongueurPlancherD').show();
 
}
function functChoixMaxD()
{
   $('jsMatiereB').show();
   
   $('jsLongueurPlancherA').hide();
   $('jsLongueurPlancherB').show();
   $('jsLongueurPlancherC').show();
   $('jsLongueurPlancherD').show();
 
}
function functChoixMaxE()
{
   $('jsMatiereB').hide();
   
   $('jsLongueurPlancherA').hide();
   $('jsLongueurPlancherB').hide();
   $('jsLongueurPlancherC').show();
   $('jsLongueurPlancherD').show();
 
}
function functChoixA()
{
   $('jsBesoinA').show();
   $('jsBesoinB').show();
   $('jsBesoinC').show();
   $('jsBesoinD').show();
}
function functChoixB()
{
   $('jsBesoinA').show();
   $('jsBesoinB').show();
   $('jsBesoinC').show();
   $('jsBesoinD').hide();
}
function functChoixC()
{
   $('jsBesoinA').show();
   $('jsBesoinB').show();
   $('jsBesoinC').hide();
   $('jsBesoinD').hide();
}


function functPF()
{
   $('blocPlateforme').show();
   $('blocEchafaudage').hide();
}
function functEchaf()
{
   $('blocPlateforme').hide();
   $('blocEchafaudage').show();
}

function findCat()
{
   if($('jsCatProd'))
   {
      if($('jsProd'+$F('jsPCatProd')))$('jsProd'+$F('jsPCatProd')).show();
      if($('jsProd'+$F('jsCatProd')))
      {
         if($('jsC'+$F('jsPCatProd')))$('jsC'+$F('jsPCatProd')).show();
         $('jsProd'+$F('jsCatProd')).show();
         
      }
   }
}
function initFormContact()
{
   var zeForm2 = new Validation('zeFormValide',{
      useTitles:true,
      stopOnFirst:true,
      onFormValidate: function() {$('todo').value = "submit_quest";}
   });


   if($('searchSubmitter')) {
      Event.observe('searchSubmitter', 'click', function() {$('search_todo').value = "email-subscribe"; $('zeForm').submit();});
   }

   if($('errMsg')) {
      if($('errMsg').innerHTML  != '') {
         Element.show('errMsg'); Effect.BlindUp('errMsg', {delay:3});
      }
   }
}

// ouvre une fenêtre en popup

function open_window(url, height, width)
{
 window.open(url, 'popup', 'height='+height+', width='+width+', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
}
function click_Region()
{
   $$('.jsArea').each(function(obj){

      Event.observe(obj,'click',function(){

      open_layer(obj.id)});
   });
   
   $$('.btnFermer').each(function(obj){

      Event.observe(obj,'click',close_layer);
   });
   
}
function open_layer(element)
{
   close_layer();

   Celement = element.replace('jsL','l');
   $(Celement).show();

}

function close_layer()
{
   $$('.jsLayer').each(function(obj){
      obj.hide();
   });
}

/***************************************************************************************/
// Nouvelle carte commerciaux
/***************************************************************************************/
function click_RegionNG()
{
  if($('jsLayer'))
  { 
     Event.observe('jsBtnFermer','click',btnFermerHideMe);
      
      $$('#Map area').each(function(obj){
   
         Event.observe(obj,'click',function(myClick){
                 var tab_tmp = this.id.split('_');
                 
                 var id_comm = tab_tmp[2],dpt_click = tab_tmp[1],
                     layer      = $('jsLayer'),
                     url = '../s02_corporate/_ajax_commercial.php',
                     top =  (myClick.layerY || myClick.y)-20 + 'px',
                     left = (myClick.layerX || myClick.x) + 'px' ;
           
                  $('jsLayer').setStyle({'top':top,'left':left}) 
                  new Ajax.Request(url, 
                                   {method: 'get',
                                    parameters:{id_comm: id_comm,dpt_click: dpt_click},
                                    evalJS: true,
                                    onSuccess: function(transport) {     
                                                var objContent = transport.responseText.evalJSON();
                                                if(objContent.maj)
                                                {
                                                   layer.hide();     
                                                   Event.stopObserving('jsBtnFermer','click',btnFermerHideMe);
                                                   layer.update(objContent.content);
                                                   Event.observe('jsBtnFermer','click',btnFermerHideMe);
                                                   layer.show();
                                                }
                                             }
                                   });       
         });
      });
   }
}
function btnFermerHideMe(Layer)
{
  $('jsLayer').hide()
}

function initConfigurateur()
{


   $$('.jsGamme').each(function(obj){
      obj.checked=false;
      Event.observe(obj,'click',function(){set_SelectSousGamme(obj.value);});
    });

   $$('.jsProd').each(function(obj){
      obj.checked=false;
      Event.observe(obj,'click',function(){get_ProdCompo(obj.value);});
    });
}

function set_SelectSousGamme(id)
{
   // on cache tous les bloc de sélection de sous gammes
   $$('.jsSousGamme').each(function(obj){obj.hide();});
   $('jsCritere').hide();

   // Et on affichage le bloc de la sous gamme sélectionné (sauf si gamme =D49 car pas de sous gamme dans ce cas)
   switch(id)
   {
     case 'F3000' : $('jsTitleQuelTypeF3000').show();
                    $('jsF3000').show();
                    $('produit_D49').checked=false;
     break;

     case 'M4X'   : $('jsTitleQuelTypeMulti4x').show();
                    $('jsM4X').show();
                    $('produit_D49').checked=false;
     break;

     case 'D49' : $('gamme_F3000').checked=false;
                  $('gamme_Multi4x').checked=false;
                  get_ProdCompo(id);
     break;
   }
}

function get_ProdCompo(id)
{
   // mise a jour des paramètres du configurateur en fonction de la gamme de produit choisi
   URL = '/fr/s04_contact/s04p09_devis_express.php'
   pars = 'prod='+id;
   new Ajax.Request(URL, {
     method: 'get',
     parameters : pars,
     onSuccess:function(transport)
               {
                  var myObject = transport.responseText.evalJSON();
                  if(typeof myObject.erreur == 'undefined')
                  {

                     $('jsLongueur').replace(myObject.longueur);
                     $('jsHauteur').replace(myObject.hauteur);
                     $('jsCritere').show();
                  }
                  else
                  {
                     $('jsCritere').hide();
                     alert(myObject.erreur);
                  }
                  initFormDevisExpress();

               }
         });
}

function initFormDevisExpress()
{
   var zeForm2 = new Validation('zeform',{
      useTitles:true,
      stopOnFirst:true
   });
}

function initFormJeux()
{
   var zeForm3 = new Validation('zeFormJeux',{
      useTitles:true,
      stopOnFirst:true,
      onFormValidate: function() {$('todo').value = "submit_quest";}
   });

   if($('searchSubmitter')) {
      Event.observe('searchSubmitter', 'click', function() {$('search_todo').value = "email-subscribe"; $('zeForm').submit();});
   }

   if($('errMsg')) {
      if($('errMsg').innerHTML  != '') {
         Element.show('errMsg'); Effect.BlindUp('errMsg', {delay:3});
      }
   }
}
