$('a[rel=facebox]').facebox();


$("#formLogin").submit(function()
{
    //remove all the class add the messagebox classes and start fading
    $("#msgbox").removeClass().addClass('messagebox').text('Vérification....').fadeIn(1000);
    //check the username exists or not from ajax
    $.post("php/ajax_login.php",{
        user_name:$('#con_email').val(),
        password:$('#password_con').val(),
        rand:Math.random()
    } ,function(data)

    {
            if(data=='yes') //if correct login detail
            {
                $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
                {
                    //add message and change the class of the box and start fading
                    $(this).html('Connection.....').addClass('messageboxok').fadeTo(900,1,
                        function()
                        {
                            //redirect to secure page
                            document.location=document.URL;//'compte-resultat.html';
                        });
                });
            }
            else
            {
                $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
                {
                    //add message and change the class of the box and start fading
                    $(this).html('Identifiant ou mot de passe incorrects...').addClass('messageboxerror').fadeTo(200,1).fadeTo(2000,1).fadeTo(200,0);
                });
            }
        });
    return false;//not to post the  form physically
});


function formvalidateMotdePasse(form) {
    form.validate({
        submitHandler: function() {

            if (form.valid())
            {
                form.ajaxSubmit(function() {
                    form.clearForm();
                    jQuery.facebox(function() {
                        jQuery.get('resultat.php', function(data) {
                            jQuery.facebox( data )
                        })
                    })

                })
            }
        }
        ,
        rules: {
            emailMdpOublie: {
                required:true,
                email:true,
                minlength:3
            },

            captcha: {
                required: true,
                remote: {
                    url: "php/verifiecaptcha1.php",
                    type: "get"
                }
            }
        },
        messages:	 {
            captcha: 		{
                required: "Entrer les caractères comme sur l'image au-dessus:",
                remote: jQuery.format("le code actuel est incorrect.")
            }
        }
    });
}


