$(document).ready(function() {
  $('#password').strength({type: 'app'});

  $('#form-new-password').validate({
    onkeyup: function(element) {
      if ($(element).valid()) {
        $(element).closest('.ftr-field').removeClass('error').find('.ftr-field__error').remove();
      }
    },
    onsubmit: true,
    showErrors: function(errorMap, errorList) {
      $.each(errorList, function() {
        $($(this)[0].element).closest('.ftr-field').addClass('error').find('.ftr-field__error').remove();
        $($(this)[0].element).closest('.ftr-field').append('<span class="ftr-field__error">' + $(this)[0].message + '</span>');
      });
    },
    rules: {
      confirm: {
        equalTo: '#password'
      }
    },
    messages: {
      confirm: {
        equalTo: 'As senhas não conferem.'
      }
    }
  });
});
