$(document).ready(function(){
	// VALIDATION IDENTIFICATION
	$("#formident").submit(function() {
		var conteneur = $("#moncompte");
		var poserreur = 1;
		
		var input = $("input[name*='form_log']");
		if (IdentChampVide(input.val())==false || input.val() == 'e-mail') {IdentLight(input);return (false);}

		var input = $("input[name*='form_pass']");
		if (IdentChampVide(input.val())==false || input.val() == 'password') {IdentLight(input);return (false);}

		return true;

	});
	
	// FONCTION CREATION DIV
	function IdentLight(obj) {
		obj.addClass('erreur');
	}
	
	// FONCTION CHAMP VIDE
	function IdentChampVide(val) {
		val = val.replace(/[ ]/g,"");
		if (val=="" ) {
			return (false);
		}
		return (true);
	}
	
	// ENLEVE LES MSG ERROR QUAND FOCUS
	$("input, textarea").bind('focus','click',function(event) {
		var diverror = "error"+$(this).attr("id");
		var diverror = $("#"+diverror+"");
		$(this).removeClass('erreur');
		diverror.fadeOut(function () {
			diverror.remove();
			}
		);
	});
	
	
	// CREER FAUX PASSWORD
	$("#moncompte .login").bind('focus','click',function(event) {

		var obj = $(this).attr('value');
		if(obj == 'e-mail'){
			$(this).attr('value','');
		}
	});
	$("#moncompte .login").blur(function() {
		var obj = $(this).attr('value').replace(/[\s]{2,}/g,"");
		if(obj == '' ){
			$(this).attr('value','e-mail');
		}
	});
	
	$("#moncompte .password").live("focus", function() {
		var obj = $(this).attr('value');
		if(obj == 'password'){
			$(this).replaceWith('<input type="password" class="password" name="form_pass" maxlength="12" />');
			var obj = $("#moncompte .password");
			obj.focus();
		}
	});
	$("#moncompte .password").live("blur", function() {
		var obj = $(this).attr('value').replace(/[\s]{2,}/g,"");
		if(obj == '' ){
			$(this).replaceWith('<input type="text" class="password" name="form_pass" maxlength="12" value="password" />');
		}
	});
	
	// BOITE CONFIRMATION DECONNEXION
	$('#identifie h2 span').click( function() {
		jConfirm('&Ecirc;tes-vous s&ucirc;r de vouloir vous d&eacute;connecter ?', 'Veuillez confirmer...', function(r) {
			if (r==true){
				$.post("inc/deconnexion.php", { },function success(data){
					location.href = document.location.href;
				});
				
			}
		});
	});
});
