               document.location.href = "/classroom"
             else
               document.location.href = "/profile"
+
+  onTeamRegistration: (e) ->
+    e.preventDefault()
+    apiCall "POST", "/api/team/create", {team_name: @state.team_name, team_password: @state.team_password}
+    .done (resp) ->
+      switch resp.status
+        when 0
+            apiNotify resp
+        when 1
+            document.location.href = "/profile"
+
+  onTeamJoin: (e) ->
+    e.preventDefault()
+    e.preventDefault()
+    apiCall "POST", "/api/team/join", {team_name: @state.team_name, team_password: @state.team_password}
+    .done (resp) ->
+      switch resp.status
+        when 0
+            apiNotify resp
+        when 1
+            document.location.href = "/profile"
 
   setPage: (page) ->
     @setState update @state,

    lastname: @linkState "lastname"
    firstname: @linkState "firstname"
    email: @linkState "email"

    <div>
      <Col md={6} mdOffset={3}>
        <LoginForm setPage={@setPage} status={@state.page} onRegistration={@onRegistration}
          onLogin={@onLogin} onPasswordReset={@onPasswordReset} {...links}/>
      </Col>
    </div>

$ ->
  React.render <AuthPanel/>, document.getElementById("auth-box")

        </form>
      </Panel>


TeamManagementForm = React.createClass

  componentDidMount: ->
    $("input").prop 'required', true

  componentDidUpdate: ->
    $("input").prop 'required', true

  render: ->
    towerGlyph = <Glyphicon glyph="tower"/>
    lockGlyph = <Glyphicon glyph="lock"/>

    <Panel>
      <form onSubmit={@props.onTeamJoin}>
        <Input type="text" valueLink={@props.teamName} addonBefore={towerGlyph} label="Team Name"/>
        <Input type="password" valueLink={@props.teamPassword} addonBefore={lockGlyph} label="Team Password"/>
        <Col md={6}>
          <span>
            <Button type="submit">Join Team</Button>
            <Button onClick={@props.onTeamRegistration}>Register Team</Button>
          </span>
        </Col>
        <Col md={6}>
          <a href="#" onClick={() -> document.location.href = "/profile"}>Play as an individual.</a>
        </Col>
      </form>
    </Panel>
        
AuthPanel = React.createClass
  mixins: [React.addons.LinkedStateMixin]
  getInitialState: ->
    page: "Login"
    settings: {}

  componentWillMount: ->
    apiCall "GET", "/api/team/settings"
    .done ((req) ->
      console.log req
      @setState update @state,
        settings: $set: req.data
     ).bind this

  onRegistration: (e) ->
    e.preventDefault()
    apiCall "POST", "/api/user/create_simple", @state
    .done ((resp) ->
      console.log resp
      apiNotify resp
      console.log @state
      switch resp.status
        when 1
          if @state.settings.max_team_size > 1
            @setPage "Team Management"
          else
            document.location.href = "/profile"
    ).bind this

  onPasswordReset: (e) ->
    e.preventDefault()
