/*************************
*     iniFront.js
*  
* evenement jquery du front
* @author nicolas rossi
*************************/
 

 $(function(){  
        
       
        
       $("#boxChangeLanguage a").click(function()
       {
            var lang = $(this).attr("id");             
            $.ajax({
                    type: "post",
                    url: sPath+"data/manageAjax.php",                     
                    data: "action=switchLangage&lang="+lang,
                    dataType: "xml",  
                    success: function(xml){
                        if($(xml).find('ERREUR').text()=='oui')
                        {
                            
                        }
                        else {                            
                            window.location.reload(false);  
                        } 
                    } 
            }); 
       }); 
       
       $("#txtRecherche").click(function()
       {
            $(this).val(""); 
            $(this).unbind( "click"); 
            
       });
       
     
        
          
       /***************************/
       /***    MENU EXTRANET    ***/
       /***************************/
       $("#extranetMenu > ul > li").hover(function()
          {    
              //$(this).addClass("colorSubMenu1");          
              $(this).find("ul.extranetSousMenu1").show();
              $(this).find("a:first").attr("id","mainMenuHover")/*.css("padding","5px 9px")*/; 
              $("#mainMenuHover").css("padding","5px 10px");
          },function()
          {          
              //$(this).removeClass("colorSubMenu1");
              $("#mainMenuHover").css("padding","5px 11px");
              $("#extranetMenu ul:first li a").removeAttr("id")/*.css("padding","5px 10px 5px 10px")*/;
              //$(this).find("ul.extranetSousMenu1").hide();
              $("#extranetMenu .extranetSousMenu1").hide();
              
          }); 
          //sous menu 2
       $("#extranetMenu ul.extranetSousMenu1 > li").hover(function()
          {  
              //$(this).addClass("colorSubMenu2");                 
              $(this).find("ul.extranetSousMenu2").show();
              $(this).find("a:first").css("background", "#7f7f7f");              
          },function()
          {    
              //$(this).removeClass("colorSubMenu2");  
              $(this).find("a:first").css("background", "#616161"); 
              //$(this).find("ul.extranetSousMenu2").hide(); 
              $("#extranetMenu .extranetSousMenu2").hide();
          }); 
          //sous menu 3
         $("#extranetMenu ul.extranetSousMenu2 > li").hover(function()
          {  
              //$(this).addClass("colorSubMenu2");                 
              $(this).find("ul.extranetSousMenu3").show();
              $(this).find("a:first").css("background", "#969696");
          },function()
          {    
              //$(this).removeClass("colorSubMenu2");  
              //$(this).find("ul.extranetSousMenu3").hide();
              $("#extranetMenu .extranetSousMenu3").hide(); 
              $(this).find("a:first").css("background", "#7f7f7f"); 
          });  
         
     
      

      
       /*****************************************/ 
      /**** overlay login homepage extranet ****/ 
      
      $("#extranetOverlayLogin").insertAfter("#wrapper");
       
       $("#extranetSectionChoice .openLogin").overlay({
            effect: 'apple',
            expose: '#f1f1f1',
            left: 'center', 
            top: '25%',            
            target: '#extranetOverlayLogin'            
       }); 
       
       $("#link_pwd_oublie").overlay({
        effect: 'apple',
        expose: '#f1f1f1',
        left: 'center', 
        top: '25%',            
        target: '#extranetForgetPwd'            
       });
       
       $("#link_pwd_oublie").click(function()
       {
            $("#forgerFormIcon img").hide();
            $("#forgetPwdMail").val("");
            $("#forgetFormMsgSuccess").hide();
            $("#submitForgetMail").show();             
            //$("#forgetFormMsg").empty(); 
       });
       
       $("#link_contact").overlay({
        effect: 'apple',
        expose: '#f1f1f1',
        left: 'center', 
        top: '20%',            
        target: '#extranetContact'            
       });
       
       
       $("#submitForgetMail").click(function()
       {
            var mail = $("#forgetPwdMail").val();
            //verificiation du mail si bon on envoie au php pour vérifier en base de données
            if(checkmail(mail))
            {   
                    $.ajax({
                        type: "post",
                        url: sPath+"data/manageAjax.php",
                        data: "action=forgetPwd&mail="+mail,
                        dataType: "xml",
                         beforeSend: function(){
                            $("#forgerFormIcon img").hide();
                            $("#forgetPwdLoadIcon").fadeIn();   
                            $("#forgetFormMsg span").hide();                                        
                        },                        
                        success: function(xml){ 
                                if($(xml).find('ERREUR').text()=='oui')
                                {
                                    $("#forgerFormIcon img").hide();  
                                    $("#forgetFromWrong").show(); 
                                    if($(xml).find('MESSAGE').text()=='noresponse'){
                                     $("#forgetFormMsgNoResponse").show();
                                    }
                                    else if($(xml).find('MESSAGE').text()=='badmail'){
                                      $("#forgetFormMsgBadMail").show();               
                                    }                                                            
                                    //$("#forgetFormMsg").html($(xml).find('MESSAGE').text()).css("color","#aa0000");
                                }
                                else {
                                    $("#forgerFormIcon img").hide(); 
                                    $("#forgetFromTrue").show();
                                    $("#forgetFormMsgSuccess").show();
                                    $("#submitForgetMail").hide();
                                    //$("#forgetFormMsg").html($(xml).find('MESSAGE').text()).css("color","#085699");
                                }
                            }
                           
                      });        
            }
            else {
            $("#forgerFormIcon img").hide(); 
            $("#forgetFromWrong").show(); 
            $("#forgetFormMsgBadMail").show();            
            }  
            
       });
       
       
       $("#link_contact").click(function()
       {
             $("#contactMessage").val("");
             $("#contactFormMsg span").hide();
             $('#submitSendContact').show();
             
       }); 
       
       $("#submitSendContact").click(function()
       {
            var name = $("#contactName").val();
            var numClient = $("#contactNumClient").val();
            var phone = $("#contactPhone").val();
            var mail = $("#contactMail").val();
            var message = $("#contactMessage").val();
            var section = $("#sectionName").val();
            var sectionId = $("#sectionId").val();
            
            
           
           $.ajax({
                        type: "post",
                        url: sPath+"data/manageAjax.php",
                        data: "action=sendContact&name="+name+"&numClient="+numClient+"&phone="+phone+"&mail="+mail+"&message="+message+"&section="+section+"&sectionId="+sectionId,
                        dataType: "xml",
                        beforeSend: function(){
                            $("#contactFormIcon img").hide();
                            $("#contactPwdLoadIcon").fadeIn();
                            $("#contactFormMsg span").hide();                                           
                        },                        
                        success: function(xml){ 
                                if($(xml).find('ERREUR').text()=='oui')
                                {
                                    $("#contactFormIcon img").hide();  
                                    $("#contactFromWrong").show();                              
                                    $("#contactFormMsgChamps").html($(xml).find('MESSAGE').text()); 
                                    $("#contactFormMsgChamps").show();  
                                }
                                else if($(xml).find('ERREUR').text()=='non'){
                                    $("#contactFormIcon img").hide(); 
                                    $("#contactFromTrue").show(); 
                                    //$("#contactFormMsg").html($(xml).find('MESSAGE').text()).css("color","#085699");    
                                    $('#submitSendContact').hide();                               
                                    $("#contactFormMsgSuccess").show();
                                    
                                }
                        },
                        error: function(xml){                                                               
                             $("#contactPwdLoadIcon").fadeOut(); 
                             //$("#contactFormMsgChamps").html($(xml).find('ERREUR').text());
                             $("#contactFormMsgError").show();  
                        }       
                           
           });
       
       });   
      
 
        /*** scroller home page export ****/
        $("#extranetScrollHome").scrollable({
        speed:800,
        loop: true,        
        size:7,
        items: '#extranetScrollHome .items',
        item: '#extranetScrollHome div.homeItem',
        clickable:false,
        next: '.forward',
        prev: '.backward' 
        }).circular()./*autoscroll({
        interval: 1500        
        }).*/mousewheel(); 
        
        
        $("#extranetNewsContainer").tabs("#extranetNewsContainer div.newsText", {tabs: 'h2', effect: 'slide', initialIndex: 0});
        
        $("#buttonSearchAdvanced").toggle(function()
        {         
            $("#extranetAdvancedSearch").slideDown();
            $("#buttonMoreless").addClass("buttonLess");
            $("#buttonMoreless").removeClass("buttonMore");
        },function()
        {         
           $("#extranetAdvancedSearch").slideUp();
           $("#buttonMoreless").addClass("buttonMore");
           $("#buttonMoreless").removeClass("buttonLess");
        });
        
        $(".homeItem").hover(function()
        {
           $(this).find(".homeItemTip").show();
        },function()
        {  
           $(this).find(".homeItemTip").hide();
        });
        
        
        
        
        
      
         $("#extranetGallery .thumbnail").hover(function(){
                $(this).find("a.galleryImgTitle").addClass("galleryImgTitleHover");        
                //$(this).removeClass("galleryImgTitle"); 
         },function(){
                //$(this).addClass("galleryImgTitle"); 
                $(this).find("a.galleryImgTitle").removeClass("galleryImgTitleHover"); 
         });  
         
         
         /** WSLIDE SUR LA GALLERY PHOTOS **/
         if ($.fn.wslide)
         { 
              $('ul#wslideGallery').wslide({
                  width: 940, 
                  height: 410,
                  duration:300,        
                  horiz: true,
                  autolink: 'pagerGallery'         
              });
          }  
          
         if ($.fn.wslide)
         { 
              $('ul#wslideDirectory').wslide({
                  width: 940, 
                  height: 710,
                  duration:300,        
                  horiz: true,
                  autolink: 'pagerGallery'         
              });
          }   
        
          $("div#fileSlider").scrollable({                  
                items: '.items',                    
                item: 'div.itemsBox',
                clickable: false,
                size: 7,
                next: '.forward', 
                prev: '.backward'  
          }).mousewheel();  
      
            $(".itemsBox").hover(function()
            {
               $(this).find(".itemBoxTip").show();
            },function()
            {  
               $(this).find(".itemBoxTip").hide();
            });
      
      
         /*** OVERLAY TERME OF USE *****/
         $("#termeOfUsePopUp").insertAfter("#wrapper"); 
      
         $("#conditionsPopUp").overlay({
            effect: 'apple',
            expose: '#f1f1f1',
            left: 'center', 
            top: '15%',            
            target: '#termeOfUsePopUp'            
         }); 
         
         
                  
        /**********************************************************************/
        /************************    gestion téléchargement    ****************/
        /**********************************************************************/
        $("#conditions").click(function()
        {                       
            if($("#conditions").is(":checked"))
             {
                
                
                 var type = $("input[name=fileUnilangue]").val();                  
                  if(type == 'uni')
                  {
                        $("#downloadFile").attr('href',$("input[name=fileLocation]").val());
                        $("#idFileName").val($("input[name=fileLocation]").attr("rel"));
                        $("#downloadFile").show();
                        //var link = $("input[name=fileLocation]").val();
                        //window.location(link);
                  }
                  else if(type == 'multi')
                  {
                        if($("input[name=choiceLangueFile]").is(":checked"))
                        {       
                                $("#downloadFile").show();
                        }
                        
                  } 
            }
             else {
                 $("#downloadFile").hide();
            }       
        });
        
        $("input[name=choiceLangueFile]").click(function()
        { 
             $("#downloadFile").attr('href',$(this).val());
             $("#idFileName").val($(this).attr("rel"));
              
             if($("#conditions").is(":checked"))
             {
                 $("#downloadFile").show(); 
             } 
        });
       
        
        
        //lancement du log de téléchargement
        $("#downloadFile").click(function()
        {
            var idUser = $("#idUser").val();      
            var idFileName = $("#idFileName").val();  
            logDownload(idUser,idFileName);    
        });
       
       
       
       
       
       
        
           

   //lancement fonction preload d'image pour les images ï¿½ charger (hover sur action) 
      preload(
          sPathImg+"sitesLPG.gif",
          sPathImg+"overlay/white.png",
          sPathImg+"overlay/whiteRemix.png",
          sPathImg+"overlay/white_large.png",
          sPathImg+"overlay/close.png",
          sPathImg+"flag/France-Flag.png",
          sPathImg+"flag/Italy-Flag.png",
          sPathImg+"download.gif",
          sPathImg+"flag/England-flag.png"
      );   
    


 });//fin du onLoad
 

 
/**
* @desc récupération en ajax d'un define word with translate class
* @param word 
**/
function getWordTranslate(word)
{
    
    $.ajax({
        type: "post",
        url: sPath+"data/manageTranslate.php",
        data: "action=getWordDefine&word="+word,
        dataType: 'text',                          
        success: function(data){
            if(data > 0)
            {   
                   write(data);
            }
            else return false;                        
        }
     }); 
       
}

function logDownload(idUser, idFileName)
{     
       //alert(idUser+" : "+idFileName);
       
       if(idUser=='')
       idUser = 'unknown';
       
       $.post( sPath+"data/manageLog.php", { action: "logDownload", user: idUser, file: idFileName } );
       
}