<%! from django.utils.translation import ugettext as _ %>
<%!
  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}").format(course_number=course.display_number_with_default) | h}</title></%block>

<%block name="bodyclass">view-iframe-content 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) {
        if (xhr.responseText != "") {
          window.top.location.href = xhr.responseText;
        }
        else {
          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 ${'has-option-verified' if len(course_modes) > 1 else ''}" href="#">${_("Register for")} <strong>${course.display_number_with_default | h}</strong>
            %if len(course_modes) > 1:
            <span class="track">
            and choose your student track
            </span>
            %endif
        </a>
        %else:
          <div class="action registration-closed is-disabled">${_("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>
