<%inherit file="base.html" />
<%block name="title">Sign up</%block>

<%block name="content">
<section class="main-container">

  <section class="main-content">
    <header>
      <h3>Sign Up for edX</h3>
      <hr>
    </header>

    <div id="register">

      <form id="register_form" method="post">
        <div id="register_error" name="register_error"></div>
        <label>E-mail</label>
        <input name="email" type="email" placeholder="E-mail">
        <label>Password</label>
        <input name="password" type="password" placeholder="Password">
        <label>Public Username</label>
        <input name="username" type="text" placeholder="Public Username">
        <label>Full Name</label>
        <input name="name" type="text" placeholder="Full Name">
        <label>Your Location</label>
        <input name="location" type="text" placeholder="Your Location">
        <label>Preferred Language</label>
        <input name="language" type="text" placeholder="Preferred Language">
        <label class="terms-of-service">
          <input name="terms_of_service" type="checkbox" value="true">
          I agree to the
          <a href="#">Terms of Service</a>
        </label>
        
        <!-- no honor code for CMS, but need it because we're using the lms student object -->
          <input name="honor_code" type="checkbox" value="true" checked="true" hidden="true">

        <div class="submit">
          <input name="submit" type="submit" value="Create My Account">
        </div>
        </form>
        
        <section class="login-extra">
        <p>
        <span>Already have an account? <a href="#">Login.</a></span>
        </p>
        </section>

    </div>

<script type="text/javascript">
  (function() {
    function getCookie(name) {
      return $.cookie(name);
    }

    function postJSON(url, data, callback) {
      $.ajax({type:'POST',
        url: url,
        dataType: 'json',
        data: data,
        success: callback,
        headers : {'X-CSRFToken':getCookie('csrftoken')}
      });
    }

    $('form#register_form').submit(function(e) {
      e.preventDefault();
      var submit_data = $('#register_form').serialize();

      postJSON('/create_account',
        submit_data,
        function(json) {
          if(json.success) {
            $('#register').html(json.value);
          } else {
            $('#register_error').html(json.value).stop().css("background-color", "#933").animate({ backgroundColor: "#333"}, 2000);
          }
        }
      );
    });
  })(this)
</script>

  </section>

</section>
</%block>
