<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewTM.aspx.cs" Inherits="Mail_NewTM" ValidateRequest="false" meta:resourcekey="Page" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="stylesheet" href="../libs/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" href="../libs/bootstrapValidator.min.css" />
    <link rel="stylesheet" href="../libs/fontawesome/css/all.min.css" />
    <link rel="stylesheet" href="../libs/kendoui/2023.3.1114/styles/bootstrap-3.css" />
    <script type="text/javascript" src="../libs/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="../libs/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../libs/bootstrapValidator.min.js"></script>
    <script src="../libs/kendoui/2023.3.1114/mjs/kendo.editor.js" type="module"></script>
</head>
<body>
    <style>
        .mailAddrRemove
        {
            color: #FF9151;
        }
    </style>
    <script type="text/javascript">
        var submitType = "";
        var senderNameActb = null;
        var darkMode = false;

        $(function () {
            Dialog.setMessage('<asp:Literal runat="server" Text="<%$ Resources:Dialog, Title%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, OK%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, Cancel%>" />');
            Dialog.setUseBrowserConfirm(<%=AppSetting.UseBrowserConfirm%>);
            darkMode = (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches);
            toRcpts = new Recipients();
            ccRcpts = new Recipients();
            bccRcpts = new Recipients();
            InitEditor();
            if ("<%=WebUser.CurrentUser.UiLanguage%>" == "ko") kendo.culture("ko-KR");

            $("#form1").bootstrapValidator()
                .on('success.form.bv', function (e) {
                    // 폼 서브미션 금지하고 __doPostBack 호출
                    e.preventDefault();
                    if (toRcpts.Length() == 0) {
                        $("#toRcptWarning").collapse("show");
                        var $form = $(e.target);
                        $form.bootstrapValidator("disableSubmitButtons", false);
                        return;
                    }
                    var postBack = "";
                    if (submitType == "send") {
                        // 메일을 발송하시겠습니까?
                        Dialog.confirm({
                            content: '<asp:Literal runat="server" Text="<%$ Resources:, Msg01%>" />',
                            ok: function () {
                                $("#ToRcptsHidden").val(Recipients.ToJsonString(toRcpts));
                                $("#CcRcptsHidden").val(Recipients.ToJsonString(ccRcpts));
                                $("#BccRcptsHidden").val(Recipients.ToJsonString(bccRcpts));
                                GrabTextFromEditor();
                                __doPostBack("SendButton", "");
                            },
                            cancel: function () {
                                // confirm 취소 시 서브밋 버튼 활성화
                                var $form = $(e.target);
                                $form.bootstrapValidator("disableSubmitButtons", false);
                            }
                        });
                    } else if (submitType == "save") {
                        // 임시 보관함에 저장하시겠습니까?
                        Dialog.confirm({
                            content: '<asp:Literal runat="server" Text="<%$ Resources:, Msg02%>" />',
                            ok: function () {
                                $("#ToRcptsHidden").val(Recipients.ToJsonString(toRcpts));
                                $("#CcRcptsHidden").val(Recipients.ToJsonString(ccRcpts));
                                $("#BccRcptsHidden").val(Recipients.ToJsonString(bccRcpts));
                                GrabTextFromEditor();
                                __doPostBack("SaveButton", "");
                            },
                            cancel: function () {
                                // confirm 취소 시 서브밋 버튼 활성화
                                var $form = $(e.target);
                                $form.bootstrapValidator("disableSubmitButtons", false);
                            }
                        });
                    }
                });

            $.ajax({
                type: "POST",
                url: "GetRecipients.aspx/GetAutoCmplRecipientList4Actb",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var autoCmplArray = response.d;
                    var actbObj = actb($("#mailAddrText").get(0), autoCmplArray, undefined, false);
                    if (darkMode) {
                        actbObj.actb_bgColor = "#202020";
                        actbObj.actb_textColor = "#d0d0d0";
                        actbObj.actb_borderColor = "#505050";
                        actbObj.actb_hColor = "#383838";
                    }

                },
                failure: function (response) {
                    Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg03%>" />');     // 자동 완성 데이터 로딩 작업을 실패했습니다.
                }
            });

            InitRecipients();
            InitAttachFile();
        });

        function Send() {
            submitType = "send";
        }

        function Save() {
            submitType = "save";
        }

        /*
            파일 첨부 관련 함수
        */
        var malwareInfected = false;        // 악성 코드 감염 여부

        function InitAttachFile() {
            kendo.ui.Upload.fn._supportsDrop = function () { return false; }    // 드래그&드롭 업로드 기능 off
            $("#files").kendoUpload({
                async: {
                    saveUrl: "../Common/UploadChunk.ashx",
                    removeUrl: "../Common/UploadRemove.ashx",
                    chunkSize: 2 * 1024 * 1024,
                    autoUpload: true
                },
                // 업로드 시작하기 전 발생
                upload: function (request) {
                    // 파라미터 추가
                    request.data = { checkMalware: true };
                    $("#addFilesOKButton").attr("disabled", true);
                },
                // 업로드 완료 시 발생
                complete: function (e) {
                    $("#addFilesOKButton").attr("disabled", false);
                },
                // 오류 응답 시 발생: 악성 코드 검출 시 발생
                error: function (e) {
                    try {
                        const cmResult = JSON.parse(e.XMLHttpRequest.responseText);
                        if (cmResult.infected) {
                            malwareInfected = true;
                            Dialog.alert(String.format('<asp:Literal runat="server" Text="<%$ Resources:, Msg12%>" />', cmResult.malware));
                        }
                    } catch {}
                }
            });
        }

        function AddFilesEx(e) {
            e.stopPropagation();
            if (malwareInfected) {
                malwareInfected = false;
                $("#files").data("kendoUpload").clearAllFiles();
            }
            $("#addFilesModal").modal();
        }

        // 파일 업로드 후 확인 버튼 클릭 -> 첨부 파일 목록을 갱신
        function AddFilesExOK() {
            $("#addFilesModal").modal("hide");
            var upload = $("#files").data("kendoUpload"), files = upload.getFiles();
            if (malwareInfected) {
                // 감염 이력이 있을 경우 모든 첨부를 제거한다.
                upload.clearAllFiles();
                malwareInfected = false;
                return;
            }
            if (files.length > 0) {
                var fileInfoList = [];
                for (var i = 0; i < files.length; i++) {
                    var file = files[i];
                    var fileInfo = {
                        Uid: file.uid,
                        Name: file.name,
                        Extension: file.extension,
                        ContentType: file.rawFile.type,
                        Size: file.size
                    };
                    fileInfoList.push(fileInfo);
                }
                $("#JsonUploadFilesHidden").val(JSON.stringify(fileInfoList));
                console.log($("#JsonUploadFilesHidden").val());
                upload.clearAllFiles();
                __doPostBack("AddAttachFileButton", "");
            }
        }

        // 첨부 파일 목록에서 파일 제거
        function RemoveFile(index) {
            $("#<%=RemoveAttachFileIndex.ClientID %>").val(index);
            __doPostBack("RemoveAttachFileButton", "");
        }

        function GotoBack() {
            // 편집한 내용은 저장되지 않습니다.\n메일 편집을 종료하시겠습니까?
            Dialog.confirm({
                content: '<asp:Literal runat="server" Text="<%$ Resources:, Msg04%>" />',
                ok: function () {
                    history.back();
                }
            });
        }

        function ShowMessage(msg) {
            Dialog.alert(msg);
        }

        /*
            Contact, Orgz Dialog 관련 함수 
        */
        var toRcpts = null;
        var ccRcpts = null;
        var bccRcpts = null;

        function InitRecipients() {
            <%=_initRecipientsScript %>;
            ShowRcptListView($("#toListView"), toRcpts);
            ShowRcptListView($("#ccListView"), ccRcpts);
            ShowRcptListView($("#bccListView"), bccRcpts);
            if (ccRcpts.Length() > 0 || bccRcpts.Length() > 0) $("#ExpandRecipients").collapse("toggle");

            $("#rcptSelectModal").on("shown.bs.modal", function () {
                $("#mailAddrText").focus();
            });

            if ("<%=AppSetting.SupportBcc%>" == "False") {
                $("#bccRegion").hide();
            }
        }        
        
        // 주소록/조직도 등에서 메일 쓰기 시 수신자 지정을 위해 사용
        function CallReturnToRecipients(displayName, value, type) {
            // 1: Email, 2: Contact, 3: Orgz 
            if (type == 1)
                toRcpts.AddMailAddress(displayName, value);
            else if (type == 2)
                toRcpts.AddMailGroup(displayName, value);
            else if (type == 3) 
                toRcpts.AddOrgz(displayName, value);
        } 
        
        var rcptType = "";      // + 버튼 클릭 시 받는이/참조/숨은참조를 구분하기 위한 변수

        // 받는이/참조/숨은참조 추가 버튼 클릭
        function OpenMailAddressDialog(rType) {
            rcptType = rType;
            OpenRcptSelectModal();
        }

        // 수신자 입력 모달창 띄우기
        function OpenRcptSelectModal() {
            $("#toRcptWarning").collapse("hide");
            $("#rcptSelectModal").modal();
            $("#mailAddrText").val("");
        }

        // 수신자 입력 모달창에서 메일 주소 입력 후 확인 버튼 클릭 시 호출: 모달을 닫고 입력한 수신자를 UI에 출력한다.
        function AddMailAddress() {
            $("#rcptSelectModal").modal("hide");
            var mailAddr = $("#mailAddrText").val();
            switch (rcptType) {
                case "to":
                    toRcpts.AddMailAddressEx(mailAddr);
                    ShowRcptListView($("#toListView"), toRcpts);
                    break;
                case "cc":
                    ccRcpts.AddMailAddressEx(mailAddr);
                    ShowRcptListView($("#ccListView"), ccRcpts);
                    break;
                case "bcc":
                    bccRcpts.AddMailAddressEx(mailAddr);
                    ShowRcptListView($("#bccListView"), bccRcpts);
                    break;
            }
        }

        // 주소록 버튼 클릭
        function OpenContact() {
            var url = "../Contact/SelectRcpt.aspx?RcptType=" + rcptType;
            window.open(url, "SelectRcpt");
        }

        // 조직도 버튼 클릭
        function OpenOrgz() {
            var url = "../Contact/SelectOrgzEx.aspx?RcptType=" + rcptType;
            window.open(url, "SelectOrgz");
        }

        // SelectRcpt.aspx, SelectOrgz.aspx에서 데이터를 반환하기 위해 호출
        function ReturnToRecipients(param) {
            var rcpts = Recipients.FromJsonString(param);
            toRcpts.AddRecipients(rcpts);
            $("#rcptSelectModal").modal("hide");
            ShowRcptListView($("#toListView"), toRcpts);
        }
       
        function ReturnCcRecipients(param) {
            var rcpts = Recipients.FromJsonString(param);
            ccRcpts.AddRecipients(rcpts);
            $("#rcptSelectModal").modal("hide");
            ShowRcptListView($("#ccListView"), ccRcpts);
        } 
       
        function ReturnBccRecipients(param) {
            var rcpts = Recipients.FromJsonString(param);
            bccRcpts.AddRecipients(rcpts);
            $("#rcptSelectModal").modal("hide");
            ShowRcptListView($("#bccListView"), bccRcpts);
        }

        // Recipients 오브젝트에 저장되어 있는 수신자 목록을 UI에 출력한다.
        function ShowRcptListView(target, rcptList) {
            // 수신자 목록(to, cc, bcc) 별로 삭제 이벤트를 따로 연결하기 위해 고유 클래스 이름(toListView_remove, ...)을 생성
            var clsName = target.attr("id") + "_remove";
            target.empty();
            for (var i = 0; i < rcptList.recipients.length; i++) {
                var rcpt = rcptList.recipients[i];
                var name = "";
                switch (rcpt.type) {
                    case RcptMailAddr: name = rcpt.name; break;
                    case RcptMailGroup: name = "@[" + rcpt.name + "]"; break;
                    case RcptOrgz: name = "#[" + rcpt.name + "]"; break;
                }
                var tag = "<span class='label label-info'>" + HtmlEncode(name) + " <span class='fa-solid fa-xmark " + clsName +  " mailAddrRemove' data-value='" + i + "'></span></span> ";
                target.append(tag);
            }
            // 메일 주소 삭제 이벤트
            $("." + clsName).click(function () {
                var index = $(this).data("value");
                rcptList.RemoveByIndex(index);
                // 한 항목 삭제 후 목록 재구성
                ShowRcptListView(target, rcptList);
            });
        }

        function IgnoreEnterKey(event) {
            if (event.keyCode == 13) return false;
            return true;
        }

        function HtmlEncode(value) {
            return $('<div/>').text(value).html();
        }
        
        function AddSignature(id) {
            $.ajax({
                type: "POST",
                url: "CallAjax.aspx/GetSignatureEx2",
                data: JSON.stringify({ id: id }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var sigId = "<%=_signatureId%>";
                    var sigHtml = response.d;
                    var editor = $("#MsgTextBox").data("kendoEditor");
                    var element = editor.body.querySelector("#" + sigId);                     
                    if (element != null) {
                        element.innerHTML = sigHtml;
                    } else {
                        editor.paste("<p>&nbsp;</p><div id='" + sigId + "'>" + sigHtml + "</div><p>&nbsp;</p>");
                    }
                },
                failure: function (response) {
                    Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg06%>" />'); // 서명 데이터 로딩 작업을 실패했습니다.
                }
            });
        }

        function InitEditor() {
            var html = $("#MsgTextBox").val();
            var $content = $($.parseHTML("<div>" + html + "</div>"));
            // 모든 수신확인 이미지 제거
            var $imgs = $content.find("img");
            $imgs.each(function () {
                const src = $(this).attr('src');
                if (src.search(/\/External\/MailRead.ashx\?read=[0-9a-f]{8}-[0-9a-f]{4}/) > 10) {
                    $(this).remove();
                }
            });
            // 모든 #mc_container unwrap
            var mcContainer = $content.find("#mc_container");
            if (mcContainer.length > 0) mcContainer.contents().unwrap();
            html = $content.html();
            // textarea 값을 변경 후 kendoEditor를 생성하면 변경된 값이 적용되지 않고 원 값이 적용되는 문제가 있어 아래와 같이 생성 후 직접 적용한다.
            //$("#MsgTextBox").val(html);

            $("#MsgTextBox").kendoEditor({
                tools: KendoEditorTools,
                resizable: {
                    content: true,
                    toolbar: false
                },
                stylesheets: [
                    "../css/EditorCSS.ashx"
                ],
                paste: onEditorPaste
            });
            // 에디터 생성 후 html 등록
            $("#MsgTextBox").data("kendoEditor").value(html);
        }

        function GrabTextFromEditor() {
            var textGrab = "<div>" + $("#MsgTextBox").data("kendoEditor").value() + "</div>";
            textGrab = $(textGrab).text();
            $("#MsgTextBoxText").val(textGrab);
        }

        function onEditorPaste(e) {
            const dataVal = e.html;
            //console.log("paste dataVal: " + dataVal);
            var imgUrls = [];
            const regex = /<img[^>]+src=["']?((http|https):\/\/[^"'>\s]+)["']?[^>]*>/ig;
            while ((match = regex.exec(dataVal)) !== null) {
                imgUrls.push(match[1]);
            }
            //console.log("imgUrls=" + imgUrls);

            if (imgUrls.length > 0) {
                // *** 중요 *** 이미지 로딩 전 에디터 붙여넣기를 강제 취소 시킨다.
                e.html = "";

                var newTag = dataVal;
                Base64Image_loadAllImages(imgUrls).then(images => {
                    images.forEach(img => {
                        if (img == null) return;
                        const canvas = document.createElement("canvas");
                        canvas.width = img.naturalWidth;
                        canvas.height = img.naturalHeight;
                        const ctx = canvas.getContext('2d');
                        ctx.drawImage(img, 0, 0);
                        const base64 = canvas.toDataURL("image/png");
                        newTag = newTag.replace(img.src, base64);
                    });
                    //console.log("newTag=" + newTag);
                    var editor = $("#MsgTextBox").data("kendoEditor");
                    editor.paste(newTag);
                }).catch(error => {
                    console.error("Image loading failed:", error);
                });
            }
        }
    </script>

    <form id="form1" runat="server"
        data-bv-feedbackicons-valid="glyphicon glyphicon-ok" 
        data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
        data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <CompositeScript>
                <Scripts>
                    <asp:ScriptReference Path="~/libs/tabs/common.js" />
                    <asp:ScriptReference Path="~/libs/tabs/dialog.js" />
                    <asp:ScriptReference Path="~/libs/tabs/Recipients.js" />
                    <asp:ScriptReference Path="~/libs/tabs/actb.js" />
                    <asp:ScriptReference Path="~/libs/tabs/actb_common.js" />
                    <asp:ScriptReference Path="~/libs/tabs/base64image.js" />
                </Scripts>
            </CompositeScript>
        </asp:ScriptManager>

        <div class="container-fluid">
            <div class="row" id="toolBar" data-spy="affix">
                <div class="col-xs-12" style="padding-top:2px;padding-bottom:2px;">
                    <button type="submit" id="sendToolButton" class="btn btn-primary" onclick="Send()" ><span class="fa-solid fa-paper-plane"></span> <asp:Localize ID="Localize1" runat="server" meta:resourcekey="L01">보내기</asp:Localize></button>
                    <button type="submit" id="saveToolButton" class="btn btn-primary" onclick="Save()"><span class="fa-solid fa-download"></span> <asp:Localize ID="Localize2" runat="server" meta:resourcekey="L02">임시저장</asp:Localize></button>
                    <span>&nbsp;</span>
                    <button type="button" id="Button2" class="btn btn-primary" onclick="GotoBack();"><span class="fa-solid fa-xmark"></span></button>
                </div>
            </div>
        </div>

        <div class="container-fluid" style="padding-top:40px">            
            <div class="form-group">
                <div class="row">
                    <div class="col-xs-10">
                        <label for="addToButton"><asp:Localize ID="Localize3" runat="server" meta:resourcekey="L03">받는이</asp:Localize>:</label>
                        <span id="toListView" style="font-size:larger"></span>
                        <button type="button" id="addToButton" class="btn btn-default" onclick="OpenMailAddressDialog('to')"><span class="fa-solid fa-plus"></span></button>
                        <span id="toRcptWarning" class="text-danger collapse small"><asp:Localize ID="Localize4" runat="server" meta:resourcekey="L04">수신자를 지정 바랍니다.</asp:Localize></span>
                    </div>
                    <div class="col-xs-2 text-right">
                        <span id="expandRcptUI" class="fa-solid fa-chevron-down mc-likeLink" data-toggle="collapse" data-target="#ExpandRecipients"></span>
                    </div>
                </div>
            </div>
            <div id="ExpandRecipients" class="collapse">
                <div class="form-group">
                    <label for="addCcButton"><asp:Localize ID="Localize5" runat="server" meta:resourcekey="L05">참조</asp:Localize>:</label>
                    <span id="ccListView" style="font-size:larger"></span>
                    <button type="button" id="addCcButton" class="btn btn-default" onclick="OpenMailAddressDialog('cc')"><span class="fa-solid fa-plus"></span></button>
                </div>
                <div class="form-group" id="bccRegion">
                    <label for="addBccButton"><asp:Localize ID="Localize6" runat="server" meta:resourcekey="L06">숨은 참조</asp:Localize>:</label>
                    <span id="bccListView" style="font-size:larger"></span>
                    <button type="button" id="addBccButton" class="btn btn-default" onclick="OpenMailAddressDialog('bcc')"><span class="fa-solid fa-plus"></span></button>
                </div>
                <div class="form-group <%=_cssSenderName%>">
                    <label for="SenderNameComboBox"><asp:Localize ID="Localize7" runat="server" meta:resourcekey="L07">보내는 이름</asp:Localize>:</label>
                    <asp:DropDownList ID="SenderNameComboBox" runat="server" CssClass="form-control">
                    </asp:DropDownList>
                </div>
                <div class="form-group <%=_cssSenderAddr%>">
                    <label for="SenderAddrComboBox"><asp:Localize ID="Localize8" runat="server" meta:resourcekey="L08">보내는 메일 주소</asp:Localize>:</label>
                    <asp:DropDownList ID="SenderAddrComboBox" runat="server" CssClass="form-control">
                    </asp:DropDownList>
                </div>
            </div>
            <div class="form-group">
                <label for="SubjectTextBox"><asp:Localize ID="Localize9" runat="server" meta:resourcekey="L09">제목</asp:Localize>:</label>
                <input type="text" runat="server" id="SubjectTextBox" name="SubjectTextBox" class="form-control" placeholder="<%$ Resources:, Ph01%>" autocomplete="off"
                    required data-bv-notempty-message="<%$ Resources:, Msg05%>" />
            </div>
            <asp:UpdatePanel ID="attachPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
                <ContentTemplate>
                    <div class="row" style="padding-bottom:0.5em">
                        <div class="col-xs-12" data-toggle="collapse" data-target="#attachList">
                            <strong><asp:Localize ID="Localize10" runat="server" meta:resourcekey="L10">첨부 파일</asp:Localize>:</strong> 
                            <asp:Label ID="AttachSummaryLabel" runat="server"></asp:Label>
                            <button type="button" id="addAttachButton" class="btn btn-default" onclick="AddFilesEx(event)"><span class="fa-solid fa-plus"></span></button>
                        </div>
                    </div>
                    <ul id="attachList" runat="server" class="list-group collapse">
                        <asp:Literal ID="AttachListTag" runat="server" />
                    </ul>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="AddAttachFileButton" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="RemoveAttachFileButton" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
            <div class="form-group">
                <label for="MsgTextBox"><asp:Localize ID="Localize11" runat="server" meta:resourcekey="L11">본문</asp:Localize>:</label>
                <textarea class="form-control" style="height:380px" id="MsgTextBox" runat="server" EnableViewState="false"></textarea>
                <asp:HiddenField ID="MsgTextBoxText" runat="server" EnableViewState="false"></asp:HiddenField>
            </div>
            <div class="form-group">
                <div class="dropdown">
                    <button type="button" id="replyToolButton" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
                        <asp:Localize ID="Localize17" runat="server" meta:resourcekey="L17">서명 추가</asp:Localize> <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <asp:Repeater ID="SigRepeater" runat="server" DataSourceID="FolderDataSource">
                            <ItemTemplate>
                                <li><a href="#" onclick="AddSignature('<%# Eval("ID") %>');return false;"><%#: Eval("Name") %></a></li>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ul>
                </div>
            </div>
            <div>
                <asp:PlaceHolder ID="MsgBodyHolder" runat="server" EnableViewState="false"></asp:PlaceHolder>
            </div>
        </div>
        <asp:HiddenField ID="JsonUploadFilesHidden" runat="server"></asp:HiddenField>

        <asp:ObjectDataSource ID="FolderDataSource" runat="server" TypeName="MailSigDataSource" SelectMethod="GetSignatures" >
        </asp:ObjectDataSource>

        <div style="display:">            
            <asp:LinkButton ID="SendButton" runat="server" OnClick="SendButton_Click" /> 
            <asp:LinkButton ID="SaveButton" runat="server" OnClick="SaveButton_Click" /> 
            <asp:LinkButton ID="AddAttachFileButton" runat="server" OnClick="AddAttachFileButton_Click" /> 
            <asp:LinkButton ID="RemoveAttachFileButton" runat="server" OnClick="RemoveAttachFileButton_Click" />
            <asp:HiddenField ID="RemoveAttachFileIndex" runat="server" />
            <!-- Recipients HiddenField -->
            <asp:HiddenField ID="ToRcptsHidden" runat="server" /> 
            <asp:HiddenField ID="CcRcptsHidden" runat="server" />
            <asp:HiddenField ID="BccRcptsHidden" runat="server" /> 
        </div>
    </form>

    <div class="modal fade" id="rcptSelectModal" role="dialog" data-backdrop="static">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header" style="">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4><asp:Localize ID="Localize12" runat="server" meta:resourcekey="L12">수신자 선택</asp:Localize></h4>
                </div>
                <div class="modal-body">
                    <form role="form">
                        <div class="form-group">
                            <label for="email"><asp:Localize ID="Localize13" runat="server" meta:resourcekey="L13">메일 주소</asp:Localize>:</label>
                            <input type="text" runat="server" id="mailAddrText" name="mailAddrText" class="form-control" placeholder="<%$ Resources:, Ph02%>" autocomplete="off" onkeydown="return IgnoreEnterKey(event);" />
                        </div>
                        <div class="form-group">
                            <button type="button" id="addContactButton" class="btn btn-default" onclick="OpenContact();"><asp:Localize ID="Localize14" runat="server" meta:resourcekey="L14">주소록</asp:Localize></button>
                        </div>
                        <div class="form-group">
                            <button type="button" id="addOrgzButton" class="btn btn-default" onclick="OpenOrgz();"><asp:Localize ID="Localize15" runat="server" meta:resourcekey="L15">조직도</asp:Localize></button>
                        </div>
                        <div>&nbsp;</div>
                        <button type="button" class="btn btn-success btn-block" id="addAddrOKButton" onclick="AddMailAddress()"><asp:Localize ID="Localize16" runat="server" meta:resourcekey="L16">확인</asp:Localize></button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="addFilesModal" role="dialog" data-backdrop="static">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header" style="">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4><asp:Localize ID="Localize18" runat="server" meta:resourcekey="L18">파일 첨부</asp:Localize></h4>
                </div>
                <div class="modal-body">
                    <form role="form">
                        <div class="form-group">
                            <input type="file" name="files" id="files" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-block" id="addFilesOKButton" disabled onclick="AddFilesExOK()">
                                <asp:Localize ID="Localize19" runat="server" meta:resourcekey="L19">확인</asp:Localize></button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
