﻿var arrTopMenu = new Array();
if (document.images) { //Preload images
    var prePath = "/DBTmo2.0/Media/Menu_";
    arrTopMenu[0] = new Object(); arrTopMenu[0].src = prePath + "Home_D.png";
    arrTopMenu[1] = new Object(); arrTopMenu[1].src = prePath + "Home_H.png";
    arrTopMenu[2] = new Object(); arrTopMenu[2].src = prePath + "FAQs_D.png";
    arrTopMenu[3] = new Object(); arrTopMenu[3].src = prePath + "FAQs_H.png";
    arrTopMenu[4] = new Object(); arrTopMenu[4].src = prePath + "Support_D.png";
    arrTopMenu[5] = new Object(); arrTopMenu[5].src = prePath + "Support_H.png";
    arrTopMenu[6] = new Object(); arrTopMenu[6].src = prePath + "SignIn_D.png";
    arrTopMenu[7] = new Object(); arrTopMenu[7].src = prePath + "SignIn_H.png";
    arrTopMenu[8] = new Object(); arrTopMenu[8].src = prePath + "SignOut_D.png";
    arrTopMenu[9] = new Object(); arrTopMenu[9].src = prePath + "SignOut_H.png";
}
function OnTopMenu(id, idx) { if (document.images) document.images[id].src = arrTopMenu[idx].src; }
function OnLeftMenuClick(url) { if (url != undefined) document.location.href = url; }

function GetClientId(controlId, useOnlyStandardObject) {
    return $("*[id$='" + controlId + "']").get(0);
}

//function GetClientId(controlId, useOnlyStandardObject) {
//    /// <summary>object GetClientId(controlId, useRadObject) to obtain control object.</summary>
//    /// <param name="controlId">control ID of the </param>
//    /// <param name="useOnlyStandardObject">true if use only standard object; otherwise false (default value is false)</param>
//    /// <return>control object</param>
//    var body = document.getElementsByTagName("body");
//    var id = body[0].attributes["controlPrefix"];

//    if (useOnlyStandardObject == undefined || useOnlyStandardObject == null) useOnlyStandardObject = false;

//    var clientObject = null;
//    var lastIndex = id.value.lastIndexOf("_");
//    var postfix = ((lastIndex >= 0) ? postfix = id.value.substring(lastIndex, id.value.length) : "");
//    var numOfMasters = (id.value.replace(new RegExp(postfix, "g"), "")).split("_");
//    var prefix = id.value;
    
//    for (index = 0; index <= numOfMasters.length; index++) {

//        clientId = prefix + "_" + controlId;
//        // telerik
//        if (!useOnlyStandardObject) {
//            if (clientObject == null) clientObject = $find(clientId);
//            if (clientObject != null) clientObject.id = clientId;
//        }
//        // server control
//        if (clientObject == null) clientObject = document.getElementById(clientId);

//        // html control
//        if (clientObject == null) clientObject = document.getElementById(controlId);

//        if (clientObject != null) break;

//        prefix = prefix.substring(0, prefix.lastIndexOf(postfix));        
//    }
//    return clientObject;
//}

function SetScrollBar(controlId, offsetX, offsetY) {
    /// <summary>SetScrollBar(controlId, offsetX, offsetY) sets scroll position of target control object.</summary>
    /// <param name="controlId">control ID of the target</param>
    /// <param name="offsetX">offsetX of scroll position</param>
    /// <param name="offsetY">offsetY of scroll position</param>
    var node = GetClientId(controlId);
    if (node == null || node == undefined) return;
    var scrollLeft = node.offsetLeft;
    var scrollTop = node.offsetTop
    while (node) {
        scrollTop = scrollTop + node.offsetTop;
        node = node.offsetParent;
    }
    window.scrollTo(scrollLeft + offsetX, scrollTop + offsetY);
}

function SetFocus(focusedControlId) {
    /// <summary>SetFocus(focusedControlId) sets focus of target control object.</summary>
    /// <param name="focusedControlId">control ID of the target</param>
    var control = GetClientId(focusedControlId, true);
    try {
        control.focus();
        control.select();
    } catch (e) { }
}

function ShowAlert() {
    var message = "<span class='text_02'>Please provide information for the missing REQUIRED fields. You can navigate to other links after completing the mandatory information.</span>";

    radalert(message, 470, 150, 'Required Information Missing');

    return false;
}

// Namespace
var Dbtmo = window.Dbtmo || {};
// Singleton
Dbtmo.Validation = function () {
    //----------------------
    // Private Interface
    //----------------------
    // Message Template
    var MSG_001 = "Please enter {0}.";
    var MSG_002 = "Invalid {0}.";
    var MSG_003 = "Angle brackets (< >) are not allowed.";
    var MSG_004 = "Please select {0}.";
    var MSG_005 = "Please enter valid {0}. Use alphabets and (<span class='text_maroon'> -', space</span>) only.";
    var MSG_006 = "{0}";
    var MSG_007 = "{0} does not match";
    var MSG_008 = "{0} should contain at least {1} characters.";
    var MSG_009 = "{0} should contain alphabets and numbers only.";
    var MSG_010 = "File extension is invalid.";
    var MSG_011 = "{0} should contain at most {1} characters.";
    var MSG_012 = "{0} must be different.";
    var focusedControlId = "";
    // Common validation
    function IsAlphaNumeric(value) { var pattern = /^([a-z]|[A-Z]|[0-9])+$/; return (value != "" && value.match(pattern) == null) ? false : true; }
    function IsAlphaSpecial(value) { /* accept [-] [,] [']*/var pattern = /^([a-z]|[A-Z])+([a-z]|[A-Z]|\-|\,|['']|\ )*$/; return (value != "" && value.match(pattern) == null) ? false : true; }
    function IsAngleBracket(value) { return (value.indexOf('<') > -1 || value.indexOf('>') > -1) ? true : false; }
    function IsAllowedFileExtensions(value1, value2) { var extensionfile = value1.split("."); var extensionAccepted = value2.split(":"); var i = 0; for (i = 0; i < extensionAccepted.length; i++) { if (("." + extensionfile[extensionfile.length - 1]).toLowerCase() == extensionAccepted[i].toLowerCase()) return true; } return false; }
    function IsEmail(value) { var pattern = /^([a-zA-Z0-9''_]+)([a-zA-Z0-9''_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; return (value != "" && value.match(pattern) == null) ? false : true; }
    function IsEmpty(value) { return (value == ""); }
    function IsEqual(value1, value2) { return (value1 == value2); }
    function IsLengthMin(value, length) { return (value.length >= length); }
    function IsLengthMax(value, length) { return !(value.length <= length); }
    function IsGreater(value1, value2) { return (value1 > value2); }
    function IsNumeric(value) { var pattern = /^([0-9])+$/; return (value != "" && value.match(pattern) == null) ? false : true; }
    function IsPhone(value) { var pattern = /^\d{3}-\d{3}-\d{4}$/; return (value != "" && value.match(pattern) == null) ? false : true; }
    function IsSelected(value) { return (value > 0) ? true : false; }
    function IsSelectedRad(value) { return (value >= 0) ? true : false; } // this is used for only rad combobox
    function IsZipcode(value) { var pattern = /^(\d{5}|\d{5}-\d{4})$/; return (value != "" && value.match(pattern) == null) ? false : true; }
    function IsListChecked(value) { for (var j = 0; j < value.rows.length; j++) { for (var i = 0; i < value.rows[j].cells.length; i++) { if (value.rows[j].cells[i].firstChild != null && value.rows[j].cells[i].firstChild.checked) return true; } } return false; }

    // Utility Method
    function Trim(value) { return value.replace(/^\s*(\b.*\b|)\s*$/, "$1"); }
    function SetMessage(targetControl, focusedControl, errMsgControl, messageId, errMsgParam, errMsgAppend) {
        var errMsgControl = document.getElementById(errMsgControl.id);
        var parameters = errMsgParam.split(":");
        var message = messageId;
        for (i = 0; i < parameters.length; i++) message = message.replace("{" + i + "}", parameters[i]);
                
        errMsgControl.className = "bi bi-x-circle-fill error";
        errMsgControl.innerHTML = (errMsgAppend != undefined || errMsgAppend) ? (errMsgControl.innerHTML + message + "<br/>") : message + "<br/>";
        SetTargetControlStyle(targetControl.id);
        if (focusedControlId == "") focusedControlId = focusedControl.id;
    }
    function InitControls(targetControlId, errMsgControlId, errMsgAppend) {
        var targetControl = GetClientId(targetControlId, true);
        var errMsgControl = GetClientId(errMsgControlId);
        if (!errMsgAppend) errMsgControl.innerHTML = "";
        errMsgControl.className = errMsgControl.className.replace("bi bi-x-circle-fill error", "");
        targetControl.className = targetControl.className.replace(" border_04", "");
    }
    function SetTargetControlStyle(targetControlId) {
        var targetControl = GetClientId(targetControlId);
        targetControl.className = targetControl.className + " border_04";
    }
    //----------------------
    // Public Interface
    //----------------------
    return {
        RemoveError: function (targetControlId, errMsgControlId) {
            InitControls(targetControlId, errMsgControlId, false);
        },

        SetFocus: function () {
            /// <summary>boolean SetFocus() to set first error control.</summary>
            if (focusedControlId != "") {
                var control = GetClientId(focusedControlId, true);
                try {
                    SetScrollBar(focusedControlId, 0, -40);
                    control.focus();
                    control.select();
                } catch (e) { }
                focusedControlId = "";
            }
        },

        // Wrapper - Specific validation check
        CheckCaptcha: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckCaptchatargetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with alphabets or numbers.</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (!IsAlphaNumeric(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_002, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckDateRad: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckDateRad(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if date is selected (if mandatory is true).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId + "_wrapper", errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(GetClientId(targetControl.id + "_wrapper"), GetClientId(targetControl.id), errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckDateCompare: function (targetControl1Id, targetControl2Id, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckEqual(ttargetControl1Id, targetControl2Id, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) and if two fields are matched.</summary>
            /// <param name="targetControl1Id">Id of 1st target control to validate</param>
            /// <param name="targetControl2Id">Id of 2nd target control to validate</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControl1Id, errMsgControlId, errMsgAppend);
            InitControls(targetControl2Id, errMsgControlId, errMsgAppend);
            var targetControl1 = GetClientId(targetControl1Id);
            var targetControl2 = GetClientId(targetControl2Id);
            var errMsgControl = GetClientId(errMsgControlId);
            if (!IsGreater(targetControl2.value, targetControl1.value)) {
                SetMessage(targetControl1, GetClientId(targetControl1.id + "_Input"), errMsgControl, MSG_006, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckDefault: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckDefault(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) without any angle bracket.</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (IsAngleBracket(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_003, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckDefaultWithMaxLength: function (targetControlId, mandatory, maxlength, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckDefault(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) without any angle bracket.</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (IsAngleBracket(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_003, errMsgParam, errMsgAppend); return false;
            }
            if (IsLengthMax(Trim(targetControl.value), maxlength)) {
                errMsgParam = errMsgParam + ":" + maxlength;
                SetMessage(targetControl, targetControl, errMsgControl, MSG_011, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckDefaultRad: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckDefault(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) without any angle bracket.</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl._text))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (IsAngleBracket(Trim(targetControl._text))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_003, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckDropDownList: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckDropDownList(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if item is selected (if mandatory is true).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && !IsSelected(targetControl.selectedIndex)) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_004, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckDropDownListRad: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckDropDownList(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if item is selected (if mandatory is true).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            //var value = "";
            //try { value = targetControl.get_selectedItem().get_value(); } catch (e) { }
            //if (value == "") value = -1;
            //if (mandatory && !IsSelectedRad(value)) {
            //    SetMessage(targetControl, GetClientId(targetControl.id + "_Input"), errMsgControl, MSG_004, errMsgParam, errMsgAppend); return false;
            //}
            var value = "";
            try { value = targetControl.get_selectedItem().get_value(); } catch (e) {
                try {
                    value = targetControl.control.get_selectedItem().get_value();
                } catch (e) { }
            }
            if (value == "") value = -1;
            if (!isNaN(value) && mandatory && !IsSelectedRad(value)) {
                SetMessage(targetControl, GetClientId(targetControl.id + "_Input"), errMsgControl, MSG_004, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckEmail: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckEmail(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with a correct email format.</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (!IsEmail(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_002, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckNotEqual: function (targetControl1Id, targetControl2Id, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckEqual(ttargetControl1Id, targetControl2Id, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) and if two fields are matched.</summary>
            /// <param name="targetControl1Id">Id of 1st target control to validate</param>
            /// <param name="targetControl2Id">Id of 2nd target control to validate</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControl1Id, errMsgControlId, errMsgAppend);
            InitControls(targetControl2Id, errMsgControlId, errMsgAppend);
            var targetControl1 = GetClientId(targetControl1Id);
            var targetControl2 = GetClientId(targetControl2Id);
            var errMsgControl = GetClientId(errMsgControlId);
            if (!IsEqual(Trim(targetControl1.value), Trim(targetControl2.value))) {
                SetMessage(targetControl1, targetControl1, errMsgControl, MSG_007, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckEqual: function (targetControl1Id, targetControl2Id, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckEqual(ttargetControl1Id, targetControl2Id, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) and if two fields are matched.</summary>
            /// <param name="targetControl1Id">Id of 1st target control to validate</param>
            /// <param name="targetControl2Id">Id of 2nd target control to validate</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControl1Id, errMsgControlId, errMsgAppend);
            InitControls(targetControl2Id, errMsgControlId, errMsgAppend);
            var targetControl1 = GetClientId(targetControl1Id);
            var targetControl2 = GetClientId(targetControl2Id);
            var errMsgControl = GetClientId(errMsgControlId);
            if (IsEqual(Trim(targetControl1.value), Trim(targetControl2.value))) {
                SetMessage(targetControl1, targetControl1, errMsgControl, MSG_012, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckListAndOther: function (targetControl1Id, targetControl2Id, errMsgControl1Id, errMsgControl2Id, errMsgParam1, errMsgParam2, errMsgAppend1, errMsgAppend2) {
            /// <summary>boolean CheckRadio(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if radio is selcted (if mandatory is true).</summary>
            /// <param name="targetControl1Id">Id of target control 1 to validate (list control)</param>
            /// <param name="targetControl2Id">Id of target control 2 to validate (textbox)</param>
            /// <param name="errMsgControl1Id">Id of control 1 to set error message</param>
            /// <param name="errMsgControl2Id">Id of control 2 to set error message</param>
            /// <param name="errMsgParam1">parameterts for error message 1. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgParam2">parameterts for error message 2. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend1">true if message 1 is appended; otherwise false</param>
            /// <param name="errMsgAppend2">true if message 2 is appended; otherwise false</param>
            InitControls(targetControl1Id, errMsgControl1Id, errMsgAppend1);
            InitControls(targetControl2Id, errMsgControl2Id, errMsgAppend2);
            var targetControl1 = GetClientId(targetControl1Id);
            var targetControl2 = GetClientId(targetControl2Id);
            var errMsgControl1 = GetClientId(errMsgControl1Id);
            var errMsgControl2 = GetClientId(errMsgControl2Id);

//            var resultList = this.CheckRadio(targetControl1Id, false, errMsgControl1Id, errMsgParam1);
//            var resultTextBoxRequiredYes = this.CheckDefault(targetControl2Id, true, errMsgControl2Id, errMsgParam2);
//            var resultTextBoxRequiredNo = this.CheckDefault(targetControl2Id, false, errMsgControl2Id, errMsgParam2);

//            if (resultList && resultTextBoxRequiredYes) {
//                // Case 1: one of the list is selected (checked), and textbox entry is empty or valid
//                this.RemoveError(targetControl1Id, errMsgControl1Id);
//                return true;
//            }
//            else if (!resultList && (resultTextBoxRequiredYes || !resultTextBoxRequiredNo)) {
//                // Case 2: none of the list is selected (checked), and textbox entry is not empty and invalid
//                this.RemoveError(targetControl1Id, errMsgControl1Id);
//                return true;
//            }
//            else if (!resultList && !resultTextBoxRequiredYes) {
//                // Case 3: none of the list is selected (checked), and textbox entry is empty
//                return false;
//            }
//            else {
//                return true;
            //            }

            //Case 1: A item in the list is selected 
            if (IsListChecked(targetControl1)) {
                //Case 1.1: textbox contains angle brackets
                if (IsAngleBracket(Trim(targetControl2.value))) {
                    SetMessage(targetControl2, targetControl2, errMsgControl2, MSG_003, errMsgParam2, errMsgAppend2); return false;
                }
                //Case 1.2: textbox does not contains angle brackets
                else {
                    return true;
                }
            }
            //Case 2: A item in the list is not selected
            else {
                //Case 2.1: textbox is empty
                if (IsEmpty(Trim(targetControl2.value))) {
                    SetMessage(targetControl1, targetControl1, errMsgControl1, MSG_001, errMsgParam1, errMsgAppend1); return false;
                }
                //Case 2.2: textbox contains angle brackets
                else if (IsAngleBracket(Trim(targetControl2.value))) {
                    SetMessage(targetControl2, targetControl2, errMsgControl2, MSG_003, errMsgParam2, errMsgAppend2); return false;
                }
                //Case2.3: textbox contains valid information
                return true;
            }
        },

        CheckName: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckName(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with alphabets and accecpted special chars ([-] [,] [']).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (!IsAlphaSpecial(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_005, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckNonNegativeNumeric: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckName(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with alphabets and accecpted special chars ([-] [,] [']).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (!IsNumeric(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_002, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckNewPassword: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckName(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with alphabets, numbers and minimum length 4.</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (!IsAlphaNumeric(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_009, errMsgParam, errMsgAppend); return false;
            }
            if (!IsLengthMin(Trim(targetControl.value), 4)) {
                errMsgParam = errMsgParam + ":4";
                SetMessage(targetControl, targetControl, errMsgControl, MSG_008, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckPhone: function (targetControl1Id, targetControl2Id, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckPhone(targetControl1Id, targetControl2Id, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with a correct phone format (optioanl extension number).</summary>
            /// <param name="targetControl1Id">Id of target control to validate</param>
            /// <param name="targetControl2Id">Id of target control (extension number) to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControl1Id, errMsgControlId, errMsgAppend);
            InitControls(targetControl2Id, errMsgControlId, errMsgAppend);
            var targetControl1 = GetClientId(targetControl1Id);
            var targetControl2 = GetClientId(targetControl2Id);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl1.value))) {
                SetMessage(targetControl1, targetControl1, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (IsEmpty(Trim(targetControl1.value)) && !IsEmpty(Trim(targetControl2.value))) {
                SetMessage(targetControl1, targetControl1, errMsgControl, MSG_002, errMsgParam, errMsgAppend); return false;
            }
            if (!IsPhone(Trim(targetControl1.value))) {
                SetMessage(targetControl1, targetControl1, errMsgControl, MSG_002, errMsgParam, errMsgAppend); return false;
            }
            if (!IsEmpty(Trim(targetControl2.value)) && !IsNumeric(Trim(targetControl2.value))) {
                SetMessage(targetControl2, targetControl2, errMsgControl, MSG_002, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckRadio: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckRadio(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if radio is selcted (if mandatory is true).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && !IsListChecked(targetControl)) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_004, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckRadioListRad: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckRadioListRad(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if radio is selcted (if mandatory is true).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);

            if (targetControl != undefined) {
                if (mandatory && targetControl.control._selectedIndex <0) {
                    SetMessage(targetControl, targetControl, errMsgControl, MSG_004, errMsgParam, errMsgAppend); return false;
                }
            }
            return true;
        },

        CheckUploadRad: function (targetControlId, mandatory, errMsgControlId, allowedFileExtensions, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckUploadRad(targetControlId, mandatory, errMsgControlId, allowedFileExtensionserrM, sgParam, errMsgAppend) checks if item is selected (if mandatory is true).</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            debugger;
            if (mandatory && IsEmpty(targetControl.control.getFileInputs()[0].value)) {
                SetMessage(targetControl, GetClientId(targetControl.id + "ListContainer"), errMsgControl, MSG_004, errMsgParam, errMsgAppend); return false;
            }
            if (!IsAllowedFileExtensions(targetControl.control.getFileInputs()[0].value, allowedFileExtensions)) {
                SetMessage(targetControl, GetClientId(targetControl.id + "ListContainer"), errMsgControl, MSG_010, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckUsername: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckName(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with alphabets</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (IsAngleBracket(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_003, errMsgParam, errMsgAppend); return false;
            }
            if (!IsAlphaNumeric(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_009, errMsgParam, errMsgAppend); return false;
            }
            return true;
        },

        CheckZip: function (targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) {
            /// <summary>boolean CheckZip(targetControlId, mandatory, errMsgControlId, errMsgParam, errMsgAppend) checks if field is entered (if mandatory is true) with a correct zip format.</summary>
            /// <param name="targetControlId">Id of target control to validate</param>
            /// <param name="mandatory">true if mandatory; otherwise false</param>
            /// <param name="errMsgControlId">Id of control to set error message</param>
            /// <param name="errMsgParam">parameterts for error message. (use separator [:] for multiple parameters) e.g., "Message", "Message1:Message2"</param>
            /// <param name="errMsgAppend">true if message is appended; otherwise false</param>
            InitControls(targetControlId, errMsgControlId, errMsgAppend);
            var targetControl = GetClientId(targetControlId);
            var errMsgControl = GetClientId(errMsgControlId);
            if (mandatory && IsEmpty(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_001, errMsgParam, errMsgAppend); return false;
            }
            if (!IsZipcode(Trim(targetControl.value))) {
                SetMessage(targetControl, targetControl, errMsgControl, MSG_002, errMsgParam, errMsgAppend); return false;
            }
            return true;
        }
    }
} ();

//---------------------------------------------------------------
// The following code are "AJAX" error handling (Include connection handling)
// TODO: [MT - 03/15/10] The following error handling is done by Aki
//---------------------------------------------------------------

function EndRequestHandler(sender, args) {
    if (args.get_error() != undefined) {
        var message = args.get_error().message;
        var code = String(args.get_error().httpStatusCode);
        // ErroCode: http://support.microsoft.com/kb/193625
        var pattern = /^(([0])|([1][2][0][0-2][0-9])|([1][2][0][3][0|1|2|3|4|6|7|8|9])|([1][2][0][4][0-3])|([1][2][1][1][0-1])|([1][2][1][3][0-8])|([1][2][1][5][0-6]))$/;

        if (code != "" && code.match(pattern) != null) {
            alert("Internet Connection is not available. Please check your connection.");
            args.set_errorHandled(true);
        }
        else {
            // onerror is called
        }
    }
}

window.onerror = function(message, url, line) {

    try {
        //[JS - 01/25/24] This error message can be safely ignored. Issue with Chromium
        if (message.toLowerCase().search("resizeobserver") >= 0) {
            return false;
        }
    }
    catch (e) {
    }

    var param = "";

    var errorAjax = false;

    try {
        var errorLog = message.split(":");

        if (errorLog != null && errorLog.length > 0) {

            for (i = 0; i < errorLog.length; i++) {

                if (errorLog[i].indexOf("errorLogId") >= 0) {

                    var parts = errorLog[i].split("=");

                    param = "?errorLogId=" + parts[1];
                }
                else if (errorLog[i].indexOf("errorAjax") >= 0) {

                    errorAjax = true;
                }
            }
        }
    }
    catch (e) { }

    // client script error
    if (!errorAjax) {
        param = "?errorClientScript=[" + message.replace("<", "#") + "]:url[" + url + "]:line[" + line + "]";
    }

    param = param + ((param == "") ? "?" : "&") + "master=" + GetClientId("uxInputImmediateMasterPage").value;

    window.location.href = "/DBTmo2.0/Error.aspx" + param;

    return true;
}
//---------------------------------------------------------------
// The following code are "Connectivity" error handling
// TODO: [MT - 03/15/10] The following error handling is done by Aki
//---------------------------------------------------------------

// Register onClick event handler for IE and FF
if (window.captureEvents) {
    window.captureEvents(Event.CLICK);
    window.onclick = OnClickHandler;
}
else {
    document.onclick = OnClickHandler;
}

// Checks connectivity for clicked controls
function OnClickHandler(e) {
    var el = (typeof event !== 'undefined') ? event.srcElement : e.target
    var type = "";
    var control = el;
    var result = true;
    
    while (control) {
        // this checks connectivity for controls
        if (control.nodeName.toLowerCase() == "input" && control.getAttribute("type").toLowerCase() == "submit" && !IsConnected()) {
            result = false;
        }
        else if (control.nodeName.toLowerCase() == "input" && control.getAttribute("type").toLowerCase() == "button" && !IsConnected()) {
            result = false; 
        }
        else if (control.nodeName.toLowerCase() == "select" && !IsConnected()) {
            result = false; 
        }
        else if (control.nodeName.toLowerCase() == "a" && !IsConnected()) {
            result = false; 
        }

        if (!result) {
            alert("Internet Connection is not available. Please check your connection.");
            return false; 
        }
        
        control = control.parentNode;
    }

    fixTelerikControlScroll();
}

// Checks connectivity using XMLHttpRequest or navigator.onLine property
var resultAfterXmlHttpRequest = false;
var xmlhttp
function IsConnected() {
    xmlhttp = null;
    try {
        if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
            var ffversion = new Number(RegExp.$1)
            if (ffversion >= 3) {
                return navigator.onLine;
            }
        }
        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    } catch (e) {
        //For IE it comes here.
        //alert("Permission UniversalBrowserRead denied.");
    }
    // code for IE
    if (window.ActiveXObject) {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
            var ieversion = new Number(RegExp.$1)
            if (ieversion >= 8) {
                return navigator.onLine;
            }
        }
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    // code for Mozilla, etc.
    else if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }

    try {
        if (xmlhttp != null) {
            xmlhttp.onreadystatechange = state_Change;
            // the request should be handled synchronously
            // use any image to test 
            xmlhttp.open("GET", "/DBTmo2.0/Media/Button_AddApplicants_D.png?timestamp=" + new Date().getTime(), false); 
            xmlhttp.send(null);
            return resultAfterXmlHttpRequest;
        }
        else {
            //browser does not support XMLHTTP
            return false;
        }
    }
    catch (e) {
        return false;
    }
    return connectionResult;
}

function state_Change() {
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState == 4) {
        try {
            // check if there is a problem retrieving XML data
            resultAfterXmlHttpRequest = (xmlhttp.status == 200);
        } catch (err) {
            //Internet is NOT Connected.
            resultAfterXmlHttpRequest = false;
        }
    }
}

function radConfirmLocalization(ok, cancel) {
    Telerik.Web.UI.RadWindowUtils.Localization = {
        "OK": (ok != null && ok != "") ? ok : "OK",
        "Cancel": (cancel != null && cancel != "") ? cancel : "Cancel",
        "Close": "Close"
    };
    return true;
}

function scrollTop() {
    window.document.body.scrollTop = 0;
    window.document.documentElement.scrollTop = 0;
}

//This fix the issue of scrolling a Telerik control in mobile - the page scrolls instead without this code
function fixTelerikControlScroll() {
    // For RadGrid - .RadGrid .RadTouchExtender
    // For RadScheduler - .rsContentScrollArea.RadTouchExtender
    // For RadComboBox - .rcbScroll
    // For RadDropDownList - .rddlList
    var fixed = $telerik.$(".RadGrid .RadTouchExtender, .rsContentScrollArea.RadTouchExtender, .rcbScroll, .rddlList");
    fixed.on('touchmove', function (e) {
        e.preventDefault();
    });
}
