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

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script language="javascript" type="text/javascript" src='<%=ResolveUrl("~/ckeditor/ckeditor.js")%>'></script>
    <asp:PlaceHolder ID="pnlSelectData" runat="server">
        <div class="form" style="width: 700px; padding: 10px;">
            <table cellpadding="0" cellspacing="0" border="0" class="table_form">
                <tr>
                    <td style="text-align: center">
                        <input name="rdoData" type="radio" checked="checked" value="0" />对选中的记录进行推广
                        <input name="rdoData" type="radio" value="1" />对全部列表记录进行推广
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center">
                        <input id="btnNext" type="button" value=" 下一步 " class="btn_77px" />
                        <input type="button" value=" 返 回 " onclick="art.dialog.close();return false;" class="btn_77px" />
                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                $(document).ready(function () {
                    $.each($('input[name="rdoData"]'), function () { if ($(this).val() == '<%=SelectDataType %>') $(this).attr("checked", "true"); })
                    $("#btnNext").click(function () {
                        var selectData = $('input[name="rdoData"]:checked').val();
                        if (selectData == "0") {
                            if ('<%=Ids %>'.length == 0) {
                                alert("请选择要进行推广的记录");
                                return;
                            }
                            window.location.href = "SelectData.aspx?s=1&datatype=<%=DataType %>&Ids=<%=Ids %>&Filter=<%=Server.UrlEncode(Filter) %>&SelectData=0";
                        }
                        else {
                            window.location.href = "SelectData.aspx?s=1&datatype=<%=DataType %>&Ids=<%=Ids %>&Filter=<%=Server.UrlEncode(Filter) %>&SelectData=1";
                        }
                    })
                });
            </script>
        </div>
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="pnlAddMode" runat="server" Visible="false">
        <div class="form" style="width: 700px; height: 550px; padding: 10px;">
            <table cellpadding="0" cellspacing="0" border="0" class="table_form">
                <tr>
                    <td>
                        <input name="rdoPromoteType" type="radio" value="1" />加入已有推广计划 <span style="display: none;"
                            class="promotelist">
                            <asp:DropDownList ID="ddlPromoteList" runat="server">
                                <asp:ListItem Value="">请选择推广计划</asp:ListItem>
                            </asp:DropDownList>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input name="rdoPromoteType" type="radio" checked="checked" value="0" />新建推广计划
                    </td>
                </tr>
                <tr class="addForm">
                    <td>
                        <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>
                                    <div style="width: 400px;">
                                        <span class="insert_tags"></span>
                                    </div>
                                </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: '180',
                        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'
                    })
                   
                                    </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>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center">
                        <span class="sendset">
                            <asp:CheckBox ID="chkSendSet" runat="server" Text="保存后是否立即发送" />
                        </span>
                        <input id="btnSave" type="button" value=" 保 存 " class="btn_77px" />
                        <input id="btnUp" type="button" value=" 上一步 " class="btn_77px" />
                        <input type="button" value=" 返 回 " onclick="art.dialog.close();return false;" class="btn_77px" />
                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                $(document).ready(function () {
                    $('input[name="rdoPromoteType"]').click(function(){
                       if($(this).val() == "0"){
                          $(".promotelist").hide(); 
                          $(".addForm").show();
                          $(".sendset").show();
                       }
                       else{
                          $(".promotelist").show(); 
                          $(".addForm").hide();
                          $(".sendset").hide();
                       }
                    })
                    $("#btnSave").click(function () {
                        //把编辑值赋值到实际文本框，编辑器只在有post动作时才把值赋值给实际文本框。
                        CKEDITOR.instances.<%=txtEmailContent.ClientID %>.updateElement(); 
                        $("#btnSave").attr("disabled", "true");
                        CreateZhezao($(".form"), "zhezhao");
                        $("#aspnetForm").ajaxSubmit({
                            url: "/crm/promote/SelectData.aspx?op=Save&datatype=<%=DataType %>&Ids=<%=Ids %>&Filter=<%=Server.UrlEncode(Filter) %>&SelectData=<%=SelectDataType %>",
                            success: function (result) {
                                if(result.indexOf("ok:") > -1) {
                                    alert("保存成功\r\n"+result.replace("ok:",""));
                                    CloseReload();
                                } else {
                                    alert(result);
                                }
                                $("#btnSave").removeAttr("disabled");
                                $("#zhezhao").remove();
                            }
                        });
                        return false;
                    })
                    $("#btnUp").click(function () {
                        window.location.href = "SelectData.aspx?s=0&datatype=<%=DataType %>&Ids=<%=Ids %>&Filter=<%=Server.UrlEncode(Filter) %>&SelectData=<%=SelectDataType %>";
                    })
                    $("#<%=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());
                        }
                    })

                     $(".ctl_content").keyup(changeNum);
                });
                //插入图片
                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>
        </div>
    </asp:PlaceHolder>
</asp:Content>
