$(document).ready(function() {

    $("#formLogin").submit(function(event) {
        if(checkconnection()){

            var formData = {
                ident: $("#ident").val(),
                date: $("#date").val(),
                from: $("#from").val(),
                event: $("#event").val()
            };

            $.ajax({
                type: "POST",
                url: "json.php?jsonData=login",
                data: formData
            }).done(function(data) {
                var json = $.parseJSON(data);
                if(!json.success) { 
                    $("#divAlerte").empty();
                    $("#divAlerte").html('<div class="alert alert-danger alertLogin" role="alert">Erreur d\'authentification</div>');
                    $("#divAlerte").show();
                    window.setTimeout(function() {
                        $("#divAlerte").fadeTo(600, 0).slideUp(600, function(){
                            $(this).hide();
                            $(this).css('opacity', '1');
                        });
                    }, 1000); 
                } else {
                    window.location = "/home.php";   
                }
            });
            event.preventDefault();
            
        } else {
            event.preventDefault();
            $("#divAlerte").empty();
            $("#divAlerte").append('<div class="alert alert-warning alertLogin" role="alert">Vous n\'êtes pas connecté à internet</div>');
            $("#divAlerte").show();
            window.setTimeout(function() {
                $("#divAlerte").fadeTo(600, 0).slideUp(600, function(){
                    $(this).hide(); 
                    $(this).css('opacity', '1');
                });
            }, 1000);
        }
    })
});