// JavaScript Document
/*## FORM formulaire ##*/

function showInfoComp(toShow){
	//alert(toShow);
	jQuery('#'+toShow).toggle('slow');
}

function formulaireForm(){	
//alert('toto');
	jQuery("#nb_enfants_foyer").bind('change', function(){
		makeChildBirthday(this.value)
	});
	
	
// conditionne affichage marquess de lait

	jQuery("#marque_lait .hide").hide();
	jQuery("#infos_complementaires #type_lait4").bind('change', function(){
		if((jQuery('input:checkbox[name=type_lait4]:checked').val()==undefined) && (jQuery('input:checkbox[name=type_lait5]:checked').val()==undefined)){
			jQuery("#marque_lait .hide").hide();
		}else{
			jQuery("#marque_lait .hide").show();
		}
	});
	jQuery("#infos_complementaires #type_lait5").bind('change', function(){
		if((jQuery('input:checkbox[name=type_lait4]:checked').val()==undefined) && (jQuery('input:checkbox[name=type_lait5]:checked').val()==undefined)){
			jQuery("#marque_lait .hide").hide();
		}else{
			jQuery("#marque_lait .hide").show();
		}
	});	
	
	//-- Verifie que pas plus de 2 reponses a la question sur l alimentation
	jQuery("#bloc9 input").bind('change', function(){											  
		var nbCheck=0;
		var thisCheckId='';	
		jQuery("#bloc9 input").each(function() { 
							thisCheck		=	(jQuery('#'+this.id).is(":checked") ? 1 : 0);
							thisCheckId		+=	(jQuery('#'+this.id).is(":checked") ? this.id+'&' : '');
							nbCheck			=	parseInt(thisCheck) + parseInt(nbCheck);
		});		
		if(nbCheck>=2){		
							desactiveChecks(thisCheckId);
							jQuery('<input id="bonne_alimentation_full" name="bonne_alimentation_full" value="ok" type="hidden" />').appendTo('#bloc9');							
		}else{				
							activeChecks();
							jQuery('#bonne_alimentation_full').remove();
		}
	});	
}




function makeChildBirthday(nbEnfants){
		if(nbEnfants!=0){
			jQuery('#dateNaissanceEnfantsLabel').fadeIn();
			jQuery('#dateNaissanceEnfants').fadeIn();
			jQuery('#dateNaissanceEnfants').empty();
			for(i=0; i<nbEnfants; i++){
				jQuery('<input name="ageEnfant_'+i+'" id="ageEnfant_'+i+'" class="calendar ageEnfant" type="text"/><label for="ageEnfant_'+i+'">Enfant '+eval(i+1)+'</label><p class="clear"/>').appendTo('#dateNaissanceEnfants');
			}
			jQuery(function() {
				jQuery('.calendar').datepicker({
					changeMonth: true,
					changeYear: true,
					yearRange: 'c-100:c+12'
				});
			});
		}else{
			jQuery('#dateNaissanceEnfantsLabel').fadeOut();
			jQuery('#dateNaissanceEnfants').fadeOut();	
		}	
}	





function desactiveChecks(checks){
	checks	=	checks.split("&");
	checks[0];
	checks[1];
	jQuery("#bloc9 input").each(function() {
		if((this.id!=checks[0])&&(this.id!=checks[1])){									
			jQuery("#bloc9 input#"+this.id).attr('disabled','disabled');
		}
	});	
}
function activeChecks(){
	jQuery("#bloc9 input").each(function() { 
		jQuery("#bloc9 input").removeAttr('disabled');
	});	
}
function verifBonneAlim(state){
	if(state=='ok'){
		jQuery('#BonneAlimentationContainer > input').each(function(){
			if(jQuery('#'+this.id).attr('checked')==false){
				jQuery("#bloc9 input#"+this.id).attr('disabled','disabled');
			}
		})											  
	}
}
/*## Fin FORM formulaire ##*/
