<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false"  CodeBehind="sendEmail.aspx.cs"   Inherits="ZYDN.Web.system.sysSetup.sendEmail" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>邮件模板</title>
    <link rel="stylesheet" type="text/css" href="../skins/CSS/main.css" />
    <link rel="stylesheet" type="text/css" href="../skins/CSS/Sys.css" />
    <style type="text/css">
         table{border-collapse:collapse;border-color:#D9E9F8;color:#01439a; font-size:14px;border:1px solid #cccccc;}
        .oushutd{border-top:1px #cccccc solid; font-size:12px; text-align:left;color:#01439a; line-height:20px;background-color:#F0F5FB;padding-left:5px;padding-right:5px;}
        .jishutd{border-top:1px #cccccc solid;text-align:left; line-height:20px;font-size:12px;background-color:#FFFFFF;padding-left:5px;padding-right:5px;}
    </style>
    <script type="text/javascript" language="javascript" src="../JS/JFramework.js"></script>
    <script type="text/javascript" language="javascript" src="../JS/Sys.js"></script>
    <script type="text/javascript" language="javascript">
    //获取所有模板的名称
    function BindAllTeam()
    {
        var objAjax=new JAjax();
	    var objResponse=new JHttpResponse();
    	objResponse.write("toUser","");	
    	var out=objAjax.getText("post","SpoolerPage.aspx?type=getTeampName",objResponse,null);
    	if(out!=null&&out!="")
    	{     
    	      var str=out.split(c2);
              var sel=document.getElementById("TName");
              while((sel.length)>1)
              sel.remove(1);
              for(var i=0;i<str.length-1;i++)
              {
                  var Every=str[i].split(c1);
                  var varItem = new Option(Every[1], Every[0]);      
                  sel.options.add(varItem);
              }
            sel.onmouseover="";
         }
         else
         {
            var sel=document.getElementById("TName");
            while((sel.length)>1)
            sel.remove(1);
            document.getElementById("txtMun").innerText="";
            editTxt.Composition.document.body.innerHTML=="";
            document.getElementById("TeName").value="";
         }
    }
    //选择模板
    function selectTemp(obj)
    {
         var sID=obj.id;
         var stemp=document.getElementById(sID);
         var ID=null;
         var selName=null;
          for(var i=0;i<stemp.length;i++){
            if(stemp[i].selected==true){
              ID=stemp[i].value; 
              selName=stemp[i].innerText;
              document.getElementById("dd").value=ID;
            }
         }
         if(parseInt(ID)>0)
         {
             var objAjax=new JAjax();
	         var objResponse=new JHttpResponse();
             objResponse.write("teampID",ID);	
             var out=objAjax.getText("post","SpoolerPage.aspx?type=sctTempMsg",objResponse,null);
             if(out!=null&&out!="")
             {
               var str=out.split(c1)
               document.getElementById("txtMun").innerText=str[0];
               editTxt.Composition.document.body.innerHTML=str[1];
             }
             document.getElementById("TeName").value=selName;
         }
         if(ID=="0")
         {        
             document.getElementById("txtMun").innerText="";
             editTxt.Composition.document.body.innerHTML=="";
             document.getElementById("TeName").value="";
         }
     }
       //保存模板
         function submt()
         {
           var index=document.getElementById("dd").value;
           var v=new validate();
	       v.form=document.getElementById("form1");
	        if (!v.start()){  //验证必填项
	            return ;
	        }
           var objAjax=new JAjax();
           var objResponse=new JHttpResponse();
           var txt=editTxt.GetContent();//获取模板编辑内容
           var txtMun=document.getElementById("txtMun").value;//获取主题
           var tempName=document.getElementById("TeName").value;//获取模板名称
           if(tempName==""||tempName==null)
           {
             alert("模板名称不能够为空");
             return;
           }
           if(txtMun==""||txtMun==null)
           {
             alert("主题不能够为空");
             return;
           }
           if(txt==null||txt=="")
           {
             alert("模板内容不能够为空");
             return;
           }
           var getValue=editTxt.GetContent();
           objResponse.write("txt",getValue);	
           objResponse.write("txtMun",txtMun);	
           objResponse.write("tempName",tempName);	
           if(index==null||index=="")
           {
             objResponse.write("teampID","0");	
           }
           else
           {
             objResponse.write("teampID",index);	
           }
           var out=objAjax.getText("post","SpoolerPage.aspx?type=saveDate",objResponse,null);
           if(out=="1")
           {
            alert("保存成功");
            window.location.href="sendEmail.aspx";
            return;
           }
           else
           {
            alert("保存失败");
            return;
           }
         }
         //删除选中的模板
         function del()
         {
          var index=document.getElementById("dd").value;
          if(index==""||index==null)
          {
           alert("请选择你要删除的模板");
           return;
          }
          else
          {
           if(confirm("是否删除模板"))
           {
             var objAjax=new JAjax();
             var objResponse=new JHttpResponse();
             objResponse.write("index",index);
             var out=objAjax.getText("post","SpoolerPage.aspx?type=elTeap",objResponse,null);
             if(out=="1")
             {
              alert("删除成功");
              BindAllTeam();
              return;
             }
             else
             {
              alert("删除失败");
              return;
             }
             	
           }
          }
         }
         function loadPage()
         {
             loadBodyclick();
		    writeFettleLeft("提示:内置代码调用说明 : 用户名调用代码为“$Username”，日期/时间的调用代码为“$DateTime”,注册连接“$RegUrl” ") //状态栏提示
         }
    </script>
</head>
<body onload="loadPage()">
    <form id="form1" runat="server">
    <div>
        <table border="0" cellpadding="0" cellspacing="0">
             <tr class="tr1">
					<td class="oushutd" align="right" style="text-align: right; width: 130px;">载入已有模板：</td>
					<td class="oushutd" style="width: 509px">				
						<select name="TName" id="TName" onmouseover="BindAllTeam()" onChange="selectTemp(this)" style="width: 154px"><option value="0">选择已有的模板</option></select>
                        <input type="button" class="button" name="delbut" id="delbut" value="删除选中的模板" onClick="javascript:del();"/>&nbsp;
                        <input type="button" class="button" name="but" id="but" value=" 保存模板 " onClick="submt();" />
                        <input type="hidden" name="dd" id="dd" value="" />
					</td>
			  </tr>
			   <tr>
                    <td class="jishutd" align="right" style="text-align: right; width: 130px;">模板名：</td>
                    <td class="jishutd" style="width: 509px" ><input title="模板名称" type="text" name="TeName" id="TeName" isV="1" usehtml="1" notnull="1" />
                        <font color="#FF0000">注:如果与已存在的模板名相同,原模板将被覆盖</font>
                    </td>
              </tr>	
              <tr>
                    <td class="oushutd" style="text-align: right; width: 130px;">主题：</td>
                    <td class="oushutd" style="width: 509px"><input title="主题" id="txtMun" type="text" isv="1" usehtml="1" notnull="1" style="width: 641px" /></td>
               </tr>
               <tr>
                    <td class="jishutd" style="text-align:right; width: 130px;">内容：</td>
                    <td class="jishutd" style="text-align:left; vertical-align:top; width: 509px;"><div id="editTextDiv" style="height: 450px; width: 650px"><iframe src="" id="editTxt" name="editTxt" style="width: 100%; height: 100%" marginwidth="0" marginheight="0" align="top" scrolling="no" frameborder="0"></iframe></div></td>
               </tr>
        </table>
     </div>
     <script type="text/javascript" language="javascript">
              //将编辑器载入
        $("editTxt").src="../editor/Editor.htm";
     </script>
    </form>
</body>
</html>
