




function SetFixedGrid() {
    $(document).ready(function () {
        
        try {
            arrData = $('#ctl00_MainContent_dgvWfSetupRpt').find('.GridItem').get();
            $(arrData).each(function (i, j) {
                $.each(arrData[i].children, function (a, b) {
                    var tdWidth = b.offsetWidth - 31;
                    b.style.minWidth = (tdWidth + 14);
                });
            });
            $('#ctl00_MainContent_dgvWfSetupRpt>tbody>tr:eq(1)>td').each(function (i, j) {
                var tdWidth = (j.offsetWidth) - 31;
                if ($('#ctl00_MainContent_dgvWfSetupRpt>tbody>tr:eq(1)>td').length != 1) {
                    if (!isNaN(tdWidth)) {
                        //$("#ctl00_MainContent_grd_BookingMode .GridHeader th:eq(" + i + ")").css("min-width", tdWidth);
                        $("#ctl00_MainContent_dgvWfSetupRpt .GridHeader th:eq(" + i + ")").css("min-width", tdWidth + 14);  //Added by Varsha on 30-07-2019 || Reason:header should be central align
                    }
                }
                else {
                    $("#ctl00_MainContent_dgvWfSetupRpt .GridHeader th:eq(" + i + ")").css("min-width", 0);
                }
            });
            
            if ($(".Grid").find("thead").length <= 0) {
                $("<thead />").insertBefore($(".Grid:first-child>tbody"));
                $(".Grid:first-child thead").append($(".Grid:first-child").find(".GridHeader"));
                $(".Grid:first-child thead").css("position", "relative");
                //$(".Grid:first-child thead").css("width", "1920px");
                $(".Grid:first-child thead").css("z-index", "9");
            }

            $('#ctl00_MainContent_dgvWfSetupRpt>tbody').css("top", $('#ctl00_MainContent_dgvWfSetupRpt>thead:first-child').height());
            $("#ctl00_MainContent_dgvWfSetupRpt>tbody").css("overflow-y", "auto");
            $("#ctl00_MainContent_dgvWfSetupRpt>tbody").css("display", "block");
            $("#ctl00_MainContent_dgvWfSetupRpt:first-child thead:first-child").css("display", "inline-block");
            var heigthForGrid = $(".dvGridWidth").height() - ($("#ctl00_MainContent_dgvWfSetupRpt .GridHeader").outerHeight());
            $("#ctl00_MainContent_dgvWfSetupRpt> tbody").css("height", (heigthForGrid) - 20);
            $("#ctl00_MainContent_dgvWfSetupRpt> tbody").css("margin-top", $("#ctl00_MainContent_dgvWfSetupRpt.GridHeader").height());
            return;
        } catch (error) { console.log(error.message); }

        return;
    });
}

//------------------------------------------

function isNumberKey(evt) {
    //alert(10);
    
    var charCode = (evt.which) ? evt.which : evt.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function getenter() {
    if (event.keyCode == 13)// Enter
    {
        
        $("#ctl00_MainContent_Button1").click();
    }
}

function getenterWF() {
    if (event.keyCode == 13)// Enter
    {
        
        document.getElementById('ctl00_MainContent_BtnEntWF').click();
    }
}

//function getenterQM() {
//    if (event.keyCode == 13)// Enter
//    {
//        
//        $("ctl00_MainContent_BtnEntQM").click();
//    }
//}

function getenterQM() {
    if (event.keyCode == 13)// Enter
    {
        
        //document.getElementById('<%=BtnEntQM.ClientID%>').click();
        //ctl00_MainContent_BtnEntQM
        document.getElementById('ctl00_MainContent_BtnEntQM').click();
    }
}

function getenterWB() {
    if (event.keyCode == 13)// Enter
    {
        
        document.getElementById("ctl00_MainContent_BtnEntWB").click();
    }
}

function getenterWUM() {
    if (event.keyCode == 13)// Enter
    {
        
        document.getElementById("ctl00_MainContent_BtnEntWUM").click();
    }
}

function enterKeyEventQBA() {
    if (event.keyCode == 13)
    { document.getElementById("ctl00_MainContent_btnEnterKeyQBA").click(); }
}

function enterKeyEventQBM() {
    if (event.keyCode == 13)
    { document.getElementById("ctl00_MainContent_btnEnterKeyQBM").click(); }
}

function enterKeyEventWEM() {
    if (event.keyCode == 13)
    { document.getElementById("ctl00_MainContent_btnEnterKeyWEM").click(); }
}

function enterKeyEventBUG() {
    if (event.keyCode == 13)
    { document.getElementById("ctl00_MainContent_btnEnterKeyBUG").click(); }
}

function enterKeyEventCUG() {
    if (event.keyCode == 13)
    { document.getElementById("ctl00_MainContent_btnEnterKeyCUG").click(); }
}

function enterKeyEventWBM() {
    if (event.keyCode == 13)
    { document.getElementById("ctl00_MainContent_btnEnterKeyWBM").click(); }
}

function getenterFAC() {
    if (event.keyCode == 13)// Enter
    {
        
        document.getElementById("ctl00_MainContent_BtnEntFAC").click();
    }
}

function getenterAT() {
    if (event.keyCode == 13)// Enter
    {
        
        document.getElementById("ctl00_MainContent_BtnEntAT").click();
    }
}


function bgColour(btn) {

    $(btn).css('border', 'none !important');
}






$(document).ready(function () {
    SetSorting_Filter1();
    SetGridColumnFreeze();

});
var freezeCols, GridX, GridY = 0;

function SetGridColumnFreeze() {
    try {
        freezeCols = 0;
        var TotalWt = 0;
        $('.Grid').find('th').each(function (i, j) {
            wt = $('.GridItem td').eq(i)[0].offsetWidth;
            $(j).css({ "width": wt, "min-width": wt });
            $('.GridItem td').eq(i).css({ "width": wt, "min-width": wt });
            TotalWt += wt;
        })
       
        if ($('.Grid').find('thead').length == 0) {
            $('.Grid').find('thead').remove();
            $('<thead></thead>').insertBefore($('.Grid').find('tbody'));
            $('.Grid').find('thead').append($('.Grid .GridHeader'));
        }

        GridX = ($('.Grid').offset().left + 20);
        if (freezeCols != 0) {
            $('.Grid tbody td:nth-child(1), .Grid tbody td:nth-child(2), .Grid thead th:nth-child(1), .Grid thead th:nth-child(2)').css({ "background-color": "#e6e6e6 !important", "position": "relative", "left": "0px", "border": "solid 3px  #000000 !important" }).addClass("freezeCols");

           }

        $('.Grid tbody').scroll(function (e) {
            $('.Grid thead').css("left", (-1) * Number($(".Grid tbody").scrollLeft()));
            if (freezeCols != 0) {
                $('.Grid tbody td:nth-child(1), .Grid tbody td:nth-child(2), .Grid thead th:nth-child(1), .Grid thead th:nth-child(2)').css({"background-color": "#e6e6e6 !important", "position":"relative", "left": $(".Grid tbody").scrollLeft(), "border":"solid 3px  #000000 !important" }).addClass("freezeCols");
             } 
        });

        GridWH = Number((window.innerWidth - 12) - GridX);
        $('.Grid').prop("width", GridWH + 'px');
        if (($('.Grid')[0].offsetWidth) >= TotalWt) {
            $('.Grid').prop("width", (TotalWt+20) + 'px');
        } else {
             $('.Grid').prop("width", GridWH + 'px');
        }


        GridY = ($('.Grid').offset().top + $('.Grid thead').height()) + 20;
        GridHT = Number(window.innerHeight - 40) - GridY;
        if ($('.Grid  tbody').height() >= GridHT) {
            $('.Grid  tbody').height(GridHT);
        }
       

        $(window).resize(function () {
            GridWH = Number((window.innerWidth - 12) - GridX);
            $('.Grid').prop("width", GridWH + 'px');
            if (($('.Grid')[0].offsetWidth) >= TotalWt) {
                $('.Grid').prop("width", (TotalWt + 20) + 'px');
            } else {
                $('.Grid').prop("width", GridWH + 'px');
            }

            GridY = ($('.Grid').offset().top + $('.Grid thead').height()) + 20;
            GridHT = Number(window.innerHeight - 40) - GridY;
            if ($('.Grid  tbody').height() >= GridHT) {
                $('.Grid  tbody').height(GridHT);
            }
        });
        Sys.WebForms.PageRequestManager.getInstance().remove_endRequest();
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () { SetGridColumnFreeze() });

    } catch (er) { }
}


 