<%! from django.core.urlresolvers import reverse %>
<%namespace name='static' file='static_content.html'/>

<section id="login-modal" class="modal login-modal">
  <div class="inner-wrapper">
    <header>
      <h2>Log In</h2>
      <hr>
    </header>

    <form id="login_form" class="login_form" method="post" data-remote="true" action="/login">
      <label for="login_email">E-mail</label>
        <input id="login_email" type="email" name="email" placeholder="e.g. yourname@domain.com" />
      
      <label for="login_password">Password</label>
        <input id="login_password" type="password" name="password" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;" />  
      
      <label for="login_remember_me" class="remember-me">
        <input id="login_remember_me" type="checkbox" name="remember" value="true" />
        Remember me
      </label>
      
      <div class="submit">
        <input name="submit" type="submit" value="Access My Courses">
      </div>
    </form>

    <section class="login-extra">
      <p>
        <span>Not enrolled? <a href="#signup-modal" class="close-login" rel="leanModal">Sign up.</a></span>
        <a href="#forgot-password-modal" rel="leanModal" class="pwd-reset">Forgot password?</a>
      </p>
% if settings.MITX_FEATURES.get('AUTH_USE_OPENID'):
      <p>
      <a href="${MITX_ROOT_URL}/openid/login/">login via openid</a>
      </p>
% endif
    </section>

    <a href="#" class="close-modal" title="Close Modal">
      <div class="inner">
        <p>&#10005;</p>
      </div>
    </a>
  </div>
</section>

<script type="text/javascript">
(function() {
   $(document).delegate('#login_form', 'ajax:success', function(data, json, xhr) {
     if(json.success) {
        next = getParameterByName('next');
        if(next) {
           location.href = next;
       } else {
           location.href = "${reverse('dashboard')}";
       }
     } else {
       if($('#login_error').length == 0) {
         $('#login_form').prepend('<div id="login_error" class="modal-form-error"></div>');
       }
       $('#login_error').html(json.value).stop().css("display", "block");
     }
   });
   
   // removing close link's default behavior
   $('#login-modal .close-modal').click(function(e) {
    e.preventDefault();
   });
})(this)
</script>
