$(document).ready(function(){
		
	var courrielValid = false ;
	var defaultString = $("#input_courriel").val();
	
	$("#choixInfolettre").hide() ;
	$("#submitForm").hide() ;
	
	/* Verifie si au moins une checkbox est cochée */
	function countChecked() {
      var n = $("input:checked").length;
      if(n>0 && courrielValid=="1"){
		$("#submitForm").show() ;
		$("#fake").hide() ;
	  }else{
		$("#submitForm").hide() ;
		$("#fake").show() ;
	  }
    }
	
	/* Vérifie la validité du courriel */
	function checkCourriel() {
		courrielValid = $.ajax({ 
		type: "GET", 
		data: "courriel="+$("#input_courriel").val(), 
		url: ajaxPath+"verifEmail.php",
		async: false,
		success: function(msg){
			//alert( "Data Saved: " + msg );
		}
		}).responseText;
		countChecked();	
	}
	
    countChecked();
    $(":checkbox").click(countChecked);
	 
	/* Efface champs quand focus et ouvre choix */
	$("#input_courriel").focus(function(){	
		if ($(this).val() == defaultString) {
			$(this).val(''); 
			$("#choixInfolettre").slideDown("slow");
		}
	}); 
	
	/* Verifie la bonne forme du courriel */
	$("#input_courriel").keyup(checkCourriel);
	$("#input_courriel").change(checkCourriel);

	/* Soumission du formulaire */
	$("form:first").submit(function() {
		var infos = $(this).serialize(); 
		$.ajax({ 
			type: "GET", 
			data: infos, 
			url: $(this).attr("action"), 
			success: function(msg){
				//alert( "Data Saved: " + msg );
			}
		}); 
		$("#choixInfolettre").slideUp("slow");
		$("#inputCourriel").html("Merci") ;
		return false;
	});
});

