<script src="/javascripts/i18n/jquery.ui.datepicker-zh-CN.js" type="text/javascript"></script>
<div id="popbox_upload" class="mb10" style="margin-top: -30px;color:#15bccf;  font-size:16px;">
  <div class="upload_con">
    <h2 style="text-align: center"><%= l(:label_upload_files)%></h2>
    <div class="upload_box">
      <%= error_messages_for 'attachment' %>
      <div id="network_issue" style="color: red; display: none;"><%= l(:label_file_upload_error_messages)%></div>

      <%= form_tag(course_files_path(course), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %>
          <input type="hidden" name="in_course_toolbar" value="Y">
          <!--<p class="c_grey fr mt10 mr5">-->
          <div class="c_dark">
            <input name="course_attachment_type[]" type="checkbox" value="1" checked class="c_dark" >课件</input>&nbsp;<span class="c_grey">|</span>&nbsp;
            <input name="course_attachment_type[]" type="checkbox" value="2" class="c_dblue">软件</input>&nbsp;<span  class="c_grey">|</span>&nbsp;
            <input name="course_attachment_type[]" type="checkbox" value="3" class="c_dblue">媒体</input>&nbsp;<span  class="c_grey">|</span>&nbsp;
            <input name="course_attachment_type[]" type="checkbox" value="4" class="c_dblue">代码</input>&nbsp;<span  class="c_grey">|</span>&nbsp;
            <input name="course_attachment_type[]" type="checkbox" value="6" class="c_dblue">论文</input>&nbsp;<span  class="c_grey">|</span>&nbsp;
            <input name="course_attachment_type[]" type="checkbox" value="5" class="c_dblue">其他</input></a>
          </div>
          <div class="cl"></div>
          <div>
          <%= render :partial => 'files/new_style_attachment_list',:locals => {:container => course} %>
          </div>
          <div class="cl"></div>
          <div class="mb5">
            <label class="fl c_dark f14" style="margin-top: 4px;">附件描述：</label>
            <div class="fl">
              <input  type="text" name="description"  placeholder="文件描述" class="InputBox fl W160">
            </div>
            <div class="cl"></div>
          </div>

          <% if User.current.allowed_to?(:as_teacher,course) %>
              <div class="mb5">
                <label class="fl c_dark f14" style="margin-top: 4px;">延迟发布：</label>
                <div class="calendar_div fl">
                    <input  type="text" name="publish_time" id="attachment_publish_time" placeholder="发布日期(可选)" class="InputBox fl W120 calendar_input" readonly="readonly">
                    <%#= calendar_for('attachment_publish_time')%>
                </div>
                <span class="fl c_red f12" style="margin-top: 4px;" id="publish_time_notice"></span>
                <div class="cl"></div>
              </div>
          <% end %>
          <a href="javascript:void(0);" class=" fr courseSendCancel mr40" onclick="hideModal();"><%= l(:button_cancel)%></a>
          <a id="submit_resource" href="javascript:void(0);" class="c_white courseSendSubmit fr" onclick="submit_course_resource();"><%= l(:button_confirm)%></a>
          <%#= submit_tag '确定',:onclick=>'submit_course_resource();',:onfocus=>'this.blur()',:id=>'submit_resource',:class=>'sendSourceText fr' %>
      <% end %>
    </div>

  </div>
  <% content_for :header_tags do %>
      <%= javascript_include_tag 'attachments' %>
  <% end %>
</div>

<script>
    function regex_publish_time()
    {
        var myDate = new Date();
        if($.trim($("#attachment_publish_time").val()) == "")
        {
            return true;
        } else{
            var publish_time = Date.parse($("#attachment_publish_time").val());
            if(Date.parse(formate_date(myDate)) > publish_time)
            {
                $("#publish_time_notice").text("发布日期不能小于当前日期");
                return false;

            }
            else
            {
                $("#publish_time_notice").text("");
                return true;
            }
        }
    }
    function submit_course_resource()
    {
        <% if User.current.allowed_to?(:as_teacher,course) %>
            if(regex_publish_time()) {
                $('#submit_resource').parent().submit();
            }
        <% else %>
            $('#submit_resource').parent().submit();
        <% end %>
    }
    $(function(){
        var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: 0, showOn: 'button', buttonImageOnly: true, buttonImage: '/images/public_icon.png', showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true};
        $('#attachment_publish_time').datepicker(datepickerOptions);
    });
</script>