// fonction de switch des nouveautés
function switchNouveautes(id)
{//alert("passer page"+id);

if(id!=undefined)
{
 $.ajax({
   type: "GET",
   url: "lib/pages/nouveautes_accueil.php",
   data: "id="+id,
   success: function(msg){
	   //alert("passer page"+msg);
    $("#bloc_nouveautes").html(msg); 
	
   }
 });
}
}


$(document).ready(function (){
			
	
			$("#flivraisonv").validate({
	onfocusout: true,
onkeyup: true
/*showErrors: function(errorMap, errorList) { 
if (errorList.length > 0) {
jQuery('#msgerror').html( errorList[0].message);        }    },*/

});

			
							
							
				//validation formulaire inscription
				
		 $("#finscriptionv").validate({
	onfocusout: true,
onkeyup: true, 
showErrors: function(errorMap, errorList) { 
if (errorList.length > 0) {
jQuery('#msgerror').html( errorList[0].message);        }    },

rules: {
    passwd: "required",
    passwd2: {
      equalTo: "#passwd"
    }
  }




});
				
				
				
			
			// rafaraichissement captcha				   
	$("#refreshimg").live("click",function(){
		$.post('captcha/newsession.php');
		$("#captchaimage").load('captcha/image_req.php');
		return false;
	});
	
	// validation du formulaire contact
	$("#contactForm").validate({
		rules: {
			captcha: {
				required: true,
				remote: "captcha/process.php"
			}
		},
		messages: {
			captcha: "<br/>Captcha correcte doit être saisi. <br/>Cliquez le captcha pour générer de nouveau."	
		}
	
	/*	success: function(label) {
			label.addClass("valid").text("Valid captcha!")
		},*/
		
	});
			
			
							
		//faqs
		
	$("a.rubfaq").click(function(){
								 
								 
			$("div.reponses_zone").not($(this).nextAll("div.reponses_zone:first")).slideUp("fast");				 
	$(this).nextAll("div.reponses_zone:first").slideDown("fast");							 
								 
								 });
							
			
			$("#adresseliv").click(function(){
											 //alert("testnc");	
								
					 if ($(this).not(":checked") ) {
						 
  	                $("#tablivraison input").not($(this)).val("");
					$("#tablivraison input.requi").addClass("required");
					//alert("testnc");							
										
					}
					 if ($(this).is(":checked") ) {
						$("#tablivraison input.requi").removeClass("required");
					//alert("testc");
						
						}
					
					});
					
								
							

							
							
 // light box videos
if($("a.fancyboxvideo").length>0)
$("a.fancyboxvideo").fancybox({ 'hideOnContentClick': true,
		   					'frameWidth': 350,
		   					'frameHeight': 270 });							
							
//Evenement ouverture fermeture menu
/*$("#menu div").click(function(){ 
							  if($(this).attr("class")!='rubouverte')
							  {
							  var menuencours=$(this); $("#menu div").not(menuencours).children("ul").slideUp("fast",function(){ $(this).parent("div").removeClass("rubouverte"); $(this).parent("div").addClass("rub");  menuencours.children("ul").slideDown("slow"); menuencours.addClass("rubouverte"); menuencours.removeClass("rub");   }); 
							  }
							  });*/

//Evenement click suiv prec nouveautes accueil
$("#newp a.precnouv").live("click",function(){ switchNouveautes($("#newp a.numerotselec").prev("a.numerot:first").attr("name")); });
$("#newp a.suivnouv").live("click",function(){switchNouveautes($("#newp a.numerotselec").next("a.numerot:first").attr("name")); });
							
							
//Evenement click bt authentification		
$("#bt_authentification").click(function(){
								//alert("email "+$("#temail").val()+"   pass"+$("#tpassword").val());		 
						 $.ajax({
   type: "POST",
   url: "lib/check_user.php",
   data: "email="+$("#temail").val()+"&password="+$("#tpassword").val(),
   success: function(msg){
	   
	  // alert (msg);
	   if(msg=="ok")
	   $("#fidentite").submit()
	   
	   if(msg=="ko")
	   $("#msg_echec").html('Echec authentification ! ');
    
	
   }
 });							 
										 
										 
										 
										 });	

//Evenement click bt passe oublier		
$("#bt_oubli").click(function(){
								//alert("email "+$("#temail").val()+"   pass"+$("#tpassword").val());		 
						 $.ajax({
   type: "POST",
   url: "lib/oubli_pass.php",
   data: "email="+$("#temailo").val()+"",
   success: function(msg){
	 
	   $("#msg_echeco").html(msg);
    
	
   }
 });							 
										 
										 
										 
										 });							
			
			
							
							
							});
