<%! from django.utils.translation import ugettext as _ %>
<%! from microsite_configuration.middleware import MicrositeConfiguration %>

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

## Define a couple of helper functions to make life easier when
## embedding theme conditionals into templates. All inheriting
## templates have access to these functions, and we can import these
## into non-inheriting templates via the %namespace tag.
<%def name="theme_enabled()">
  <% return settings.FEATURES.get("USE_CUSTOM_THEME", False) %>
</%def>

<%def name="stanford_theme_enabled()">
  <%
    if not theme_enabled():
      return False

    return getattr(settings, "THEME_NAME", None) == "stanford"
  %>
</%def>

<!DOCTYPE html>
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7" lang="en-us"><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8" lang="en-us"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9" lang="en-us"><![endif]-->
<!--[if gt IE 9]><!--><html lang="en-us"><!--<![endif]-->
<head>
  <%block name="title">
    % if stanford_theme_enabled():
      <title>${_("Home")} | class.stanford.edu</title>
    % else:
      ## "edX" should not be translated
      <title>${MicrositeConfiguration.get_microsite_configuration_value('platform_name', settings.PLATFORM_NAME)}</title>

      <meta http-equiv="X-UA-Compatible" content="IE=edge">

      <script type="text/javascript">
        /* immediately break out of an iframe if coming from the marketing website */
        (function(window) {
          if (window.location !== window.top.location) {
            window.top.location = window.location;
          }
        })(this);
      </script>
    % endif
  </%block>

  <script type="text/javascript" src="/jsi18n/"></script>

  <link rel="icon" type="image/x-icon" href="${static.url(MicrositeConfiguration.get_microsite_configuration_value('favicon_path', settings.FAVICON_PATH))}" />

  <%static:css group='style-vendor'/>
  <%static:css group='style-app'/>
  <%static:css group='style-app-extend1'/>
  <%static:css group='style-app-extend2'/>

  <%static:js group='main_vendor'/>

  <%block name="headextra"/>

<%
  if theme_enabled():
    header_extra_file = 'theme-head-extra.html'
    header_file = 'theme-header.html'
    google_analytics_file = 'theme-google-analytics.html'
    footer_file = 'theme-footer.html'

    style_overrides_file = None

  else:
    header_extra_file = None
    header_file = MicrositeConfiguration.get_microsite_template_path('navigation.html')
    google_analytics_file = MicrositeConfiguration.get_microsite_template_path('google_analytics.html')
    footer_file = MicrositeConfiguration.get_microsite_template_path('footer.html')

    style_overrides_file = MicrositeConfiguration.get_microsite_configuration_value('css_overrides_file')
%>

  % if header_extra_file:
    <%include file="${header_extra_file}" />
  % endif

  <!--[if lt IE 9]>
    <script src="${static.url('js/html5shiv.js')}"></script>
  <![endif]-->

  <meta name="path_prefix" content="${EDX_ROOT_URL}">
  <meta name="google-site-verification" content="_mipQ4AtZQDNmbtOkwehQDOgCxUUV2fb_C0b6wbiRHY" />

  % if not course:
    <%include file="${google_analytics_file}" />
  % endif

  <%include file="widgets/segment-io.html" />


% if style_overrides_file:
  <link rel="stylesheet" type="text/css" href="${static.url(style_overrides_file)}" />
% endif

</head>

<body class="<%block name='bodyclass'/>">
  <a class="nav-skip" href="#content">${_("Skip to this view's content")}</a>

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

% if not suppress_toplevel_navigation:
  <%include file="${header_file}" />
%endif

  <section class="content-wrapper" id="content">
    ${self.body()}
    <%block name="bodyextra"/>
  </section>

% if not suppress_toplevel_navigation:
  <%include file="${footer_file}" />
% endif

  <script>window.baseUrl = "${settings.STATIC_URL}";</script>
  <%static:js group='application'/>
  <%static:js group='module-js'/>

  <%block name="js_extra"/>
</body>
</html>

<%def name="login_query()">${
  "?course_id={0}&enrollment_action={1}".format(
    html.escape(course_id),
    html.escape(enrollment_action)
  ) if course_id and enrollment_action else ""
}</%def>


