 # Password settings
 Template.settingsPassword.events =
   'click button.change-password': (event, template) ->
-    PASSWORD_READY_FOR_VALIDATION = true
-    PASSWORD_CONFIRMATION_READY_FOR_VALIDATION = true
+    passwordReadyForValidation = true
+    passwordConfirmationReadyForValidation = true
     passwordFormMessages.resetMessages()
     event.preventDefault()
     currentPassword = $('#current-password').val()

  !passwordFormMessages.getErrorMessage field

validatePassword = (newPassword, messageField) ->
  return unless PASSWORD_READY_FOR_VALIDATION
  try
    User.validatePassword newPassword, messageField
    passwordFormMessages.resetMessages messageField

usernameFormMessages = new FormMessages()
passwordFormMessages = new FormMessages()
passwordReadyForValidation = false
passwordConfirmationReadyForValidation = false
usernameReadyForValidation = false

resetUsernameForm = ->
  usernameFormMessages.resetMessages()
  usernameReadyForValidation = false

resetPasswordForm = ->
  passwordFormMessages.resetMessages()
  $('#current-password').val('')
  $('#new-password').val('')
  $('#new-password-confirmation').val('')
  passwordReadyForValidation = false
  passwordConfirmationReadyForValidation = false

# Reset forms when settings page becomes active
Deps.autorun ->
