<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ExhibitorMaster.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>


<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Scripts/DatePicker/themes/base/ui.all.css" rel="stylesheet" type="text/css" />
    <link href="<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Scripts/DatePicker/themes/base/ui.datepicker.css" rel="stylesheet" type="text/css" />
    <script src="<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Scripts/DatePicker/ui.datepicker.js" type="text/javascript"></script>
    <script src="<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Scripts/CheckInfo.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#CurrentPosition").html("现场专访");
            $("#menu91").css("visibility", "visible");

            $("#BeforeDate").datepicker({ dateFormat: 'yy-mm-dd', clearText: '清除', closeText: '关闭', prevText: '上月', nextText: '下月', currentText: ' ', monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'] });
            $("#DuringDate").datepicker({ dateFormat: 'yy-mm-dd', clearText: '清除', closeText: '关闭', prevText: '上月', nextText: '下月', currentText: ' ', monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'] });

            $("input[name^='Before']").attr("disabled", true);
            $("input[name^='During']").attr("disabled", true);
            $("textarea[name^='Answer']").attr("disabled", true);

            $("#ckbBefore").click(function () {
                var checked = $(this).attr("checked");
                $("#BeforeName").attr("disabled", !checked);
                $("#BeforeRank").attr("disabled", !checked);
                $("#BeforeEmail").attr("disabled", !checked);
                $("#BeforeDate").attr("disabled", !checked);
                if (checked) {
                    $("#BeforeName").focus();
                }
                areaState();
            });
            $("#ckbDuring").click(function () {
                var checked = $(this).attr("checked");
                $("#DuringName").attr("disabled", !checked);
                $("#DuringRank").attr("disabled", !checked);
                $("#DuringEmail").attr("disabled", !checked);
                $("#DuringDate").attr("disabled", !checked);
                if (checked) {
                    $("#DuringName").focus();
                }
                areaState();
            });

            //判断填写状态
            var bName = $.trim($("#BeforeName").val());
            var bRank = $.trim($("#BeforeRank").val());
            var bEmail = $.trim($("#BeforeEmail").val());
            var bDate = $.trim($("#BeforeDate").val());
            var dName = $.trim($("#DuringName").val());
            var dRank = $.trim($("#DuringRank").val());
            var dEmail = $.trim($("#DuringEmail").val());
            var dDate = $.trim($("#DuringDate").val());
            if (bName != "" && bRank != "" && bEmail != "") {
                $("#ckbBefore").attr("checked", true);
                $("#BeforeName").attr("disabled", false);
                $("#BeforeRank").attr("disabled", false);
                $("#BeforeEmail").attr("disabled", false);
                $("#BeforeDate").attr("disabled", false);
            }
            if (dName != "" && dRank != "" && dDate != "") {
                $("#ckbDuring").attr("checked", true);
                $("#DuringName").attr("disabled", false);
                $("#DuringRank").attr("disabled", false);
                $("#DuringEmail").attr("disabled", false);
                $("#DuringDate").attr("disabled", false);
            }
            areaState();
        });
        function areaState() {
            var ckbB = $("#ckbBefore").attr("checked");
            var ckbD = $("#ckbDuring").attr("checked");
            if (ckbB || ckbD) {
                $("textarea[name^='Answer']").attr("disabled", false);
            } else {
                $("textarea[name^='Answer']").attr("disabled", true);
            }
        }

        function Save() {
            var answersObj = $("textarea[name^='Answer']");
            if (answersObj.length <= 0) {
                MsgTip.show({ msg: "主办还没有设置专访问题！", ico: "warning", top: 340 });
                return;
            }

            var bName = $.trim($("#BeforeName").val());
            var bRank = $.trim($("#BeforeRank").val());
            var bEmail = $.trim($("#BeforeEmail").val());
            var bDate = $.trim($("#BeforeDate").val());
            var dName = $.trim($("#DuringName").val());
            var dRank = $.trim($("#DuringRank").val());
            var dEmail = $.trim($("#DuringEmail").val());
            var dDate = $.trim($("#DuringDate").val());

            var ckbB = $("#ckbBefore").attr("checked");
            if (ckbB) {
                if (bName == "") {
                    $("#BeforeName").focus();
                    MsgTip.show({ msg: "请输入姓名！", ico: "warning", top: 340 });
                    return;
                }
                if (bRank == "") {
                    $("#BeforeRank").focus();
                    MsgTip.show({ msg: "请输入职务！", ico: "warning", top: 340 });
                    return;
                }
                if (bEmail == "") {
                    $("#BeforeEmail").focus();
                    MsgTip.show({ msg: "请输入Email！", ico: "warning", top: 340 });
                    return;
                } else {
                    if (!checkEmail(bEmail)) {
                        $("#BeforeEmail").focus();
                        MsgTip.show({ msg: "Email格式不正确！", ico: "warning", top: 340 });
                        return;
                    }
                }
//                if (bDate == "") {
//                    $("#BeforeDate").focus();
//                    MsgTip.show({ msg: "请选择日期！", ico: "warning", top: 340 });
//                    return;
//                }
            }
            var ckbD = $("#ckbDuring").attr("checked");
            if (ckbD) {
                if (dName == "") {
                    $("#DuringName").focus();
                    MsgTip.show({ msg: "请输入姓名！", ico: "warning", top: 340 });
                    return;
                }
                if (dRank == "") {
                    $("#DuringRank").focus();
                    MsgTip.show({ msg: "请输入职务！", ico: "warning", top: 340 });
                    return;
                }
                if (dEmail == "") {
//                    $("#BeforeEmail").focus();
//                    MsgTip.show({ msg: "请输入Email！", ico: "warning", top: 340 });
//                    return;
                } else {
                    if (!checkEmail(bEmail)) {
                        $("#DuringEmail").focus();
                        MsgTip.show({ msg: "Email格式不正确！", ico: "warning", top: 340 });
                        return;
                    }
                }
                if (dDate == "") {
                    $("#DuringDate").focus();
                    MsgTip.show({ msg: "请选择日期！", ico: "warning", top: 340 });
                    return;
                }
            }
            if (ckbB || ckbD) {
                var answersObj = $("textarea[name^='Answer']");
                for (var i = 0; i < answersObj.length; i++) {
                    var answer = $.trim($(answersObj[i]).val());
                    if (answer == "") {
                        $(answersObj[i]).focus();
                        MsgTip.show({ msg: "请填写回答问题！", ico: "warning", top: 640 });
                        return;
                    }
                }
                $("#f1").submit();
            } else {
                window.scrollTo(0);
                MsgTip.show({ msg: "请选择是否填写展前受访人或现场受访人，填写后保存！", ico: "warning", top: 340 });
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <center>
            <form id="f1" action="" method="post">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="left">
                        组委会将联合数十家合作媒体，以独特视角，免费为您提供展会前期和现场的媒体专访及报道。
                    </td>
                </tr>
                <tr>
                    <td>
                    <%
                        List<string> questionLi = ViewData["Question"] as List<string>;
                        
                        System.Data.DataRow dr = ViewData["SpecialVisit"] as System.Data.DataRow;
                        string bName = "";
                        string bRank = "";
                        string bEmail = "";
                        string bDate = "";
                        string dName = "";
                        string dRank = "";
                        string dEmail = "";
                        string dDate = "";
                        string[] answers = new string[questionLi.Count];
                        if (dr != null)
                        {
                            bName = Server.HtmlEncode(dr["SvtBeforeName"].ToString());
                            bRank = Server.HtmlEncode(dr["SvtBeforeRank"].ToString());
                            bEmail = Server.HtmlEncode(dr["SvtBeforeEmail"].ToString());
                            if (dr["SvtBeforeDate"].ToString() != "")
                            {
                                bDate = Convert.ToDateTime(dr["SvtBeforeDate"]).ToShortDateString();
                            }
                            dName = Server.HtmlEncode(dr["SvtDuringName"].ToString());
                            dRank = Server.HtmlEncode(dr["SvtDuringRank"].ToString());
                            dEmail = Server.HtmlEncode(dr["SvtDuringEmail"].ToString());
                            if (dr["SvtDuringDate"].ToString() != "")
                            {
                                dDate = Convert.ToDateTime(dr["SvtDuringDate"]).ToShortDateString();
                            }
                            string[] answerStr = dr["SvtAnswers"].ToString().Split(';');
                            for (int i = 0; i < answerStr.Length; i++)
                            {
                                if (i < questionLi.Count)
                                {
                                    answers[i] = answerStr[i];
                                }
                                else
                                {
                                    break;
                                }
                            }
                        } 
                    %>
                        <table width="100%" border="1" cellpadding="3" cellspacing="0" style="line-height:17px;">
                            <tr>
                                <td align="left" colspan="4">展前受访人：（是否填写<input type="checkbox" id="ckbBefore" name="ckbBefore" />）</td>
                            </tr>
                            <tr>
                                <td align="left" width="100">姓名：</td>
                                <td align="left"><input type="text" class="text" id="BeforeName" name="BeforeName" value="<%=bName %>" /></td>
                                <td align="left" width="120">职务：</td>
                                <td align="left"><input type="text" class="text" id="BeforeRank" name="BeforeRank" value="<%=bRank %>" /></td>
                            </tr>
                            <tr>
                                <td align="left">Email：</td>
                                <td align="left"><input type="text" class="text" id="BeforeEmail" name="BeforeEmail" value="<%=bEmail %>" /></td>
                                <td align="left">受访日期：</td>
                                <td align="left"><input type="text" class="text" id="BeforeDate" name="BeforeDate" value="<%=bDate %>" readonly="readonly" /></td>
                            </tr>
                            <tr>
                                <td align="left" colspan="4">现场受访人：（是否填写<input type="checkbox" id="ckbDuring" name="ckbDuring" />）</td>
                            </tr>
                            <tr>
                                <td align="left">姓名：</td>
                                <td align="left"><input type="text" class="text" id="DuringName" name="DuringName" value="<%=dName %>" /></td>
                                <td align="left">职务：</td>
                                <td align="left"><input type="text" class="text" id="DuringRank" name="DuringRank" value="<%=dRank %>" /></td>
                            </tr>
                            <tr>
                                <td align="left">Email：</td>
                                <td align="left"><input type="text" class="text" id="DuringEmail" name="DuringEmail" value="<%=dEmail %>" /></td>
                                <td align="left">现场受访日期：</td>
                                <td align="left"><input type="text" class="text" id="DuringDate" name="DuringDate" value="<%=dDate %>" readonly="readonly" /></td>
                            </tr>
                            <tr>
                                <td align="left">展会前期：</td>
                                <td align="left" colspan="3"><%=ViewData["BeforeInfo"]%></td>
                            </tr>
                            <tr>
                                <td align="left">展会现场：</td>
                                <td align="left" colspan="3"><%=ViewData["DuringInfo"]%></td>
                            </tr>
                            <tr>
                                <td align="left" colspan="4">
                                    请就如下问题谈谈您的看法(必填)：<br />
                                    <%
                                        for (int i = 0; i < questionLi.Count; i++)
                                        {
                                            string question = questionLi[i];
                                    %>
                                    <%=question %><br />
                                    <textarea rows="3" cols="70" id="Answer<%=i %>" name="Answer<%=i %>"><%=Server.HtmlEncode(answers[i]) %></textarea><br />
                                    <%        
                                        }  
                                    %>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td align="center">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><div class="button" onclick="Save()">保 存</div></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <script type="text/javascript">
                            var message = "<%=ViewData["Message"] %>";
                            if (message != "") {
                                MsgTip.show({ msg: message, ico: "warning", top: 340 });
                            }
                        </script>
                    </td>
                </tr>   
            </table>
            </form>
        </center>
    </div>
</asp:Content>
