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

$(function(){
     
     if($.fn.cycle)
     {      
         $('#slideHomePage').cycle({
            fx: 'scrollHorz',
            speed: 1500,
            pager: '#nav',
            timeout: 4000
         });
         
         $("#slideHomePage").hover(function()
         {
               $('#slideHomePage').cycle('pause');
         },function()
         {
              $('#slideHomePage').cycle('resume');  
         });
         
     }
     
     $("#menu > li.menu_with_submenu").hover(function()
    {
            $(this).find(".sousmenu_deroulant").show();
            $(this).find("a:first").attr("id","mainMenuHover"); 
            $("#slideHomePage").css("z-index",-1);                  
            $("#divSearch").css("z-index",0);                  
            $("#divParam").css("z-index",-1);                  
    },function()
    {
           $("#menu .sousmenu_deroulant").hide();    
           $(this).find("a:first").removeAttr("id");  
           $("#slideHomePage").css("z-index",1);  
           $("#divSearch").css("z-index",2);                  
            $("#divParam").css("z-index",1); 
    });
    
    $("#lastMenu").hover(function()
    {
         $("li.finmenu").addClass("finmenu_hover");    
    },function()
    {
        $("li.finmenu").removeClass("finmenu_hover"); 
    });
     
     
      if ($.fn.wslide)
      { 
              $('ul#wslideGalleryPhotos').wslide({
                  width: 940, 
                  height: 710,
                  duration:300,        
                  horiz: true,
                  autolink: 'pagerGallery'         
              });
      }  
      
    
      
           /*
      
            $("#container_wslide").scrollable(
                speed:800, 
                items: '.items',
                item: '.item',                
                next: '.forward',
                prev: '.backward',
                api: true,
                onSeek: function(event, i) {
                   alert("toto");         
                }    
            );
                  */
   
      
      if ($.fn.lightBox)
      {
          $('#wslideGalleryPhotos a').lightBox({
                imageLoading: 'http://www.lpgsystems.net/img/lightbox-ico-loading.gif',
                imageBtnClose: 'http://www.lpgsystems.net/img/lightbox-btn-close.gif',
                imageBtnPrev: 'http://www.lpgsystems.net/img/lightbox-btn-prev.gif',    
                imageBtnNext: 'http://www.lpgsystems.net/img/lightbox-btn-next.gif'
           });
      }
     
 
 
 });


 
function checkMail()
{
    
     
      var lastName = $("#txtLastName").val();      
      var firstName =  $("#txtFirstName").val();
      var city =  $("#txtCity").val();
      var zip =  $("#txtZip").val();
      var mail =   $("#txtMail").val();
      var phone =   $("#txtPhone").val();
      var message =   $("#txtMessage").val();
      $("#formulaireContactErrorManque").hide();
      
      
      $(".statusChamps img").hide();
      $(".champs").removeClass("champsRed");
      $(".champs-textarea").removeClass("champsRed");
      
      var error=false;
      
      if(lastName==''){
        $("#txtLastName").addClass("champsRed");
        $("#statusChampsLastName .iconWrong").show();
        error=true;
        
      }
      else  $("#statusChampsLastName .iconTrue").show();
      
      if(firstName==''){
        $("#txtFirstName").addClass("champsRed");
        $("#statusChampsFirstName .iconWrong").show();
        error=true;
      }
      else  $("#statusChampsFirstName .iconTrue").show();
      
      if(city==''){
        $("#txtCity").addClass("champsRed");
        $("#statusChampsCity .iconWrong").show();
        error=true;
      }
      else  $("#statusChampsCity .iconTrue").show();

      if(zip==''){
        $("#txtZip").addClass("champsRed");
        $("#statusChampsZip .iconWrong").show();
        error=true;
      }
      else  $("#statusChampsZip .iconTrue").show();
      
      if(mail==''){
        $("#txtMail").addClass("champsRed");
        $("#statusChampsMail .iconWrong").show();
        error=true;
      }
      else  $("#statusChampsMail .iconTrue").show();
      
      if(phone==''){
        $("#txtPhone").addClass("champsRed");
        $("#statusChampsPhone .iconWrong").show();
        error=true;
      }
      else  $("#statusChampsPhone .iconTrue").show();
      
      if(message==''){
        $("#txtMessage").addClass("champsRed");
        $("#statusChampsMessage .iconWrong").show();
        error=true;
      }
      else  $("#statusChampsMessage .iconTrue").show();
      
      
      if(error==false)
      {
         sendMail(lastName, firstName, city, zip, mail, phone, message);
      }
      else {
          $("#formulaireContactErrorManque").show();
      }
 
 }
 
 function sendMail(lastName, firstName, city, zip, mail, phone, message)
 {
 
       $.ajax({
                        type: "post",
                        url: "data/mail.php",
                        data: "lastName="+lastName+"&firstName="+firstName+"&city="+city+"&zip="+zip+"&mail="+mail+"&phone="+phone+"&message="+message,
                        dataType: "xml",
                        beforeSend: function(){
                            $("#btnSend").hide();
                            $("#formBouton img").show();                                               
                        },                        
                        success: function(xml){ 
                                if($(xml).find('ERREUR').text()=='oui')
                                {                                        
                                    $("#formBouton img").hide();
                                    $("#btnSend").show();
                                    $("#formulaireContactError").show();
                                      
                                }
                                else if($(xml).find('ERREUR').text()=='non') {                                   
                                   $("#formulaireContact").hide();
                                   $("#formulaireContactSuccess").show(); 
                                }
                                else if($(xml).find('ERREUR').text()=='manque') {
                                    $("#formBouton img").hide();
                                    $("#btnSend").show();
                                   $("#formulaireContactErrorManque").show();
                                } 
                        },
                        error: function(xml){                                  
                           
                        }
                           
           });     
 
 
 }
 
