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


$("#formLog").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:$('#username').val(),
        password:$('#password').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='espace-prive-commandes.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(900,1);
                });
            }
        });
    return false;//not to post the  form physically
});
$("#password").blur(function()
{
    $("#formLog").trigger('submit');
});


function favoris() { 
    if ( navigator.appName != 'Microsoft Internet Explorer' ) 
    {
        window.sidebar.addPanel("Servipar | Distributeur de consommables informatiques","http://www.servipar.fr","");
    } else {
        window.external.AddFavorite("http://www.servipar.fr","Servipar | Distributeur de consommables informatiques");
    }
} 


function formvalidate(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: {
        email: {
            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.")
        }
    }
});
}

function formvalidateami(form) {
    form.validate({
        submitHandler: function(form) {
            // do other stuff for a valid form
            if ($("#recommanderAmi").valid())
            {
                $('#recommanderAmi').ajaxSubmit(function() {
   
                    jQuery.facebox(function() {
                        jQuery.get('resultat.php', function(data) {
                            jQuery.facebox( data )
                        })
                    })
                })
            }
        }
    });
}

function formvalidatenews(form){
    form.validate({
        submitHandler: function(form){
            // do other stuff for a valid form
            if ($("#formNewsletter").valid()) {
                $('#formNewsletter').ajaxSubmit(function(){
				
                    jQuery.facebox(function(){
                        jQuery.get('resultat.php', function(data){
                            jQuery.facebox(data)
                        })
                    })
                })
            }
        }
    });
}		