﻿function checkKeepInTouchChange(sender, args) {

    var countValidated = 0;
    var countErrorMail = 0;
    var ImgargsValid = "Valid";
    var ImgargsError = "Error";
    var TooltipargsMsg = "ctl00_MasterBottomKeepInTouchContent_ToolTipErrorList";
    var TooltipDelay = 15000;

    var txbMail = document.getElementById("ctl00_MasterBottomKeepInTouchContent_txbMail").value;
    txbMail = txbMail.replace(/^\s+|\s+$/g, '');
    document.getElementById("ctl00_MasterBottomKeepInTouchContent_ErrorMail").style.display = 'none';
    toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmailInvalid", "none");
    toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMailInvalid", "none");
    toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmail", "none");
    toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMail", "none");
    if (txbMail != "") {
        if (!txbMail.match(regExpEmail)) {
            countValidated++;
            if (args != "fu") {
                document.getElementById("ctl00_MasterBottomKeepInTouchContent_ErrorMail").style.display = 'block';
                toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmailInvalid", "block");
                toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMailInvalid", "block");
                toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmail", "none");
                toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMail", "none");
                countErrorMail++;
            }
        }
        else if (txbMail.match(regExpEmail)) {
            document.getElementById("ctl00_MasterBottomKeepInTouchContent_ErrorMail").style.display = 'none';
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmailInvalid", "none");
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMailInvalid", "none");
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmail", "none");
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMail", "none");
        }
    }
    else {
        countValidated++;
        document.getElementById("ctl00_MasterBottomKeepInTouchContent_ErrorMail").style.display = 'block';
        toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmailInvalid", "none");
        toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMailInvalid", "none");
        toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmail", "block");
        toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMail", "block");
    }
    if (countErrorMail > 0) {
        countValidated++;
        if (args != "fu") {
            document.getElementById("ctl00_MasterBottomKeepInTouchContent_ErrorMail").style.display = 'block';
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmailInvalid", "block");
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMailInvalid", "block");
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorOverMsgEmail", "none");
            toggleVisibility("ctl00_MasterBottomKeepInTouchContent_ErrorMsgMail", "none");
        }
    }
    if (countValidated == 0) {
        HideCurrentTooltip();
        if (args != "fu" && args != "bt") {
            args.IsValid = true;
        }
        else {
            return countValidated;
        }
    }
    else if (countValidated > 0) {
        if (countValidated > 5) {
            TooltipDelay = 9000;
        }
        if (countValidated > 10) {
            TooltipDelay = 15000;
        }
        if (countValidated > 15) {
            TooltipDelay = 20000;
        }
        if (args != "fu") {
            var TooltipElement = $find("ctl00_MasterBottomKeepInTouchContent_ToolTipErrorList");
            if (!TooltipElement.isVisible()) {
                showToolTip(TooltipargsMsg, TooltipDelay);
            }
        }
        if (args != "fu" && args != "bt") {
            args.IsValid = false;
            
        }
        else {
            return countValidated;
        }
    }
}
function checkKeepInTouchInputChange() {
    var counterror = checkKeepInTouchChange("fu", "fu");
    if (counterror == 0) {
        var TooltipElement = $find("ctl00_MasterBottomKeepInTouchContent_ToolTipErrorList");
        HideCurrentTooltip();
    }
}