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


<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Scripts/CheckInfo.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#CurrentPosition").html("客户胸卡");
            $("#mainmenu3").css("visibility", "visible");


            var gender = $("#TktGender").val();
            if (gender == "先生") {
                $("#rdo1").attr("checked", true);
            }
            if (gender == "女士") {
                $("#rdo2").attr("checked", true);
            }
            //
            var country = $("#TktCountry").val();
            var countryCode = "";
            $("#selCountry option").each(function () {
                if ($(this).text() == country) {
                    $(this).attr("selected", true);
                    countryCode = $(this).val();
                }
            });
            //国家/地区
            if (countryCode != "") {
                if (countryCode == "852" || countryCode == "853") {
                    $("#tel1").css("display", "none");
                }
                else {
                    $("#tel1").css("display", "");
                }
            }
            //电话
            var tel = $("#TktTel").val();
            if (tel != "") {
                $("#tel0").val(tel.split("-")[0]);
                $("#tel1").val(tel.split("-")[1]);
                $("#tel2").val(tel.split("-")[2]);
                $("#tel3").val(tel.split("-")[3]);
            }

            var type = $("#Type").val();
            if (type == "Add") {

            }
            if (type == "Modify") {
                checkAll();
            }

            $("#TktName").blur(function () {
                checkName();
            });
            $("#TktRank").blur(function () {
                checkRank();
            });
            $("#TktEmail").blur(function () {
                checkEmail();
            });
            $("#TktComName").blur(function () {
                checkComName();
            });
            $("#tel1").blur(function () {
                checkTel();
            });
            $("#tel2").blur(function () {
                checkTel();
            });
            $("#tel3").blur(function () {
                checkTel();
            });
            $("#TktAddress").blur(function () {
                checkAddress();
            });
            $("#TktZipCode").blur(function () {
                checkZipCode();
            });
        });
        function checkAll() {
            checkName(); checkGender(); checkRank(); checkEmail();
            checkComName(); checkCountry(); checkTel(); checkAddress(); checkZipCode();
        }

        function isNum(num) {
            var reg = /\D/g;
            if (num != "") {
                if (reg.test(num)) {
                    return true;
                }
                else {
                    return false;
                }
            } else {
                return false;
            }
        }
        function checkPhoneNum(phoneNum) {
            //验证电话号码/传真号码合法性
            var reg = /^\d{7,}$/g;
            if (phoneNum != "") {
                if (reg.test(phoneNum)) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        function showCheckTag(id, ispass, message) {
            if (ispass == true) {
                $("#" + id).html('<font color="green">√</font>');
            } else {
                if (message == null) {
                    message = "";
                }
                $("#" + id).html('<font color="red">※' + message + '</font>');
            }
        }
        function Save() {
            if (checkSaveInfo()) {
                $("#f1").submit();
            }
        }
        function checkSaveInfo() {
            if (!checkName()) {
                MsgTip.show({ msg: "请输入姓名！", ico: "warning", top: 340 });
                $("#TktName").focus().select();
                return false;
            }
            if (!checkGender()) { 
            
            }
            if (!checkRank()) {
                MsgTip.show({ msg: "请输入职务！", ico: "warning", top: 340 });
                $("#TktRank").focus().select();
                return false;
            }
            if (!checkComName()) {
                MsgTip.show({ msg: "请输入公司名称！", ico: "warning", top: 340 });
                $("#TktComName").focus().select();
                return false;
            }
            if (!checkEmail()) {
                MsgTip.show({ msg: "请输入电子邮件！", ico: "warning", top: 340 });
                $("#TktEmail").focus().select();
                return false;
            }
            if (!checkCountry()) {
                MsgTip.show({ msg: "请选择国家！", ico: "warning", top: 340 });
                $("#selCountry").focus();
                return false;
            }
            if (!checkTel()) {
                MsgTip.show({ msg: "请输入电话！", ico: "warning", top: 340 });
                $("#tel2").focus();
                return false;
            }
            if (!checkZipCode()) {
                MsgTip.show({ msg: "请输入邮编！", ico: "warning", top: 340 });
                $("#TktZipCode").focus().select();
                return false;
            }
            if (!checkAddress()) {
                MsgTip.show({ msg: "请输入邮寄地址！", ico: "warning", top: 340 });
                $("#TktAddress").focus().select();
                return false;
            }
            return true;
        }
        function checkName() {
            var name = $("#TktName").val();
            var error = Name_Check("姓名", name);
            if (error != "") {
                showCheckTag("checkName", false, error);
                return false;
            }
            showCheckTag("checkName", true, "");
            return true;
        }
        function checkGender() {
            var gender = $("input[name='rdoGender']:checked").val();
            if (gender == "") {
                return false;
            }
            $("#TktGender").val(gender);
            return true;
        }
        function checkRank() {
            var rank = $("#TktRank").val();
            var error = Rank_Check("职务", rank);
            if (error != "") {
                showCheckTag("checkRank", false, error);
                return false;
            }
            showCheckTag("checkRank", true, "");
            return true;
        }
        function checkEmail() {
            var email = $("#TktEmail").val();
            var error = Email_Check("电子邮件", email);
            if (error != "") {
                showCheckTag("checkEmail", false, error);
                return false;
            }
            showCheckTag("checkEmail", true, "");
            return true;
        }
        function checkComName() {
            var comName = $("#TktComName").val();
            var error = CompanyName_Check("公司中文名称", comName);
            if (error != "") {
                showCheckTag("checkComName", false, error);
                return false;
            }
            showCheckTag("checkComName", true, "");
            return true;
        }
        function checkCountry() {
            var countryCode = $("#selCountry").val();
            var country = $("#selCountry").find("option:selected").text();
            if (countryCode == "") {
                showCheckTag("checkCountry", false, "请选择国家！");
                return false;
            }
            showCheckTag("checkCountry", true, "");
            $("#TktCountry").val(country);
            return true;
        }
        function checkTel() {
            var tel0 = $("#tel0").val();
            var tel1 = $("#tel1").val();
            var tel2 = $("#tel2").val();
            var tel3 = $("#tel3").val();
            if (tel1 == "" && tel0 != "852" && tel0 != "853" && tel0 != "886") {
                showCheckTag("checkTel", false, "请输入电话区号！");
                return false;
            }
            if (isNum(tel1)) {
                showCheckTag("checkTel", false, "电话区号必须为数字！");
                return false;
            }
            if (tel2 == "") {
                showCheckTag("checkTel", false, "请输入电话号码！");
                return false;
            }
            if (!checkPhoneNum(tel2)) {
                showCheckTag("checkTel", false, "电话号码至少7位数字！");
                return false;
            }
            if (isNum(tel3)) {
                showCheckTag("checkTel", false, "电话分机必须为数字！");
                return false;
            }
            showCheckTag("checkTel", true, "");
            //电话
            $("#TktTel").val($("#tel0").val() + "-" + $("#tel1").val() + "-" + $("#tel2").val() + "-" + $("#tel3").val());
            return true;
        }
        function checkAddress() {
            var address = $("#TktAddress").val();
            var error = Address_Check("中文地址", address);
            if (error != "") {
                showCheckTag("checkAddress", false, error);
                return false;
            }
            showCheckTag("checkAddress", true, "");
            return true;
        }
        function checkZipCode() {
            var zipCode = $("#TktZipCode").val();
            var error = ZipCode_Check("邮编", zipCode);
            if (error != "") {
                showCheckTag("checkZipCode", false, error);
                return false;
            }
            showCheckTag("checkZipCode", true, "");
            return true;
        }

        //选择国家
        function CountryChange() {
            var countryCode = $("#selCountry").val();

            if (countryCode != "") {
                if (countryCode == "852" || countryCode == "853") {
                    $("#tel1").css("display", "none");
                    $("#tel1").val("");
                }
                else {
                    $("#tel1").css("display", "");
                }
                $("#tel0").val("");
                $("#tel0").val(countryCode);
            }
            else {
                $("#tel0").val("");
                $("#tel1").css("width", "30px");
            }
            checkCountry();
        }

        function GoTo(str) {
            window.location = "<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Exhibitor/" + str;
        }
        function Back() {
            window.location = "<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Exhibitor/ExhiVisitCard";
        }
    </script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <center>
            <form id="f1" action="" method="post">
            <table width="100%" border="0" style="text-align: left" cellpadding="0" cellspacing="0" id="main">
                <tr>
                    <td align="left">
                        <table border='0' cellpadding="0" cellspacing="0" width="100%" align="left">
                            <tr>
                                <td class="tdMenu" onclick="GoTo('ExhiActorCard')">
                                    展商胸卡
                                </td>
                                <td class="tdMenuWidth">&nbsp;</td>
                                <td class="tdMenuSelect" onclick="GoTo('ExhiVisitCard')">
                                    客户胸卡
                                </td>
                                <td class="tdMenuWidth">&nbsp;</td>
                    <% 
                        if (FamousFurnitureExpo.Models.Helper.IfShowTrafficCard(Convert.ToInt32(Session["ExhID"])))
                        {
                    %>
                                <td class="tdMenu" onclick="GoTo('ExhiTrafficCard')">
                                    货车证
                                </td>
                                <td class="tdMenuWidth">&nbsp;</td>
                    <% 
                        }    
                    %>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td class="tdMenuLine" colspan="7"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <table border="0" cellpadding="0" cellspacing="10" width="100%">
                            <tr>
                                <td width="100" align="right">姓名：</td>
                                <td>
                                    <input class="text" type="text" id="TktName" name="TktName" value="<%=Server.HtmlEncode(Model.TktName) %>" />
                                    <span id="checkName"><font color="red">※</font></span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">称谓：</td>
                                <td>
                                    <input type="radio" id="rdo1" name="rdoGender" checked="checked" value="先生" />先生&nbsp;
                                    <input type="radio" id="rdo2" name="rdoGender" value="女士" />女士
                                    <input type="hidden" id="TktGender" name="TktGender" value="<%=Server.HtmlEncode(Model.TktGender) %>" />
                                </td>
                            </tr>
                            <tr>
                                <td align="right">职务：</td>
                                <td>
                                    <input class="text" type="text" id="TktRank" name="TktRank" value="<%=Server.HtmlEncode(Model.TktRank) %>" />
                                    <span id="checkRank"><font color="red">※</font></span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">电子邮件：</td>
                                <td>
                                    <input class="text" type="text" id="TktEmail" name="TktEmail" value="<%=Server.HtmlEncode(Model.TktEmail) %>" />
                                    <span id="checkEmail"><font color="red">※</font></span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">公司名称：</td>
                                <td>
                                    <input class="text" type="text" id="TktComName" name="TktComName" value="<%=Server.HtmlEncode(Model.TktComName) %>" />
                                    <span id="checkComName"><font color="red">※</font></span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">国家：</td>
                                <td>
                                    <div style="float: left">
                                        <select id="selCountry" name="selCountry" onchange="CountryChange()" onkeyup='this.blur();this.focus();'
                                            style="height: 22px; width: 130px;">
                                            <option value="">请选择</option>
                                            <option value="86">中国</option>
                                            <% 
                                                List<FamousFurnitureExpo.Models.ZipTel> countryLi = FamousFurnitureExpo.Models.ZipTel.GetZtpCountry();
                                                foreach (FamousFurnitureExpo.Models.ZipTel zipTel in countryLi)
                                                {
                                            %>
                                                <option value="<%=zipTel.ZtpCountryCode %>"><%=zipTel.ZtpCountry %></option>
                                            <%        
                                                }
                                            %>
                                        </select>
                                    </div>
                                    <span id="checkCountry"><font color="red">※</font></span>
                                    <input type="hidden" id="TktCountry" name="TktCountry" value="<%=Server.HtmlEncode(Model.TktCountry) %>" />
                                </td>
                            </tr>
                            <tr>
                                <td align="right">电话：</td>
                                <td>
                                    <input id="tel0" type="text" class="text" style="width: 30px;" readonly="readonly"
                                        value="" name="tel0" onkeyup="value=value.replace(/[^\d]/g,'')" />-
                                    <input id="tel1" type="text" class="text" style="width: 30px;" maxlength="5"
                                        value="" name="tel1" onkeyup="value=value.replace(/[^\d]/g,'')" />-
                                    <input id="tel2" type="text" class="text" style="width: 80px;" maxlength="10"
                                        value="" name="tel2" onkeyup="value=value.replace(/[^\d]/g,'')" />-
                                    <input id="tel3" type="text" class="text" style="width: 30px;" maxlength="6"
                                        value="" name="tel3" onkeyup="value=value.replace(/[^\d]/g,'')" />
                                    <span id="checkTel"><font color="red">※</font></span>
                                    <input type="hidden" id="TktTel" name="TktTel" value="<%=Server.HtmlEncode(Model.TktTel) %>" />
                                </td>
                            </tr>
                            <tr>
                                <td align="right">邮编：</td>
                                <td>
                                    <input class="text" type="text" id="TktZipCode" name="TktZipCode" value="<%=Server.HtmlEncode(Model.TktZipCode) %>" />
                                    <span id="checkZipCode"><font color="red">※</font></span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">邮寄地址：</td>
                                <td>
                                    <input class="text" type="text" id="TktAddress" name="TktAddress" value="<%=Server.HtmlEncode(Model.TktAddress) %>" />
                                    <span id="checkAddress"><font color="red">※</font></span>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <table border="0" cellpadding="0" cellspacing="10">
                                        <tr>
                                            <td><div class="button" onclick="Save()">保存</div></td>
                                            <td><div class="button" onclick="Back()">返回</div></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="hidden" id="Type" name="Type" value="<%=ViewData["Type"] %>" />
                                    <input type="hidden" id="TktID" name="TktID" value="<%=Model.TktID %>" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            </form>
        </center>
    </div>
</asp:Content>
