     @refreshGfx()
     @.$('form').addClass('auth-form-login')
     false
-  
+
   toggleComplete: ->
     @state = 'complete'
     @logoutOnHide = true
     @refreshGfx()
     @.$('form').addClass('auth-form-complete')
     false
-  
-  
+
+
   cancelDialog: () ->
     @hide() if $.inArray(@state, ["complete","password_change","name_change"]) >= 0
-  
+
   logoutUser: ->
     window.location.replace('/logout')
-    
+
   hide: (args) =>
     args = {} unless args
-    
+
     @logoutOnHide = args.logout if args.logout != undefined
     @callbackOnHide = args.callback if args.callback != undefined
 
     @.$('.modal').modal('hide')
     false
-  
+
   clearLastState: ->
     @.$('form').removeClass('auth-form-login').removeClass('auth-form-register').removeClass('auth-form-restore')
     false
-    
+
   submitFormFromState: (e) ->
     switch @state
       when "restore"          then @submitRestore()
       when "register"         then @submitRegister()
       when "login"            then @submitLogin()
       when "complete"         then @submitComplete()
-    
+
     e.preventDefault()
     false
-  
+
   buildErrors: (errors) ->
     t = "<ul style='text-align: left;'>"
     $.each errors, (index,error) ->
       t += "<li><strong>#{error.ref_node}</strong> #{error.message}</li>" if error.type == "field"
     t += "</ul>"
-  
+
   submitRestore: ->
-    
+
     submitData = {}
     submitData.email = @.$('#session_email').val()
-    
+
     $.ajax
       type: 'POST'
       url: "/v1/users/restore.json"

        @hide(logout: false, callback: true)
      error: (response) =>
        resp = $.parseJSON(response.responseText)
        @.$('.input-group').tooltip(
          placement: 'top'
          trigger: 'manual'
          animation: false
          title: "Something went wrong... try again later."
        ).tooltip('show')
    
  submitRegister: ->
    
    submitData = {}
    submitData.user = {}
    submitData.user.name = @.$('#session_display_name').val()
    submitData.user.email = @.$('#session_email').val()
    submitData.user.password = @.$('#session_password').val()
    
    submitData.user.confirm_registration = true
    submitData.persist_session = true
    
    $.ajax
      type: 'POST'
      url: "/v1/users.json"

        @hide(logout: false, callback: true)
      error: (response) =>
        resp = $.parseJSON(response.responseText)

        switch resp.status
          when 422
            @showTooltip(@buildErrors(resp.errors),true)
          when 403
            @logoutUser()
          # when 500
          #   # do stuff

  showTooltip: (message,html) =>
    @.$('.input-group').tooltip(
      placement: ->
        $(@.$tip).addClass('session-tooltip')
        'top'
      trigger: 'manual'
      animation: false
      html: html
      title: message
    ).tooltip('show')

  hideTooltip: => @.$('.input-group').tooltip('hide')


