
$(document).ready(function (){
	/**
	*	Fonction de connexion
	*/
    $("#subCo").live('click',function(){
        $("#subCo").attr("disabled","disabled");
        /*$("#subCo").val(" ... ");*/
        login = $('#usernameCo').val();
        pass  = $("#passwordCo").val();
		//on appel une page en ajax et en mode post grace à la fonction Jquery $.post
        $.post("/v5test/fofo/ucp.php?mode=login", {
            login:"Login",
            username:login,
            password:pass,
            redirect:"/modules/auth_log_target.php"
        }, function(data){//retour de l'appel ajax
			//on appel la page pour valider l'authentification
            $.get("/modules/auth_log_target.php",null,function(data){
                if(data == "ok"){
					//authentification réussie on recharge la page
                    location.reload();
                }else{
					//authentification échouée
                    /*$("#subCo").val("OK");*/
                    $("#errorCo").html("Erreur de connexion - <a href=\"http://forum.origine-online.com/ucp.php?mode=sendpassword\">Mot de passe oublié</a> - ");//insertion du message d'erreur
                    $("#passwordCo").val("");
                    $("#subCo").attr('disabled',false);
                }
            });
        });
    });

    /**
	*	Fonction de déconnexion
	*/
    $("#logout").click(function(){
        $.get("/v5test/fofo/ucp.php",{mode:"logout",sid:$(this).attr('sid')},function(data){
			location.reload();
        });
    });
	$("#usernameCo").focus(function(){
		if(this.value=='NICKNAME'){
			this.value=''; 
			this.className='form';
		}
	});
	$("#usernameCo").blur(function(){
		if(this.value==''){
			this.value='NICKNAME'; 
			this.className='form grey';
		}
	});
	$("#passwordCo").focus(function(){
		if(this.value=='PASSWORD'){
			this.value=''; 
			this.className='form';
			this.type='password';
		}
	});
	$("#passwordCo").blur(function(){
		if(this.value==''){
			this.value='PASSWORD'; 
			this.className='form grey';
			this.type='text';
		}
	});
});



