/* Minification failed. Returning unminified contents.
(135,6): run-time error JS1004: Expected ';'
(157,18): run-time error JS1004: Expected ';'
(160,10): run-time error JS1004: Expected ';'
(163,6): run-time error JS1004: Expected ';'
(164,25): run-time error JS1004: Expected ';'
(167,6): run-time error JS1004: Expected ';'
(179,6): run-time error JS1004: Expected ';'
(182,14): run-time error JS1004: Expected ';'
(190,21): run-time error JS1004: Expected ';'
(196,6): run-time error JS1004: Expected ';'
(199,22): run-time error JS1004: Expected ';'
(243,6): run-time error JS1004: Expected ';'
(247,32): run-time error JS1004: Expected ';'
(261,6): run-time error JS1004: Expected ';'
(268,10): run-time error JS1004: Expected ';'
(270,10): run-time error JS1004: Expected ';'
 */
/* CHANGES:
    - Simplified the setTimeout statement, so it references the WebForm_ReDisableControls method directly instead of calling it in a js-string.
*/
var __disabledControlArray = new Array();
function WebForm_ReEnableControls() {
    if (typeof (__enabledControlArray) == 'undefined') {
        return false;
    }
    var disabledIndex = 0;
    for (var i = 0; i < __enabledControlArray.length; i++) {
        var c;
        if (__nonMSDOMBrowser) {
            c = document.getElementById(__enabledControlArray[i]);
        }
        else {
            c = document.all[__enabledControlArray[i]];
        }
        if ((typeof (c) != "undefined") && (c != null) && (c.disabled == true)) {
            c.disabled = false;
            __disabledControlArray[disabledIndex++] = c;
        }
    }
    setTimeout(WebForm_ReDisableControls, 0);
    return true;
};
/* CHANGES:
    - Replaced eval with a direct referal to the function in the window object
    - Added log to console if the evaluationfunction is a string and could not be found on the windows object.
 */
function ValidatorOnLoad() {
    if (typeof (Page_Validators) == "undefined")
        return;
    var i, val;
    for (i = 0; i < Page_Validators.length; i++) {
        val = Page_Validators[i];
        if (typeof (val.evaluationfunction) == "string") {
            val.evaluationfunction = window[val.evaluationfunction];
            if (typeof (val.evaluationfunction) !== "function") {
                if (window.console && window.console.log) {
                    window.console.log("WARNING (CSP Module): evaluationfunction was a string and was not evaluated (since that is not allowed by the CSP module), but it also not found on the windows object.  " +
                        "In the method ValidatorOnLoad() in WebUIValidationOverrides.js.");
                }
            }
        }
        if (typeof (val.isvalid) == "string") {
            if (val.isvalid == "False") {
                val.isvalid = false;
                Page_IsValid = false;
            }
            else {
                val.isvalid = true;
            }
        } else {
            val.isvalid = true;
        }
        if (typeof (val.enabled) == "string") {
            val.enabled = (val.enabled != "False");
        }
        if (typeof (val.controltovalidate) == "string") {
            ValidatorHookupControlID(val.controltovalidate, val);
        }
        if (typeof (val.controlhookup) == "string") {
            ValidatorHookupControlID(val.controlhookup, val);
        }
    }
    Page_ValidationActive = true;
}

/* CHANGES:
    - Replaced eval with a direct referal to the function in the window object
    - Added log to console if the evaluationfunction is a string and could not be found on the windows object.
*/
function CustomValidatorEvaluateIsValid(val) {
    var value = "";
    if (typeof (val.controltovalidate) == "string") {
        value = ValidatorGetValue(val.controltovalidate);
        if ((ValidatorTrim(value).length == 0) &&
            ((typeof (val.validateemptytext) != "string") || (val.validateemptytext != "true"))) {
            return true;
        }
    }
    var args = { Value: value, IsValid: true };
    if (typeof (val.clientvalidationfunction) == "string") {
        val.clientvalidationfunction = window[val.clientvalidationfunction];
        if (typeof (val.evaluationfunction) !== "function") {
            if (window.console && window.console.log) {
                window.console.log("WARNING (CSP Module): evaluationfunction was a string and was not evaluated (since that is not allowed by the CSP module), but it also not found on the windows object.  " +
                    "In the method CustomValidatorEvaluateIsValid() in WebUIValidationOverrides.js.");
            }
        }
        val.evaluationfunction(val, args);
    }
    return args.IsValid;
}


/* CHANGES:
    - Replaced the string function that stops propagation with a proper function. This makes sure the event is stopped when a single input field is validated. 
    This prevents the triggering of additional validators.    
*/
function ValidatorHookupControl(control, val) {
    if (typeof (control.tagName) != "string") {
        return;
    }
    if (control.tagName != "INPUT" && control.tagName != "TEXTAREA" && control.tagName != "SELECT") {
        var i;
        for (i = 0; i < control.childNodes.length; i++) {
            ValidatorHookupControl(control.childNodes[i], val);
        }
        return;
    }
    else {
        if (typeof (control.Validators) == "undefined") {
            control.Validators = new Array;
            var eventType;
            if (control.type == "radio") {
                eventType = "onclick";
            } else {
                eventType = "onchange";
                if (typeof (val.focusOnError) == "string" && val.focusOnError == "t") {
                    ValidatorHookupEvent(control, "onblur", "ValidatedControlOnBlur(event); ");
                }
            }
            ValidatorHookupEvent(control, eventType, "ValidatorOnChange(event); ");
            if (Page_TextTypes.test(control.type)) {
                ValidatorHookupEvent(control,
                    "onkeypress",
                    'ValidatedTextBoxOnKeyPressStopPropagation()');
            }
        }
        control.Validators[control.Validators.length] = val;
    }
}

async function ValidatorOnChange(event) {
    event = event || window.event;
    Page_InvalidControlToBeFocused = null;
    var targetedControl;
    if ((typeof (event.srcElement) != "undefined") && (event.srcElement != null)) {
        targetedControl = event.srcElement;
    }
    else {
        targetedControl = event.target;
    }
    var vals;
    if (typeof (targetedControl.Validators) != "undefined") {
        vals = targetedControl.Validators;
    }
    else {
        if (targetedControl.tagName.toLowerCase() == "label") {
            targetedControl = document.getElementById(targetedControl.htmlFor);
            vals = targetedControl.Validators;
        }
    }
    if (vals) {
        for (var i = 0; i < vals.length; i++) {
            await ValidatorValidate(vals[i], null, event);
        }
    }
    await ValidatorUpdateIsValid();
}

async function  ValidatorUpdateIsValid() {
    Page_IsValid = await AllValidatorsValid(Page_Validators);
}

async function AllValidatorsValid(validators) {
    if ((typeof (validators) != "undefined") && (validators != null)) {
        var i;
        for (i = 0; i < validators.length; i++) {
            if (!validators[i].isvalid) {
                return false;
            }
        }
    }
    return true;
}

async function ValidatedTextBoxOnKeyPress(event) {
    event = event || window.event;
    if (event.keyCode == 13) {
        await ValidatorOnChange(event);
        var vals;
        if ((typeof (event.srcElement) != "undefined") && (event.srcElement != null)) {
            vals = event.srcElement.Validators;
        }
        else {
            vals = event.target.Validators;
        }
        return await AllValidatorsValid(vals);
    }
    return true;
}


async function ValidatedTextBoxOnKeyPressStopPropagation(event) {

    event = event || window.event;
    var valid = await ValidatedTextBoxOnKeyPress(event);
    if (!valid)
    {
        event.cancelBubble = true;
        if (event.preventDefault)
        {
            event.preventDefault();
            event.stopPropagation();
            return false;
        }
    }
}

/* CHANGES:
    - Replaced new Function with addEventListener, which supports adding more than 1 handler to the same event. This way, we don't need 'new Function'
*/
function ValidatorHookupEvent(control, eventType, functionPrefix) {
    var funcName = functionPrefix.split('(')[0];
    var event = eventType.split('on')[1];
    control.addEventListener(event, window[funcName]);  
}

/* CHANGES:
    - Replaced eval with a direct referal to the function in the window object
*/
function CustomValidatorEvaluateIsValid(val) {
    var value = "";
    if (typeof (val.controltovalidate) == "string") {
        value = ValidatorGetValue(val.controltovalidate);
        if ((ValidatorTrim(value).length == 0) &&
            ((typeof (val.validateemptytext) != "string") || (val.validateemptytext != "true"))) {
            return true;
        }
    }
    var args = { Value: value, IsValid: true };
    if (typeof (val.clientvalidationfunction) == "string") {
        window[val.clientvalidationfunction](val, args);
    }
    return args.IsValid;
}

/* CHANGES:
    - Added Async/Await to combine with the FileReader on UploadControl
*/
async function ValidatorValidate(val, validationGroup, event) {
    val.isvalid = true;
    if ((typeof (val.enabled) == "undefined" || val.enabled != false) && IsValidationGroupMatch(val, validationGroup)) {
        if (typeof (val.evaluationfunction) == "function") {
            val.isvalid = await val.evaluationfunction(val);
            if (!val.isvalid && Page_InvalidControlToBeFocused == null &&
                typeof (val.focusOnError) == "string" && val.focusOnError == "t") {
                ValidatorSetFocus(val, event);
            }
        }
    }
    ValidatorUpdateDisplay(val);
}

/* CHANGES:
    - Added Async/Await to await the validatorValidate function which sets the isvalid property of page_validators,
    to get the right page_isvalid value (which is determined by the page_validators isvalid property). 
*/
async function Page_ClientValidate(validationGroup) {
    Page_InvalidControlToBeFocused = null;
    if (typeof (Page_Validators) == "undefined") {
        return true;
    }
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
    await ValidatorValidate(Page_Validators[i], validationGroup, null);
    }
    await ValidatorUpdateIsValid();
    ValidationSummaryOnSubmit(validationGroup);
    Page_BlockSubmit = !Page_IsValid;
    return Page_IsValid;
};
/*
 - CHANGES: replaced eval with direct referal
*/
function Menu_GetData(item) {
    if (!item.data) {
        var a = (item.tagName.toLowerCase() == "a" ? item : WebForm_GetElementByTagName(item, "a"));
        var menu = Menu_FindMenu(a);
        try {            
            item.data = window[menu.id + "_Data"];
        }
        catch (e) { }
    }
    return item.data;
};
