﻿
function UserCheck() {
    //必填项的验证
    if (trim(document.getElementById("txtCorpName").value) == "") {
        window.alert("请输入公司名称！");
        SetFocus("txtCorpName");
        return false;
    }

    if (trim(document.getElementById("txtName").value) == "") {
        window.alert("请输入姓名！");
        SetFocus("txtName");
        return false;
    }

    if (trim(document.getElementById("txtMobile").value) == "") {
        window.alert("请输入移动电话！");
        SetFocus("txtMobile");
        return false;
    }

    if (trim(document.getElementById("txtEmail").value) == "") {
        window.alert("请输入E-mail！");
        SetFocus("txtEmail");
        return false;
    }

    if (trim(document.getElementById("txtIdCard").value) == "") {
        window.alert("请输入身份证！");
        SetFocus("txtIdCard");
        return false;
    }

    var patrn;

    //正则表达式的验证
    if (!ValideString("txtCorpPhone", /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/)) {
        window.alert("公司电话格式输入有误！");
        SetFocus("txtCorpPhone");

        return false;
    }

    if (!ValideString("txtFax", /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/)) {
        window.alert("传真格式输入有误！");
        SetFocus("txtFax");

        return false;
    }

    if (!ValideString("txtOfficePhone", /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/)) {
        window.alert("办公电话格式输入有误！");
        SetFocus("txtOfficePhone");

        return false;
    }

    if (!ValideString("txtMobile", /^[1][3,5][0-9]{9}$/)) {
        window.alert("移动电话格式输入有误！");
        SetFocus("txtMobile");

        return false;
    }

    if (!ValideString("txtEmail", /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
        window.alert("E-mail格式输入有误！");
        SetFocus("txtEmail");

        return false;
    }

    if (!ValideString("txtIdCard", /^(\d{15}|\d{18})$/)) {
        window.alert("身份证格式输入有误！");
        SetFocus("txtIdCard");

        return false;
    }

    return true;
}

function ValideString(id, patrn) {
    if (trim(document.getElementById(id).value) != "") {

        if (!patrn.exec(document.getElementById(id).value)) {
            return false;
        }
        else {
            return true;
        }
    }
    else {
        return true;
    }
}

function OpenSubmitPage() {
    if (UserCheck()) {
        var keyword = "~";
        var str = "1" + keyword;

        //公司名称
        var CorpName = document.getElementById("txtCorpName");
        //公司地址
        var CorpAddress = document.getElementById("txtCorpAddress");
        //公司电话
        var CorpPhone = document.getElementById("txtCorpPhone");
        //传真
        var Fax = document.getElementById("txtFax");

        //姓名
        var Name = document.getElementById("txtName");
        //职务
        var Duty = document.getElementById("txtDuty");
        //办公电话
        var OfficePhon = document.getElementById("txtOfficePhone");
        //移动电话
        var Mobile = document.getElementById("txtMobile");

        //E-mail
        var Email = document.getElementById("txtEmail");
        //身份证
        var IdCard = document.getElementById("txtIdCard");

        //提交按钮
        var Submit = document.getElementById("BtnSubmit");

        if (CorpName && CorpAddress && CorpPhone && Fax && Name && Duty && OfficePhon && Mobile && Email && IdCard && Submit) {
            str = str + trim(CorpName.value).replace(/~/g, "") + keyword;
            str = str + trim(CorpAddress.value).replace(/~/g, "") + keyword;
            str = str + trim(CorpPhone.value).replace(/~/g, "") + keyword;
            str = str + trim(Fax.value).replace(/~/g, "") + keyword;
            str = str + trim(Name.value).replace(/~/g, "") + keyword;

            str = str + trim(Duty.value).replace(/~/g, "") + keyword;
            str = str + trim(OfficePhon.value).replace(/~/g, "") + keyword;
            str = str + trim(Mobile.value).replace(/~/g, "") + keyword;
            str = str + trim(Email.value).replace(/~/g, "") + keyword;
            str = str + trim(IdCard.value).replace(/~/g, "");

            Submit.disabled = true;

            //alert(str);
            return str;
        }
        else {
            return "";
        }
    }
}

function OnCallbackSubmit(arg) {
    if (arg == null || arg == "") {
        return;
    }
    else {

        //提交按钮
        var Submit = document.getElementById("BtnSubmit");

        if (Submit) {
            if (arg == "0") {
                window.alert("提交失败，可能因为网络原因，请重新确认信息后点击提交！");
            }
            else if (arg == "1") {
                window.alert("提交成功！");

                //公司名称
                var CorpName = document.getElementById("txtCorpName");
                //公司地址
                var CorpAddress = document.getElementById("txtCorpAddress");
                //公司电话
                var CorpPhone = document.getElementById("txtCorpPhone");
                //传真
                var Fax = document.getElementById("txtFax");

                //姓名
                var Name = document.getElementById("txtName");
                //职务
                var Duty = document.getElementById("txtDuty");
                //办公电话
                var OfficePhon = document.getElementById("txtOfficePhone");
                //移动电话
                var Mobile = document.getElementById("txtMobile");

                //E-mail
                var Email = document.getElementById("txtEmail");
                //身份证
                var IdCard = document.getElementById("txtIdCard");

                if (CorpName && CorpAddress && CorpPhone && Fax && Name && Duty && OfficePhon && Mobile && Email && IdCard) {
                    CorpName.value = "";
                    CorpAddress.value = "";
                    CorpPhone.value = "";
                    Fax.value = "";
                    Name.value = "";
                    Duty.value = "";
                    OfficePhon.value = "";
                    Mobile.value = "";
                    Email.value = "";
                    IdCard.value = "";
                }
            }
            else {
                alert(arg);
            }

            Submit.disabled = false;
        }
    }
}
