 reloadCaptcha = ->
   apiCall "GET", "/api/user/status", {}
   .done (data) ->
-    console.log(data.data.enable_captcha)
     if data.data.enable_captcha
         Recaptcha.reload()
     ga('send', 'event', 'Registration', 'NewCaptcha')


submitRegistration = (e) ->
  e.preventDefault()

  registrationData = $("#user-registration-form").serializeObject()
  creatingNewTeam = $("#registration-new-team-page").is(":visible")
  creatingTeacherAccount = $("#registration-adviser-page").is(":visible")
  registrationData["create-new-team"] = creatingNewTeam
  registrationData["create-new-teacher"] = creatingTeacherAccount

  if creatingNewTeam
    registrationData["ctf-emails"] = $("#checkbox-emails-create").is(':checked')
    submitButton = "#register-button-create"
    logType = "NewTeam"
  else if creatingTeacherAccount
    registrationData["ctf-emails"] = $("#checkbox-emails-teacher").is(':checked')
    submitButton = "#register-button-teacher"
    logType = "NewTeacher"
  else
    registrationData["ctf-emails"] = $("#checkbox-emails-existing").is(':checked')
    submitButton = "#register-button-existing"
    logType = "JoinTeam"

  apiCall "POST", "/api/user/create", registrationData
  .done (data) ->
    switch data['status']
      when 0
        $(submitButton).apiNotify(data, {position: "right"})
        ga('send', 'event', 'Registration', 'Failure', logType + "::" + data.message)
        reloadCaptcha()
      when 1
        ga('send', 'event', 'Registration', 'Success', logType)
        if creatingTeacherAccount
            document.location.href = "/classroom"
        else
            document.location.href = "/team"

$ ->
  apiCall "GET", "/api/user/status", {}

        Recaptcha.create(recaptchaPublicKey, "captcha", { theme: "red" })

  $("#user-registration-form").on "submit", submitRegistration
