<%!
  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="../main.html" />

<%block name="js_extra">
  % if not registered:
    %if user.is_authenticated():
      ## If the user is authenticated, clicking the enroll button just submits a form
      <script type="text/javascript">
      (function() {
        $(".register").click(function() {
          $("#class_enroll_form").submit();
        });

        $(document).delegate('#class_enroll_form', 'ajax:success', function(data, json, xhr) {
          if(json.success) {
            location.href="${reverse('dashboard')}";
          }else{
	    $('#register_message').html("<p><font color='red'>" + json.error + "</font></p>");
          }
        });
      })(this)
      </script>
    %else:
      ## If the user is not authenticated, clicking the enroll button pops up the register
      ## field. We also slip in the registration fields into the login/register fields so
      ## the user is automatically registered after logging in / registering
      <script type="text/javascript">
      (function() {
        $(".register").click(function() {
          if ($(".login_form .enroll_fieldset").length === 0) {
            $(".login_form").append( $(".enroll_fieldset").first().clone() );
          }
          if ($(".register_form .enroll_fieldset").length === 0) {
            $(".register_form").append( $(".enroll_fieldset").first().clone() );
          }
        });
      })(this)
      </script>
    %endif
  %endif

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


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

<section class="course-info">
  <header class="course-profile">
    <div class="intro-inner-wrapper">
      <div class="table">
      <section class="intro">
        <hgroup>
          <h1>${course.number}: ${get_course_about_section(course, "title")}<a href="${reverse('university_profile', args=[course.org])}">${get_course_about_section(course, "university")}</a></h1>
        </hgroup>

        <div class="main-cta">
          %if user.is_authenticated():
            %if registered:
   	        <%
		  ## TODO: move this logic into a view
                  if has_access(user, course, 'load'):
                      course_target = reverse('info', args=[course.id])
                  else:
                      course_target = reverse('about_course', args=[course.id])
                  show_link = settings.MITX_FEATURES.get('ENABLE_LMS_MIGRATION')
                %>
	        %if show_link:
                <a href="${course_target}">
                %endif
                <span class="register disabled">You are registered for this course (${course.number}).</span>
	        %if show_link:
                </a>
                %endif
            %else:
                <a href="#" class="register">Register for ${course.number}</a>
	        <div id="register_message"></div>
            %endif
          %else:
            <a href="#signup-modal" class="register" rel="leanModal" data-notice='You must Sign Up or <a href="#login-modal" rel="leanModal">Log In</a> to enroll.'>Register for ${course.number}</a>
          %endif
        </div>

      </section>
      % if get_course_about_section(course, "video"):
      <a href="#video-modal" class="media" rel="leanModal">
        <div class="hero">
          <img src="${course_image_url(course)}" />
          <div class="play-intro"></div>
        </div>
      </a>
      %else:
      <div class="media">
        <div class="hero">
          <img src="${course_image_url(course)}" />
        </div>
      </div>
      % endif
    </div>
      </div>
  </header>

  <section class="container">
    <section class="details">
      <nav>
        <a href="#" class="active">Overview</a>
      ##  <a href="#">FAQ</a>
      ##  <a href="#">Requirements</a>
      ##  <a href="#">Text-book</a>
      ##  <a href="#">Syllabus</a>
      ##  <a href="#">Reviews</a>
      </nav>

      <div class="inner-wrapper">
        ${get_course_about_section(course, "overview")}
      </div>
    </section>

    <section class="course-sidebar">
      <section class="course-summary">
        <header>
          <div class="social-sharing">
            <div class="sharing-message">Share with friends and family!</div>
            <a href="http://twitter.com/intent/tweet?text=I+just+registered+for+${course.number}+${get_course_about_section(course, 'title')}+through+@edxonline:+http://www.edx.org${reverse('about_course', args=[course.id])}" class="share">
              <img src="${static.url('images/social/twitter-sharing.png')}">
            </a>
            <a href="http://www.facebook.com/EdxOnline" class="share"> <img src="${static.url('images/social/facebook-sharing.png')}">
            </a>
            <a href="mailto:?subject=Take%20a%20course%20with%20edX%20online&body=I%20just%20registered%20for%20${course.number}%20${get_course_about_section(course, 'title')}%20through%20edX:+http://edx.org/${reverse('about_course', args=[course.id])}" class="share">
              <img src="${static.url('images/social/email-sharing.png')}">
            </a>
          </div>
        </header>

        <ol class="important-dates">
          <li><div class="icon course-number"></div><p>Course Number</p><span class="course-number">${course.number}</span></li>
          <li><div class="icon start"></div><p>Classes Start</p><span class="start-date">${course.start_date_text}</span></li>

          ## End date should come from course.xml, but this is a quick hack
          % if get_course_about_section(course, "end_date"):
            <li><div class="icon end"></div><p>Classes End</p><span class="final-date">${get_course_about_section(course, "end_date")}</span></li>
          % endif

          % if get_course_about_section(course, "effort"):
            <li><div class="icon effort"></div><p>Estimated Effort</p><span class="start-date">${get_course_about_section(course, "effort")}</span></li>
          % endif

          ##<li><div class="icon length"></div><p>Course Length</p><span class="course-length">15 weeks</span></li>

          % if get_course_about_section(course, "prerequisites"):
            <li class="prerequisites"><div class="icon prereq"></div><p>Prerequisites</p><span class="start-date">${get_course_about_section(course, "prerequisites")}</span></li>
          % endif
        </ol>
      </section>
    </section>

  </section>
</section>

%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">
      </fieldset>
      <div class="submit">
        <input name="submit" type="submit" value="enroll">
      </div>
    </form>
  </div>
%endif


<%include file="../video_modal.html" />
