$(function() {
$('#formulairecata').validate({
        submitHandler: function(form) {
            // do other stuff for a valid form
            if ($(form).valid())
            {
                $(form).ajaxSubmit(function(responseText, statusText) {
                    if (responseText!="")
                        alert('probleme'+responseText);
                    else {
                        $(form).resetForm();
                        document.getElementById('image').src = 'securimage/securimage_show.php?sid=' + Math.random();
                        jQuery.facebox(function() {
                            jQuery.get('resultat.php', function(data) {
                                jQuery.facebox( data )
                            })
                        })
                    }
                })
            }
        },
    rules: {
        nom: {
            required: true
        },
        prenom: {
            required: true
        },
        adresse: {
            required: true
        },
        codepostal: {
            required: true,
            number:true
        },
        ville: {
            required: true
        },
        telephone: {
            required: true
        },
        email: {
            required: true,
            email:true
        },
        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.")
                }
    },
    // the errorPlacement has to take the table layout into account
    errorPlacement: function(error, element) {
        if ( element.is(":radio") ) {
            error.appendTo( element.parent());
        }
        else if ( element.is(":checkbox") )
            error.appendTo ( element.next() );
        else
            error.appendTo( element.parent() );
    }
});



   
});