<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" Inherits="Kesion.NET.WebSite.Course.Admin.Course.KS_Csperiod" CodeBehind="KS.CosLivePeriod.Aspx.cs" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Kesion.Course" %>
<asp:Content ID="Content2" ContentPlaceHolderID="KSContent" Runat="Server">
     <script>
         jQuery(document).ready(function () {
             showwatermarkarea();
         }
         );
         function showwatermarkarea() {
             var checkrad = jQuery("#<%=this.RadioButtonList2.ClientID %> :radio[checked]").val();
             if (checkrad == "2") {
                 jQuery("#<%=this.watermark0.ClientID %>").css("display", "none");
                jQuery("#<%=this.watermark2.ClientID %>").css("display", "");
            }else  if(checkrad=="1"){
                jQuery("#<%=this.watermark0.ClientID %>").css("display", "");  
                jQuery("#<%=this.watermark2.ClientID %>").css("display", "none");
            }
            else 
            {
                jQuery("#<%=this.watermark0.ClientID %>").css("display", "none");
                jQuery("#<%=this.watermark2.ClientID %>").css("display", "none");

            }
    }
    function searchSJ() {
        var key = jQuery("#<%=this.TxtSJKey.ClientID %>").val();
        if (key == '') {
            KesionJS.Alert("请输入试卷关键字！", "jQuery('#<%=this.TxtSJKey.ClientID %>').focus()");
                  return false;
              } else {
                  jQuery.ajax({ url: "KS.CosLivePeriod.Aspx?action=GetSJ&CourseId=<%=CourseId%>&Key=" + escape(key), success: function (d) {
                      jQuery("#<%=this.LstB2.ClientID %>").empty();
                      jQuery("#<%=this.LstB2.ClientID %>").append(d);
        }
        });
    }
}
  
function addUser() {
    var src = document.getElementById('<%=this.LstB2.ClientID %>');
    var dest = document.getElementById('<%=this.LstB1.ClientID %>');

    for (var i = 0; i < src.options.length; i++) {
        if (src.options[i].selected) {
            var exist = false;
            for (var j = 0; j < dest.options.length; j++) {
                if (dest.options[j].value == src.options[i].value) {
                    exist = true;
                    break;
                }
            }
            if (!exist) {
                var opt = document.createElement('OPTION');
                opt.value = src.options[i].value;
                opt.text = src.options[i].text;
                dest.options.add(opt);
            }
        }
    }
}

function delUser() {
    var dest = document.getElementById('<%=this.LstB1.ClientID %>');

        for (var i = dest.options.length - 1; i >= 0; i--) {
            if (dest.options[i].selected) {
                dest.options[i] = null;
            }
        }
    }

   </script>
    <script>
        function SetDownUrlByUpLoad(v,s)
        {
            jQuery("#"+s).val(v);

        }     
    
    	$(document).ready(function(){    	
    		getmyPeriod();
    	}); 

    </script>
    <script>
    	function loaddata() {
    		var key=$("#key").val();
    		if(!key)
    		{
    			alert("请输入课时名称")
    		}
    		else
    		{
    			$.ajax({
    				url: "?action=searchperiod&key=" + key + "&courseID=<%=CourseId%>&teacherid=<%=teacherid%>&userselect="+$("#userselect").val(),
   				context: document.body,
   				type: "GET",
   				success: function (data) {
   					$("#myloop").html(data);
   				}
   			});
		   }
    	}
 
    	function getmyPeriod()
    	{
    		$.ajax({
    			type: 'Post',
    			datatype: 'text',
    			url: "?action=getperiod",
    			data: { courseID:"<%=CourseId%>" },
   			success: function (msg) {
   				//alert(msg);
   				msg=msg+"#&##&##&#";
   				$("#myloop").html(msg.split("#&#")[0]);
   				$("#zhangnum").html(msg.split("#&#")[1]);
   				$("#jienum").html(msg.split("#&#")[2]);
   				$("#shinum").html(msg.split("#&#")[3]);
   				var num = $("#myloop li").length;
   				if(num==0){
   					$("#myloop").prev(".lineY").hide();
   					$("#myloop").html('<div class="empty">您还未添加任何课时</div>')
   				};
				
   				$("#myloop li").hover(function(){
   					$(this).find(".rButton").show();
   				},function(){
   					$(this).find(".rButton").hide();
   				});
				
   				$(".addButton").click(function(){
   					$(this).toggleClass("addOn");
   				});
				
   				$(".rButton .icon").hover(function(){
   					$(this).find("span").show();
   				},function(){
   					$(this).find("span").hide();
   				});
				
   				$(".rButton").click(function(){
   					doNone(click());
   				});
				
   				//展开收缩
   				click();
   				function click(){
   					$(".chapter,.section").click(function(){
   						$(this).find(".menubtn").toggleClass("menubtn2");
   						$(this).next(".box").stop().slideToggle(300);
   					});
   				};
   				//是否添加按钮
   				$(".menubtn").each(function() {
   					var num = $(this).parent().next(".box").length;
   					if(num==0){
   						$(this).hide();
   					};
   				});
   				$(".chapterBox").each(function() {
   					var i = $(this).index()+1;
   					if(i>10){
   						$(this).find(".chapter .menubtn").addClass("menubtn2");
   						$(this).find(".chapter").siblings(".box").hide();
   					};
   				});				

				
   			}
   		});
    	}
    	function doNone(evt) {
    		var e = (evt) ? evt : window.event; //判断浏览器的类型，在基于ie内核的浏览器中的使用cancelBubble
    		if (window.event) {
    			e.cancelBubble = true;
    		} else {
    			e.stopPropagation();
    		}
    	}
    	function IsDel(type)
    	{
    		if(type=="1")
    		{
    			if(confirm("是否删除该课时？"))
    			{
    				return true;
    			}
    		}
    		if(type=="0")
    		{
    			if(confirm("是否删除该章以及章下所有内容？"))
    			{
    				return true;
    			}
    		}
    		if(type=="2")
    		{
    			if(confirm("是否删除该节以及节下所有内容？"))
    			{
    				return true;
    			}
    		}
    		return false;
    	}
    </script>
<script type="text/javascript">

    function add(id,type,parentid) {
    	parent.openWin('添加章节', 'course/KS.CosAddLiveZj.aspx?action=add&type='+type+'&parentid='+parentid+'&Courseid='+id, true,600,300);
    }
    function edit(id,Periodid,type,parentid) {
    	parent.openWin('修改章节', 'course/KS.CosAddLiveZj.aspx?action=edit&type='+type+'&Courseid='+id+'&parentid='+parentid+'&Periodid='+Periodid, true,600,400);
    }

    function pro(id,parentid) {

        location.href='KS.CosLivePeriod.Aspx?action=pro&CourseId='+<%=CourseId %>+'&Periodid='+id+"&parentid="+parentid;
     }
     function next(id,parentid) {

         location.href='KS.CosLivePeriod.Aspx?action=next&CourseId='+<%=CourseId %>+'&Periodid='+id+"&parentid="+parentid;
    }

    function ExtSub(ID,event,bookid) {//阻止冒泡调用parent
     
        var e = (event) ? event : window.event;
        if (window.event) {//IE
            e.cancelBubble = true;
        } else { //FF
            e.stopPropagation();
        }
        if (jQuery('#sub'+ID).html()=='')
        {
            jQuery('#C'+ID).attr('src','../../sysimg/tree/open.gif');
            jQuery('#sub'+ID).html('<div style="padding-left:20px"><img src=../../admin/images/loading.gif>子分类加载中...</div>');
            jQuery('#ajaxmsg',window.parent.document).toggle();
            jQuery.ajax({
                type: "POST",
                url: "KS.CosLivePeriod.Aspx",
                data: "parentid="+ID+"&action=ExtSub&CourseId="+bookid,
                success: function(data){
                    jQuery('#ajaxmsg',window.parent.document).toggle();
                    jQuery("#sub"+ID).html(data);
                }
            });
 
        }
        else{
            jQuery('#sub'+ID).html('');
            jQuery('#C'+ID).attr('src','../../sysimg/tree/close.gif');
        }
    }
</script>
<script>

	      
    
	      function OtherTc() {
	          var checkrad = jQuery("#<%=this.bookclasszj.ClientID %> :radio[checked]").val();
	          if (checkrad == "1") {
	           
	              jQuery("#<%=this.Tbody5.ClientID %>").css("display", "");
	            //  jQuery("#zjclass").show();
	          } else {
	            
	              jQuery("#<%=this.Tbody5.ClientID %>").css("display", "none");
	             // jQuery("#zjclass").hide();
	          }
          }

          function intoen(id){
              var checkrad = jQuery("#d:radio[checked]").val();
	          if (checkrad==0||id==0){
	              jQuery("#inlsit").hide();
	              jQuery("#plinto").hide();
	              jQuery("#numperio").show();
	          }else{
	              jQuery("#numperio").hide();
	              jQuery("#inlsit").show();
	              jQuery("#plinto").show();
	          }
        
    }
         var issubmit = false;
	      function CheckForm() {
	          if (jQuery('#<%=this.ClassName.ClientID %>').val() == '' && jQuery("#AddType")[0].checked == false) {
	              KesionJS.Alert('请输入名称！', "jQuery('#<%=this.ClassName.ClientID %>').focus()");
	              return false;
	          }
	          var idArr = new Array();
	          var dest = document.getElementById('<%=this.LstB1.ClientID %>');
               for (var i = 0; i < dest.options.length; i++) {
                   dest.options[i].selected = "true";
                   idArr.push(dest.options[i].value);
               }
        	if (issubmit == false) {
                 issubmit = true;
                 return true;
            } else {
                return false;
            }
          }

          $(document).ready(function(){
              if (parseInt(<%=AddType.ToString()%>)==1)
	          {    
	             
	              jQuery("#<%=this.Tbody5.ClientID %>").css("display", "");
	           //   jQuery("#zjclass").show();
	          }
	          intoen(0);         
	      
	          OtherTc()
	         
	      });  

</script>
<script>
    function showToggle(id) {
        if (jQuery('#xt' + id).html() == '') {
            jQuery('#xt' + id).append('<tr class="tdbg"><td height="30" align="center" colspan="4">该章节下还没有绑定课时!</td></tr>');
        }
        var t = jQuery("#t" + id).html();
        if (t.indexOf('打开') != -1) {
            jQuery('#xt' + id).slideDown('fast');
            jQuery("#t" + id).html('<span class="tree_Open"/>关闭</span>')
        } else {
            jQuery('#xt' + id).slideUp('fast');
            jQuery("#t" + id).html('<span class="tree_Close"/>打开</span>')
        }
    }
    jQuery(document).ready(function() {
             <%if (KSCMS.S("action") == "modifyth") {%>
        jQuery(".toggleArea").html('<span class="tree_Open"/>关闭</span>');
        jQuery('.showArea').each(function(){
            if (jQuery(this).html()==''){
                jQuery(this).append('<tr class="tdbg"><td height="30" align="center" colspan="4">该章节下还没有绑定课时!</td></tr>');
            }
        });
                 <%}else{ %>
        jQuery(".toggleArea").html('<span class="tree_Close"/>打开</span>');
        jQuery(".showArea").attr("style","display:none");
                 <%} %>
    });
    var currStatue=1;
    function openAll(){
        if (currStatue==1){ //展开
            currStatue=0
            jQuery(".toggleArea").html('<span class="tree_Open"/>关闭</span>');
            jQuery('.showArea').each(function(){
                if (jQuery(this).html()==''){
                    jQuery(this).append('<tr class="tdbg"><td height="30" align="center" colspan="4">该课程下还没有绑定试卷!</td></tr>');
                }
            });
            jQuery('.showArea').show();
            jQuery("#allstate").html('[全部隐藏]');
        }else{
            currStatue=1;
            jQuery(".toggleArea").html('<span class="tree_Close"/>打开</span>');
            jQuery(".showArea").attr("style","display:none");
            jQuery("#allstate").html('[全部展开]');
        }
    }
</script>
<asp:Panel ID="ClassList" runat="server" Width="100%">
    <%if(istop==0){ %>
    <div class="listedit">
       <ul>
         <li id='p6'><a href="javascript:;" onclick="location.href='KS.CosLiveList.aspx';" class="button">返回课程列表</a></li> 
       </ul>
     </div>  
     <div class="footer_page"></div>
     <!--当前课程信息-->
     <asp:PlaceHolder ID="PlaceHolder1"  runat="server"></asp:PlaceHolder>
    <div class="content-area pageBlank">
    	<div class="myTitle">
             <div class="tabButton">
               <a class="on" class="noLeftBorder" href="KS.CosLivePeriod.Aspx?CourseId=<%=CourseId %>&teacherid=<%=teacherid%>">课时</a>
			   <a href="KS.CsTeacher.aspx?CourseId=<%=CourseId %>&teacherid=<%=teacherid%>&CosType=3">教师</a>
               <a href="KS.CsZLInfo.aspx?type=5&CourseId=<%=CourseId %>&teacherid=<%=teacherid%>">资料</a>
               <a href="KS.CosLearnRecord.aspx?courseid=<%=CourseId %>&teacherid=<%=teacherid%>&CosType=3">学员</a>
               <a href="KS.CosPJ.aspx?courseid=<%=CourseId %>&teacherid=<%=teacherid%>&CosType=3">评价</a>
             
           	</div>
            <%} %>
        	课时管理<span class="titleTips">该课程下共<span id="zhangnum"></span>章，<span id="jienum"></span>节，<span id="shinum"></span>课时</span>
       	</div>
     	<div class="quickSearch clearfix md20">
        	<div class="fr headOperation ">
            	<a onclick="add(<%=BookID.ToString()%>,0,0)" href="javascript:void(0);" class="button ml15 button_on">添加章</a>
             	<a onclick="add(<%=BookID.ToString()%>,2,0)" href="javascript:void(0);" class="button ml15 button_on">添加节</a>
             	<a href="?action=add&Addtype=1&CourseID=<%=CourseId %>&Parentid=0&teacherid=<%=teacherid%>" class="button ml15 button_on">添加课时</a>
            </div>
            <div class="SearchBox fl">
               
                <input type="text"  value="" id="key"  onkeypress="if(event.keyCode === 13){ event.preventDefault(); loaddata()}" style="margin-right:8px;"/>
                <select id="userselect" style="margin-right:8px;">
                    <option value="1">课时</option>
                    <%--<option value="0">章</option>
                    <option value="2">节</option>--%>
                </select>
                <input name="" value="搜索" type="button" class="button" onclick="loaddata()" />
            
            </div>
        </div>
   <div class="courseTips">
        	
       </div>
       <div class="clear blank10"></div>
	
        <div class="courseKeshi">
        	
        	<div class="lineY"></div>
            <ul id="myloop">
            
        	</ul>
            
        </div>
       
           </asp:Panel>
        <asp:Panel ID="ClassAdd" runat="server" Width="100%">
<style>
#DefaultFile{ margin-bottom:0;}
#upframe{ margin-top:10px;}
</style>
<!--<KS:TopNav ID="TopNav1" runat="server" Text="添加章节" /> -->  
<div class="content-area mt20">
	<div class="myTitle"><%=A=="edit"?"编辑":"添加" %>课时</div>
             <table width="100%" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable">
	
                 
                      <tr>
                       <td align="right" class="lefttd" style="width: 155px;border-top:0px;"><strong>
                           添加课程章节：</strong><br>
                         </td>
                         <td class="righttd" style="border-top:0px;">
                       <asp:RadioButtonList ID="bookclasszj" runat="server" RepeatDirection="Horizontal">
                           <%--  <asp:ListItem Value="0" Selected="True">添加章节</asp:ListItem>--%>
                             <asp:ListItem Value="1"  Selected="True">添加课时</asp:ListItem>
                       </asp:RadioButtonList>
                       </td>
                     </tr>
                         
                   
                    <tr>
                    <td class="lefttd" height="30" align="right" style="width: 155px">
                        <strong> <font color="red">*</font>标题：</strong></td>
                    <td class="righttd" width="751">
                       <span id="AddOne">
                        <asp:TextBox CssClass="textbox" ID="ClassName" runat="server"  Width="350px"></asp:TextBox>
                       </span>                     
                         </td>
                  </tr>
				     <tr>
                       <td align="right" class="lefttd" style="width: 155px; height: 37px;"><strong>
                           所属章节：</strong><br>
                         </td>
                         <td class="righttd" style="height: 37px;">
                             <asp:DropDownList ID="MyItem" runat="server" Width="250">
                             <asp:ListItem Value="0">请选择章节</asp:ListItem>
                             </asp:DropDownList>
                       </td>
                    </tr>  
                  <tbody id="Tbody5" style="display:none" runat="server">
                     <tr>
                        <td align="right" class="lefttd" height="30" style="width: 102px">
                            <strong>是否有模拟试卷：</strong></td>
                        <td class="righttd">
                            
                            <asp:RadioButtonList ID="RadioButtonList2" onclick="showwatermarkarea()" runat="server"
                                RepeatDirection="Horizontal" Height="24px">
                                <asp:ListItem Value="0" Selected="True">无</asp:ListItem>
                              <%--  <asp:ListItem Value="1">指定试卷栏目</asp:ListItem>--%>
                                <asp:ListItem Value="2">指定试卷ID</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
        <tbody id="watermark0" runat="server" style="display: none">
                        <tr>
                            <td align="right" class="lefttd">
                                <strong>试卷栏目：</strong></td>
                            <td class="righttd">
                                <asp:ListBox ID="ListSjClass" runat="server" Width="150px" SelectionMode="Multiple" Height="150px"></asp:ListBox>
                                <a class="textarea_min" href="javascript:zoomtextarea(-5,'<%=this.ListSjClass.ClientID %>');"></a>
                                <a class="textarea_max" href="javascript:zoomtextarea(5,'<%=this.ListSjClass.ClientID %>');"></a>
                            </td>
                        </tr>
                    </tbody>
            <tbody id="watermark2" style="display: none" runat="server">
                        <tr>
                            <td align="right" class="lefttd" height="30">
                                <strong>试卷ID：</strong></td>
                            <td class="righttd" valign="top">&nbsp;
         
            <table border="0" width='100%'>
                <tr>
                    <td style="width: 350px">搜索试卷：<asp:TextBox ID="TxtSJKey" runat="server" Width="160px" CssClass="textbox" />
                        <input type="button" value="搜索" class="button" onclick="searchSJ();" cssclass="button" />
                        <div class="clear blank10"></div>

                        <asp:ListBox ID="LstB2" runat="server" Width="300px" Height="200px" SelectionMode="Multiple"></asp:ListBox>
                    </td>
                    <td>
                        <p>
                            <input type="button" value=" > " onclick="addUser()" class="button" />
                        </p>
                        <br />
                        <p>
                            <input type="button" value=" < " onclick="delUser()" class="button" />
                        </p>
                    </td>
                    <td>指定试卷如下：
                 <br />
                        <asp:ListBox ID="LstB1" runat="server" Width="300px" Height="200px" SelectionMode="Multiple"></asp:ListBox>
                    </td>

                </tr>
            </table>
                              </td>
                        </tr>
                        <tr style="display:none">
                            <td align="right" class="lefttd" height="30"><strong>考试状态规定：</strong></td>
                            <td class="righttd">
                                <asp:TextBox ID="regulations" CssClass="textbox"
                                    runat="server" Width="40px" Height="23px"></asp:TextBox>%
               <font color="red">学习达到总课时的多少比例时才能考试，留空或0为不限制</font>
                            </td>
                        </tr>

                    </tbody>
             <tr style="display:none">
            <td align="right" class="lefttd" height="30">
                <strong>课时编号：</strong></td>
            <td class="righttd">
                &nbsp;<asp:label ID="TxtOrderID" runat="server"  Width="20px" Text=""></asp:label>课时</td>
        </tr>     
       </tbody>
        <asp:PlaceHolder ID="PeriodPlace"  runat="server"></asp:PlaceHolder>                    
       
   </table>

      
          <KS:Foot ID="Foot1" runat="server" OnSubmit="SaveButton_Click" />
        </asp:Panel>

		 <script>
		 	$(document).ready(function () {
		 		openAll();
		 	});

     </script>
  </div>   
</asp:Content>



