function changerTypeCoach()
{
	if($("#cbmoniteur").is(":checked"))
	{$("#zonemoniteur").removeClass("ignore");$("#zoneprive").addClass("ignore");}
	else
	{$("#zonemoniteur").addClass("ignore");$("#zoneprive").removeClass("ignore");}
	
	if($("#cbmoniprive").is(":checked"))
	{$("#zonemoniteur").removeClass("ignore");$("#zoneprive").removeClass("ignore");}
}

function choisirSalle(ids)
{
	$("#id_coach").val('0');
	$("#id_salle").val(ids);
	
	$.fancybox.close();
}

function choisirCoach(idc)
{
	$("#id_coach").val(idc);
	$("#id_salle").val('0');
	
	$.fancybox.close();
}

function majPopup()
{
	//alert("test popup")
	$(".optpersta:checked").prev("a.ajaxlien").click();
	
	if($(".optpersta:checked").is("#optcoach1"))
	{
	if($("#id_coach").val()=='0') $("#id_coach").val('');
	$("#id_salle").val('0'); 
	}
	
	if($(".optpersta:checked").is("#optcoach2"))
	{
	$("#id_salle").val('0'); 
	$("#id_coach").val('0'); 	
	}
	
	
	if($(".optpersta:checked").is("#optcoach3"))
	{
	if($("#id_salle").val()=='0') $("#id_salle").val('');
	$("#id_coach").val('0'); 
	}
	
}

function changerNbrEnf(val)
{
	if(parseInt(val)>0)
	$('#zngrossesse').removeClass('ignore'); 
	else
	$('#zngrossesse').addClass('ignore');
	
	
}


function fumeurPassPart(val)
{
	if(val=='oui')
	{$('#znfpassif').removeClass('ignore');  }
	if(val=='non')
	{$('#znfpassif').addClass('ignore'); }
}




function fumeurActPart(val)
{
	if(val=='oui')
	{$('#znfactif').removeClass('ignore');  }
	if(val=='non')
	{$('#znfactif').addClass('ignore'); }
}


function compPart(val)
{
	if(val=='oui')
	{$('#zncomp').removeClass('ignore');  }
	if(val=='non')
	{$('#zncomp').addClass('ignore'); }
}


function regimePart(val)
{
	if(val=='oui')
	{$('#znregime').removeClass('ignore');  }
	if(val=='non')
	{$('#znregime').addClass('ignore'); }
}

function dieteticienPart(val)
{
	if(val=='oui')
	{$('#zndiet').removeClass('ignore');  }
	if(val=='non')
	{$('#zndiet').addClass('ignore'); }
}

function cancerPart(val)
{
	if(val=='oui')
	{$('#zncancer').removeClass('ignore');  }
	if(val=='non')
	{$('#zncancer').addClass('ignore'); }
}

function majMotivation()
{
	if($("#motivation1").val()!==$("#motivation2").val()!==$("#motivation3").val()!==$("#motivation4").val() )
	$("#motivation_differentes").val("ok");
	else
	$("#motivation_differentes").val("");
	
}

function activitePhysique(val)
{
	if(val=='oui')
	{$('#znclub').removeClass('ignore');  $('.detail_activite').addClass('ignore'); afficherDetails();}
	if(val=='non')
	{$('#znclub').addClass('ignore'); $('.detail_activite').addClass('ignore');}
}

function afficherDetails()
{
	
	$('.detail_activite').addClass('ignore');
	
	$("#znclub input[type=checkbox]").each(function(index) {
    if($(this).is(':checked')) $("#znactiv"+$(this).attr("ind")).removeClass('ignore');
	
	
  });
	
}


function changerCP(commu)
{
var cp=$("#select_cp").val();
//alert("le code postal est"+cp);	
var id_dept=cp.substring(0,2);
//alert("le departement est"+id_dept);
$('#select_dept option[value!='+id_dept+']').attr("selected", "");	
$('#select_dept option[value='+id_dept+']').attr("selected", "selected");

$.ajax({
   type: "POST",
   url: "lib/list_commune.php",
   data: "cp="+cp,
   success: function(msg){
    $("#select_ville").replaceWith(msg);
   }
 });	
	
}

function changerCP2(commu)
{
var cp=$("#select_cp2").val();
//alert("le code postal est"+cp);	
var id_dept=cp.substring(0,2);
//alert("le departement est"+id_dept);
$('#select_dept option[value!='+id_dept+']').attr("selected", "");	
$('#select_dept option[value='+id_dept+']').attr("selected", "selected");

$.ajax({
   type: "POST",
   url: "lib/list_commune2.php",
   data: "cp="+cp,
   success: function(msg){
    $("#select_ville2").replaceWith(msg);
   }
 });	
	
}

function changerDeptCFiche()
{

	var id_dept=$("#sdeptclub").val();
	//alert("le departement est :"+id_dept);
//$("#bt_valformu").hide();
	$("#slisteclub").replaceWith('<span id="slisteclub" style="float:left;"><img src="images/ajax-loader.gif" width="16" height="16" /></span>');
//maj modele
	$.ajax({
   type: "POST",
   url: "type_modele_ajax.php",
   data: "action=deptCfiche&dept="+id_dept,
   success: function(msg){
$("#slisteclub").replaceWith(msg);
$("#slisteclub a:first").click();
   }
 });	
	
}


function changerDeptFiche()
{
	var id_dept=$("#sdeptclub").val();
	//alert("le departement est :"+id_dept);
//$("#bt_valformu").hide();
	$("#slisteclub").replaceWith('<span id="slisteclub" style="float:left;"><img src="images/ajax-loader.gif" width="16" height="16" /></span>');
//maj modele
	$.ajax({
   type: "POST",
   url: "type_modele_ajax.php",
   data: "action=deptfiche&dept="+id_dept,
   success: function(msg){
$("#slisteclub").replaceWith(msg);
$("#slisteclub a:first").click();
   }
 });	
	
}

function changerCoachFiche(ids)
{
	

	$("#ajaxfiche").replaceWith('<span id="ajaxfiche" style="float:left;"><img src="images/ajax-loader.gif" width="16" height="16" /></span>');
//maj modele
	$.ajax({
   type: "POST",
   url: "type_modele_ajax.php",
   data: "action=coachfiche&ids="+ids,
   success: function(msg){
$("#ajaxfiche").replaceWith(msg);



   }
 });	
	
}

function changerSalleFiche(ids)
{
	

	$("#ajaxfiche").replaceWith('<span id="ajaxfiche" style="float:left;"><img src="images/ajax-loader.gif" width="16" height="16" /></span>');
//maj modele
	$.ajax({
   type: "POST",
   url: "type_modele_ajax.php",
   data: "action=sallefiche&ids="+ids,
   success: function(msg){
$("#ajaxfiche").replaceWith(msg);



   }
 });	
	
}

function changerDept()
{
	var id_dept=$("#sdeptclub").val();
$("#bt_valformu").hide();
	$("#slisteclub").replaceWith('<span id="slisteclub" style="float:left;"><img src="images/ajax-loader.gif" width="16" height="16" /></span>');
//maj modele
	$.ajax({
   type: "POST",
   url: "type_modele_ajax.php",
   data: "action=deptclub&dept="+id_dept,
   success: function(msg){
$("#slisteclub").replaceWith(msg);
$("#bt_valformu").show();
/*if($("#slisteclub").val()=="0")
$("#autre_club").removeClass("ignore");
else
$("#autre_club").addClass("ignore");*/


   }
 });	
	
}

 $(document).ready(function() {
	 
//cbjour click
$(".cbjour").click(function(){
	var iddiv=$(this).attr("ind");
	if($(this).is(":checked"))
	{$("#"+iddiv).removeClass("ignore");
	$("#"+iddiv+" select").attr('disabled', '');
	}
	else
	{$("#"+iddiv).addClass("ignore");
	$("#"+iddiv+" select").attr('disabled', 'disabled');
	}
	
	
	});
	 
//faq au question
$(".reponsequest").hide();
$(".slidefaq").not(".slidefaq:first").hide();

$("a.categorieouverte").click(function(){$(this).next(".slidefaq:first").toggle();});
$("a.question").click(function(){$(this).next("p.reponsequest:first").toggle();});

	 
	 

//click sur aucun
$(".cbprobrachis:first").click(function(){
	if($(this).is(':checked'))
	$(".cbprobrachis").not(".cbprobrachis:first").attr('checked', false);
	});	 
//click sur les autres
$(".cbprobrachis").not(".cbprobrachis:first").click(function(){
	$(".cbprobrachis:first").attr('checked', false);
	});	 
	
//click sur aucun
$(".cbprobarti:first").click(function(){
	if($(this).is(':checked'))
	$(".cbprobarti").not(".cbprobarti:first").attr('checked', false);
	});	 
//click sur les autres
$(".cbprobarti").not(".cbprobarti:first").click(function(){
	$(".cbprobarti:first").attr('checked', false);
	});	 
	 
//les select probleme antecedents
$(".traitementpro").change(function(){
	var valeur=$(this).val();
	if((valeur=='Aucun'))
	$("#sante"+$(this).attr('ind')).css('visibility','hidden');
	else
	$("#sante"+$(this).attr('ind')).css('visibility','visible');
	}); 

//fancybox ajax	
	if($(".ajaxlien").length>0)
{
	$(".ajaxlien").fancybox({
		ajax : {
		    type	: "POST"
		}
	});
}
	 
	 
//fancybox
if($("#amsgbox").length>0)
{
$("#amsgbox").fancybox({
	'showCloseButton': false,
				'padding'			: 0,
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
}
//fancybox
if($("#amsgbox_val").length>0)
{
$("#amsgbox_val").fancybox({
	'showCloseButton': false,
				'padding'			: 0,
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
}
			
	$('input.qtekey').keypress(function (event){ return event.keyCode == 13 ? false : true; });		
	
	// validation formulaire de contact
	$("#fbudget").validate({
		onfocusout: false,
		onkeyup: false,
		meta: "validate",					   
		submitHandler: function(form) {
			//alert("test soummettre contact");
			if(champsTotal())
			form.submit();
		},					  
		showErrors: function(errorMap, errorList){ 
			if (errorList.length > 0) {
				//alert("erreur");
				jQuery('#inline1').html( errorList[0].message); $("#amsgbox").click();
			}
		}
	});
			
// validation formulaire de contact
/*$.validator.setDefaults({
   debug: true
});*/

jQuery.validator.addMethod("tel", function(value, element) {
      return this.optional(element) || /^[0-9\_]{10,10}$/i.test(value);
  }, "• Le téléphone doit être numérique et sans espace (ex : 0122334455)");

//method not equal to
jQuery.validator.addMethod("notEqualTo", function(value, element, param) {
 return this.optional(element) || value != $(param).val();
 }, "This has to be different...");

	$("#fvalidation").validate({
		ignore: ".ignore input,.ignore select,.ignore textarea",
		onfocusout: false,
		onkeyup: false,
		meta: "validate",					   
		submitHandler: function(form) {
			//alert("test soummettre contact");
			form.submit();	
		},					  
		showErrors: function(errorMap, errorList){ 
			if (errorList.length > 0) {
				//alert("erreur");
				jQuery('#inline1').html( errorList[0].message); $("#amsgbox").click();
			}
		}
	}); 
	
//method not equal to group
jQuery.validator.addMethod("notEqualToGroup", function(value, element, options) {
// get all the elements passed here with the same class
    var elems = $(element).parents('form').find(options[0]);
// the value of the current element
var valueToCompare = value;
// count
var matchesFound = 0;
// loop each element and compare its value with the current value
// and increase the count every time we find one
jQuery.each(elems, function(){
thisVal = $(this).val();
if(thisVal == valueToCompare){
matchesFound++;
}
});
// count should be either 0 or 1 max
if(this.optional(element) || matchesFound <= 1) {
        elems.removeClass('error');
        return true;
    } else {
        elems.addClass('error');
    }
}, jQuery.format("Please enter a Unique Value."))
	
	
	
//date habilitation	
$( "#date_abo" ).datepicker({
						dateFormat: 'dd/mm/yy'
		
		});
	$("#date_abo").datepicker('option', 'dayNamesMin', ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa']);
	$("#date_abo").datepicker('option', 'monthNames', ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Decembre']);
	 
 });
