<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="PromoteAdd.aspx.cs" Inherits="OAWeb.crm.promote.PromoteAdd" EnableViewStateMac="false"
    ValidateRequest="false" %>

<%@ Register Src="../../UserControls/SMSEmailNav.ascx" TagName="SMSEmailNav" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlace" runat="server">
    <script src="/js/jquery.form.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript" src='<%=ResolveUrl("~/ckeditor/ckeditor.js")%>'></script>
    <style type="text/css">
        .table_form .right
        {
            width: 100px;
        }
    </style>
    <!--主体左侧-->
    <table id="plc_profile" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td class="main_left">
                <uc1:SMSEmailNav ID="SMSEmailNav1" runat="server" />
            </td>
            <td class="main_center">
                <!--主体-->
                <div class="page_main">
                    <div class="page_content">
                        <div class="form" style="border: solid 1px #ddd; padding: 5px;">
                            <table cellpadding="0" cellspacing="0" border="0" class="table_form">
                                <tr>
                                    <td class="title">
                                        <em style="float: left">
                                            <img src="/images/08.gif" />
                                        </em>
                                        <h1>
                                            创建推广计划 - 推广计划信息填写
                                        </h1>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="form_submit">
                                            <table cellpadding="0" cellspacing="0" border="0" class="table_form">
                                                <tr>
                                                    <td class="right ">
                                                        <span class="red">*</span> 推广主题:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtTitle" Text="" runat="server" CssClass="text width400 "></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="right ">
                                                        发送方式:
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlMethod" runat="server">
                                                            <asp:ListItem Value="email">电子邮件</asp:ListItem>
                                                            <asp:ListItem Value="sms">短信</asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="right ">
                                                        可插入标签:
                                                    </td>
                                                    <td>
                                                        <span class="insert_tags"></span>
                                                    </td>
                                                </tr>
                                                <tr class="email_send">
                                                    <td class="right ">
                                                        <span class="red">*</span> 邮件主题:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtEmailSubject" Text="" runat="server" CssClass="text width400 "></asp:TextBox><span
                                                            class="tip01"> 邮件主题必须手动复制标签</span>
                                                    </td>
                                                </tr>
                                                <tr class="email_send">
                                                    <td class="right ">
                                                        <span class="red">*</span> 内容:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtEmailContent" runat="server" TextMode="MultiLine" Height="200px"
                                                            CssClass="text" Width="100%"></asp:TextBox>
                                                        <script type="text/javascript">
                                                            CKEDITOR.replace('<%=txtEmailContent.ClientID %>',
                    {
                        skin: 'v2',
                        width: '600',
                        height: '200',
                        font_names: '宋体/宋体;黑体/黑体;仿宋/仿宋_GB2312;楷体/楷体_GB2312;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;',
                        toolbar: [
                        ['Source', 'Bold', 'Italic', 'Underline', 'Strike', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'Link', 'Customupload', '-', 'Table', 'HorizontalRule', 'SpecialChar'],
                        ['Format', 'Font', 'FontSize', 'TextColor', 'BGColor']
                        ],
                        language: 'zh-cn',
                        filebrowserBrowseUrl: '<%=ResolveUrl("~/ckfinder/ckfinder.html")%>',
                        filebrowserImageUploadUrl: '<%=ResolveUrl("~/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images")%>',
                        removeDialogTabs: 'image:advanced;link:advanced;',
                        removeDialogTabs: 'link:advanced;link:target;image:advanced;image:target;'
                    })
                                                        </script>
                                                    </td>
                                                </tr>
                                                <tr class="sms_send hide">
                                                    <td class="right ">
                                                        <span class="red">*</span> 内容:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtSmsContent" runat="server" TextMode="MultiLine" Height="200px"
                                                            CssClass="text ctl_content" Width="400px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr class="sms_send hide">
                                                    <td class="right ">
                                                    </td>
                                                    <td>
                                                        短信输入建议不超过65个字，超过则会拆分后发送，当前已输入 <span class="green" id="content_num">0</span>/65 个字
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="right ">
                                                        <span class="email_send red">*</span><span class="email_send">发送人:</span><span class="sms_send hide">签名:</span>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtSendName" runat="server" CssClass="text width120 "></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="right ">
                                                    </td>
                                                    <td>
                                                        <input id="btnSave" type="button" value="线索队列" class="btn_77px" />
                                                        <input id="btnCustomerSave" type="button" value="客户队列" class="btn_77px" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%=ddlMethod.ClientID %>").change(function(){
               if($(this).val() == "sms") {
                  $(".sms_send").show();
                  $(".email_send").hide();
               }
               else{
                  $(".sms_send").hide();
                  $(".email_send").show();
               }
            })
            var jsonTag = eval('(<%=LoadTagData() %>)');
            $.each(jsonTag, function (name) {
                $(".insert_tags").append("<a href=\"javascript:void(0)\" class=\"field_tags\"><{" + name + "}></a> ");
            })
            $(".field_tags").live("click", function () {
                if($("#<%=ddlMethod.ClientID %>").val() == "email"){
                    CKEDITOR.instances.<%=txtEmailContent.ClientID %>.insertHtml($(this).text());
                }
                else{
                    var txt = document.getElementById("<%=txtSmsContent.ClientID %>");
                    insertAtCursor(txt, $(this).text());
                    changeNum();
                }
            })
            $("#btnSave").click(function () {
                SaveSubmit("/crm/promote/PromoteAdd.aspx?op=Save&datatype=clues",$(this));
            });
            $("#btnCustomerSave").click(function () {
                SaveSubmit("/crm/promote/PromoteAdd.aspx?op=Save&datatype=customer",$(this));
            });   
            
            $(".ctl_content").keyup(changeNum);
        });
        function SaveSubmit(urlValue,btn){
            //把编辑值赋值到实际文本框，编辑器只在有post动作时才把值赋值给实际文本框。
            CKEDITOR.instances.<%=txtEmailContent.ClientID %>.updateElement(); 
            btn.attr("disabled", "true");
            $("#aspnetForm").ajaxSubmit({
                url: urlValue,
                success: function (result) {
                    if(result.indexOf("ok:") > -1) {
                        window.location.href = result.replace("ok:","");
                    } else {
                        alert(result);
                    }
                    btn.removeAttr("disabled");
                }
            });
            return false;
        }
        //插入图片
        function UploadFun() {
            if(art.dialog != "") art.dialog.data('departValue',""); //清空防止上一次的缓存
            return OpenDialog2('/crm/promote/UploadPic.aspx?r='+Math.random(), '插入图片', function () {
                var bValue = art.dialog.data('departValue');
                if (bValue != null && bValue != "") { 
                    CKEDITOR.instances.<%=txtEmailContent.ClientID %>.insertHtml("<img src='"+bValue+"'/>");
                }
            });
        }
        //短信文本实时统计
         function changeNum() {
            $("#content_num").html($(".ctl_content").val().length);
            if ($(".ctl_content").val().length > 65) {
                $("#content_num").removeClass("green");
                $("#content_num").addClass("red");
            } else {
                $("#content_num").removeClass("red");
                $("#content_num").addClass("green");
            }
        }
    </script>
</asp:Content>
