<%!
  from django.core.urlresolvers import reverse
  from courseware.courses import course_image_url, get_course_about_section
  from courseware.access import has_access
%>
<%namespace name='static' file='../static_content.html'/>

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

<%block name="title"><title>About ${course.number}</title></%block>

<%block name="bodyclass">view-partial-mktgregister</%block>


<%block name="headextra">
  <%include file="../google_analytics.html" />
</%block>

<%block name="js_extra">
  <script type="text/javascript">
  (function() {
    $(".register").click(function(event) {
      $("#class_enroll_form").submit();
      event.preventDefault();
    });

    $('#class_enroll_form').on('ajax:complete', function(event, xhr) {
      if(xhr.status == 200) {
        window.top.location.href = "${reverse('dashboard')}";
      } else if (xhr.status == 403) {
        window.top.location.href = "${reverse('register_user')}?course_id=${course.id}&enrollment_action=enroll";
      } else {
        $('#register_error').html(
            (xhr.responseText ? xhr.responseText : 'An error occurred. Please try again later.')
        ).css("display", "block");
      }
    });
  })(this)
  </script>
</%block>

<%block name="content">
  <script src="${static.url('js/course_info.js')}"></script>

  <ul class="list-actions">
    <li class="item">
        %if user.is_authenticated() and registered:
          %if show_courseware_link:
            <a class="action access-courseware" href="${course_target}" target="_top">Access Courseware</a>
          %else:
            <div class="action is-registered">You Are Registered</div>
          %endif
        %elif allow_registration:
          <a class="action action-register register" href="#">Register for <strong>${course.number}</strong></a>
        %else:
          <div class="action registration-closed">Registration Is Closed</div>
        %endif
    </li>
  </ul>

%if not registered:
  <div style="display: none;">
    <form id="class_enroll_form" method="post" data-remote="true" action="${reverse('change_enrollment')}">
      <fieldset class="enroll_fieldset">
        <input name="course_id" type="hidden" value="${course.id}">
        <input name="enrollment_action" type="hidden" value="enroll">
        <input type="hidden" name="csrfmiddlewaretoken" value="${ csrf_token }">
      </fieldset>
      <div class="submit">
        <input name="enroll" type="submit" value="enroll">
      </div>
    </form>
  </div>
%endif
</%block>
