<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomGroup_Form.aspx.cs" Inherits="RM.Web.Training.CustomGroup.CustomGroup_Form" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
 <title><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Edit")%>/<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("group_zdyfz")%></title>
    <link href="/Themes/Styles/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/artDialog.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/iframeTools.source.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/Validator/JValidator.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Live/swfobject.js"></script>
    
    <script type="text/javascript">
       //获取表单值
        function SaveForm() {
            var CustomName = $("#CGName").val();
            var Customdes = $("#CGDescr").val();            
            if (!CheckDataValid('#form1')) {
                return false;
            } else if (CustomName.length <= 0) {
                showWarningMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("group_zdyfzmc")%><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("group_notnull")%>");
                return false;
            } else if (editor.isEmpty()) {            
                showWarningMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("CustomExam_Form_msbnwk")%>");
                return false;
            }  else {
                //同步数据到文本框
                editor.sync();
                return true;
            }
        }
        //////////////////////////////////////////////////////////
        
//var $ExamPlan_ExamId = $("#ExamPlan_ExamId"); //隐藏域对象
var $promptBg = $("#promptBg"); //正在加载模板
var isLoad = false; //是否正在异步加载

$(function () {
//    $ExamPlan_ExamId = $("#ExamPlan_ExamId"); //隐藏域对象
    $promptBg = $("#promptBg");
    //模糊查询文本框
    $("#CGName").keydown(function (e) {
        var event = e || event; //兼容性处理
        if (event.keyCode == 27) {
            $promptBg.stop().hide(0, function () {
                $promptBg.html("");
            });
            return;
        } else if (event.keyCode == 37 || event.keyCode == 39) return;
        else if (event.keyCode == 13) {
            var $obj = $(".activePrompt");
            if ($obj.length < 1) return false;
            //$ExamPlan_ExamId.val($obj.attr("data"));
            $("#CGName").val($obj.text().substring(0, $obj.text().length - 2));
            $promptBg.stop().hide(0, function () {
                $promptBg.html("");
            });
            return false;
        }
        if ($("#loadIcon").length < 1) {
            if (event.keyCode == 38) { //向上
                if ($(".activePrompt").length < 1) {//第一个
                    $(".promptLink").last().addClass("activePrompt");
                    return false;
                }
                $currObj = $(".activePrompt").parent();
                if ($currObj.prev().length < 1) return false; //最后一个
                var $nextObj = $currObj.prev().children("a");
                $(".activePrompt").removeClass("activePrompt");
                $nextObj.addClass("activePrompt");
                return false;
            }
            if (event.keyCode == 40) { //向下
                if ($(".activePrompt").length < 1) {//第一个
                    $(".promptLink").eq(0).addClass("activePrompt");
                    return false;
                }
                $currObj = $(".activePrompt").parent();
                if ($currObj.next().length < 1) return false; //最后一个
                var $nextObj = $currObj.next().children("a");
                $(".activePrompt").removeClass("activePrompt");
                $nextObj.addClass("activePrompt");
                return false;
            }
        }
    });
   //文本框聚焦事件
    function textChange() {
        if (isLoad) return;
        $("#promptBg").show(0);
        var inputvalue = $("#CGName").val();
        isLoad = true;        
        $.get("/Training/CustomGroup/GetCustomGroup.ashx", { action:"getcgname", cgname:encodeURI( inputvalue) }, function (data) {
            isLoad = false;
            if (!data || parseInt(data) == -1) {
                $promptBg.stop().hide(0, function () {
                    $promptBg.html("");
                });
                return; //没有查询到数据或者异常
            }
            $("#promptBg").html(data);
            $(".promptLink").hover(function () {//绑定事件
                $(this).addClass("activeLink");
            }, function () {
                $(this).removeClass("activeLink");
            });
            $(window).one("click", function () {
                $promptBg.stop().hide(0, function () {
                    $promptBg.html("");
                });
            });
        });
    }

    if ($.browser.msie) {//根据兼容性绑定不同的文本改变事件
        $("#CGName").bind("input propertychange", textChange);
    } else {
        $("#CGName").bind("input", textChange);
    }
});
//点击文本后事件
function choiseExam(obj, e, kemu) {
    var id = $(obj).attr("data");
    var name = $(obj).text().substring(0, $(obj).text().length - 2);
    $("#CGName").val(name);
    //addNew(id, name, kemu);   
    $("#cslist").show();
    $promptBg.stop().hide(0, function () {
        $promptBg.html("");
    });
    stopBubble(e);
    function stopBubble(e) {
        if (e && e.stopPropagation) {
            e.stopPropagation();
        } else {
            window.event.cancelBubble = true;
        }
    }
    //获取选择文本的相关信息
     $.get("/Training/CustomGroup/GetCustomGroup.ashx", 
    { action:"getcours", gid:id }, function (data) {
        if(data!=null&& data!="" && data!="[]"&& data!="-1"){
            var str = eval(data);
            addCours(str);
        }
    });

      $.get("/Training/CustomGroup/GetCustomGroup.ashx", 
    { action:"getcginfo", gid:id }, function (data) {
        if(data!=null&& data!="" && data!="[]"&& data!="-1"){
            var str = eval("("+data+")");
            //CGName = model.CGName, 
            //CGFID = model.CGFID,
             $("#FileUpload1").val(str["CGImg"]);
             
             $("#CGDescr").val(str["CGDescr"]);
             $("#Remark1").val(str["Remark1"]);
             $("#CustomGroup_sort").val(str["CustomGroup_sort"]);             
             $("#CustomGroup_FileResource").val(str["CustomGroup_FileResource"]);
             $("#FileUpload1").val(str["FileUpload1"]);
             //CustomGroup_Organize = model.CustomGroup_Organize           
        }
    });

}
//绑定相关信息
function addCours(data){
    $("#tabcoures").show();
    var csids="";
    for(var i=0;i<data.length;i++){
        if(csids==""){
            csids=data[i]["Courseware_CsID"];
        }else{
            csids+=","+data[i]["Courseware_CsID"];
        }
        $("#coures").append("<tr><td><input type='checkbox' checked='checked' name='checkbox_cs' value='" +data[i]["Courseware_CsID"] + "'></td><td><input  value='" + data[i]["Courseware_CsName"] + "' name='checkbox_name_" + i + "' style='width: 200px;' /></td><td><input style='width:150px;'  value='" + data[i]["CoursewareType_CtName"] + "' name='checkbox_Type_" + i + "'/></td></tr>");
    }
    $("#csids").val(csids);
    csids="";
}


//增加新数据
var rowindex = 1;
function addNew(id, name, Type) {
    $("#tablebody tbody").append("<tr><td><input type='checkbox' checked='checked' name='checkbox_cs' value='" + rowindex + "|" + id + "'></td><td><input  value='" + name + "' name='checkbox_name_" + rowindex + "' style='width: 200px;' /></td><td><input style='width:150px;'  value='" + Type + "' name='checkbox_Type_" + rowindex + "'/></td></tr>");
    rowindex++;
}
    </script>

    <style type="text/css">
        
    #cblExamPlan{  border:0; width:500px;}
    #cblExamPlan tr{  border:0; }
    #cblExamPlan td{  border:0; height:0px; padding:0px; margin:0px; line-height:0px; }
    #promptBg ul, #promptBg li { padding: 0; margin: 0; list-style: none; }
    #tabcoures{ padding:0px; margin:0px; display:none;  }
    #tabcoures tr,td,th{ border:0;}
    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style=" height:550px;overflow-y:scroll;">
     <table id="tablebody" border="0" cellpadding="0" cellspacing="0" class="frm">        
     
        <tr>
            <th style="width: 80px;">
                <font color="red">*</font><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("group_zdyfzmc")%>：
            </th>
            <td>
            
            <div style="position: relative;">
                <input id="CGName" runat="server" type="text" class="txt" datacol="yes" err="自定义分组名称"
                    checkexpession="NotNull" style="width: 200px" />
                 <%--<input type="hidden" value="" runat="server" id="ExamPlan_ExamId" />--%>
                 <input type="hidden" value="" runat="server" id="csids" />
                    <div id="promptBg" style="display: none; cursor: pointer; position: absolute; width: 228px;
                            background-color: White;">
                            <div id="loadIcon" style="text-align: center; line-height: 18px;">
                                <img src="../../Themes/Images/loading1.gif" alt="" />
                                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Loading")%>
                            </div>
                        </div>
            </div>
                <table id="tabcoures" cellpadding="0" cellspacing="0"   >
                    <thead><tr><td></td><td>课件名称</td><td>课件分类</td></tr></thead>
                    <tbody id="coures"></tbody>
                </table>
            </td>
            <td rowspan="4"> <img id="Image1" style="width:45px; height:45px;"  runat="server" /></td>
        </tr>
        <tr>
            <th><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("CertificateType_Node")%>：</th>
            <td>
                <select id="ddlCGName" class="select" runat="server" style="width: 50%">
                </select>

            </td>
        </tr>
        <tr>
        <th>
             <font color="red">*</font><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("user_group")%>：
        </th>
        <td>
           <script src="/Themes/Scripts/GetuserControl.js" type="text/javascript"></script>
        </td>
        </tr>
        <tr>
            <th>
                <font color="red">*</font><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Button_List_ico")%>：
            </th>
            <td>            
            <asp:FileUpload ID="FileUpload1" runat="server" style=" width:252px;" />
            </td>
        </tr>
<%--        <tr>
            <th>
                <font color="red"></font><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("MyExamPlan-km")%> :
            </th>
            <td>                
                <asp:DropDownList ID="kemu" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="kemu_SelectedIndexChanged">
                </asp:DropDownList>
            </td>
        </tr>--%>
              
        <tr>
            <th><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("group_zdyfz")%><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("group_miaoshu")%>：
            </th>
            <td colspan="2" >

            <script src="/Themes/Scripts/kindeditor/kindeditor-min.js" type="text/javascript"></script>
                    <script type="text/javascript">
                        var editor;
                        KindEditor.ready(function (K) {
                            editor = K.create('#CGDescr', {
                                allowFileManager: true,
                                allowUpload: true,
                                uploadJson: '/WeiXin/UploadImage.ashx',
                                minHeight: 200
                            });
                        });
                    </script>                    
                <textarea id="CGDescr" class="txtRemark" runat="server" style="width: 680px;"></textarea>
            </td>
        </tr>
        <tr>
        <th>类型：</th>
        <td><input id="Remark1" type="text" runat="server" class="txt" /> </td>       
        </tr>
        
          <tr>
            <th>
                 <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SortIndex")%>：
            </th>
            <td>
                <input id="CustomGroup_sort" runat="server"  datacol="yes" checkexpession="NotNull"  type="text" err="排序码" class="txt" />
            </td>
        </tr>

        <tr>
        <th>视频地址：</th>
        <td>
        <p class="file-box" id="moviebutton" style="display: block; margin-top: 6px; border: 1px #ccc solid;
        background: #f4f4f4; height: 30px; line-height: 30px; width: 94%; padding: 1px 3px;overflow:hidden;" title=" <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_zyyhttp")%>">
        <input type="button" onclick="shangchuan_mo()" value="<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_bdspsc")%>" /> <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_zyyhttp")%>
    </p>
        <input id="CustomGroup_FileResource" type="text" runat="server" class="txt"  style="width:200px;" /><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_zcmp4")%></td>
        </tr>
    </table>
    
    <div class="frmbottom">
        <asp:LinkButton ID="Save" runat="server" class="l-btn" OnClientClick="return SaveForm();"
            OnClick="Save_Click"><span class="l-btn-left">
            <img src="/Themes/Images/disk.png" alt="" /><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Save")%></span></asp:LinkButton>
        <a class="l-btn" href="javascript:void(0)" onclick="OpenClose();"><span class="l-btn-left">
            <img src="/Themes/Images/cancel.png" alt="" /><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Close")%></span></a>
    </div>
    </div>
    </form>
    
    <div id="tksup" style=" display:none; border: 1px #ccc solid;width: 610px;  margin-top:-430px;  margin-left:110px; background-color:White; padding-left:10px;">
       
    </div>
    
    <script type="text/javascript">   
         
         var addtype=0;
    //视频上传
    function shangchuan_mo(){
        addtype=1;
         var flashvars = {
                FileType:'*.html;*.htm;*.shtml;*.flv;*.mp4',
                FileMaxCount:10,
                FilePath:'/Training/Courseware/Courseware_movieAdd.ashx',
                FileSize:1024*300
            };
            FlexUpload(flashvars);
    }
    
    //Flex文件上传
    function FlexUpload(flashvars)
    {
        $("#tksup").show();
        $("#tksup").append("<div id='ad1'></div>");

        var swfVersionStr = "10.0.0";
        var xiSwfUrlStr = "/live/playerProductInstall.swf";
        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "sameDomain";
        params.allowfullscreen = "true";
        var attributes = {};
        attributes.id = "ad1";
        attributes.name = "ad1";
        attributes.align = "middle";
        swfobject.embedSWF("/Live/TKS-UP.swf", "ad1","600", "270", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
    }
    
     //Flex上传回调函数
    //---name:为文件名---data:FilePath地址返回值
    function uploadCompelete(name,data){
        if(addtype==1){//视频
            if (data=="1") {
                   showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_size")%>",2000, 5);
              }else if(data=="3"){
                 showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Abnormal network connection")%>", 2000, 5);
               }else if(data =="4"){
                 showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_not")%>", 2000, 5);
               }else {
                    path=data;
                    if (path != "") {
                        //name = name.substring(name.lastIndexOf("\\") + 1, name.lastIndexOf("."));
                        //$("#fileinfo").append("<li><input type=\"text\" name=\"fileChapters\" value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("ChapterPlan_Form_zjm")%> \" /><input type=\"text\" name=\"filename\" value=\"" + decodeURI(name) + "\" /><input type=\"text\" name=\"filepath\" value=\"" + path + "\"  style=\"width: 300px\" /><select name=\"fileTrySess\"><option value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_buyunx")%>\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_baom")%></option><option value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_yunx")%>\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Courseware_shikan")%></option></select><input type='button' value='×' onclick='moviedelete(this)'/></li>");                        
                        $("#CustomGroup_FileResource").val(path);
                    }
               }
        }else{
            
        }        
    }
    
    //全部文件上传结束后触发
    function uploadEnd(name){
        $("#tksup").hide();
        $("#ad1").remove();
    }
    
</script>                    
        
</body>
</html>