﻿

    $(document).on("click", function (evt) {
        LastKeyDown = "click";
    });
    $(document).on("keydown", function (evt) {
        console.log(evt.key);
        LastKeyDown = evt.key;
    });  

function GetDataSourceItems(ControlID, componentType) {
    var inputid = $("#" + ControlID);
    var DS = $(inputid)[componentType]("getDataSource");
    return DS._store._array;
}

        var Is_DD_Refresh = false;
        var DropDown_DataGrid;
        var MomentDateFormat = "DD/MM/YYYY HH:mm:ss.SSS";
        var Timeout500 = 500;
        var Timeout100 = 100;
        var Timeout1000 = 1000;
        function ConvertJsonDateToString(inputdate) {
            var newDate = new Date(parseInt(inputdate.substr(6)));
            var datemonth = newDate.getMonth() + 1;
            newDate = datemonth + "-" + newDate.getDate() + "-" + newDate.getFullYear();
            return newDate;
        }
        function FormatDateToddMMyyyy(date) {
            if (isValidDate(date)) {
                var month = date.getMonth() + 1;
                var year = date.getFullYear();
                var day = date.getDate();
                return day + "/" + month + "/" + year;
            }
            else {
                return "";
            }
        }
        function JS_Json_Date_To_ddMMyyyy(inputdate) {
            var _date = new Date(inputdate);
            if (isValidDate(_date)) {
                return (moment(_date, MomentDateFormat).format(MomentDateFormat))
            }
            return null;
        }
        function isValidDate(value) {
            // Invalid Date: getTime() returns NaN
            return value && !(value.getTime && value.getTime() !== value.getTime());
        }
        function getDifferenceInDays(Fromdate, Todate) {
            const diffInMs = Todate - Fromdate;
            return diffInMs / (1000 * 60 * 60 * 24);
        }
        function getDiffinHrMin(FrTime, ToTime) {
            var hour = "";
            var minutes = "";
            var timeDiff = ToTime.getTime() - FrTime.getTime();
            hour = Math.floor(timeDiff / 1000 / 60 / 60);
            hour = ('' + hour).slice(-2);
            timeDiff -= hour * 1000 * 60 * 60;
            minutes = Math.floor(timeDiff / 1000 / 60);
            minutes = ('' + minutes).slice(-2);
            return [hour, minutes];
        }
        function createGuid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        }
        function IsUndefinedOrNull(data) {
            if (typeof (data) === "undefined" || data === null) {
                return true;
            }
            return false;
        }
        String.prototype.toProperCase = function () {
            return this.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
        };
        function IsNullOrWhitespace(controlid, controltype = "dxTextBox", value = null) {
            if (controlid != null && controlid.length > 0) {
                value = ($("#" + controlid))[controltype]("instance").option("value");
            }
            return !value || !value.trim();
        }
        async function Refresh_DD_DataGrid(DatagridInstance) {
            Is_DD_Refresh = true;
            await DatagridInstance.refresh();
            Is_DD_Refresh = false;
        }
        async function Refresh_DropDown(DD_ID) {
            Is_DD_Refresh = true;
            await $("#" + DD_ID).dxDropDownBox("instance").getDataSource().reload();
            Is_DD_Refresh = false;
        }
        async function DataGrid_OnContentReady(e, dropdown_component) {
            if (e.component.option("searchPanel.text") != null && e.component.option("searchPanel.text").length > 0) {
                if (e.component.totalCount() == 1) {
                    await e.component.selectRowsByIndexes(0);
                }
            }
        }

        async function DataGrid_keyDown(e, dropdown_component) {
            var dataGrid = e.component;
            var dataGrid_ID = e.element[0].id;
            if (e.event.key == "Enter") {
                e.event.stopImmediatePropagation();
                var focusedElement = $("#" + dataGrid_ID + " .dx-focused").parent()[0];
                if ($(focusedElement).attr('aria-selected') == "true") {
                    dropdown_component.focus();
                    dropdown_component.close();
                }
                else {
                    var rowCount = dataGrid.totalCount();
                    for (i = 0; i < rowCount; i++) {
                        if (focusedElement === dataGrid.getRowElement(i)[0]) {
                            dropdown_component.focus();
                            dropdown_component.close();
                            await dataGrid.selectRows([dataGrid.getKeyByRowIndex(i)], false);
                            break;
                        }
                    }
                }
            }
        }
        function DataGrid_OnEditorPreparing(e, dropdown_component) {
            if (e.parentType !== "searchPanel" && e.parentType !== "filterRow") {
                return;
            }
            var dataGrid = e.component;
            if (e.parentType == "searchPanel") {
                dataGrid.clearFilter("search");
                e.updateValueTimeout = 10;
                e.editorOptions.onKeyDown = e => {
                    if (e.event.keyCode === 40) //down arrow
                    {
                        dataGrid.focus(dataGrid.getCellElement(0, 0));
                        e.event.preventDefault();
                    }
                    if (e.event.key == "Enter") {
                        e.event.stopImmediatePropagation();
                        dropdown_component.focus();
                        dropdown_component.close();
                        if (dataGrid.getVisibleRows().length > 0) {
                            dataGrid.selectRows([dataGrid.getKeyByRowIndex(0)], false);
                        }
                        e.event.preventDefault();
                    }
                }
            }
            else if (e.parentType == "filterRow") {
                e.editorOptions.onKeyDown = e => {
                    if (e.event.keyCode === 40) //down arrow
                    {
                        dataGrid.focus(dataGrid.getCellElement(0, 0));
                        e.event.preventDefault();
                    }
                }
            }
        }
        function DataGrid_OnRowClick(e, dropdown_component) {
            if (e.isSelected) {
                dropdown_component.focus();
                dropdown_component.close();
            }
        }
        var LastKeydown;
        function DropDown_Close(e) {
            //console.log(LastKeyDown);
            if (LastKeyDown != "Tab") {
                if (!($(".dx-texteditor").find("input").is(":focus"))) {
                    e.component.focus();
                }
            }
            var dropdown_DatagridID = Get_DropDown_DataGrid_ID(null, e.component);
            if (dropdown_DatagridID.length > 0) {
                $("#" + dropdown_DatagridID).dxDataGrid("instance").clearFilter("search");
            }
            DropDown_KeyPress_text = "";
        }
        function DropDown_Click() {
            setTimeout(function () {
                $(".dx-datagrid-search-panel").find("input").focus();
                $(".dx-datagrid-search-panel").find("input").val(null);
            }, 10);
            DropDown_KeyPress_text = "";
        }
        var DropDown_KeyPress_text = "";
        function DropDown_KeyPress(e) {
            if (e.event.which != 13 && e.event.which != 9 && e.event.which != 32) //enter tab space
            {
                if (e.component.option("readOnly") == false && e.component.option("disabled") == false) {
                    e.component.open();
                    var DD_Grid = $(e.component.content().find(".DropDownDataGrid"));
                    if (DD_Grid.length > 0) {
                        DD_Grid.dxDataGrid("instance").clearFilter("search");
                    }
                    else {
                        $(".dx-datagrid-search-panel").find("input").val("");
                    }
                    if (e.event.which >= 48 && e.event.which <= 105 && e.event.which != 91 && e.event.which != 92 && e.event.which != 93) {
                        DropDown_KeyPress_text += e.event.key;
                        if (DD_Grid.length > 0) {
                            DD_Grid.dxDataGrid("instance").searchByText(DropDown_KeyPress_text);
                        }
                        else {
                            $(".dx-datagrid-search-panel").find("input").val(DropDown_KeyPress_text);
                        }
                    }
                    DD_Grid = null;
                }
            }
        }
        function Focus_FirstEditable_Field(formId, actionMethod = null) {
            var focusable = $("#" + formId).find('input:enabled,.dx-button.FormActionButton[tabindex="0"],div.dx-checkbox[tabindex="0"],div.dx-radiogroup[tabindex="0"]').filter(':visible:not(input[aria-readonly="true"],div.dx-radiogroup[aria-readonly="true"],div.dx-checkbox[aria-readonly="true"])');
            if (focusable.length > 0) {
                focusable.eq(0).focus();
            }
            focusable = null;
        }
        function Set_Form_View_Delete_Mode(colourcode = null, formId = null, ActionMethod = null, DisableControls = true) {
            if (ActionMethod != null) {
                if (ActionMethod.includes("New") || ActionMethod.includes("Edit")) {
                    return;
                }
            }
            if (colourcode == null) {
                if (ActionMethod.includes("View")) {
                    colourcode = "#000080";
                }
                if (ActionMethod.includes("Delete")) {
                    colourcode = "#000000";
                    //colourcode = "#505256";
                }
            }
            var element = $("#" + formId).find('label,input:not(".dx-button-submit-input"),div.dx-checkbox,div.dx-radiogroup,div.dx-textarea').filter(':visible');
            if (element.length > 0) {
                var labels = element.filter('label');
                if (labels.length > 0) {
                    (labels).addClass("disabletxt").removeClass("text-red");
                }
                var dxelement = element.filter(':not(label)');
                var dxelement_length = dxelement.length;
                if (dxelement_length > 0) {
                    dxelement.css('color', colourcode);
                    if (DisableControls == true) {
                        dxelement.each(function () {
                            var widget = $(this).closest('.dx-widget');
                            widget.removeClass("input-read-only");
                            var data = widget.data();
                            var dxComponentName = data.dxComponents[0];
                            if (dxComponentName.indexOf("dxPrivateComponent") < 0) {
                                //widget[dxComponentName]("instance").option("disabled", true);
                                widget[dxComponentName]("instance").option("readOnly", true);
                                widget[dxComponentName]("instance").option("focusStateEnabled", false);
                            }
                            widget = null;
                            data = null;
                            dxComponentName = null;
                        });
                    }
                }
                element = null;
                labels = null;
                dxelement = null;
                dxelement_length = null;
            }
        }
        function DisableLabel(formId) {
            var list = $("#" + formId).find(".control-label");
            if (list.length > 0) {
                (list).addClass("disabletxt").removeClass("text-red");
            }
            list = null;
        }
        function AssignIDtoLabel(formId, prefix) {
            var index = 1;
            var list = $("#" + formId).find("label");
            if (list.length > 0) {
                list.each(function () {
                    if ($(this).prop("id").length == 0) {
                        $(this).prop("id", "Label_" + prefix + "_" + index);
                        index++;
                    }
                })
            }
            list = null;
        }
        function Fieldset_SetDisable(FieldsetID, disable) {
            var list = $("#" + FieldsetID).find("label");
            $("#" + FieldsetID).prop("disabled", disable);
            if (disable) {
                list.addClass("disabletxt").removeClass("text-red");
            }
            else {
                list.removeClass("disabletxt").removeClass("text-red");
            }
        }
        function Control_SetReadOnly(ControlID, componentType, Readonly, colorCode = null) {
            var inputid = "#" + ControlID;
            if (Readonly == false) {
                if (colorCode == null) {
                    colorCode = "#000080";
                }
                $(inputid).removeClass("input-read-only");
            }
            else { $(inputid).addClass("input-read-only"); }
            if (colorCode != null) {
                $(inputid).find('input').css('color', colorCode);
            }
            ($(inputid))[componentType]("instance").option("readOnly", Readonly);
            ($(inputid))[componentType]("instance").option("focusStateEnabled", !Readonly);
        }
        function Control_SetDisable(ControlID, componentType, Disable, colorCode = null) {
            var inputid = $("#" + ControlID);
            if (Disable == false) {
                if (colorCode == null) {
                    colorCode = "#000080";
                }
            }
            if (colorCode != null) {
                inputid.find('input').css('color', colorCode);
            }
            ($(inputid))[componentType]("instance").option("disabled", Disable);
        }

        function Control_SetColor(ControlID, colorCode) {
            var inputid = $("#" + ControlID);
            if (colorCode.toUpperCase == "DIMGRAY") {
                colorCode = "#696969";
            }
            if (colorCode.toUpperCase == "NAVY") {
                colorCode = "#000080";
            }
            if (colorCode.toUpperCase == "GRAY") {
                colorCode = "#808080";
            }
            inputid.find('input').css('color', colorCode);
        }
        function FocusOnFirstClientSideBrokenRule(ValidationResult) {
            var brokenID = ValidationResult.brokenRules[0].validator._$element[0].id;
            if (brokenID != null && brokenID.length > 0) {
                $("#" + brokenID).find('input').focus();
            }
        }
        function ValidateForm(e, ValidationGroup = "") {
            var result = e ? e.validationGroup.validate() : DevExpress.validationEngine.validateGroup(ValidationGroup);
            if (result.isValid == false) {
                var brokenID = result.brokenRules[0].validator._$element[0].id;
                if (brokenID != null && brokenID.length > 0) {
                    $("#" + brokenID).find('input').focus();
                }
            }
            return result.isValid;
        }
        function FormInitialSettings(Form, Tag) {
            setTimeout(function () {
                Set_Form_View_Delete_Mode(null, Form, Tag);
                Focus_FirstEditable_Field(Form);
                HideLoader_Ready();
            }, Timeout500);
        }
        function GetDayNumberWithSuffix(DayofMonth) {
            switch (DayofMonth) {
                case "1":
                case "21":
                case "31":
                case "41":
                case "51":
                case "61":
                case "71":
                case "81":
                case "91":
                case "101":
                case "121":
                    return DayofMonth + "st";
                    break;
                case "2":
                case "22":
                case "32":
                case "42":
                case "52":
                case "62":
                case "72":
                case "82":
                case "92":
                case "102":
                case "122":
                    return DayofMonth + "nd";
                    break;
                case "3":
                case "23":
                case "33":
                case "43":
                case "53":
                case "63":
                case "73":
                case "83":
                case "93":
                case "103":
                case "123":
                    return DayofMonth + "rd";
                    break;
                default:
                    return DayofMonth + "th";
                    break;
            }
        }
        function Get_DropDown_DataGrid_ID(DropdownId = null, Component = null) {
            if (Component) {
                var id = "#" + (((Component.content())[0]).id);
                //var ScrollView = $(id).dxScrollView("instance").content();
                var DGid = ((Component.content())[0]).firstElementChild.id;
            }
            else if (DropdownId) {
                var id = "#" + ((($("#" + DropdownId).dxDropDownBox("instance").content())[0]).id);
                //var ScrollView = $(id).dxScrollView("instance").content();
                var DGid = (($("#" + DropdownId).dxDropDownBox("instance").content())[0]).firstElementChild.id;
            }
            return DGid;
        }
        function DeleteCookie(cookieName) {
            var expires = "expires=" + new Date() - 1;
            document.cookie = cookieName + "=;" + expires + ";path=/";
        }
        function dragElement(elmnt) {
            var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
            elmnt.onmousedown = dragMouseDown;
            function dragMouseDown(e) {
                e = e || window.event;
                e.preventDefault();
                // get the mouse cursor position at startup:
                pos3 = e.clientX;
                pos4 = e.clientY;
                document.onmouseup = closeDragElement;
                // call a function whenever the cursor moves:
                document.onmousemove = elementDrag;
            }
            function elementDrag(e) {
                e = e || window.event;
                e.preventDefault();
                // calculate the new cursor position:
                pos1 = pos3 - e.clientX;
                pos2 = pos4 - e.clientY;
                pos3 = e.clientX;
                pos4 = e.clientY;
                // set the element's new position:
                elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
                elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
            }
            function closeDragElement() {
                // stop moving when mouse button is released:
                document.onmouseup = null;
                document.onmousemove = null;
            }
        }
        function HideAlert(alert) {
            setTimeout(function () {
                alert.hide();
            }, 2000);
        }
        function MultiUserPrevention(PopupID, Message, title, GridName) {
            $("#" + PopupID).dxPopup('hide');
            var showAlert = DevExpress.ui.dialog.alert(Message, title);
            showAlert.done(function () {
                RefreshGridView(GridName);
            });
        }
        function NoRightsPrevention(Closetab = false, PopupID = "", Message = 'Not Allowed', title = 'No Rights') {
            var showAlert = DevExpress.ui.dialog.alert(Message, title);
            showAlert.done(function () {
                if (Closetab == true) {
                    btnCloseActiveTab();
                }
                else if (!IsNullOrWhitespace(null, "", PopupID)) {
                    $("#" + PopupID).dxPopup('hide');
                }
            });
        }
        function isMobile() {
            var check = false;
            (function (a) {
                if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
                    check = true;
            })(navigator.userAgent || navigator.vendor || window.opera);
            return check;
        };
        var isMobile = isMobile();
        function isDesktop() {
            var check = true;
            if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
                check = false;
            }
            return check;
        }
        var isDesktop = isDesktop();
        //var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
        function RefreshCashBookGrid() {
            if (typeof CashBookListGrid !== 'undefined') {
                Grid_Display();
            }
        }
        function RefreshGridView(GridName) {

            if (GridName == "CashBookListGrid") {
                RefreshCashBookGrid();
            }
            else {
                if (typeof ASPxClientControl.GetControlCollection().GetByName(GridName) !== 'undefined' && ASPxClientControl.GetControlCollection().GetByName(GridName) != null) {
                    GridViewDoCallback(ASPxClientControl.GetControlCollection().GetByName(GridName), function () { ASPxClientControl.GetControlCollection().GetByName(GridName).Refresh(); });
                }
            }
        }
        function PerformCallbackGridView(GridName) {
            if (typeof ASPxClientControl.GetControlCollection().GetByName(GridName) !== 'undefined' && ASPxClientControl.GetControlCollection().GetByName(GridName) != null) {
                GridViewDoCallback(ASPxClientControl.GetControlCollection().GetByName(GridName), function () { ASPxClientControl.GetControlCollection().GetByName(GridName).PerformCallback(); });
            }
        }
        var GridViewPendingCallbacks = {};
        function GridViewDoCallback(sender, callback) {
            if (sender.InCallback()) {
                GridViewPendingCallbacks[sender.name] = callback;
                sender.EndCallback.RemoveHandler(GridViewDoEndCallback);
                sender.EndCallback.AddHandler(GridViewDoEndCallback);
            }
            else {
                callback();
            }
        }
        function GridViewDoEndCallback(s, e) {
            var pendingCallback = GridViewPendingCallbacks[s.name];
            if (pendingCallback) {
                pendingCallback();
                delete GridViewPendingCallbacks[s.name];
            }
        }
        async function ResetDropdownWithSameValue(ddID, DG_Instance = null) {
            if ($("#" + ddID).dxDropDownBox("option", "value")) {
                var ddvalue = $("#" + ddID).dxDropDownBox("option", "value");
                $("#" + ddID).dxDropDownBox("reset");
                if (ddvalue != null && ddvalue.length > 0) {
                    if (DG_Instance == null) {
                        $("#" + ddID).dxDropDownBox("option", "value", ddvalue[0]);
                    }
                    else {
                        if (DG_Instance.getRowIndexByKey(ddvalue[0]) > -1) {
                            await DG_Instance.selectRows(ddvalue);
                        }
                    }
                }
            }
        }
        var AllKeysThatAreDownArray = []; // for stopping keydown to trigger multiple times
        function Check_keydownEventRepeat(e) {
            if ($.inArray(e.keyCode, $.unique(AllKeysThatAreDownArray)) === -1) {
                return false;
            }
            return true;
        }
    
/*@* DD and other utilities *@*/
    
        //var AuditIconArray = ["Date", "Amount", "Item", "Head", "Cash", "Party", "Address", "ID", "Quantity", "TDS", "Phone", "Percent", "Attach", "General1", "General2", "General3", "GreenTick"]; //list of all buttons
    var AuditIconArray = ["RedCross", "DoubleTick", "GreenTick"];
    function OnGridAuditBtn_Init(s, e)//adding glow effect to buttons on hover
    {
        ASPxClientUtils.AttachEventToElement(s.GetMainElement(), "mouseover", function (event) {
            $(this).addClass("GridFloatAuditBtn");
        });
    ASPxClientUtils.AttachEventToElement(s.GetMainElement(), "mouseout", function (event) {
        $(this).removeClass("GridFloatAuditBtn");
            });
        }
    function OnGridRowMouseHoverIn(event, row, grid, VisbleIndex, KeyValue) {
            if (LoginUserType == "AUDITOR" || LoginUserType == "SUPERUSER") {
        //var PrevRowID = "#" + grid + "_PreviewRow_" + KeyValue;
        //$(PrevRowID).show();
        $("." + grid + "_PreviewRow_" + KeyValue).show();      //showing preview row using css class

            }
        }
    function OnGridRowMouseHoverOut(event, row, grid, VisbleIndex, KeyValue) {
            if (LoginUserType == "AUDITOR" || LoginUserType == "SUPERUSER") {
        //var PrevRowID = "#" + grid + "_PreviewRow_" + KeyValue;
        //$(PrevRowID).hide();
        $("." + grid + "_PreviewRow_" + KeyValue).hide(); //hiding preview row using css class
            }
        }
    function OnGridPrevRowMouseHoverIn(event, row, grid, VisbleIndex, KeyValue) {
            if (LoginUserType == "AUDITOR" || LoginUserType == "SUPERUSER") {
        //var PrevRowID = "#" + grid + "_PreviewRow_" + KeyValue;
        //$(PrevRowID).show();
        $("." + grid + "_PreviewRow_" + KeyValue).show();
            }
        }
    function OnGridPrevRowMouseHoverOut(event, row, grid, VisbleIndex, KeyValue) {
            if (LoginUserType == "AUDITOR" || LoginUserType == "SUPERUSER") {
        //var PrevRowID = "#" + grid + "_PreviewRow_" + KeyValue;
        //$(PrevRowID).hide();
        $("." + grid + "_PreviewRow_" + KeyValue).hide();
            }
        }
    function OnGridCellClick(event, cell, colIndex, rowIndex, Grid, KeyValue, FieldName, CompactMode = "False", VouchingMode) {
            if (VouchingMode != "False") {
                if (LoginUserType == "AUDITOR" || LoginUserType == "SUPERUSER") {
                    if (event.button == 0) {
                        if (cell.style.backgroundColor.length > 0) {
                            if (cell.style.backgroundColor == 'lightgreen') {
        cell.style.backgroundColor = 'pink';
    cell.style.color = "black";
                            }
    else if (cell.style.backgroundColor == 'pink') {
        cell.style.backgroundColor = "";
    cell.style.color = "";
                            }
                        }
    else {
        cell.style.backgroundColor = 'lightgreen';
    cell.style.color = "black";
                        }
    var SessionStorageValue = CalculateHighlightedCell(Grid, KeyValue, CompactMode);
    var SessionStorageKey = KeyValue + "|" + Grid + "_Highlight";
    SetSessionStorage(SessionStorageKey, SessionStorageValue);
                    }
                }
            }
        }
    function OnGridCommandCellClick(event, cell, rowIndex, Grid) {
            if (LoginUserType == "AUDITOR" || LoginUserType == "SUPERUSER") {
        ASPxClientControl.GetControlCollection().GetByName(Grid).ExpandDetailRow(rowIndex);
            }
        }
    function OnGridAuditBtn_Click(s, e, VisbleIndex, KeyValue, Grid, Btn) {
            var DivID = "#" + CalculateAuditIconDivID(Grid, Btn, KeyValue);
    if ($(DivID).is(':hidden')) //if icon absent show it
    {
        $(DivID).show();
            }
    else {
        $(DivID).hide();
            }
    var SessionStorageValue = CalculateVisibleAuditIcons(Grid, KeyValue);
    var SessionStorageKey = KeyValue + "|" + Grid;
    SetSessionStorage(SessionStorageKey, SessionStorageValue);
        }
    function CalculateVisibleAuditIcons(Grid, KeyValue) //getting all visble icons in a row
    {
            var Result = "";
    for (var i = 0; i < AuditIconArray.length; i++) {
                var DivID = "#" + CalculateAuditIconDivID(Grid, AuditIconArray[i], KeyValue);
    if ($(DivID).is(':visible')) {
        Result = Result.trim() + AuditIconArray[i] + "|";
                }
            }
    return Result;
        }
    function CalculateHighlightedCell(Grid, KeyValue, CompactMode) {
            var result = "";
    var Selector = "#" + Grid + " " + "." + Grid + "_DataRow_" + KeyValue;//row class
    if (CompactMode == "False") {
        $(Selector).find('td').each(function ()//getting all tds that have background color in a row
        {
            if (this.id.length > 0) {
                var FieldName = this.id.split('|')[1]; //getting field name from id of td
                if (FieldName) {
                    if (FieldName.length > 0) {
                        var BackColor = (document.getElementById(this.id)).style.backgroundColor;
                        if (BackColor.length > 0) {
                            result = result.trim() + FieldName + "^" + BackColor + "|";
                        }
                    }
                }
            }
        });
            }
    else {
        $(Selector).find('div.compact_column_data').each(function ()//getting all divs that have background color in a row
        {
            if (this.id.length > 0) {
                var FieldName = this.id.split('|')[1]; //getting field name from id of td
                if (FieldName) {
                    if (FieldName.length > 0) {
                        var BackColor = (document.getElementById(this.id)).style.backgroundColor;
                        if (BackColor.length > 0) {
                            result = result.trim() + FieldName + "^" + BackColor + "|";
                        }
                    }
                }
            }
        });
            }
    return result;
        }
    function SetSessionStorage(key, value) {
        sessionStorage.setItem(key, value);
        }
    function GetSessionStorage(Grid) {
            if (LoginUserType == "AUDITOR" || LoginUserType == "SUPERUSER") {
                if (sessionStorage.length > 0) {
                    for (let i = 0; i < sessionStorage.length; i++) {
                        var key = sessionStorage.key(i);
    if (key.endsWith(Grid + "_Highlight"))//for highlight
    {
                            var values = sessionStorage.getItem(key);
    var RowKeyValue = sessionStorage.key(i).split('|')[0];
                            if (values != null && values.length > 0) {
                                var value_part = values.split('|');
    for (let j = 0; j < value_part.length; j++) {
                                    var FieldName = value_part[j].split("^")[0];
    var BackColor = value_part[j].split("^")[1];
    var CellID = Grid + "_Cell_" + RowKeyValue + "|" + FieldName;
    if (document.getElementById(CellID) != null) {
        (document.getElementById(CellID)).style.backgroundColor = BackColor;
    (document.getElementById(CellID)).style.color = "black";
                                    }
                                }
                            }
                        }
    else if (key.endsWith(Grid))//for icons
    {
                            var values = sessionStorage.getItem(key);
    var RowKeyValue = sessionStorage.key(i).split('|')[0];
                            if (values != null && values.length > 0) {
                                var value_part = values.split('|');
    for (let j = 0; j < value_part.length; j++) {
                                    var DivId = "#" + CalculateAuditIconDivID(Grid, value_part[j], RowKeyValue);
    $(DivId).show();
                                }
                            }
                        }
                    }
                }
            }
        }
    function ClearSessionStorage(Grid = null) {
            if (Grid == null) {
        sessionStorage.clear();
            }
    else {
                for (let i = 0; i < sessionStorage.length; i++) {
                    var key = sessionStorage.key(i);
    if (key.endsWith(Grid + "_Highlight"))//for highlight
    {
        sessionStorage.removeItem(key);
                    }
    else if (key.endsWith(Grid)) {
        sessionStorage.removeItem(key);
                    }
                }
            }
        }
    function CalculateAuditIconDivID(Grid, Btn, KeyValue) {
            var DivID = Grid + "_Audit_" + Btn + "_Icon_" + KeyValue;
    return DivID;
        }

/*@* Auditor Working *@*/


    
        function TransformText(text) {
            if (text == null) {
                return text
            }
            text = text.replace(/&quot;|&amp;|&lt;|&gt;|&#172;/gi, function (x) {
                return TransformCharacters(x);
            });
            return text;
        }
        function TransformCharacters(charStr) {
            if (charStr == "&quot;") {
                return "\"";
            }
            else if (charStr == "&amp;") {
                return "&";
            }
            else if (charStr == "&lt;") {
                return "<";
            }
            else if (charStr == "&gt;") {
                return ">";
            }
            else if (charStr == "&#172;") {
                return "¬";
            }
        }
        function BracketKeyPressEvent(e) {
            if (e.key == "[") {
                $(this).val($(this).val() + "(");
                e.preventDefault();
            }
            if (e.key == "]") {
                $(this).val($(this).val() + ")");
                e.preventDefault();
            }
            if (e.key == "'") {
                $(this).val($(this).val() + "`");
                e.preventDefault();
            }
        }
        function TransformTextForDB(formID = "") {
            var GetTextBoxes = formID.length > 0 ? document.getElementById(formID).getElementsByClassName("CleanTextForDB") : document.getElementsByClassName("CleanTextForDB");
            if (GetTextBoxes && GetTextBoxes.length > 0) {
                for (var i = 0; i < GetTextBoxes.length; i++) {
                    if (GetTextBoxes[i].id) {
                        GetTextBoxes[i].oninput = function (evt) {
                            CleanTextForDB(evt);
                        };
                    }
                    //if (GetTextBoxes[i].id)
                    //{
        //    $("#" + GetTextBoxes[i].id).bind('paste', function (ev)
        //    {
        //        setTimeout(function ()
        //        {
        //            CleanTextForDB(ev)
        //        });
        //    });
        //}
    }
            }
        }
    function transformTypedChar(charStr) {
            if (charStr == "'") {
        charStr = "";
            }
    else if (charStr == "[") {
        charStr = "";
            }
    else if (charStr == "]") {
        charStr = "";
            }
    else if (charStr == "!") {
        charStr = "";
            }
    else if (charStr == "&") {
        charStr = "";
            }
    else if (charStr == "<") {
    charStr = "";
            }
            else if (charStr == ">") {
        charStr = "";
            }
    return charStr;
        }
    function CleanTextForDB(evt) {
        evt.target.value = evt.target.value.replace(/'|<|>|&|!|\[|\]/gi, function (x) {
            return transformTypedChar(x);
        });
    if ((evt.target.className).includes("TextBoxUpperCase")) {
        TransfromTextToUpperCase(evt);
            }
    if ((evt.target.className).includes("OnlyDigit")) {
        AllowOnlyDigits(evt);
            }
        }
    function AllowOnlyDigits(evt) {
        evt.target.value = evt.target.value.replace(/[^0-9]/g, '');
        }
    function TransfromTextToUpperCase(evt) {
        evt.target.value = evt.target.value.toUpperCase();
        }
    function TextBox_OnContentReady(e) {
            var data = e.component.option("value");
            if (data != null && data.length > 0) {
                if (data.search(/'|<|>|&|!|\[|\]/gi) >= 0) {
        data = data.replace(/'|<|>|&|!|\[|\]/gi, function (x) {
            return transformTypedChar(x);
        });
    e.component.option("value", data);
                }
            }
        }
    function RestrictNumberBoxLength(MaxLength, ClassName = null, ElementID = null) {
            if (ElementID == null) {
        $("." + ClassName).each(function () {
            $(this).dxNumberBox({
                onInput: function (e) {
                    var inputElement = e.event.target;
                    if (inputElement.value.length > MaxLength)
                        inputElement.value = inputElement.value.slice(0, MaxLength);
                }
            });
        });
            }
    else {
        $("#" + ElementID).dxNumberBox({
            onInput: function (e) {
                var inputElement = e.event.target;
                if (inputElement.value.length > MaxLength)
                    inputElement.value = inputElement.value.slice(0, MaxLength);
            }
        });
            }
        }


    
    /*Popup related code*/

        var sessionclearpath = "";
        var dontaskpopupcloseconfirmation = true;
        var PopupCloseCallFromPayment = false;
        var PopupCloseCallFromAttachment = false;
        var AttachmentWindowRecurringCount = 0;
        var ClosingScreenParentDivClass = "";
        function OpenDynamicPopup(PopupTitle, LoadURL, maxHeight = "auto", maxWidth = "100%", viaAjax = false, AjaxSuccessData = null) {
            ShowLoader(PopupTitle);
        if (!$("#Dynamic_Content_popup").dxPopup("instance")) {
            $("#Global_popup").append("<div id='Dynamic_Content_popup'>");
        $("#Dynamic_Content_popup").dxPopup();
            }
        else {
            $("#Dynamic_Content_popup").dxPopup("instance").resetOption("height");
        $("#Dynamic_Content_popup").dxPopup("instance").resetOption("width");
        $("#Dynamic_Content_popup").dxPopup("instance").resetOption("position");
            }
        $("#Dynamic_Content_popup").dxPopup("instance").option("title", PopupTitle)
        $("#Dynamic_Content_popup").dxPopup("instance").option("height", maxHeight)
        $("#Dynamic_Content_popup").dxPopup("instance").option("width", maxWidth)
        $("#Dynamic_Content_popup").dxPopup("instance").option("position.my", "top");
        $("#Dynamic_Content_popup").dxPopup("instance").option("position.at", "top");
        $("#Dynamic_Content_popup").dxPopup("instance").option("position.of", "#body");
        $("#Dynamic_Content_popup").dxPopup("instance").option("fullScreen", false);
        $("#Dynamic_Content_popup").dxPopup({onHiding: function (e) {Dynamic_Content_popup_hiding(e)} });
        $("#Dynamic_Content_popup").dxPopup({onHidden: function (e) {PopupOnHidden(e)} });
        $("#Dynamic_Content_popup").dxPopup({onShown: function (e) {PopupOnShown(e)} });
        $("#Dynamic_Content_popup").dxPopup({onShowing: function (e) {PopupOnShowing(e)} });
        loadDataintoPopup("Dynamic_Content_popup", viaAjax, LoadURL, AjaxSuccessData, PopupTitle);
        }
        function OpenPopup(PopupID, PopupTitle = "", LoadURL = null, maxHeight = "auto", maxWidth = "100%", viaAjax = false, AjaxSuccessData = null) {
            ShowLoader(PopupTitle);
        var Popupid = "#" + PopupID;
        if (!$(Popupid).dxPopup("instance")) {
            $("#Global_popup").append("<div id='" + PopupID + "'>");
        $(Popupid).dxPopup();
            }
        $(Popupid).dxPopup("instance").resetOption("height");
        $(Popupid).dxPopup("instance").resetOption("width");
        $(Popupid).dxPopup("instance").option("title", PopupTitle)
        $(Popupid).dxPopup("instance").option("height", maxHeight)
        $(Popupid).dxPopup("instance").option("width", maxWidth)
        $(Popupid).dxPopup("instance").option("showCloseButton", true)
        $(Popupid).dxPopup("instance").option("position.my", "top");
        $(Popupid).dxPopup("instance").option("position.at", "top");
        $(Popupid).dxPopup("instance").option("position.of", "#form");
        $(Popupid).dxPopup("instance").option("fullScreen", false);
        $(Popupid).dxPopup({onShowing: function (e) {PopupOnShowing(e)} });
        $(Popupid).dxPopup({onHidden: function (e) {PopupOnHidden(e)} });
        $(Popupid).dxPopup({onShown: function (e) {PopupOnShown(e)} });
        if (Popupid == "#Dynamic_Content_popup") {
            $(Popupid).dxPopup({ onHiding: function (e) { Dynamic_Content_popup_hiding(e) } });
            }
        loadDataintoPopup(PopupID, viaAjax, LoadURL, AjaxSuccessData, PopupTitle);
        }
        function loadDataintoPopup(Popupid, viaAjax, LoadURL, AjaxSuccessData, PopupTitle) {
            ShowLoader(PopupTitle);
        var content = $("<div id='result_" + Popupid + "' class='PopupContentDiv'></div>");
        content.html("");
        var scrollView = $("<div id='scrollView_" + Popupid + "' class='ScrollViewDiv'></div>");
        scrollView.append(content);
        scrollView.dxScrollView({
            height: "100%",
        width: '100%',
        useNative: false,
        showScrollbar: 'onHover',
        scrollByThumb: true,
        scrollByContent: true,
        bounceEnabled: false
            });
        $("#" + Popupid).dxPopup({
            contentTemplate: function (contentElement) {
            contentElement.append(scrollView);
        return contentElement;
                }
            });
        if (viaAjax == false) {
            content.load(LoadURL, function () {
                HideLoader();
                $("#" + Popupid).dxPopup("instance").show();
            });
            }
        else {
            content.html(AjaxSuccessData);
        HideLoader();
        $("#" + Popupid).dxPopup("instance").show();
            }
        }
        function HidePopup(PopupID) {
            var Popupid = "#" + PopupID;
        $(Popupid).dxPopup("hide");
        }
        function Dynamic_Content_popup_hiding(e) {
            HideLoader();
        if (dontaskpopupcloseconfirmation == true) {
                if (sessionclearpath != "") {
            $.ajax
                ({
                    type: 'GET',
                    url: sessionclearpath,
                    cache: false,
                    success: function (data) { sessionclearpath = ""; }
                });
                }
        if (PopupCloseCallFromPayment) {
            //$("#Payment_ParentDiv").remove();
            PopupCloseCallFromPayment = false;
                }
        if (PopupCloseCallFromAttachment) {
                    if (AttachmentWindowRecurringCount > 0) {
                        if (typeof AttachmentListGrid !== "undefined" && ASPxClientUtils.IsExists(AttachmentListGrid) && AttachmentListGrid.GetMainElement()) {
            AttachmentListGrid.Refresh();
                        }
                    }
        AttachmentWindowRecurringCount = 0;
        PopupCloseCallFromAttachment = false;
                }
        if (IsRegisteredForAudit == 1)//Registration Completed
        {
            RegisterForAuditSuccess();
        IsRegisteredForAudit = 0;
                }
            }
        else if (dontaskpopupcloseconfirmation == false) {
            e.cancel = true;
        var result = DevExpress.ui.dialog.confirm('Are You Sure You want To Cancel...?', "Confirm");
        result.done(function (dialogResult) {
            dontaskpopupcloseconfirmation = dialogResult;
        if (dialogResult) {
            $("#Dynamic_Content_popup").dxPopup("hide");
                    }
        else {
            FocusButtonOnPopupCloseConfirmationNo($("#Dynamic_Content_popup"));
                    }
                });
            }
        }
        function PopupOnHidden(e) {
            var popupid = e.element[0].id;
        var PopupContentDiv = $("#result_" + popupid);
            if (PopupContentDiv.length > 0) {
            ClosingScreenParentDivClass = PopupContentDiv[0].firstElementChild == null ? "" : PopupContentDiv[0].firstElementChild.className;
        PopupContentDiv = null;
            }
        else {
            ClosingScreenParentDivClass = "";
            }
        if (ClosingScreenParentDivClass.toLowerCase().includes("_clearreference")) {
            ClearPopupClosingScreenReferences();
            }
        if (popupid == "Dynamic_Content_popup") {
            e.component.content()[0].innerHTML = "";
        e.component.dispose();
        $("#Dynamic_Content_popup").remove();
            }
        }
function ShowLoader(message = "", showLoadingWithMessage = true) {
    if ($("#loadPanel").dxLoadPanel("instance").option("visible")) {
        $("#loadPanel").dxLoadPanel("instance").option("visible", false);
    }
    if (showLoadingWithMessage) {
        $("#loadPanel").dxLoadPanel("instance").option("message", message + " Loading...");
    }
    else {
        $("#loadPanel").dxLoadPanel("instance").option("message", message + "...");
    }
    $("#loadPanel").dxLoadPanel("instance").option("visible", true);
}
function HideLoader() {
    $("#loadPanel").dxLoadPanel("instance").resetOption("message");
    $("#loadPanel").dxLoadPanel("instance").option("visible", false);
}

        function PopupOnShowing(e) {
            ShowLoader();
        var Content = e.component.content();
        var Overlay = Content.closest(".dx-overlay-wrapper");
            if (Overlay.length > 0) {
                if (!(Overlay.hasClass('popupresponsive'))) {
            Overlay.addClass('popupresponsive');
                }
            }
            if (Content.length > 0) {
            SetScrollView(Content, e.element[0].id);
            }
        HideLoader();
        }
        function PopupOnShown(e) {
            ShowLoader();
        var Content = e.component.content();
        if (!isDesktop) {
                var WindowHeight = document.documentElement.clientHeight;
        var PopupHeight = Content.height();
        var PopupWidth = Content.width();
                if (PopupHeight > WindowHeight) {
            e.component.option("width", "97%");
        e.component.option("height", "97%");
                }
        else {
            e.component.option("height", PopupHeight + 40);
        e.component.option("width", PopupWidth + 15);
                }
                // resizeScrollview(e);
            }
        else {
            $(Content).on('dxmousewheel', function (evt) { evt.stopPropagation(); });
        var form = $(Content).find('form:first');
                if (form.length > 0 && form[0].id.length > 0) {
            Focus_FirstEditable_Field(form[0].id);
                }
        form = null;
            }
        Content = null;
        HideLoader();
        }
        function SetScrollView(PopupContentElement, Popupid) {
            if ((!(PopupContentElement.hasClass("dx-scrollable"))) && PopupContentElement.children(".dx-scrollable").length == 0) {
                var content = PopupContentElement.children();
        var scrollView = $("<div id='scrollView_" + Popupid + "' class='ScrollViewDiv'></div>");
        scrollView.append(content);
        scrollView.dxScrollView({
            height: "100%",
        width: '100%',
        useNative: false,
        showScrollbar: 'onHover',
        scrollByThumb: true,
        scrollByContent: true,
        bounceEnabled: false
                });
        PopupContentElement.html("");
        PopupContentElement.append(scrollView);
            }
        }
        function resizeScrollview(e) {
            var scrollview = $("#scrollView_" + e.element[0].id);
            if (scrollview.length > 0) {
            scrollview.dxScrollView("instance").option("height", e.component.content().height());
        scrollview.dxScrollView("instance").option("width", e.component.content().width());
        scrollview.dxScrollView("update");
            }
        }
        function StandardizeCallURL(URL) {
            var urlParams = new URLSearchParams(window.location.search);
        if (URL.includes("?")) { return URL + "&SessionGUID=" + urlParams.get('SessionGUID'); }
        else { return URL + "?SessionGUID=" + urlParams.get('SessionGUID'); }
        }
        function CreateCustomConfirmDialog(Title = "", Message = "", ForDelete = false) {
            Message = Message.length == 0 ? (ForDelete == true ? "Sure You Want To Delete This Entry...?" : "Sure You Want To Cancel This Entry...?") : Message;
        var CustomConfirmDialog = DevExpress.ui.dialog.custom({
            title: Title,
        messageHtml: Message,
        buttons: [
        {
            text: 'Yes',
        elementAttr:
        {
            id: "CustomConfirmDialog_YesButton"
                        },
        onClick: function () {
                            return true
                        }
                    },
        {
            text: 'No',
        elementAttr:
        {
            id: "CustomConfirmDialog_NoButton"
                        },
        onClick: function () {
                            return false
                        }
                    }
        ],
        popupOptions:
        {
            elementAttr:
        {
            id: "CustomConfirmDialog_Popup"
                    },
        onShown: function (e) {
                        if (ForDelete) {
            $(".dx-dialog-button:last").focus();
                        }
        else {
            $(".dx-dialog-button:first").focus();
                        }
                    },
        onHidden: function (e) {
            e.component.dispose();
        $("#CustomConfirmDialog_Popup").remove();
                    }
                }
            });
        return CustomConfirmDialog;
        }
        function AutoHideAlertDialog(Message = "", Title = "") {
            var AutoHideDialog = DevExpress.ui.dialog.custom({
            title: Title,
        messageHtml: Message,
        buttons: [{
            text: 'OK',
        elementAttr:
        {
            id: "AutoHideAlertDialog_OKButton"
                    },
        onClick: function () {
                        return true
                    }
                }],
        popupOptions:
        {
            elementAttr:
        {
            id: "AutoHideAlertDialog_Popup"
                    },
        onShowing: function (e) {
            //$("#AutoHideAlertDialog_OKButton").hide();
        },
        onShown: function (e) {
            //setTimeout(function ()
            //{
            //    if ($("#AutoHideAlertDialog_OKButton").length > 0)
            //    {
            //        $("#AutoHideAlertDialog_OKButton").click();
            //    }
            //},800)
        },
        onHidden: function (e) {
            e.component.dispose();
        $("#AutoHideAlertDialog_Popup").remove();
                    }
                }
            });
        return AutoHideDialog.show();
        }
        function ClearAllReferences(MainDivClass) {
            var ID = "";
        var allWidgets = $("." + MainDivClass + " .DevexpressComponents");    //removing devexpress compnenets
        allWidgets.each(function () {
            ID = this.id;
                if (ID.length > 0) {
            ASPxClientControl.GetControlCollection().Remove(ASPxClientControl.GetControlCollection().GetByName(ID));
        delete window[ID];
                }
            });
        allWidgets = $("." + MainDivClass + " .DropDownDataGrid"); //removing dropdown data grid
        allWidgets.each(function () {
            $(this).dxDataGrid("dispose");
        $(this).html("");
        $(this).remove();
            });
        allWidgets = $("." + MainDivClass).find(".dx-widget");  //removing devextreme components
        allWidgets.each(function () {
                if (this.id.length > 0) {
                    var data = $(this).data();
        if (data) {
                        if (data.dxComponents) {
                            var dxComponentName = data.dxComponents[0];
        if (dxComponentName.indexOf("dxPrivateComponent") < 0) {
            $(this)[dxComponentName]("dispose");
        $(this).remove();
                            }
                        }
                    }
                }
        else {
            $(this).html("");
        $(this).remove();
                }
            })
        allWidgets = $("." + MainDivClass + " *"); // removing child dom nodes
        var len = allWidgets.length, i = 0;
        for (i; i < len; i++) {
            allWidgets[i].innerHtml = "";
        allWidgets[i].remove();
            }
        allWidgets = null;
        ID = null;
        if (MainDivClass != "LeftPane_Div_ClearReference") {
            $("." + MainDivClass).html(""); // removing parent dom node
        $("." + MainDivClass).remove();
            }
        if (MainDivClass == "NoteBook_ClearReferences" && $(".TabPanalMenu-tabs .active").attr("id") == "contact_Frm_NoteBook_Info") {
            $(".TabPanalMenu-tabs li.active").prev().addClass("active");
        $(".TabPanalMenu-tabs li.active").prev().find("a").trigger("click");
        removeElement(document.getElementById("Frm_NoteBook_Info"));
        removeElement(document.getElementById("contact_Frm_NoteBook_Info"));
                if (AllOpenControlTabs.indexOf("Frm_NoteBook_Info") > -1) {
            AllOpenControlTabs.splice($.inArray("Frm_NoteBook_Info", AllOpenControlTabs), 1);
                }
            }
        else if (MainDivClass == "DailyBalance_ClearReferences" && $(".TabPanalMenu-tabs .active").attr("id") == "contact_DailyBalances") {
            $(".TabPanalMenu-tabs li.active").prev().addClass("active");
        $(".TabPanalMenu-tabs li.active").prev().find("a").trigger("click");
        removeElement(document.getElementById("DailyBalances"));
        removeElement(document.getElementById("contact_DailyBalances"));
                if (AllOpenControlTabs.indexOf("DailyBalances") > -1) {
            AllOpenControlTabs.splice($.inArray("DailyBalances", AllOpenControlTabs), 1);
                }
            }

        }
        function FocusButtonOnPopupCloseConfirmationNo(popupSelector) {
            var PopupContent = $((popupSelector.dxPopup("content"))[0]);
        var formButtons = PopupContent.find('form:first .FormActionButton:last');
            if (formButtons.length > 0) {
            formButtons.focus();
            }
        formButtons = null;
        PopupContent = null;
        }
        function DeleteAfterConfirmation(Title = "", Message = "", formSelector) {
            CreateCustomConfirmDialog(Title, Message, true).show().done(function (dialogResult) {
                if (dialogResult) {
                    formSelector.submit();
                }
                else {
                    var formButtons = formSelector.find('.FormActionButton:first');
                    if (formButtons.length > 0) {
                        formButtons.focus();
                    }
                    formButtons = null;
                    formSelector = null;
                }
            });
        }
function maskInputString(value, LeavefromStart, LeavefromEnd, Mask = "*")
{
    var SlicedFromStart = ""; 
    var SlicedFromEnd = ""; 
    var valueLength = value.length;   
    if (LeavefromStart > 0)
    {
        SlicedFromStart = value.slice(0, LeavefromStart);
    }
    if (LeavefromEnd > 0) {
        SlicedFromEnd = value.slice(-LeavefromEnd);
    }
    var paddedLength = valueLength - (LeavefromStart + LeavefromEnd);
    var maskedString = "".padStart(paddedLength, Mask)
    return SlicedFromStart + maskedString + SlicedFromEnd;
}

  



    
   
    
