<%inherit file="main.html" />

<%namespace name='static' file='static_content.html'/>
<%namespace file='main.html' import="login_query"/>
<%! from django.core.urlresolvers import reverse %>
<%! from django.utils import html %>
<%! from django_countries.countries import COUNTRIES %>
<%! from student.models import UserProfile %>
<%! from datetime import date %>
<%! import calendar %>

<%block name="title"><title>Register for edX</title></%block>

<%block name="js_extra">
  <script type="text/javascript">
    $(function() {

      var view_name = 'view-register';

      // adding js class for styling with accessibility in mind
      $('body').addClass('js').addClass(view_name);

      // new window/tab opening
      $('a[rel="external"], a[class="new-vp"]')
      .click( function() {
      window.open( $(this).attr('href') );
      return false;
      });

      // form field label styling on focus
      $("form :input").focus(function() {
        $("label[for='" + this.id + "']").parent().addClass("is-focused");
      }).blur(function() {
        $("label").parent().removeClass("is-focused");
      });

    });

    (function() {
      toggleSubmitButton(true);

      $('#register-form').on('submit', function() {
        toggleSubmitButton(false);
      });

      $('#register-form').on('ajax:complete', function() {
        toggleSubmitButton(true);
      });

      $('#register-form').on('ajax:success', function(event, json, xhr) {
        if(json.success) {
          $('.message.submission-error').removeClass('is-shown');
          location.href="${reverse('dashboard')}";
       } else {
         $('.status.message.submission-error').addClass('is-shown');
         $('.status.message.submission-error .message-copy').html(json.value).stop().css("display", "block");
         $(".field-error").removeClass('field-error');
         $("[data-field='"+json.field+"']").addClass('field-error')
       }
      });
    })(this);

    function toggleSubmitButton(enable) {
      var $submitButton = $('form .form-actions #submit');

      if(enable) {
        $submitButton.
          removeClass('is-disabled').
          removeProp('disabled').
          html('Create my edX Account');
      }
      else {
        $submitButton.
          addClass('is-disabled').
          prop('disabled', true).
          html('Processing your account information &hellip;');
      }
    }
  </script>
</%block>

<section class="introduction">
  <header>
    <h1 class="sr">Register for edX</h1>
  </header>
</section>

<section class="register container">
  <section role="main" class="content">
    <header>
      <h2 class="sr">Registration Form</h2>
    </header>

    <form role="form" id="register-form" method="post" data-remote="true" action="/create_account">

      <!-- status messages -->
      <div role="alert" class="status message">
        <h3 class="message-title">We're sorry, edX enrollment is not available in your region</h3>
        <p class="message-copy">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
      </div>

      <div role="alert" class="status message submission-error">
        <h3 class="message-title">The following errors occured while processing your registration: </h3>
        <ul class="message-copy"> </ul>
      </div>

      <p class="instructions">
        Please complete the following fields to register for an edX account. <br />
        Required fields are noted by <strong class="indicator">bold text and an asterisk (*)</strong>.
      </p>

      <fieldset class="group group-form group-form-requiredinformation">
        <legend class="sr">Required Information</legend>

        % if has_extauth_info is UNDEFINED:

        <ol class="list-input">
          <li class="field required text" id="field-email">
            <label for="email">E-mail</label>
            <input class="" id="email" type="email" name="email" value="" placeholder="example: username@domain.com" />
          </li>
          <li class="field required password" id="field-password">
            <label for="password">Password</label>
            <input id="password" type="password" name="password" value="" />
          </li>
          <li class="field required text" id="field-username">
            <label for="username">Public Username</label>
            <input id="username" type="text" name="username" value="" placeholder="example: JaneDoe" />
            <span class="tip tip-input">Will be shown in any discussions or forums you participate in</span>
          </li>
          <li class="field required text" id="field-name">
            <label for="name">Full Name</label>
            <input id="name" type="text" name="name" value="" placeholder="example: Jane Doe" />
            <span class="tip tip-input">Needed for any certificates you may earn <strong>(cannot be changed later)</strong></span>
          </li>
        </ol>

        % else:

        <div class="message">
          <h3 class="message-title">Welcome ${extauth_email}</h3>
          <p class="message-copy">Enter a public username:</p>
        </div>

        <ol class="list-input">
          <li class="field required text" id="field-username">
            <label for="username">Public Username</label>
            <input id="username" type="text" name="username" value="${extauth_username}" placeholder="example: JaneDoe" />
            <span class="tip tip-input">Will be shown in any discussions or forums you participate in</span>
          </li>
        </ol>

        % endif
      </fieldset>

      <fieldset class="group group-form group-form-secondary group-form-personalinformation">
        <legend class="sr">Optional Personal Information</legend>

        <ol class="list-input">
          <li class="field-group">
            <div class="field select" id="field-education-level">
              <label for="education-level">Highest Level of Education Completed</label>
              <select id="education-level" name="level_of_education">
                <option value="">--</option>
                %for code, ed_level in UserProfile.LEVEL_OF_EDUCATION_CHOICES:
                <option value="${code}">${ed_level}</option>
                %endfor
              </select>
            </div>

            <div class="field select" id="field-gender">
              <label for="gender">Gender</label>
              <select id="gender" name="gender">
                <option value="">--</option>
                %for code, gender in UserProfile.GENDER_CHOICES:
                <option value="${code}">${gender}</option>
                %endfor
              </select>
            </div>

            <div class="field select" id="field-yob">
              <label for="yob">Year of Birth</label>
              <select id="yob" name="year_of_birth">
                <option value="">--</option>
                %for year in UserProfile.VALID_YEARS:
                <option value="${year}">${year}</option>
                %endfor
              </select>
            </div>
          </li>
        </ol>
      </fieldset>

      <fieldset class="group group-form group-form-personalinformation2">
        <legend class="sr">Optional Personal Information</legend>

        <ol class="list-input">
          <li class="field text" id="field-address-mailing">
            <label for="address-mailing">Mailing Address</label>
            <textarea id="address-mailing" name="mailing_address" value=""></textarea>
          </li>

          <li class="field text" id="field-goals">
            <label for="goals">Please share with us your reasons for registering with edX</label>
            <textarea id="goals" name="goals" value=""></textarea>
          </li>
        </ol>
      </fieldset>

      <fieldset class="group group-form group-form-accountacknowledgements">
        <legend class="sr">Account Acknowledgements</legend>

        <ol class="list-input">
          <li class="field-group">
            <div class="field required checkbox" id="field-tos">
              <input id="tos-yes" type="checkbox" name="terms_of_service" value="true" />
              <label for="tos-yes">I agree to the <a href="${marketing_link('TOS')}" class="new-vp">Terms of Service</a></label>
            </div>

            <div class="field required checkbox" id="field-honorcode">
              <input id="honorcode-yes" type="checkbox" name="honor_code" value="true" />
              <label for="honorcode-yes">I agree to the <a href="${marketing_link('HONOR')}" class="new-vp">Honor Code</a></label>
            </div>
          </li>
        </ol>
      </fieldset>

% if course_id and enrollment_action:
      <input type="hidden" name="enrollment_action" value="${enrollment_action | h}" />
      <input type="hidden" name="course_id" value="${course_id | h}" />
% endif

      <div class="form-actions">
        <button name="submit" type="submit" id="submit" class="action action-primary action-update">Register <span class="orn-plus">+</span> Create My Account</button>
      </div>
    </form>
  </section>

  <aside role="complementary">
    <header>
      <h3 class="sr">Registration Help</h3>
    </header>

    <div class="cta">
      <h3>Already registered?</h3>
      <p class="instructions">
        <a href="${reverse('signin_user')}${login_query()}">
          Click here to log in.
        </a>
      </p>
    </div>

    <div class="cta cta-welcome">
      <h3>Welcome to edX</h3>
      <p>Registering with edX gives you access to all of our current and future free courses. Not ready to take a course just yet? Registering puts you on our mailing list – we will update you as courses are added.</p>
    </div>

    <div class="cta cta-nextsteps">
      <h3>Next Steps</h3>
      <p>As part of joining edX, you will receive an activation email.  You must click on the activation link to complete the process.  Don’t see the email?  Check your spam folder and mark edX emails as ‘not spam’.  At edX, we communicate mostly through email.</p>
    </div>

    <div class="cta cta-help">
      <h3>Need Help?</h3>
      <p>Need help in registering with edX? 
        <a href="${marketing_link('FAQ')}">
            View our FAQs for answers to commonly asked questions.
        </a>  
        Once registered, most questions can be answered in the course specific discussion forums or through the FAQs.</p>
    </div>
  </aside>
</section>
