 
     return # Make sure CoffeeScript does not return anything
 
+  'focus input': (event, template) ->
+    usernameFormMessages.resetMessages '' # Reset global messages
+
+    return # Make sure CoffeeScript does not return anything
+
 Template.settings.usernameExists = ->
   !!Meteor.person().user?.username
 

changePassword = (currentPassword, newPassword, callback) ->
  try
    User.validatePassword newPassword, "new-password"
    # We check this manually because changePassword error throws global 'Match failed' error if current password is empty string
    throw new FormError 400, "Incorrect password" unless currentPassword
    Accounts.changePassword currentPassword, newPassword, callback
  catch error
    callback error


usernameFormMessages = new FormMessages()
usernameReadyForValidation = false
usernameFieldModified = false

passwordFormMessages = new FormMessages()
newPasswordReadyForValidation = false
newPasswordFieldModified = false

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

resetPasswordForm = ->
  passwordFormMessages.resetMessages()
  $('#current-password').val('')
  $('#new-password').val('')
  newPasswordReadyForValidation = false
  newPasswordFieldModified = false

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