<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.APPCode" %>
<%@ Import Namespace="Kesion.Weixin" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载
    DataRow dr = null;

    public static int parentid = 0;
    public int SuCaiId = 0;
    public int num = 0;
    public string Content = string.Empty;
    public string title = string.Empty;
    public string PicUrl = string.Empty;
    public string Type = "0";
    public string Intro = string.Empty;
    public string Url = string.Empty;
    public string action = string.Empty;
    public int id = 0;
    public int Show_cover_pic = 0;
    public int keytype = 1;
    public int picId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        string DoMethod = KSCMS.S("do");
        if (string.IsNullOrEmpty(DoMethod))
        {
            DoMethod = KSCMS.S("action");
        }
        __info.Panel1 = false;
        parentid = Utils.StrToInt(KSCMS.S("parentid"));
        SuCaiId = Utils.StrToInt(KSCMS.S("sucaiId"));
        switch (DoMethod)
        {
            case "modify":
                num = Utils.StrToInt(DataFactory.GetOnlyValue("select count(*) from ks_weixinpigmsg where parentid=" + SuCaiId)) + 1;
                Modify();
                __info.Panel1 = true;
                break;
            case "delete":
                delete();
                break;
            case "add":
                num = 0;
                __info.Panel1 =true;
                break;
            case "save":
                Btn_Save_Click();
                break;
        }
    }
    private void delete()
    {
        #region 删除
        using (DataTable dt = DataFactory.GetDataTable("select  * from  KS_weixinpigmsg where ParentID=" + SuCaiId))
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    Hashtable ht = new Hashtable();
                    ht.Add("id", dr["id"].ToString());
                    CommonData.Delete("KS_weixinpigmsg", ht);
                }
            }
        }
        Hashtable ht2 = new Hashtable();
        ht2.Add("id", SuCaiId);
        CommonData.Delete("KS_weixinpigmsg", ht2);
        Msg.Alert("恭喜，删除成功!",BasicField.GetUserUrl("wx/wx_PicMsg"));
        #endregion
    }
    private void Modify()
    {
        using (DataTable dt = DataFactory.GetDataTable("select top 1 * from  KS_weixinpigmsg where id=" + SuCaiId))
        {
            if (dt.Rows.Count > 0)
            {
                dr = dt.Rows[0];
                Intro = dr["Info"].ToString();
                Content = dr["content"].ToString();
                PicUrl = dr["picurl"].ToString();
                title = dr["title"].ToString();
                Type = dr["ispic"].ToString();
                Url = dr["url"].ToString();
                id = Utils.StrToInt(dr["id"].ToString());
                keytype = Utils.StrToInt(dr["SystemType"].ToString());

            }
        }
    }
    public string GetModifystr(int num, int parentID)
    {
        string str = string.Empty;
        num = 0;
        if (parentID != 0)
        {
            using (DataTable dt = DataFactory.GetDataTable("select  * from  KS_weixinpigmsg where ParentID=" + parentID))
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {

                        num++;
                        str += string.Format(@"<li id=""appmsg_item{0}"" num=""{0}"" >
			     <div class=""left_img_box_list"">
				  <div class=""add_sc_img"">
                   <div class=""add_sc_img_right"">
				  <img src=""{1}""  id=""img_box{0}""/>
				   </div>
				   <div class=""add_sc_img_left{0}"" id=""defaulttitle{0}"">
				  <a class=""title_add_sc"">{2}</a>
				   </div>
				   <div class=""clear""></div>
				   </div>
				  <div class=""sc_default_title_bg"">
				   <a href=""javascript:deletesucai({0},{3})"" class=""order_by_delete""><img src=""/admin/weixin/images/scdelete.png"" /></a>
			       </div> 
                      <input id=""keytype{0}""  name=""keytype{0}"" type=""hidden"" value=""{11}""/>
                   <input type=""hidden"" name=""default_title{0}"" id=""default_title{0}"" value=""{2}""/>
                  <textarea id=""default_content{0}"" name=""default_content{0}"" cols=""20"" rows=""2"" style=""display:none"">{4}</textarea>
                  
                    <input type=""hidden"" name=""default_url{0}"" id=""default_url{0}"" value=""{5}""/>
                    <textarea name=""default_intro{0}"" id=""default_intro{0}"" style=""display:none"">{6}</textarea>
                    <input type=""hidden"" name=""default_img{0}"" id=""default_img{0}""  value=""{1}""/>
                    <input type=""hidden"" name=""default_type{0}"" id=""default_type{0}"" value=""{7}"" />
                    <input type=""hidden"" name=""default_ID{0}"" id=""default_ID{0}"" value=""{3}""/>
                    <input type=""hidden"" name=""default_ShowPic{0}"" value=""{8}"" id=""default_ShowPic{0}"" />
		            <input type=""hidden"" name=""default_tuwen{0}"" id=""default_tuwen{0}"" value=""{9}"" />
                    <input type=""hidden"" name=""default_course{0}"" id=""default_course{0}""  value=""{10}""/>
                    <input id=""CosType{0}"" type=""hidden""  name=""CosType{0}""/>
                    <input id=""TxtTuWenID{0}"" type=""hidden""  name=""TxtTuWenID{0}""/>
                    <input id=""TxtcourseID{0}"" type=""hidden""  name=""TxtcourseID{0}""/>
                    <textarea id=""ShowTxtTuWen{0}"" style=""width:300px;height:200px;display:none""></textarea>
                    <textarea id=""ShowTxtcourse{0}"" style=""width:300px;height:200px;display:none""></textarea>
                  </li>", num, dr["picurl"].ToString(), dr["title"].ToString(), dr["id"].ToString(), dr["content"].ToString(), dr["url"].ToString(), dr["info"].ToString(), dr["ispic"].ToString(), dr["Show_cover_pic"].ToString(), dr["tuwenid"].ToString(), dr["courseid"].ToString(), dr["SystemType"].ToString());
                    }
                }
            }
        }
        return str.ToString();
    }
    public string GetParam(string field)
    {
        #region 获取dr的值
        if (dr != null)
        {
            return dr[field].ToString();
        }
        else
        {
            return "";
        }

        #endregion
    }
    public string GetChildSu(int suid)
    {
        StringBuilder sb = new StringBuilder();
        using (DataTable dt = DataFactory.GetDataTable("select  * from  KS_weixinpigmsg where ParentID=" + suid))
        {

            if (dt.Rows.Count > 0)
            {
                string str = " <div class=\"sc_ulbottom_con\"> <ul class=\"sc_ulse\">";
                foreach (DataRow dr in dt.Rows)
                {
                    str += string.Format(@"<li>
						
						<div class=""add_sc_img_right""><img src=""{0}"" id=""img_right1""></div>
						<div class=""add_sc_img_left1"" style=""float: left;"">
						<a class=""title_add_sc"">{1}</a>
						</div>
						<div class=""clear""></div>
					</li>", dr["picurl"].ToString(), Utils.CutStr(dr["title"].ToString(), 45));

                }
                str += "</ul></div>";
                sb.Append(str);
            }
        }
        return sb.ToString();

    }
    protected void Btn_Save_Click()
    {
        #region 保存
        int num = Utils.StrToInt(KSCMS.S("tiaoshu"));
        int parentid = 0;
        for (int i = 0; i <= num; i++)
        {
            Hashtable ht = new Hashtable();
            if (i == 0)
            {
                #region 父级
                ht.Add("ParentID", 0);
                if (KSCMS.S("default_type" + i) == "1")
                {
                    if (!string.IsNullOrEmpty(KSCMS.S("default_title" + i)))
                    {
                        ht.Add("title", KSCMS.S("default_title" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_img" + i)))
                    {
                        ht.Add("picurl", KSCMS.S("default_img" + i));

                        #region 根据图片路径得到缩列图Media_ID
                        string access_token = ks_weixin.IsExistAccess_Token(1);
                        bool isRemote = false;
                        string pic = KSCMS.S("default_img" + i); //
                        if (pic.ToLower().StartsWith("http:"))
                        {
                            string filename = Utils.RndNum(5) + DateTime.Now.ToFileTimeUtc() + pic.Substring(pic.LastIndexOf("."));
                            string SavePath = MyCache.GetCacheConfig(0) + MyCache.GetCacheConfig(22) + "/temp/" + filename;
                            Kesion.Publics.UtilsFile.CreateFolders(MyCache.GetCacheConfig(0) + MyCache.GetCacheConfig(22) + "/temp/");
                            //KSCMS.Die(Kesion.APPCode.Public.SaveRemoteFile(pic, SavePath)+"=="+ pic + "===" + SavePath);
                            if (Kesion.APPCode.Public.SaveRemoteFile(pic, SavePath).Equals(true))
                            {
                                isRemote = true;
                                pic = SavePath;
                            }
                            else
                            {
                                Msg.Alert("图片[" + pic + "]存储失败，请选择其它图文！");
                            }
                        }
                        string msg = UploadMedia(ks_weixin.IsExistAccess_Token(1), "thumb", Utils.GetMapPath(pic)); // 上图片返回媒体ID

                        string media_id = ks_weixin.GetJsonValue(msg, "media_id");
                        if (isRemote)
                        {
                            Kesion.Publics.UtilsFile.DelFile(pic);
                        }
                        ht.Add("Media_ID", media_id);
                        #endregion
                    }

                    ht.Add("IsPic", KSCMS.S("default_type" + i));

                    if (KSCMS.S("keytype" + i) == "1")
                    {
                        if (!string.IsNullOrEmpty(KSCMS.S("default_tuwen" + i)))
                        {
                            #region 图文
                            string url = string.Empty;
                            string[] names = string.Concat(KSCMS.S("default_tuwen" + i), "§").Split('§');
                            using (DataTable dt2 = DataFactory.GetDataTable("select Top 1 * from KS_EnterpriseNews where id=" + Utils.StrToInt(names[2].ToString()) + ""))
                            {
                                if (dt2.Rows.Count > 0)
                                {
                                    DataRow dr2 = dt2.Rows[0];
                                    ht.Add("Info", dr2["intro"].ToString());
                                    ht.Add("content", dr2["content"].ToString());
                                    url = MyCache.GetCacheConfig(5) + BasicField.GetEplistContentUrl(Utils.StrToInt(dr2["SchoolID"].ToString()), "action-news,archive-archive,paramID-" + dr2["id"].ToString());
                                }
                                ht.Add("url", url);
                                ht.Add("Show_cover_pic", 0);
                                ht.Add("tuwenid", KSCMS.S("default_tuwen" + i));
                                ht.Add("SystemType", 1);
                                #endregion
                            }
                        }
                    }
                     
                    if (KSCMS.S("keytype" + i) == "3")
                    {
                        if (!string.IsNullOrEmpty(KSCMS.S("TxtcourseID" + i)))
                        {
                            #region 课程
                         
                            string[] names = string.Concat(KSCMS.S("TxtcourseID" + i), "§").Split('§');
                            string tableName = "KS_Course";
                            if (Utils.StrToInt(KSCMS.S("costype" + i)) == 0)
                            {
                                tableName = "KS_CourseFace";
                            }
                            using (DataTable dt2 = DataFactory.GetDataTable("select Top 1 * from " + tableName + " where courseid=" + Utils.StrToInt(names[2].ToString()) + ""))
                            {
                                if (dt2.Rows.Count > 0)
                                {
                                    DataRow dr2 = dt2.Rows[0];
                                    ht.Add("Info", dr2["name"].ToString());
                                    ht.Add("content", dr2["intro"].ToString());
                                }
                            }
                            ht.Add("url", GetUrl( Utils.StrToInt(names[2].ToString()),Utils.StrToInt(KSCMS.S("costype" + i))));
                            ht.Add("Show_cover_pic", 0);
                            ht.Add("courseid", Utils.StrToInt(names[2].ToString()));
                            ht.Add("costype", Utils.StrToInt(KSCMS.S("CosType" + i)));
                            ht.Add("SystemType", 3);
                            #endregion
                        }
                    }
                }
                else if (KSCMS.S("default_type" + i) == "0")
                {
                    #region 自定义
                    if (!string.IsNullOrEmpty(KSCMS.S("default_title" + i)))
                    {
                        ht.Add("title", KSCMS.S("default_title" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_img" + i)))
                    {
                        ht.Add("picurl", KSCMS.S("default_img" + i));

                        #region 根据图片路径得到缩列图Media_ID
                        string access_token = ks_weixin.IsExistAccess_Token(1);
                        bool isRemote = false;
                        string pic = KSCMS.S("default_img" + i);
                        if (pic.ToLower().StartsWith("http:"))
                        {
                            string filename = Utils.RndNum(5) + DateTime.Now.ToFileTimeUtc() + pic.Substring(pic.LastIndexOf("."));
                            string SavePath = MyCache.GetCacheConfig(0) + MyCache.GetCacheConfig(22) + "/temp/" + filename;
                            if (Kesion.APPCode.Public.SaveRemoteFile(pic, SavePath).Equals(true))
                            {
                                isRemote = true;
                                pic = SavePath;
                            }
                        }

                        string msg = UploadMedia(access_token, "thumb", Utils.GetMapPath(pic)); // 上图片返回媒体ID
                        string media_id = ks_weixin.GetJsonValue(msg, "media_id");
                        if (isRemote)
                        {
                            Kesion.Publics.UtilsFile.DelFile(pic);
                        }
                        ht.Add("Media_ID", media_id);
                        #endregion
                    }
                    ht.Add("IsPic", KSCMS.S("default_type" + i));
                    if (!string.IsNullOrEmpty(KSCMS.S("default_intro" + i)))
                    {
                        ht.Add("Info", KSCMS.S("default_intro" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_content" + i)))
                    {
                        ht.Add("content", KSCMS.S("default_content" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_url" + i)))
                    {
                        ht.Add("url", KSCMS.S("default_url" + i));
                    }
                    ht.Add("Show_cover_pic", KSCMS.S("default_ShowPic" + i));
                    #endregion
                }

                if (SuCaiId != 0)
                {
                    CommonData.Update("KS_WeixinPigmsg", ht, "where id=" + SuCaiId);
                    parentid = SuCaiId;
                }
                else
                {
                    #region 增加
                    ht.Add("typeflag", new TemporaryVar().GroupID);
                    ht.Add("userid", new TemporaryVar().UserID);
                    ht.Add("addtime", DateTime.Now);
                    ht.Add("AddPeople", new TemporaryVar().UserName);
                    ht.Add("Type", 0);
                    CommonData.Insert("KS_WeixinPigmsg", ht);
                    parentid = CommonData.GetMaxId("KS_WeixinPigmsg", "id");
                    #endregion
                }
                #endregion
            }

            else
            {
                #region 子级
                ht.Add("ParentID", parentid);

                if (KSCMS.S("default_type" + i) == "1")
                {
                    if (!string.IsNullOrEmpty(KSCMS.S("default_title" + i)))
                    {
                        ht.Add("title", KSCMS.S("default_title" + i));
                        ht.Add("IsPic", KSCMS.S("default_type" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_img" + i)))
                    {
                        ht.Add("picurl", KSCMS.S("default_img" + i));

                        #region 根据图片路径得到缩列图Media_ID
                        string access_token = ks_weixin.IsExistAccess_Token(1);
                        bool isRemote = false;
                        string pic = KSCMS.S("default_img" + i); //

                        if (pic.ToLower().StartsWith("http:"))
                        {
                            string filename = Utils.RndNum(5) + DateTime.Now.ToFileTimeUtc() + pic.Substring(pic.LastIndexOf("."));
                            string SavePath = MyCache.GetCacheConfig(0) + MyCache.GetCacheConfig(22) + "/temp/" + filename;
                            if (Kesion.APPCode.Public.SaveRemoteFile(pic, SavePath).Equals(true))
                            {
                                isRemote = true;
                                pic = SavePath;
                            }
                        }
                        string msg = UploadMedia(ks_weixin.IsExistAccess_Token(1), "thumb", Utils.GetMapPath(pic)); // 上图片返回媒体ID
                        string media_id = ks_weixin.GetJsonValue(msg, "media_id");
                        if (isRemote)
                        {
                            Kesion.Publics.UtilsFile.DelFile(pic);
                        }
                        ht.Add("Media_ID", media_id);
                        #endregion
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_tuwen" + i)))
                    {
                        #region 图文
                        string[] names = string.Concat(KSCMS.S("default_tuwen" + i), "§").Split('§');
                        string url = string.Empty;
                        using (DataTable dt2 = DataFactory.GetDataTable("select Top 1 * from KS_EnterpriseNews where id=" + Utils.StrToInt(names[2].ToString()) + " "))
                        {
                            if (dt2.Rows.Count > 0)
                            {
                                DataRow dr2 = dt2.Rows[0];
                                ht.Add("Info", dr2["intro"].ToString());
                                ht.Add("content", dr2["content"].ToString());
                                url =MyCache.GetCacheConfig(5)+  BasicField.GetEplistContentUrl(Utils.StrToInt(dr2["SchoolID"].ToString()), "action-news,archive-archive,paramID-" + dr2["id"].ToString());
                            }
                        }
                        ht.Add("url", url);
                        ht.Add("Show_cover_pic", 0);
                        ht.Add("tuwenid", KSCMS.S("default_tuwen" + i));
                        ht.Add("SystemType", 1);
                        #endregion
                    }
                 
                    if (!string.IsNullOrEmpty(KSCMS.S("TxtcourseID" + i)))
                    {
                        #region 课程
                         
                        string[] names = string.Concat(KSCMS.S("TxtcourseID" + i), "§").Split('§');

                        string tableName = "KS_Course";
                        if (Utils.StrToInt(KSCMS.S("costype" + i)) == 0)
                        {
                            tableName = "KS_CourseFace";
                        }
                        using (DataTable dt2 = DataFactory.GetDataTable("select Top 1 * from " + tableName + " where courseid=" + Utils.StrToInt(names[2].ToString()) + ""))
                        {
                            if (dt2.Rows.Count > 0)
                            {
                                DataRow dr2 = dt2.Rows[0];
                                ht.Add("info", dr2["name"].ToString());
                                ht.Add("content", dr2["intro"].ToString());
                            }
                        }

                        ht.Add("url", GetUrl( Utils.StrToInt(names[2].ToString()),Utils.StrToInt(KSCMS.S("costype" + i))));
                        ht.Add("Show_cover_pic", 0);
                        ht.Add("costype", Utils.StrToInt(KSCMS.S("costype" + i)));
                        ht.Add("courseid", names[2].ToString());
                        ht.Add("SystemType", 3);
                        #endregion
                    }
                }
                else if (KSCMS.S("default_type" + i) == "0")
                {
                    #region 自定义
                    if (!string.IsNullOrEmpty(KSCMS.S("default_title" + i)))
                    {
                        ht.Add("title", KSCMS.S("default_title" + i));
                        ht.Add("IsPic", KSCMS.S("default_type" + i));
                        ht.Add("Show_cover_pic", KSCMS.S("default_ShowPic" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_img" + i)))
                    {
                        ht.Add("picurl", KSCMS.S("default_img" + i));

                        #region 根据图片路径得到缩列图Media_ID
                        string access_token = ks_weixin.IsExistAccess_Token(1);
                        bool isRemote = false;
                        string pic = KSCMS.S("default_img" + i); //
                        if (pic.ToLower().StartsWith("http:"))
                        {
                            string filename = Utils.RndNum(5) + DateTime.Now.ToFileTimeUtc() + pic.Substring(pic.LastIndexOf("."));
                            string SavePath = MyCache.GetCacheConfig(0) + MyCache.GetCacheConfig(22) + "/temp/" + filename;
                            if (Kesion.APPCode.Public.SaveRemoteFile(pic, SavePath).Equals(true))
                            {
                                isRemote = true;
                                pic = SavePath;
                            }
                        }
                        string msg = UploadMedia(ks_weixin.IsExistAccess_Token(1), "thumb", Utils.GetMapPath(pic)); // 上图片返回媒体ID
                        string media_id = ks_weixin.GetJsonValue(msg, "media_id");
                        if (isRemote)
                        {
                            Kesion.Publics.UtilsFile.DelFile(pic);
                        }
                        ht.Add("Media_ID", media_id);
                        #endregion
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_intro" + i)))
                    {
                        ht.Add("Info", KSCMS.S("default_intro" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_content" + i)))
                    {
                        ht.Add("content", KSCMS.S("default_content" + i));
                    }
                    if (!string.IsNullOrEmpty(KSCMS.S("default_url" + i)))
                    {
                        ht.Add("url", KSCMS.S("default_url" + i));
                    }
                    #endregion
                }
                if (SuCaiId != 0)
                {
                    if (!string.IsNullOrEmpty(KSCMS.S("default_title" + i)))
                    {
                        if (Utils.StrToInt(KSCMS.S("default_ID" + i)) != 0)
                        {
                            CommonData.Update("KS_WeixinPigmsg", ht, "where id=" + Utils.StrToInt(KSCMS.S("default_ID" + i)));
                        }
                        else
                        {
                            CommonData.Insert("KS_WeixinPigmsg", ht);
                        }
                    }
                }
                else
                {
                    #region 增加
                    ht.Add("typeflag", new TemporaryVar().GroupID);
                    ht.Add("addtime", DateTime.Now);
                    ht.Add("AddPeople", new TemporaryVar().UserName);
                    ht.Add("Type", 0);
                    CommonData.Insert("KS_WeixinPigmsg", ht);
                    #endregion
                }
                #endregion
            }
        }
        Msg.Alert("恭喜，保存成功！", BasicField.GetUserUrl("wx/wx_Picmsg"));

        #endregion
    }


    /// <summary>
    /// 上传媒体返回媒体ID
    /// </summary>
    public static string UploadMedia(string access_token, string type, string path)
    {
        // 设置参数
        string url = string.Format("https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={0}&type={1}", access_token, type);
        return ks_weixin.HttpUploadFile(url, path, "media");
    }
    public string GetUrl(int courseid,int cosType)
    {
        string value = "courseview";
        if (cosType == 0)
        {
            value = "faceview";
        }
        else if (cosType == 5)
        {
            value = "liveview";
        }
        return BasicField.GetRewriteUrl(value, courseid);
    }
</script>
<%
	if (!isLoadPage) return;
%>
   <script>

   	$(function () {
   		$(".menu1box ul li").click(function () {
   			var k = $(this).index();
   			aa(k);
   		});
   	});
   	function aa(k) {
             
   		// alert(nowIndex);
   		// return;
   		var sucaiId=$("#default_ID"+nowIndex).val();

   		$(".menu1box ul li").each(function (index, domEle) {
   			$(this).attr("class", "");
   		});
   		$(".menu1box ul li").each(function (index, domEle) {
   			if (k == index) {
   				if (k == 0) {
   					$("#keytype"+nowIndex).val('1');
                       
   					var url="<%=BasicField.GetUserUrl("wx/wx_TuWenList","frame-no,action-sucai")%>";
      					url=url+",sendid-"+num+",sucaiId-"+sucaiId;

      					$('#iframemain'+nowIndex).attr('src', ''+url+'');
					  }  else if (k == 1) {
					  	$("#keytype"+nowIndex).val('3');
					  	var url="<%=BasicField.GetUserUrl("wx/wx_courseList","frame-no,action-sucai")%>";
      					url=url+",sendid-"+num+",sucaiId-"+sucaiId;
      					$('#iframemain'+nowIndex).attr('src', ''+url+'');
					  }
              
			  	$(this).attr("class", "hit");
			  }
      		});

	  }


      </script>
 <link href="/SysImg/teacher/css/newswx.css" rel="stylesheet" />
 <div class="t_tybox">
 <div class="tytitle"><h4>微信素材管理</h4></div>
 <form name="myForm" method="post" action="<%=BasicField.GetUserUrl("wx/wx_PicMsg") %>" id="myForm">
 <input name="action" value="" type="hidden" id="action" />
 <input name="do" value="" type="hidden" id="domethod" />
  <div class="console_body">   
  <div class="prompt_bg" style="display:none" id="Loading">
		 <div class="prompt_box">
		 <p><img src="/admin/weixin/images/loading.gif" />正在同步，请耐心等待...</p>
		 </div>
	 </div>
	  <%if (__info.Panel1)
	 {
		 Kesion.APPCode.EditorAPI.EchoHead(); %>
 <div ID="Panel1">

     <div class="myTitle toptitle">添加/编辑素材</div>
     <div style="overflow:hidden; padding-top:20px;">
     <input id="tiaoshu" type="hidden" name="tiaoshu" value="<%=num%>"/>
        <div class="left_img_box">
           
		  <ul class="sucai_img_list">
           
		   <li class="xz" id="appmsg_item0" num="0">
			   
               <div class="left_img_default">
			      <div class="default_img_box">
				     <img src="/SysImg/nopic.gif" id="img_box0"/>
					 <span class="sc_default_title" id="defaulttitle0">标题</span>
				  </div>
			   </div>
			    <input type="hidden"  name="sucaiId" value="<%=SuCaiId%>"/>
				<input type="hidden"  name="parentid" value="<%=parentid%>"/>
                <input id="keytype0" type="hidden"  name="keytype0" value="<%=keytype%>"/>
               <input type="hidden" name="default_title0" id="default_title0" value="<%=title %>"/>
               <textarea id="default_content0" name="default_content0" cols="20" rows="2" style="display:none"><%=Content %></textarea>
               <input type="hidden" name="default_url0" id="default_url0" value="<%=Url %>"/>
               <textarea name="default_intro0" id="default_intro0" style="display:none"><%=Intro %></textarea>
               <input type="hidden" name="default_img0" id="default_img0" value="<%=PicUrl %>"/>
               <input type="hidden" name="default_type0" id="default_type0" value="<%=Type %>"/>
                <input type="hidden" name="default_ID0" id="default_ID0" value="<%=id%>"/>
                <input type="hidden" name="default_ShowPic0" id="default_ShowPic0" value="<%=Show_cover_pic%>"/>
                 <input type="hidden" name="default_tuwen0" id="default_tuwen0" />
                <input type="hidden" name="default_course0" id="default_course0" />
				  <input id="CosType0" type="hidden"  name="CosType0"/>
                <input id="TxtTuWenID0" type="hidden"  name="TxtTuWenID0"/>
                <input id="TxtcourseID0" type="hidden"  name="TxtcourseID0"/>
                <textarea id="ShowTxtTuWen0" style="width:300px;height:200px;display:none"></textarea>
                <textarea id="ShowTxtcourse0" style="width:300px;height:200px;display:none"></textarea>
		   </li>
		   <%=GetModifystr(num,SuCaiId)%>
		  </ul>
		  <a class="add_one" href="javascript:Add();">
               <i class="add_one_css">增加一条</i>
          </a>
		</div>

        <div class="sc_right">
            <div style="border-bottom: 1px solid #eee;">
       <table id="RadioButtonList1" onclick="showStatus();" border="0">
		<tr>
			<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="0" <%=Utils.StrToInt(GetParam("ispic"))==0?"checked":"" %> /><label for="RadioButtonList1_0">自定义</label></td>
			<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="1" <%=Utils.StrToInt(GetParam("ispic"))==1?"checked":"" %> /><label for="RadioButtonList1_1">系统</label></td>
		</tr>
	</table>

            </div> 
            <div id="xitongdetail" style="display:none">
                  <script>
                  	$(function () {
							$(".menu1box ul li").click(function () {
								var k = $(this).index();
								jump(k);
							});
                  	});
                  	function jump(k) {
                  		$(".menu1box ul li").each(function (index, domEle) {
                  			$(this).attr("class", "");
                  		});
                  		$(".menu1box ul li").each(function (index, domEle) {
                  			if (k == index) {
                  				$(this).attr("class", "hit");
                  				$('.sucai_img_list li').each(function(){
                  					if($(this).attr("class")=="xz")
                  					{
                  						$(this).click();
                  					}
                  				});
                  			}
                  		});
                  	}
                  </script>
                 <div class="tabs1" style="border:none; margin-top:0;">
                                <div class="menu1box">
                                    <ul class="menu1">
                                        <li class="hit">
                                            <i class="fa fa-newspaper-o"></i>
                                            <a href="javascript:;" >图文</a>
                                        </li>
                                    
                                       
                                       <li>
                                            <i class="fa fa-photo"></i>
                                            <a href="javascript:;">课程</a>
                                        </li>
                                
                                        <div class="clear"> </div>
                                    </ul>
                                </div>
                                <div class="main1box" style="min-height:auto;">
<!--                                      <div class="main">-->
                                        <dt class="mbimg" style="display:block; " id="mybox1">
                                            <iframe class="editArea-ifrm" frameborder="no" border="0" src="<%=BasicField.GetUserUrl("wx/wx_TuWenList","frame-no,action-sucai,sucaiId-"+SuCaiId+"") %>" style="width:100%" name="iframemain0" id="iframemain0"> </iframe>
                                        </dt>
                                     <!-- </div>-->
                                    </div>
                                </div>

            </div>
            <div id="zidingyideatil">
            <div class="title">
            <span class="txt" id="titename">标题：</span>
	       <input name="TxtTitle" type="text" id="TxtTitle" value="<%=GetParam("title") %>"" class="inp245" onkeydown="out_title();" onKeyUp="out_title();" style="width:350px;" />   
            </div>
                 <div class="content">
              <span class="txt">内容：</span>
             <textarea name="TxtContent" rows="2" cols="20" id="TxtContent" style="height:220px;width:100%;"><%=GetParam("content") %></textarea>
                   <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtContent", "Common");%>
            </div>
            <div class="info">
              <span class="txt">摘要：</span>
            <textarea name="Txtinfo" rows="2" cols="20" id="Txtinfo" onKeyUp="out_intro();" onkeydown="out_intro();" style="height:80px;width:100%;background-color: #fff;"><%=GetParam("Info") %></textarea>   

            </div>
            <div class="default"><span class="txt">选择图片：</span>
    <table cellspacing="0" cellpadding="0"><tr><td>         
   <input name="TxtPic" type="text" id="TxtPic" class="inp245" onfocus="out_pic();" value="<%=GetParam("picurl") %>" onclick="out_pic()" onkeydown="out_pic();" onKeyUp="out_pic();" style="width:350px;" /></td>

          <td style="padding-left:4px;padding-top:15px; vertical-align:middle;*padding-top:12px; "> <%=Kesion.APPCode.UploadAPI.EchoUpload("userclasspic","TxtPic",150) %></td>
      
           <td><img id="showTxtPic" src="<%=GetParam("picurl") %>"  height="30" style="border:1px solid #f1f1f1;" onerror="this.src='../../sysimg/nopic.gif'"/></td>
          </tr>
         </table>
      
          <span style="display:none" style=" margin-right:5px;"><input id="CheckBox1" type="checkbox" name="CheckBox1" onclick="checkboxOnclick(this);" /></span>封面图片显示在正文中
                
         </div>

            <div class="url">
          <span class="txt">链接地址：</span>
		  <input name="TxtUrl" type="text" id="TxtUrl" class="inp245" onKeyUp="out_url();" value="<%=GetParam("url") %>" onkeydown="out_url();" style="width:350px;" />

         </div>

		</div>
		  <input type="submit" name="Btn_Save" value="保存" onclick="$('#domethod').val('save')" id="Btn_Save" class="sc_save_button" />
        </div>
   </div>
       </div>

	   <%} %>
 <div class="content_wrap1">

 <%if(!__info.Panel1){ %>
    <div ID="Panel2">
        <div class="search_group">
          <div class="search" style="margin-left:0; width:50%;">
             <input name="TxtKey" type="text" id="TxtKey" class="search_box" />
              <input type="submit" name="buttonsearch" value=" " id="buttonsearch" class="search_btn" />
          </div>
        </div>
    <div style="float:right;margin-right: 20px;">
	<input type="submit" name="TbButton" value="同步素材" onclick="return(TongBu());" id="TbButton" class="add_sc_button" style=" margin-left:10px;" />
     <input type="submit" name="Button1" value="+添加素材" id="Button1" onclick="$('#domethod').val('add')" class="add_sc_button" style=" margin-left:10px;" />
     <input type="submit" name="Btn_Del" value="删除素材" onclick="$('#domethod').val('delete')" id="Btn_Del" class="add_sc_button" style=" margin-left:0;" />
     <span class="quanxuan" style="float:right; height:29px; line-height:29px;"><input type="checkbox" name="chkall" id="chkall" onClick="CheckAll(this.form);" style=" vertical-align:middle;"/>全选</span>

	 <div class="clear"></div>
	</div>
		<div class="clear"></div>
       <div class="sc_show_conlist">
	    <ul class="sc_ul_con">
	   <%
	   int CurrPage = new BasicField().GetCurrPage;
	   string sqlParam = "ks_weixinpigmsg where parentid=0  and typeflag=" + new TemporaryVar().GroupID + " and userid="+new TemporaryVar().UserID+"";
            int pagesize = 20;
            int recordcount, pagecount;
            if (!string.IsNullOrEmpty(KSCMS.S("TxtKey")))
				sqlParam += " and (title like N'%" + KSCMS.S("TxtKey") + "%' or Info like N'%" + KSCMS.S("TxtKey") + "%' or  content like N'%" + KSCMS.S("TxtKey") + "%')";
            #region 日期限制
            if (!string.IsNullOrEmpty(KSCMS.S("adddate")))
            {
                if (Utils.IsDateTime(KSCMS.S("adddate")))
                {
                    sqlParam += " and [AddTime]>='" + KSCMS.S("adddate") + "'";
                }
            }
            #endregion
			using (DataTable dt = DataFactory.GetPage("*", sqlParam, "id", "order by id desc", CurrPage, pagesize, out recordcount, out pagecount))
			{
				if (dt.Rows.Count > 0)
				{
					foreach (DataRow dr in dt.Rows)
					{
						KSCMS.W(" <li class=\"sc_ul_con_li\"><div class=\"sc_ul_con_liBox\"><div class=\"op_sc_con\">"+

               " <a style=\"text-align:center; position:relative; height:37px;\"><input type=\"checkbox\"  name=\"ids\" id=\"ids\" value=\""+dr["id"].ToString()+"\" style=\"vertical-align:middle; position:absolute; top:11px; left:40%; right:40%;\" /></a>"+

				"<a href=\""+BasicField.GetUserUrl("wx/wx_Picmsg","action-modify,sucaiId-"+dr["id"].ToString()+"")+"\"><i class=\"sc_bianjian\"></i></a>"+
				"<a href=\""+BasicField.GetUserUrl("wx/wx_Picmsg","action-delete,sucaiId-"+dr["id"].ToString()+"")+"\" style=\"border: none;margin-left: -2px;\"><i class=\"sc_shanchu\"></i></a>"+
				"<div class=\"clear\"></div></div>"+
		  "<div class=\"sc_ultop_con\"><div class=\"sc_ultime\">"+dr["AddTime"].ToString()+"</div>"+
			"<div class=\"sc_ulimgt\"><img src=\""+(Convert.ToString(dr["picurl"].ToString())==string.Empty?"/SysImg/nopic.gif":dr["picurl"].ToString()) +"\" />"+
			  "<div class=\"sc_ulimg_t\"><a href=\"#\">"+dr["title"].ToString()+"</a></div></div></div>"+
		 " <div class=\"bottom_big_box\">"+GetChildSu(Utils.StrToInt(dr["id"].ToString())) +"</div></div></li>");
					}
				}
				else
				{
					KSCMS.W(" <div class=\"norecord\" style=\"display: text-align:center;\"> <span style=\"text-align:center\">暂无素材 </span></div>");
				}
			}
		 %>
	                         </ul>
                                    <div class="clear"></div>
                         
   </div>
   <div class="fy_box">
    <%
            #region 分页
            string PageStr = "[KS:PageStr1]";
			BasicField.ReplaceFilterPage(ref PageStr, CurrPage, pagesize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>
     </div>
     <div class="clear"></div>
</div>
<%} %>

</div>
  </div>
     <script>
     	//加载的效果
     	$(function () {
     		var w = 250;
     		var h = 50;
     		$(".prompt_box").css("position", "fixed");
     		$(".prompt_box").css("width", w).css("height", h);
     		var x = ($(window).width() - w) / 2;
     		var y = ($(window).height() - h) / 3;
     		$(".prompt_box").css("top", y).css("left", x);
     	});

        </script>
     <script type="text/javascript">
     	function TongBu() {
     		$("#Loading").show();
     		$.ajax({
     			url: "/plus/course/wxajax.aspx?action=tongbu&rnd=" + Math.random(),
     			context: document.body,
     			type: "get",
     			success: function (data) {
     				if (data =='ok') {
     					KesionJS.Alert("恭喜,同步成功", "location.reload();");
     				} else {
     					KesionJS.Alert("对不起,同步失败", "location.reload();");
     				}
     				$("#Loading").hide();
     			}
     		});
     		return false;
     	}  
     	function HuoQu(){
     		//获取
     		jQuery(parent.document).find("#ajaxmsg").toggle();
     		$.ajax({
     			url: "KS.Picmsg.aspx?action=huoqu&rnd=" + Math.random(),
     			context: document.body,
     			type: "get",
     			success: function (data) {
     				if (data =='ok') {
     					KesionJS.Alert("恭喜,获取成功", "location.reload();");
     				} else {
     					KesionJS.Alert("对不起,获取失败", "location.reload();");
     				}
     				jQuery('#ajaxmsg', window.parent.document).fadeOut("slow");
     			}
     		});
     		return false;
     	}

         </script>
   
     <script>
     	var num=<%=num%>;
     	var nowIndex=0;
     	var oldnum=nowIndex;
     	var editor='';
     	$(function(){	
     		initialSelect();   //初始化选择中框   
     		if($("#default_title0").val()!='')
     		{
     			$("#defaulttitle0").html($("#default_title0").val());
     		}
     		if($("#default_img0").val()!='')
     		{
     			$("#img_box"+nowIndex).attr("src",$("#default_img0").val()); 
     		}

     		$('.sucai_img_list li').eq(0).click();

     		for (var i=1;i<=num;i++)
     		{
     			jQuery("#mybox1").append('<iframe class="editArea-ifrm" frameborder="no" border="0" src="<%=BasicField.GetUserUrl("wx/wx_TuWenList","frame-no,action-sucai,sucaiId-"+SuCaiId+"")%>" style="width:100%" name="iframemain'+i+'" id="iframemain'+i+'"> </iframe>');
               
     		}
     	});
		 function initialSelect(){
		 	$('.sucai_img_list li').click(function(){
		 		var k = $(this).attr("num");
		 		oldnum=nowIndex;
		 		nowIndex=k; 
		 		$('.sucai_img_list li').removeClass('xz');
		 		$(this).addClass('xz');
		 		fz(nowIndex);//赋值
				
		 	});
		 }
		 function fz(num)//赋值
		 {
		 	var nowType=parseInt($("#default_type"+num).val()); 
		 	// alert(nowType);
		 	if (editor!=''&&nowType==0){
		 		$("#default_content"+oldnum).html(editor.getContent());
		 		editor.setContent('');
		 	}
		 	//切换添加面板
		 	$("#RadioButtonList1").find("input").each(function(){
		 		if (parseInt($(this).attr("value"))==nowType){
		 			$(this).attr("checked",true);
		 		}
		 	});
		 	if (nowType==0){
		 		jQuery("#xitongdetail").hide();
		 		jQuery("#zidingyideatil").show();
		 	}else{
		 		jQuery("#xitongdetail").show();
		 		jQuery("#zidingyideatil").hide();
		 	}

		 	if (nowType==0){  //自定义的
		 		if (editor!=''){
		 			if ($("#default_content"+num).val()!=''){
		 				editor.setContent($("#default_content"+num).val());
		 			}else{
		 				editor.setContent('');
		 			}
		 		}
		 	}else{  //系统
		 		var keytype=$("#keytype"+num).val();
		 		var id=$("#default_ID"+num).val();
		 		$(".editArea-ifrm").hide().eq(num).show();
		 		if(keytype==1)
		 		{
		 			$(".menu1box ul li").removeClass("hit");
		 			$(".menu1box ul li").eq(0).addClass("hit");
		 			var url="<%=BasicField.GetUserUrl("wx/wx_TuWenList","frame-no,action-sucai")%>";
		 			url=url+",sendid-"+num+",sucaiId-"+id;
		 			$('#iframemain'+num).attr('src', ''+url+'');
		 		}
		 		else if(keytype==3){
		 			$(".menu1box ul li").removeClass("hit");
		 			$(".menu1box ul li").eq(1).addClass("hit");
		 			var url="<%=BasicField.GetUserUrl("wx/wx_courseList","frame-no,action-sucai")%>";
		 			url=url+",sendid-"+num+",sucaiId-"+id;
		 			$('#iframemain'+num).attr('src', ''+url+'');
		 		}
		 	}
		 	if($("#default_title"+num).val()!=''){
		 		jQuery("#TxtTitle").val($("#default_title"+num).val());
		 	}
		 	else
		 	{
		 		jQuery("#TxtTitle").val('');
		 	}
		 	if($("#default_url"+num).val()!=''){
		 		jQuery("#TxtUrl").val($("#default_url"+num).val());
		 	}
		 	else
		 	{
		 		jQuery("#TxtUrl").val('');
		 	}
		 	if($("#default_img"+num).val()!=''){
		 		jQuery("#TxtPic").val($("#default_img"+num).val());
		 	}
		 	else
		 	{
		 		jQuery("#TxtPic").val('');
		 	}
		 	if($("#default_intro"+num).val()!=''){
		 		jQuery("#Txtinfo").val($("#default_intro"+num).val());
		 	}
		 	else{
		 		jQuery("#Txtinfo").val("");
		 	}
		 	var checkrad =$("#default_ShowPic"+num).val();  
		 	if(checkrad==1)
		 	{
		 		$("#CheckBox1").attr("checked",true);
		 	}
		 	else{
		 		$("#CheckBox1").attr("checked",false);
		 	}
         
		 }
     	var box = null;
     	var isreload = false;
     	function openWin(title, url, reload, width, height) {
     		if (width == null) width = 760;
     		if (height == null) height = 450;
     		isreload = reload;
     		box = $.dialog.open(url, {
     			id: 'topbox', lock: true, title: title, width: width, height: height, close: function () {
     				if (isreload) {
     					top.frames['main'].location.reload();
     				}
     			}
     		});
     	}
 </script>

   <script>
   	function showStatus() {
   		var checkrad = $("#RadioButtonList1 :radio[checked]").val();
   		// alert(checkrad);
   		if (checkrad == "1") {
   				jQuery("#xitongdetail").show();
   				jQuery("#zidingyideatil").hide();
   				$("#default_type"+nowIndex).val('1');
   				clearziyi(nowIndex);//清空自定义
                 
   				return true;
		   } else {
		   		jQuery("#xitongdetail").hide();
		   		jQuery("#zidingyideatil").show();
		   		$("#default_type"+nowIndex).val('0');
		   		clear(nowIndex);//清空系统
		   	
		   		return true;
		   }
              
	   }

	   function checkboxOnclick(checkbox){
	   	if(checkbox.checked == true){
	   		$("#default_ShowPic"+nowIndex).val('1');
	   	}
	   	else{
	   		$("#default_ShowPic"+nowIndex).val('0');
	   	}
	   }
	   function Add(){
	   	if($(".sucai_img_list").find("li").length>=7)
	   	{
	   		alert("对不起！,每个主多条图文的子多条图文最多只能7个!");
	   		return;
	   	}
	   	num++;

	   	var defaultType=jQuery("#RadioButtonList1 :radio[checked]").val();
				var keytype=$("#keytype"+num).val();
               
				jQuery("#mybox1").append('<iframe class="editArea-ifrm" frameborder="no" border="0" src="<%=BasicField.GetUserUrl("wx/wx_TuWenList","frame-no,action-sucai,sucaiId-"+SuCaiId+"")%>" style="width:100%" name="iframemain'+num+'" id="iframemain'+num+'"> </iframe>');
               
                $("#tiaoshu").val(num);
                var str='<li id="appmsg_item'+num+'" num="'+num+'" >'
						+'<div class="left_img_box_list">'
						+'<div class="add_sc_img">'
						+'<div class="add_sc_img_right">'
						+'<img src="/SysImg/nopic.gif"  id="img_box'+num+'"/>'
						+'</div>'
						+'<div class="add_sc_img_left'+num+'" id="defaulttitle'+num+'">'
						+'<a class="title_add_sc">标题</a>'
						+'</div>'
				   
						+'<div class="clear"></div>'
						+'</div>'
						+'<div class="sc_default_title_bg">'
						+'<a href="javascript:del('+num+')" class="order_by_delete"><img src="/admin/weixin/images/scdelete.png" /></a>'
						//+'<a title="上移" href="javascript:;" onclick="pic_move(this,1);">上移</a>'
						+'</div>'
						+'</div> '
						+' <input type="hidden" name="default_title'+num+'" id="default_title'+num+'" />'
						+' <textarea id="default_content'+num+'" name="default_content'+num+'" cols="20" rows="2" style="display:none"></textarea>'
						+' <input id="keytype'+num+'"  name="keytype'+num+'" value="1" type="hidden"  />'
						+' <input type="hidden" name="default_url'+num+'" id="default_url'+num+'"/>'
						+' <textarea name="default_intro'+num+'" id="default_intro'+num+'" style="display:none"></textarea>'
						+' <input type="hidden" name="default_img'+num+'" id="default_img'+num+'"  />'
						+' <input type="hidden" name="default_type'+num+'" id="default_type'+num+'" value="'+defaultType+'" />'
						+' <input type="hidden" name="default_ID'+num+'>" id="default_ID'+num+'" value="0"/>'
						+' <input type="hidden" name="default_ShowPic'+num+'" value="0" id="default_ShowPic'+num+'" />'
						+' <input type="hidden" name="default_tuwen'+num+'" id="default_tuwen'+num+'" />'
						+' <input type="hidden" name="default_course'+num+'" id="default_course'+num+'" />'
					   +' <input id="TxtTuWenID'+num+'" type="hidden"  name="TxtTuWenID'+num+'"/>'
					   +' <input id="CosType'+num+'" type="hidden"  name="CosType'+num+'"/>'
					   +' <input id="TxtcourseID'+num+'" type="hidden"  name="TxtcourseID'+num+'"/>'
					   +'<textarea id="ShowTxtTuWen'+num+'" style="width:300px;height:200px;display:none"></textarea>'
					   +'<textarea id="ShowTxtcourse'+num+'" style="width:300px;height:200px;display:none"></textarea>'
					   +'</li>';
         
                $(".sucai_img_list").append(str);
                initialSelect();         
			}
      
			function del(id){
				// $("#tiaoshu").val(num);
				$("#appmsg_item"+id).remove();

			}
			function deletesucai(id,sucaiid){
				$.ajax({
					url: "/plus/course/wxajax.aspx?action=deletechild&childID="+sucaiid,
					context: document.body,
					type:"get",
					success: function (data) {
						if (data =='ok') {
							$("#appmsg_item"+id).remove();
							KesionJS.Alert("删除成功");
						} else {
							KesionJS.Alert("删除失败");
						}
					}
				});
			}
			function pic_move(obj,fx){
				var box_d=jQuery(obj).parent().parent().parent();
				var box_fx='';
				if (fx==1)
				{
					box_fx=box_d.prev();
				}
				else
				{box_fx='';}
				if ( box_fx.length > 0 ) {
					if(fx==1) box_fx.before(box_d.clone());
					if(fx==1 )box_d.remove();
				}
			}
			//设置编辑器内容
			function setcontent(){
				if (parseInt($("#default_type"+nowIndex).val())==0){
					$("#default_content"+nowIndex).val(editor.getContent());
				}
			}
			function out_title(){
				var titile=jQuery("#TxtTitle").val();
				$("#defaulttitle"+nowIndex).html(titile);
				$("#default_title"+nowIndex).val(titile);
				setcontent();
			}
			function out_pic(){
				var pic=jQuery("#TxtPic").val();
       	$("#img_box"+nowIndex).attr("src",pic); 
       	$("#default_img"+nowIndex).val(pic);
       	setcontent();
       }
     
       function out_intro(){
       	var info=jQuery("#Txtinfo").val();
       	$("#default_intro"+nowIndex).val(info);
       	setcontent();
       }
       function out_url(){
       	var url=jQuery("#TxtUrl").val();
       	$("#default_url"+nowIndex).val(url);
       	setcontent();
       }
       function check(){
       	setcontent();
       	for(var i=0;i<=num;i++)
       	{
       		var title=$("#default_title"+i).val();
       		var pic=$("#default_img"+i).val();
       		var info=$("#default_intro"+i).val();
       		var url=$("#default_url"+i).val();
       		var content=$("#default_content"+i).val();
       		var default_type=parseInt($("#default_type"+i).val());

       		if (title!=undefined && title==''){
       			if (default_type==1){
       				KesionJS.Alert("请选择图文消息"+i);
       			}else{
       				KesionJS.Alert("请输入标题","$('#<TxtTitle').focus();");
       			}
			   	return false;
			   }
		   	if(pic!=undefined && pic==''){
		   		KesionJS.Alert("请上传图片","$('#TxtPic').focus();");
		   		return false;
		   	}
		   	if (default_type==0){

		   		if(content!=undefined && content==''){
		   			KesionJS.Alert("请输入内容","editor.focus();");
		   			return false;
		   		}
		   		if(info!=undefined && info==''){
		   			KesionJS.Alert("请输入摘要","$('#Txtinfo').focus();");
		   			return false;
		   		}
			   	if(url!=undefined && url==''){
			   		KesionJS.Alert("请输入链接","$('#TxtUrl').focus();");
			   		return false;
			   	}

			   }

		   }
	   	return true;
           
	   }

	   function clear(nowIndex){
	   	//alert(nowIndex);
	   	$("#defaulttitle"+nowIndex).html('标题');
	   	$("#img_box"+nowIndex).attr("src",'/SysImg/nopic.gif'); 
	   	$("#default_img"+nowIndex).val('');  
	   	$("#default_url"+nowIndex).val('');
	   	$("#default_intro"+nowIndex).val('');
	   	$("#default_title"+nowIndex).val('');
	   	$("#default_content"+nowIndex).html('');
          
             
	   	jQuery("#TxtUrl").val('');
	   	jQuery("#Txtinfo").val("");
	   	jQuery("#TxtTitle").val('');
	   	jQuery("#TxtPic").val('');
	   	editor.setContent('');

	   }
	   function clearziyi(nowIndex)
	   {
	   	$("#defaulttitle"+nowIndex).html('标题');
	   	$("#img_box"+nowIndex).attr("src",'/SysImg/nopic.gif'); 
	   	$("#default_img"+nowIndex).val('');  
	   	$("#default_title"+nowIndex).val('');
         
	   }
        </script>
   
   

 </form>
 </div>