// JavaScript Document
 $(document).ready(function() {	
							
		$("input:checkbox").each( function() {
		(this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
	});
	// function to 'check' the fake ones and their matching checkboxes
	$(".fakecheck").click(function(){
		($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
		$(this.hash).trigger("click");
		return false;
	});
	
	$("#email").focus(function(){
		//alert('focus');
		$(this).attr("value","");
		$(this).empty();					   
	});
		
		$("#connectform").submit(function(){
		
		var email = $("#email");
		var password = $("#password");
		var cookie = $("#cookie");
		
		//alert(cookie.attr('checked'));
		
		 $.ajax({ 
							type: "POST",
							async: false,
							url:'script_public/login.php',
							data:'email='+email.val()+'&password='+password.val()+'&cookie='+cookie.attr('checked'),
							success: function(retour){ 
								//alert(retour);
								if(retour==1)
								{
									 $.ajax({ 
												type: "POST",
												async: false,
												url:'script_public/verif_login.php',
												success: function(retour2){ 
													//alert(retour);
													
													$("#connexion_form").empty().html(retour2);
													
												} 
									}); 
								}
								else
								{
									//alert("Pas connecté");
									$("#retour_connect").empty().html("Mauvais login ou mot de passe");	
								}
							} 
				}); 



		return false;
										   
		});
		
		
		$("#logout").click(function(){
		 $.ajax({ 
							type: "POST",
							async: false,
							url:'script_public/logout.php',
							success: function(retour){ 
								if(retour==1)
								{
									 $.ajax({ 
												type: "POST",
												async: false,
												url:'script_public/verif_login.php',
												success: function(retour2){ 
													//alert(retour);
													
													$("#connexion_form").empty().html(retour2);
													
												} 
									}); 
								}
								else
								{
									//alert("Pas deconnecté");
										
								}
							} 
				}); 								  
										  
										  
		});
		
							
							
							
							
});
