 		else
 			$(passwordFormGroup).removeClass 'has-success'
 			$(passwordFormGroup).addClass 'has-error'
-	# Username validation helper function
-	usernameStatus = (state, hint) ->
-		$(usernameFormGroup).removeClass 'has-error has-success'
-		$(usernameFeedback).removeClass 'glyphicon-ok glyphicon-remove glyphicon-refresh'
-		$(usernameFeedback).hide()
-		# state
-		if state is 'checking'
-			$(usernameFeedback).addClass 'glyphicon-refresh'
-			$(usernameFeedback).show()
-		if state is 'ok'
-			$(usernameFeedback).addClass 'glyphicon-ok'
-			$(usernameFeedback).show()
-			$(usernameFormGroup).addClass 'has-success'
-		if state is 'error'
-			$(usernameFeedback).addClass 'glyphicon-remove'
-			$(usernameFeedback).show()
-			$(usernameFormGroup).addClass 'has-error'
-		# hint
-		if not hint? then hint = ''
-		$(usernameFeedback).attr('title', hint)
 	# Username validation
+	usernameStatus = nameStatusHelper(usernameFormGroup, usernameFeedback)
 	$("body").on 'change', usernameField, ->
 		if validation.usernameIsValid($(usernameField).val())
 			usernameStatus 'checking', 'Проверяем, свободен ли логин'

		if confirm('Вы уверены?') == false
			event.preventDefault()
		return

	# Registration page stuff


					usernameStatus 'ok', 'Логин свободен'
		else
			usernameStatus 'error', 'Логин неправильный'
	
	# Character name validation
	charnameStatus = nameStatusHelper('#character-name-form-group', '#character-name-feedback')
	$("body").on 'change', '#character-name', ->
		name = this.value
		if validation.characterNameIsValid(name)
			charnameStatus 'checking', 'Проверяем, свободно ли имя'
			$.getJSON "/ajax/isCharacterNameBusy/#{encodeURIComponent(name)}", (data) ->
				if data.name != name
					charnameStatus 'empty'
					return
				if data.isCharacterNameBusy
					charnameStatus 'error', 'Такое имя уже занято'
				else
					charnameStatus 'ok', 'Имя свободно'
		else
			charnameStatus 'error', 'Имя неправильное'
