$('input[name="newsletter_email"]').on('focus', function(event) {
  $('.js-newsletter-email').removeClass('error');
  $('.js-newsletter-email .ftr-field__error').remove();
});

$('.js-btn-inscrever').on('click', function(event) {
  event.preventDefault();
  $.ajax({
    url: 'index.php?route=common/module_newsletter/newsletter',
    type: 'POST',
    data: 'email=' + $("input[name='newsletter_email']").val(),
    dataType: 'json',
    beforeSend: function() {
      $('.js-btn-inscrever').prop('disabled', true);
    },
    complete: function() {
      $('.js-btn-inscrever').prop('disabled', false);
    },
    success: function(json) {
      if (json['error']) {
        $('.js-newsletter-email').addClass('error');
        $('.js-newsletter-email').append('<span class="ftr-field__error">' + json['error'] + '</span>');
      }

      if (json['success']) {
        $("input[name='newsletter_email']")
          .val('')
          .removeClass('on');
        notificationMsg(json['success'], 'success');
      }
    },
  });
});
