﻿var a = 0;
function ShowDelegate(Id1, Id2, Id3, Id4, Id5) {
    document.getElementById(Id1).style.visibility = "hidden";
    document.getElementById(Id1).style.display = "none";
    document.getElementById(Id2).style.visibility = "hidden";
    document.getElementById(Id2).style.display = "none";
    document.getElementById(Id3).style.visibility = "visible";
    document.getElementById(Id3).style.display = "block";
    document.getElementById(Id4).style.visibility = "visible";
    document.getElementById(Id4).style.display = "block";
    document.getElementById(Id5).style.visibility = "visible";
    document.getElementById(Id5).style.display = "block";
}
function HidDelegate(Id1, Id2, Id3, Id4, Id5, ctl) {
    document.getElementById(Id1).style.visibility = "visible";
    document.getElementById(Id1).style.display = "block";
    document.getElementById(Id2).style.visibility = "visible";
    document.getElementById(Id2).style.display = "block";
    document.getElementById(Id3).style.visibility = "hidden";
    document.getElementById(Id3).style.display = "none";
    document.getElementById(Id4).style.visibility = "hidden";
    document.getElementById(Id4).style.display = "none";
    document.getElementById(Id5).style.visibility = "hidden";
    document.getElementById(Id5).style.display = "none";
    document.getElementById(ctl + "_txtName").value = "";
    document.getElementById(ctl + "_txtNameEn").value = "";
    document.getElementById(ctl + "_txtPosition").value = "";
    document.getElementById(ctl + "_txtDep").value = "";
    document.getElementById(ctl + "_txtTel").value = "";
    document.getElementById(ctl + "_txtTelPrefix").value = "";
    document.getElementById(ctl + "_txtTelMiddle").value = "";
    document.getElementById(ctl + "_txtFax").value = "";
    document.getElementById(ctl + "_txtFaxPrefix").value = "";
    document.getElementById(ctl + "_txtFaxMiddle").value = "";
    document.getElementById(ctl + "_txtMobile").value = "";
    document.getElementById(ctl + "_txtMobilePrefix").value = "";
    document.getElementById(ctl + "_txtEmail").value = "";
    $("#" + ctl + "_hidShow").val("");
    initCtlDefault(ctl);
}
String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function check(Id, Id2) {
    var txtBox = document.getElementById(Id);
    if (txtBox.value.Trim() == "") {
        document.getElementById(Id2).style.display = "block";
        document.getElementById(Id2).style.visibility = "visible";
    }
    else {
        document.getElementById(Id2).style.display = "none";
        document.getElementById(Id2).style.visibility = "hidden";
        if (txtBox.id.indexOf("email") != -1 || txtBox.id.indexOf("Email") != -1) {
            var patterns = new Object();
            patterns.email = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+$/;
            if (!patterns["email"].test(txtBox.value)) {
                document.getElementById(Id2).style.display = "block";
                document.getElementById(Id2).style.visibility = "visible";
                alert("Email格式不正确!");
                txtBox.value = "";
            }
            else {
                document.getElementById(Id2).style.display = "none";
                document.getElementById(Id2).style.visibility = "hidden";
            }
        }
    }
}
//btn reset
function clearAll() {
    var txts = document.getElementsByTagName("input");
    for (var i = 0; i < txts.length; i++) {
        if (txts[i].type == "text") {
            txts[i].value = "";
        }
        else if (txts[i].type == "checkbox" || txts[i].type == "radio") {
            txts[i].checked = false;
        }
    }
    var labels = document.getElementsByTagName("label");
    for (var i = 0; i < labels.length; i++) {
        if (labels[i].innerText.Trim() == "！") {
            labels[i].style.display = "none";
            labels[i].style.visibility = "hidden";
        }
    }
    initInput();
}
function showTxt(Id1, Id2) {
    var check = document.getElementById(Id1);
    var txt = document.getElementById(Id2);
    if (check.checked) {
        txt.style.display = "block";
        txt.style.visibility = "visible";
    }
    else {
        txt.style.display = "none";
        txt.style.visibility = "hidden";
    }
}







//****************************************************************************/
// add watermark to textbox  with attribute notnull value is true.
//*****************************************************************************/
var defaultVal = "请填写"; // Deault TextBox Value
var defaultColor = "Red"; // Default TextBox Color
var defaultSelectText = "请选择";

function initInput() {
    $("input[type=text]").each(function() {
        if ($(this).attr("notnull") == "true") {
            if ($.trim($(this).val()) == "") {
                $(this).val(defaultVal);
                $(this).css("color", defaultColor);
            }
        }
    });
}
function initCtlDefault(id) {
    $("input[type=text][notnull='true'][name^='" + id + "']").each(function() {

        if ($.trim($(this).val()) == "") {
            $(this).val(defaultVal);
            $(this).css("color", defaultColor);
        }

    });
}
function bindInputFocus() {
    $("input[type=text]").focus(function() {
        if ($(this).attr("notnull") == "true") {
            if ($.trim($(this).val()) == defaultVal) {
                $(this).val("");
            }
            $(this).css("color", "");
        }
    });
}
function bindInputBlur() {
    $("input[type=text]").blur(function() {
        if ($(this).attr("notnull") == "true") {
            if ($.trim($(this).val()) == "") {
                $(this).val(defaultVal);
                $(this).css("color", defaultColor);

            }
        }
    });
}

function validateCtl(id) {
    var isValid = true;
    var isEmailValid = true;
    var lastNullCtl = null;
    var lastNullEmailCtl = null;

    $("input[type=text][notnull='true'][name^='" + id + "']").each(function() {

        var id = $(this).attr("id") + "";

        if (id.indexOf("email") > 0 || id.indexOf("Email") > 0) {
            if (!isValidEmail($.trim($(this).val()))) {
                if (isEmailValid) {
                    lastNullEmailCtl = $(this);
                }
                isEmailValid = false;

            }
        }
        else {
            if ($.trim($(this).val()) == defaultVal || $.trim($(this).val()) == "") {
                if (isValid) {
                    lastNullCtl = $(this);
                }
                isValid = false;
            }
        }


    });
    if (!isEmailValid) {
        alert("邮件格式不正确！");
        lastNullEmailCtl.focus();
        return false;
    }
    if (!isValid) {
        alert("必填项不能为空！");
        lastNullCtl.focus();
        return false;
    }
    return true;

}
function isValidEmail(value) {
    var patterns = new Object();
    patterns.email = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+$/;
    if (!patterns["email"].test(value)) {
        return false;
    }
    return true;
}
function getText(selectId) {
    var txt = $("#" + selectId + " option:selected").text();
    if (txt == defaultSelectText);
    {
        txt = "";
    }
    return txt;
}

function IsChecked(id) {
    var isChecked = false;
    $("input[type=checkbox][name^='" + id + "']").each(function() {
      
    
            if ($(this).attr("checked") == true) {
                isChecked = true;

        }
    });
    return isChecked;
}

