/* Minification failed. Returning unminified contents.
(1,1): run-time error CSS1019: Unexpected token, found '$'
(1,2): run-time error CSS1019: Unexpected token, found '('
(1,11): run-time error CSS1031: Expected selector, found ')'
(1,11): run-time error CSS1025: Expected comma or open brace, found ')'
(8,43): run-time error CSS1002: Unterminated string: 'envoi du formulaire de connexion
(59,51): run-time error CSS1002: Unterminated string: 'utilisateur
(65,51): run-time error CSS1002: Unterminated string: 'erreur
(75,2): run-time error CSS1019: Unexpected token, found ')'
(75,3): run-time error CSS1019: Unexpected token, found ';'
 */
$(document).ready(function () {

    console.log('pl');

    // Formulaire de connexion
    var logOnForm = $(".form-logon");

    // A l'envoi du formulaire de connexion
    logOnForm.submit(function (e) {
        e.preventDefault();
        e.stopPropagation();

        // Validation des champs
        $.validator.unobtrusive.parse(logOnForm);

        // On vérifie si le formulaire est valide
        if ($(logOnForm).valid()) {

            $.ajax({
                type: 'POST',
                url: logOnForm.attr("action"),
                data: logOnForm.serialize(),
                // En cas de succès
                success: function (result) {

                    // Si on a un résultat 
                    if (result != null && result != "" && result == "pt-logon") {

                        $('#alert-area').hide();

                        $("#producer-part").show();
                        $("#ProducerName").autocomplete({
                        source: function (request, response) {
                            $.ajax({
                                type: "POST",
                                data: { search: $("#ProducerName").val() },
                                url: '/LogOn/GetPTUserLogOnProducer',
                                success: function (result) {
                                    response($.map(result, function (item) {
                                        return {
                                            label: item.name,
                                            value: item.name,
                                            object: item
                                        }
                                    }))
                                }
                            });
                            },
                                minLength: 2,
                                messages: {
                                    noResults: '',
                                    results: function () { }
                                }
                        });
                    }
                    else {
                        var jqResult = $(result);

                        //on redirige l'utilisateur
                        if (!jqResult.hasClass('alert')) {
                            $('#alert-area').hide();
                            location.href = logOnForm.attr("data-redirect");
                        }
                        else {
                            //affichage de l'erreur
                            $('#alert-area').html(jqResult);
                            $('#alert-area').show();
                        }
                    }
                }
            });
        }
    });

});
