function PromptDialog(obj, title, dialogText) {
    try {
        if ($("#pageName").html() != null) {
            title = "Confirmation - " + $("#pageName").html();
            //alert($("#pageName").html());
        }
        //AkshayD 15-Dec-2021 Distinct name provided for conform box UWI-246
        if (!dialogConfirmed && document.getElementById('UCPdialog') == null) {
            $('html').append(String.Format("<div id='UCPdialog' title='{0}'><p style='float:left;'><span class='ui-icon ui-icon-alert' style='float:left; margin:0 5px 20px 0;'></span>{1}</p></div>",
                title, dialogText));
            //alert("hi " + title);
            $('#UCPdialog').dialog
                ({
                    height: 220,
                    width: 350,
                    modal: true,
                    resizable: false,
                    draggable: true,
                    close: function (event, ui) { $('html').find('#UCPdialog').remove(); },
                    buttons:
                    {
                        'Yes': function () {
                            //  alert("Fsdege");
                            // alert(obj.Text);
                            //$(this).dialog('close');
                            //dialogConfirmed = true;
                            //if (obj) obj.click();
                            //dialogConfirmed = false;
                            //$("#ctl00$MainContent$oUCPCtrl$hdnPrpmptYes").click();
                            // obj.click();
                            //document.getElementById("<%=hdnPrpmptYes.ClientID%>").click();
                            //alert(2)

                            //document.getElementById("#ct100_MainContent_oUCPCtrl_hdnPrpmptYes").click();
                            $("#ctl00_MainContent_oUCPCtrl_hdnPrpmptYes").click();
                            $(this).dialog('close');
                            //  alert("AAA");
                        },
                        'No': function () {
                            //  alert('hyryhjregr');
                            $(this).dialog('close');
                        }
                    }
                });
        }

        return dialogConfirmed;

        $(".ui-widget-overlay").height($("body").height());

    }
    catch (error) {
        //console.log("Error: " + error);
    }
}

var intervalID = 0;

//function UCPTimer1() {

//    var TimeInterval = 1000;

//    if (intervalID != $(".txtIntervalID").val()) {

//        window.clearInterval($(".txtIntervalID").val());
//    } else {
//        window.clearInterval($(".txtIntervalID").val());
//    }

//    intervalID = setTimeout(function () {

//        console.log(intervalID + " + " + $(".txtIntervalID").val());

//        if (intervalID != $(".txtIntervalID").val()) {
//            window.clearInterval($(".txtIntervalID").val());
//            $(".txtIntervalID").val(intervalID);
//        }

//        var t1 = Number($(".lblTimer").text());
//        if (Number(t1 - 1) == 0) {
//            $(".lblTimer").text("00");
//            clearInterval($(".txtIntervalID").val());
//            clearInterval(intervalID);
//            document.getElementById("ctl00_MainContent_oUCPCtrl_btnTimerLapsedUCP").click();
//        }
//        else {
//            $(".lblTimer").text(t1 - 1);
//        }

//        console.log(intervalID + " :: " + $(".txtIntervalID").val());

//    }, TimeInterval);

//}

/*
function UCPTimer() {
    var intervalID_str = 0;
    var Reprice_TimeInterval = 1000;
    
    sIntervalID = localStorage.getItem("intervalID1");

    if (intervalID_str != sIntervalID) {
        if (sIntervalID != "NaN") {
            clearInterval(sIntervalID);
        }
        else {
            clearInterval(intervalID_str);
        }
        localStorage.setItem("intervalID1", intervalID_str);
    }
    intervalID_str = setInterval(function () {
        var TimerVal;
        TimerVal = localStorage.getItem("TimerVal");
        TimerVal = ((TimerVal == "null" || "NaN" ? $(".lblTimer").text() : TimerVal));

        if ((Number(TimerVal)) == 0) {
            $(".lblTimer").text("00");
            window.clearInterval(intervalID_str);
            localStorage.removeItem("TimerVal");
            localStorage.removeItem("intervalID1");
            document.getElementById("ctl00_MainContent_oUCPCtrl_btnTimerLapsedUCP").click();
        }
        else {
            if ((Number(TimerVal) - 1) <= 9) {
                $(".lblTimer").text("0" + (Number(TimerVal) - 1));
            }
            else {
                TimerVal = (Number(TimerVal) - 1);
                $(".lblTimer").text(TimerVal);
            }
        }
        localStorage.setItem("TimerVal", TimerVal);
        localStorage.setItem("intervalID1", intervalID_str);
      
    }, Reprice_TimeInterval);
        }
*/


var intervalID_str;
var sIntervalID;
var Reprice_TimeInterval = 1000;
var TimerVal;

function UCPTimer() {
    try {

        if (intervalID_str != undefined || intervalID_str != null) {
            stopInterval(intervalID_str, sIntervalID);
        }
        timer = $('input[id$="hdnTimerStart"]').val();

        if (timer == "True") {
            console.clear();
            TimerVal = localStorage.getItem("TimerVal");
            TimerVal = Number(TimerVal == null ? Number($(".lblTimer").text()) : TimerVal);
            TimerVal = Number((TimerVal != null) || TimerVal == "NaN" ? Number($(".lblTimer").text()) : Number(TimerVal));
            t = Number($(".lblTimer").text());

            if (TimerVal < t) {
                TimerVal = t;
                localStorage.setItem("TimerVal", TimerVal);
                //$('input[id$="hdntimervalue"]').val = TimerVal
                
                if (sIntervalID != undefined) {
                    clearInterval(sIntervalID);
                }
                if (intervalID_str != undefined) {
                    clearInterval(intervalID_str);
                }
                localStorage.removeItem("intervalID1");


            }

            intervalID_str = setInterval(function () {

                TimerVal = localStorage.getItem("TimerVal");
                TimerVal = Number(TimerVal == null ? Number($(".lblTimer").text()) : TimerVal);
                t = Number($(".lblTimer").text());

                if (TimerVal < t) {
                    TimerVal = t;
                }

                TimerVal = Number((TimerVal != null) || TimerVal == "NaN" ? Number($(".lblTimer").text()) : Number(TimerVal));

                sIntervalID = localStorage.getItem("intervalID1");
                sIntervalID = ((sIntervalID == null ? sIntervalID : Number(sIntervalID)));
                sIntervalID = ((sIntervalID != null || sIntervalID == "NaN") ? Number(sIntervalID) : sIntervalID);

                if (intervalID_str != sIntervalID && sIntervalID != null) {
                    window.clearInterval(sIntervalID);
                    sIntervalID = intervalID_str;
                    localStorage.removeItem("intervalID1");
                    localStorage.setItem("TimerVal", TimerVal);
                    if ($(".lblTimer").text() == "00") {
                        window.clearInterval(sIntervalID);
                        window.clearInterval(intervalID_str);
                    }
                }

                if ((Number(TimerVal)) == 0) {
                    $(".lblTimer").text("00");
                    
                    stopInterval(intervalID_str, sIntervalID);
                    localStorage.removeItem("TimerVal");
                    localStorage.removeItem("intervalID1");
                    //console.log(TimerVal + " : " + intervalID_str + " : " + sIntervalID);
                    $('input[id$="hdnTimerStart"]').val('');
                    document.getElementById("ctl00_MainContent_oUCPCtrl_btnTimerLapsedUCP").click();

                }
                else {

                    TimerVal = Number(TimerVal) - 1;

                    if (Number(TimerVal) < 9) {
                        $(".lblTimer").text("0" + (Number(TimerVal)));
                    }
                    else {
                        $(".lblTimer").text(TimerVal);
                    }
                    localStorage.setItem("intervalID1", intervalID_str);
                    localStorage.setItem("TimerVal", TimerVal);
                }
                //---change colors after 30-20-10
                if (Number(TimerVal) >= 20) {
                    $(".lblTimer").css("color", "#204A87");
                }
                else if (Number(TimerVal) > 10) {
                    $(".lblTimer").css("color", "#4E9A06");
                }
                else if (Number(TimerVal) >= 6) {
                    $(".lblTimer").css("color", "#F4A460");
                }

                else if (Number(TimerVal) <= 5) {
                    $(".lblTimer").css("color", "#B7274C");
                }


            }, Reprice_TimeInterval);
        }
    }
    catch (er) {
        alert(er.message);
    }

    function stopInterval(intervalID_str, sIntervalID) {
        window.clearInterval(intervalID_str);
        window.clearInterval(sIntervalID);

    }


}

function refreshRMW() {
    window.top.$("#ct100_MainContent_btnLoad").click();
}


function HybridInputClass_Filter() {
    $(".HybridInputClass").each(function () {
        var hybridwidth = this.clientWidth;
        var prev = $(this).parent().parent().find('td:first')[0].clientWidth;
        var newwidth = hybridwidth - prev - 14;
        $(this).css('width', newwidth);
    });
}




function CloseWindow(stokenID) {
    // alert('Rohit');
    try {
        $.support.cors = true;
        $.ajax({
            type: "POST",
            url: "../FinIQ_User_Controls/ShareSearch/WebMethod.aspx/CloseWorkflowBlotterPopUP",
            cache: false,
            data: "{'stokenID':'" + stokenID + "'}",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            crossDomain: true,
            async: true,
            complete: function (XMLHttpRequest, textStatus, errorThrown) {
            },
            success: function (data) {
                //alert(data);
                objData = jQuery.parseJSON(data.d);
                $('.tbl_cust1').hide();
                var objData = jQuery.parseJSON(data.d);
                if (objData != null) {
                    if (objData.length === 0) {
                    }
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                try {
                    //console.log(textStatus);

                } catch (er) {
                    //console.log(er.message);
                }
            }
        });
    } catch (er) {
        //console.log(er.message);
    }
}
function CloseIFrame() {

    var lblid = frameElement.parentNode.id;
    //var str = lblid.indexof("_lblLaunchProductInfo");
    //var index = lblid.charAt(str - 1);
    parent.View_OrderEntry(lblid.charAt(lblid.indexOf("_lblLaunchProductInfo") - 1));
    //window.top.$("#ctl00_MainContent_dlProductPriceDetails_ctl0" + cntrl + "_lblLaunchProductInfo");
}
function SetCountDown_Timer() {
    $(document).ready(function () {
        $(".lblTimer").each(function (i, k) {
            TimerControl = (k.id).replace("_lblTimer", "");

            ValidityTime = $("#" + TimerControl + "_hdnValidityTime").val();
            localStorage.removeItem(TimerControl);

            $("#" + TimerControl + "_hdnTimerStart").val("True");
            TimerStart = $("#" + TimerControl + "_hdnTimerStart").val();

            if ($("#" + TimerControl + "_hdnIntervalID").val() != "") {
                clearInterval($("#" + TimerControl + "_hdnIntervalID").val());
                localStorage.removeItem(TimerControl);
            }
            if (TimerStart == "True") {
                Time_CountDown(TimerControl, "", ValidityTime);
            }
            else {
                clearInterval($("#" + TimerControl + "_hdnIntervalID").val());
                localStorage.removeItem(TimerControl);
                $("#" + TimerControl + "_hdnStartTime").val('0');
            }
        });
    });
}

StartTime = "";
function Time_CountDown(TimerControl, StartTime, ValidityTime) {
    try {
        $(document).ready(function () {

            // alert(TimerControl + " : " + $("#" + TimerControl + "_hdnTimerStart").val());
            if ($("#" + TimerControl + "_hdnIntervalID").val() != "") {
                clearInterval($("#" + TimerControl + "_hdnIntervalID").val());
            }
            if ($("#" + TimerControl + "_hdnTimerStart").val() == "True") {
                var iIntervalID = setInterval(function () {
                    try {
                        if (($("#" + TimerControl + "_hdnIntervalID").val() != "") && ($("#" + TimerControl + "_hdnIntervalID").val() != iIntervalID)) {
                            clearInterval($("#" + TimerControl + "_hdnIntervalID").val());
                            localStorage.removeItem(TimerControl);
                        }
                        $("#" + TimerControl + "_hdnIntervalID").val(iIntervalID);
                        if ($("#" + TimerControl + "_lblTimer").text() == "") {
                            if (localStorage.getItem(TimerControl) != null) {
                                ValidityTime = localStorage.getItem(TimerControl);
                            }
                            $("#" + TimerControl + "_lblTimer").text(Number(ValidityTime));
                        }

                        if (Number($("#" + TimerControl + "_lblTimer").text()) == 0) {
                            $("#" + TimerControl + "_lblTimer").text('');
                            clearInterval($("#" + TimerControl + "_hdnIntervalID").val());
                            localStorage.removeItem(TimerControl);

                            $("#" + TimerControl + "_btnSave").attr("disabled", "disabled");
                            $("#" + TimerControl + "_lblTimer").closest(".gbMasterTable").find("input[value='Save']").each(function () {
                                $(this).attr("disabled", "disabled");
                                $(this).prop("disabled", true);
                                $("#" + TimerControl + "_hdnTimerStart").val('False');
                            });
                        }
                        else {
                            $("#" + TimerControl + "_lblTimer").closest(".gbMasterTable").find("input[value='Save']").each(function () {
                                $(this).prop("disabled", false);
                                $(this).removeAttr("disabled");
                            });
                            $("#ctl00_MainContent_btnSave").prop("disabled", "");
                            $("#" + TimerControl + "_btnSave").prop("disabled", "");

                            TimerVal = Number($("#" + TimerControl + "_lblTimer").text()) - 1

                            if (Number(TimerVal) < 10) {
                                $("#" + TimerControl + "_lblTimer").text("0" + (Number(TimerVal)));
                            }
                            else {
                                $("#" + TimerControl + "_lblTimer").text(TimerVal);
                            }

                            localStorage.setItem(TimerControl, TimerVal);

                            if (Number(TimerVal) >= 20) {
                                $("#" + TimerControl + "_lblTimer").css("color", "#204A87");
                            }
                            else if (Number(TimerVal) < 20 && Number(TimerVal) >= 10) {
                                $("#" + TimerControl + "_lblTimer").css("color", "#4E9A06");
                            }
                            else if (Number(TimerVal) < 10 && Number(TimerVal) >= 6) {
                                $("#" + TimerControl + "_lblTimer").css("color", "#F4A460");
                            }

                            else if (Number(TimerVal) <= 5) {
                                $("#" + TimerControl + "_lblTimer").css("color", "#B7274C");
                            }

                        }
                    } catch (er) { alert(er.message); }
                }, 1000)
            }
        });
    } catch (er) { alert(er.message); }
}

// $("input[id$='btnTimerLapsedUCP']").click(); 
function stopInterval(intervalID_str, sIntervalID) {
    $("#" + TimerControl + "_hdnIntervalID").val(iIntervalID);
    window.clearInterval(intervalID_str);
    window.clearInterval(sIntervalID);

}




//Event Fixing Blotter

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
    function () {
        $(document).ready(function () {
            //  alert(1);
            // alert("page req");
            disableListItem();

            setTabSize();
            //alert(wt);



        });

    });

function setTabSize() {
    var wt = 0;

    $(".tabSize").each(function () {
        if ($(this).css('display') == 'block') {
            $(".tabSize").css("width", " 3000px");
            $(this).closest('table').find(' tbody tr:eq(0)').find("th").each(function () {
                if ($(this).is(':visible')) {
                    wt = (wt + 20) + Number($(this).width());
                }
            });
            $(".tabSize").css({ 'width': (wt) + "px" });

        }
    });
}

$(document).ready(function () {
    disableListItem();

});

function disableListItem() {
    $(".lstBox option").each(function () {
        $(this).prop("disabled", true);
    });
}

function setColor(chkBox) {
    //  alert(1);
    var rowspan = $(chkBox).parent().parent().attr("rowspan");
    var a;
    var checkedCount;

    if (document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value == "Pending") {
        checkedCount = parseInt(document.getElementById('<%=hdnCheckedCountPending.ClientID%>').value);
    }
    else if (document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value == "ProcessedSummary") {
        checkedCount = parseInt(document.getElementById('<%=hdnCheckedCountSummary.ClientID%>').value);
    }

    if (typeof (rowspan) == "undefined") {
        a = 1;
    }
    else {
        a = parseInt(rowspan);
    }

    var trpointer = chkBox.parentNode.parentNode.parentNode;

    if (chkBox.checked) {
        checkedCount = checkedCount + 1;
        for (var i = 0; i < a; i++) {
            $(trpointer).css("background-color", "#f6f6f6");
            trpointer = $(trpointer).next();
        }
    }
    else {
        checkedCount = checkedCount - 1;
        for (var i = 0; i < a; i++) {
            $(trpointer).css("background-color", "");
            trpointer = $(trpointer).next();
        }
    }

    if (document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value == "Pending") {
        document.getElementById('<%=hdnCheckedCountPending.ClientID%>').value = checkedCount;
    }
    else if (document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value == "ProcessedSummary") {
        document.getElementById('<%=hdnCheckedCountSummary.ClientID%>').value = checkedCount;
    }
    document.getElementById('<%=btnsetCheckedRowCount.ClientID%>').click();

}

function showMsg() {
    setTimeout(function () { $("#showMsg").fadeOut(300); }, 1000)
    $('#showMsg').show();
    setTimeout(function () { $("#showMsg").fadeOut(300); }, 1000)
}


function CreateTabs() {
    $(document).ready(function () {
        try {

            $("div[id$=tabs]").tabs();
            //  $("#ctl00_MainContent_oUCPEventFixingBlotter_tabs").tabs();
            if ($("[id$=hdnSelectedTab]") != null) {

                index = $("[id$=hdnSelectedTab]").val(); //document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTab').value;
            }
            else {
                index = 0;
            }
            CurrentTab($("[id$=hdnSelectedTab]").val());
        } catch (er) {
            //console.log(er.message);
        }
    });
}

function tabPendingClicked() {

    CurrentTab("0");
    // document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value = "Pending";
    // document.getElementById('<%=btnPending.ClientID%>').click();
    $("[id$=_hdnSelectedTabName]").val("Pending");
    document.getElementById($("[id$=btnPending]").attr("id")).click();
}

//not used therefore, ProcessedSummary is 3
function tabPreviewClicked() {
    CurrentTab("3");
    // document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value = "Preview";
    // document.getElementById('<%=btnPreview.ClientID%>').click();
    $("[id$=_hdnSelectedTabName]").val("Preview");
    document.getElementById($("[id$=btnPreview]").attr("id")).click();
}

function tabProcessedSummary() {

    try {
        CurrentTab("1");
        //document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value = "ProcessedSummary";
        // document.getElementById('<%=btnProcessedSummary.ClientID%>').click();
        $("[id$=_hdnSelectedTabName]").val("ProcessedSummary");
        document.getElementById($("[id$=btnProcessedSummary]").attr("id")).click();
    } catch (er) {
        //console.log(er.message);
    }

}

function tabVerifiedClicked() {
    CurrentTab("2");
    // document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTabName').value = "Verified";
    $("[id$=_hdnSelectedTabName]").val("Verified");
    // document.getElementById('<%=btnVerified.ClientID%>').click();
    document.getElementById($("[id$=btnVerified]").attr("id")).click();
}

function CurrentTab(index) {
    $(document).ready(function () {
        try {

            //  document.getElementById('<%=hdnSelectedTab.ClientID%>').value = index
            $("[id$=hdnSelectedTab]").val(index);
            //  document.getElementById('ctl00_MainContent_oUCPEventFixingBlotter_hdnSelectedTab').value = index
            $("div[id$=tabs]").tabs({ active: $("[id$=hdnSelectedTab]").val() });
        } catch (er) {
            //console.log(er.message);
        }
    });

}

function hideTab(index) {
    //
    if (index == 0) {
        var element = $("[id$=lnkPending]").attr("id");//document.getElementById('<%=lnkPending.ClientID%>');
        element.parentNode.removeChild(element);
    }
    else if (index == 1) {
        var element = $("[id$=lnkProcessedSummary]").attr("id");// document.getElementById('<%=lnkProcessedSummary.ClientID%>');
        element.parentNode.removeChild(element);
    }
    else {
        var element = $("[id$=lnkVerified]").attr("id");// document.getElementById('<%=lnkVerified.ClientID%>');
        element.parentNode.removeChild(element);
    }
    CreateTabs()
    //$("#ctl00_MainContent_oUCPEventFixingBlotter_tabs").tabs({ active: document.getElementById('<%= hdnSelectedTab.ClientID %>').value });
}

function txtUnderlyingKeydown(e) {
    if (e.keyCode == 13) {
        //document.getElementById('<%=btnLoad.ClientID%>').click();
        $("#ctl00_MainContent_btnLoad").focus();
    }
}

function txtTradeKeydown(e) {
    if (e.keyCode == 13) {
        //document.getElementById('<%=BtnSearch.ClientID%>').click();
        $("#ctl00_MainContent_btnLoad").focus();
    }
}

function txtFilterKeydown(e) {
    if (e.keyCode == 13) {
        //document.getElementById('<%=btnFiltersSearch.ClientID%>').click(); 
        $("#ctl00_MainContent_btnLoad").focus();
    }
}

function AllowNumericOnly(e) {
    var keycode;
    if (window.event)
        keycode = window.event.keyCode;
    else if (event)
        keycode = event.keyCode;
    else if (e)
        keycode = e.which;
    else return true;
    if ((keycode > 47 && keycode <= 57)) { return true; }
    else { return false; } return true;
}

function TxRowsPerPage_TextChanged(e) {
    if (e.keyCode == 13) {
        $("#ctl00_MainContent_btnLoad").focus();

    }
    else if (event.keyCode >= 48 && event.keyCode <= 57)
        return;
}


function AllowAlphaNumericAndDotOnly(e) {
    var keycode;
    if (window.event)
        keycode = window.event.keyCode;
    else if (event)
        keycode = event.keyCode;
    else if (e)
        keycode = e.which;
    else return true;
    //  alert(keycode);
    if ((keycode >= 48 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) || (keycode == 46)) { return true; }
    else { return false; } return true;
}

function confirmDialog() {
    $("#dialog-confirm").dialog({
        resizable: false,
        height: "auto",
        width: 400,
        modal: true,
        buttons: {
            "Yes": function () {
                $(this).dialog("close");
                hdnBtnProcessClicked();
            },
            No: function () {
                $(this).dialog("close");
            }
        }
    });
}

function hdnBtnProcessClicked() {
    document.getElementById($("[id$=hdnProcessButton]").attr("id")).click();
    //document.getElementById('<%=hdnProcessButton.ClientID%>').click();
}

function ClosePayOffSubGridRuleSchedule(closeBtnId) {

    //alert($(closeBtnId).closest("tr").prop("id"));
    $("#ctl00_MainContent_UCPPayoff_hdnViewRuleSchedule").val(($(closeBtnId).closest("tr").prop("id")))
    $(closeBtnId).closest("tr").remove();
    ($("#ctl00_MainContent_UCPPayoff_removeSession")).click()
}


function ClosePayOffSubGridRuleDetails(closeBtnId) {

    //alert($(closeBtnId).closest("tr").prop("id"));
    $("#ctl00_MainContent_UCPPayoff_hdnViewRuleDetails").val(($(closeBtnId).closest("tr").prop("id")))
    $(closeBtnId).closest("tr").remove();
    ($("#ctl00_MainContent_UCPPayoff_removeSession")).click()
}





//function ClosePayOffSubGridRuleDetails(closeBtnId) {
//      
//    alert($(closeBtnId).closest("tr").prop("id"));
//    $("#ctl00_MainContent_UCPPayoff_hdnViewRuleDetails").val(($(closeBtnId).closest("tr").prop("id")))
//    $(closeBtnId).closest("tr").remove();
//    ($("#ctl00_MainContent_UCPPayoff_removeRuleDetails")).click()
//}







function PayOffSubGridSchedule(lnkId, ShowGridList, lnkId1, ShowGridList1) {



    if (lnkId !== "") {
        var i;
        var str = ShowGridList;
        var res = str.split(",");

        if (res.length > 0) {
            for (i = 0; i < res.length; i++) {

                $("#" + res[i]).closest("tr").after('<tr id=' + res[i] + '><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top;"><input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGridRuleSchedule(this);" /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + res[i]).next().html() + '</td></tr>');
            }
        }

        //alert(lnkId);
        // $("#" + lnkId).closest("tr").after('<tr><td><input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGrid(this);  style="font-size: 10px !important;     height: 15px !important; padding-top: 0px !important;"" /></td><td colspan = "999">' + $("#" + lnkId).next().html() + '</td></tr>')


        var str1 = ShowGridList1;
        var res1 = str1.split(",");

        if (res1.length > 0) {
            for (i = 0; i < res1.length; i++) {
                //alert(res1[i]);
                $("#" + res1[i]).closest("tr").after('<tr id=' + res1[i] + '><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top;"> <input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGridRuleDetails(this);" /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + res1[i]).next().html() + '</td></tr>');

            }
        }


    }
    else {

        var str1 = ShowGridList1
        var res1 = str1.split(",");

        var str = ShowGridList
        var res = str.split(",");

        if (res.length > 0) {
            for (i = 0; i < res.length; i++) {
                // alert(res[i]);
                $("#" + res[i]).closest("tr").after('<tr id=' + res[i] + ' ><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top;"><input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGridRuleSchedule(this);" /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + res[i]).next().html() + '</td></tr>')
            }
        }



        if (res1.length > 0) {
            for (i = 0; i < res1.length; i++) {
                $("#" + res1[i]).closest("tr").after('<tr id=' + res1[i] + '><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top;"><input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGridRuleDetails(this);" /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + res1[i]).next().html() + '</td></tr>');
            }

            // $("#" + lnkId1).closest("tr").next().after('<tr><td><input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGrid(this);  style="font-size: 10px !important;     height: 15px !important; padding-top: 0px !important;"" /></td><td colspan = "999">' + $("#" + lnkId1).next().html() + '</td></tr>')
        }

    }

}




function PayOffSubGridUpdate(lnkId, ShowGridList, lnkId1, ShowGridList1) {




    var i;
    var str = ShowGridList;
    var res = str.split(",");

    if (res.length > 0) {
        for (i = 0; i < res.length; i++) {

            $("#" + res[i]).closest("tr").after('<tr id=' + res[i] + '><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top;"><input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGridRuleSchedule(this);" /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + res[i]).next().html() + '</td></tr>');
        }
    }


    var str1 = ShowGridList1;
    var res1 = str1.split(",");

    if (res1.length > 0) {
        for (i = 0; i < res1.length; i++) {
            //alert(res1[i]);
            $("#" + res1[i]).closest("tr").after('<tr id=' + res1[i] + '><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top; ">  <input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGridRuleDetails(this);" /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + res1[i]).next().html() + '</td></tr>');

        }
    }





}



function PayOffSubGridRuleDetails(lnkId, ShowGridList) {




    var str = ShowGridList
    var res = str.split(",");


    for (i = 0; i < res.length - 1; i++) {
        //alert(res[i]);
        $("#" + res[i]).closest("tr").after('<tr><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top;"><input type="button" value="X" class="CloseDetails " onclick="ClosePayOffSubGrid(this);" /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + res[i]).next().html() + '</td></tr>')

    }

    $("#" + lnkId).closest("tr").after('<tr><td style="padding:10px; border-width:1px;border-color: #e6e6e6;vertical-align:top;"><input type="button" value="X" class="CloseDetails" onclick="ClosePayOffSubGrid(this); " /></td><td colspan = "999" style="padding:20px; border-width:1px;border-color: #e6e6e6;vertical-align:top;">' + $("#" + lnkId).next().html() + '</td></tr>')

}

function CreatePTCCFrame() {


    $('html').append(String.Format("<div id='dialogPTCC'><p><iframe id = 'PTCC_iframe' allowfullscreen></iframe></p></div>"));
    $('#dialogPTCC').dialog
        ({
            height: "auto",
            width: "auto",
            top: "250px",
            left: "1000px",
            modal: true,
            resizable: false,
            draggable: true,
            close: function (event, ui) { $('html').find('#dialogPTCC').remove(); },
            buttons: false,
            //dialogClass: "myClass"

        });


    var PTCC_iframe = document.getElementById('PTCC_iframe');
    PTCC_iframe.setAttribute('src', PTCCRespobj.sa_url.toString());
    PTCC_iframe.style.width = 1000 + 'px';
    PTCC_iframe.style.height = 600 + 'px';
    PTCC_iframe.style.top = 250 + 'px';
    PTCC_iframe.style.left = 1000 + 'px';
    $('#dialogPTCC').css("top: 263.5px");
    $('#dialogPTCC').css("left: 419px");
    //PTCC_iframe.setAttribute('style', 'position: absolute !important; left: 1000px; top: 260px; z-index: 10;');
};

$(".ui-widget-overlay").height($("body").height());



//var PTCC_Div = document.createElement('div');
//PTCC_Div.setAttribute('id', 'PTCC_Div');
//PTCC_Div.setAttribute('style', 'position: absolute !important; left: 40vh; top: 30vh; z-index: 10;');





//var PTCC_iframe = document.createElement('iframe');
//PTCC_iframe.setAttribute('src', PTCCRespobj.sa_url.toString());
//PTCC_iframe.setAttribute('id', 'PTCCFrame');
//PTCC_iframe.setAttribute('style', 'border-color:navy;');
//PTCC_iframe.style.width = 1000 + 'px';
//PTCC_iframe.style.height = 600 + 'px';


//document.body.appendChild(PTCC_Div);

//$("#PTCC_Div").append(PTCC_iframe);


//var PTCCClose_Div = document.createElement('button');
//PTCCClose_Div.setAttribute('id', 'CloseButton');
//PTCCClose_Div.style.width = 30 + 'px';
//PTCCClose_Div.style.height = 30 + 'px';
//PTCCClose_Div.onclick = function () {
//    var frame = document.getElementById("PTCC_Div");
//    frame.parentNode.removeChild(frame);
//};

//$("#PTCC_Div").append(PTCCClose_Div);


function PTCC_Click(sTargetField, Param1, Param2, Param3, Param4, Param5, Param6, Param7) {
    try {
        //console.log(" PTCC Check Function START");

        JsonRequest = Param1;
        ReqJsonDataSPA = Param2;
        iurltext = Param4;
        URISPA = Param5;
        TAPEupdateURL = Param6;
        OrderUpdateURL = Param7;
        OrdJsonData = Param3;
        UCPTargetField = sTargetField;
        bindEvent(window, eventNameValue, PTCCEventHandler);
        CreateGUID();
        POSTToServer(sTargetField, ReqJsonDataSPA, JsonRequest);
        CreatePTCCFrame();

    }
    catch (exception) {
    }
};

//var ReqJsonDataSPA = { "ProductID": "1", "ProductCode": "DCD", "ProductGroupCode": "1", "UserID": "", "EntityID": "4", "RequestId": "", "iJSONRequest": "", "SPAurl": "" };
var ReqJsonDataSPA = '';
var OrdJsonData = '';
//var OrdJsonData = { "RequestId": "", "TradeID": "", "UserID": "" };
var iurltext = "";
var JsonRequest = '';
//var JsonRequest = "{\"UserID\":\"\",\"Execution_Type\":\"\",\"Direction\":\"\",\"Product\":\"\",\"Sub_product_type\":\"\",\"Portfolio_ID\":\"\",\"Maturity_Date\":\"\",\"Trade_Notional_Value_Buy\":\"\",\"Trade_Notional_Value_Sell\":\"\",\"Buy_Currency\":\"\",\"Sell_Currency\":\"\",\"Spread\":\"\",\"DDC_Flag\":\"\",\"Product_indicator\":\"\",\"Gearing_Leverage\":\"\",\"Gearing_notional\":\"\" }";
var ptcclinkflag = false;
var URISPA = "";
var userdata = "";
var TAPEupdateURL = "";
var OrderUpdateURL = "";
var removecheck = false;
var UCPTargetField = '';


var PTCCButton;
var QuoteBtn;
var TradeBtn;
var PTCCStatus;
var TimerLabel;
var Timervalue;
var checkSoftBlockStatus = false;
var PTCCRespobjval;
var PTCCRespobj;
var modal;
var close;
var usertext;
var timeoutHandle;
var uridata;
var GUIDString;
var RequestID;
var Resetbtn;
var PTCC_iframe;
var eventNameValue = 'message'; // Make this configurable. This is the event name from PTCC after clicking submit button on iframe.







function CreateGUID() {
    
    var currentdate = new Date();
    var rand = Math.round((Math.random() * (9999 - 1000) + 1000)).toString();
    GUIDString = currentdate.getFullYear() + "" + (currentdate.getMonth() + 1) + "" + currentdate.getDate() + "" + currentdate.getHours() + "" + currentdate.getMinutes() + "" + currentdate.getSeconds() + rand;
};



function StartTimer() {

    document.getElementById('timer').innerHTML = 15 + ":" + 00;
    startTimer();

    function startTimer() {
        var presentTime = document.getElementById('timer').innerHTML;
        var timeArray = presentTime.split(/[:]+/);
        var m = timeArray[0];
        var s = checkSecond((timeArray[1] - 1));
        if (s == 59) { m = m - 1 }
        if (m < 0) { m = 0; s = "00"; onLoad(); }

        document.getElementById('timer').innerHTML =
            m + ":" + s;
        timeoutHandle = setTimeout(startTimer, 1000);
    }

    function checkSecond(sec) {
        if (sec < 10 && sec >= 0) { sec = "0" + sec }; // add zero in front of numbers < 10
        if (sec < 0) { sec = "59" };
        return sec;
    }

};

//function onHardBlock(PTCCRespobj) {


//    POSTTAPEREQUEST();
//    checkSoftBlockStatus = true;
//    // TODO remove
//    //QuoteBtn.disabled = false;
//    //TradeBtn.disabled = true;
//    // $("#myModal").modal();
//};

//function onNoBlock(PTCCRespobj) {
//    //alert("noblock");
//    checkSoftBlockStatus = true;
//    //QuoteBtn.disabled = false;
//    //TradeBtn.disabled = false;
//};

//function onSoftBlock(PTCCRespobj) {
//    POSTTAPEREQUEST();

//    checkSoftBlockStatus = true;
//    // $("#myModal").modal();
//};

function bindEvent(element, eventName, eventHandler) {
    if (element.addEventListener) {
        element.addEventListener(eventName, function (e) {

            var p2 = "working";
            eventHandler(e.data, p2);
        });
    } else if (element.attachEvent) {
        element.attachEvent('on' + eventName, function (e) {

            var p2 = "working";
            eventHandler(e.data, p2);
        });
    }

};




function POSTToServer(sTargetField, ReqJsonDataSPA, JsonRequest) {
    JsonRequest = JSON.parse(JsonRequest);
    ReqJsonDataSPA = JSON.parse(ReqJsonDataSPA);
    ReqJsonDataSPA.iJSONRequest = JSON.stringify(JsonRequest);
    ReqJsonDataSPA.UserID = userdata;
    ReqJsonDataSPA.SPAurl = URISPA;
    ReqJsonDataSPA.RequestId = GUIDString;
    //console.log(JSON.stringify(ReqJsonDataSPA));

    var settings = {
        async: false,
        crossDomain: true,
        url: iurltext,
        method: "POST",
        contentType: "application/json",
        data: JSON.stringify(ReqJsonDataSPA)

    }
    $.ajax(settings).done(function (response) {

        PTCCRespobj = JSON.parse(JSON.stringify(response));
        //console.log(response);
        ptcclinkflag = true;
        $('#ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).val(JSON.stringify(response));
        $('#ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).change();

        //Post for authentication
        var settings = {
            async: false,
            crossDomain: true,
            url: PTCCRespobj.sa_url.toString(),
            type: "POST",
            contentType: "text/plain",
            data: "GUIID = " + PTCCRespobj.GUIID.toString()
        }
        $.ajax(settings).done(function (response) {
        });
        //console.log("Authentication done.");

        switch (PTCCRespobj.sa_status.toString().toUpperCase()) {

            case "HARD BLOCK":
                POSTTAPEREQUEST();
                break;

            case "PENDING ATTESTATION":
                POSTTAPEREQUEST();
                break;

            case "PENDING IRR":
                POSTTAPEREQUEST();
                break;

            case "COMPLETED WITH REMINDER":
                POSTTAPEREQUEST();
                break;

            case "COMPLETED":
                EnableQuoteBtn();
                break;

            default:
                break;
        };

    });
};


function POSTTAPEREQUEST() {
    var ReqJsonDataTAPE1 = { "ProductCode": "ELN", "ProductGroupCode": "1", "UserID": "", "EntityID": "1", "RequestId": "", "iTAPERequest": "" };//productCode =?
    ReqJsonDataTAPE1.UserID = userdata;
    ReqJsonDataTAPE1.RequestId = GUIDString;
    var settings = {
        async: false,
        crossDomain: true,
        url: TAPEupdateURL,
        method: "POST",
        contentType: "application/json",

        processData: false,
        data: JSON.stringify(ReqJsonDataTAPE1)
    }
    $.ajax(settings).done(function (response) {
    });
};

//Add Trade Reference ID as input to function POSTToServerOrder
function POSTToServerOrder() {
    OrdJsonData.TradeID = "ORD_" + GUIDString;
    OrdJsonData.RequestId = GUIDString;
    var settings = {
        async: false,
        crossDomain: true,
        url: OrderUpdateURL,
        method: "POST",

        contentType: "application/json",

        processData: false,
        data: JSON.stringify(OrdJsonData)
    }
    $.ajax(settings).done(function (response) {
    });
};


//function GetTAPEAuth() {
//    // PTCCRespobj.GUID.toString();
//    //console.log(ReqJsonDataTAPEAuth);
//    var settings = {
//        async: false,
//        crossDomain: true,
//        //"url": PTCCRespobj.sa_url + PTCCRespobj.GUID.toString() ,
//        url: 'http://localhost/PTCCApi/api/PTCCControl/1',
//        method: "GET",

//    }
//    $.ajax(settings).done(function (response) {
//    });
//};




function PTCCEventHandler(eventData, localvar) {
    //console.log(localvar);
    responseJSON = JSON.parse(eventData);

    var ReqJsonDataTAPE = { "ProductCode": "ELN", "ProductGroupCode": "1", "UserID": "", "EntityID": "0", "RequestId": "", "iTAPERequest": "" }; //productCode =?
    ReqJsonDataTAPE.UserID = userdata;
    ReqJsonDataTAPE.iTAPERequest = JSON.stringify(eventData);
    ReqJsonDataTAPE.RequestId = GUIDString;
    var settings = {
        async: false,
        crossDomain: true,
        url: TAPEupdateURL,
        method: "POST",
        contentType: "application/json",

        processData: false,
        data: JSON.stringify(ReqJsonDataTAPE)
    }

    $.ajax(settings).done(function (response) {


        PTCCRespobj = JSON.parse(JSON.stringify(response));

    });

    if (responseJSON.PTCC_STATUS.toString().toUpperCase() !== "HARD BLOCK") {

        //document.getElementById('ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).focus();
        $('#ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).val(JSON.stringify(responseJSON));
        $('#ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).change();
        //document.getElementById('ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).blur();
        // __doPostBack(document.getElementById('ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).id, "TextChanged");
        //document.getElementById('ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl0' + UCPTargetField).onchange();



        //  document.getElementById("ctl00_MainContent_oUCPCtrl_btnPTCCClick").click()

        UCPTargetField = '';
        //$('#ctl00_MainContent_oUCPCtrl_dgvCustCpty_ctl02_clmnCustomerRemark').val(JSON.stringify(responseJSON));

    }
    $('html').find('#dialogPTCC').remove();
};





var sendMessageToPTCC = function (msg) {
    PTCC_iframe.contentWindow.postMessage(msg, '*');
};

function OpenWFL(control) {
    try {
        //var notemasterid = $("#" + control.id).attr('NoteMasterId');
        var notemasterid = $("#" + control.id).html();
        //Function Added by MohiniM || 14-Jan-2021 ||For Fees tab Manual link -start
        if (notemasterid === '' || notemasterid === undefined || notemasterid === null || notemasterid == 'Manual')
            //Function Added by MohiniM || 14-Jan-2021 ||For Fees tab Manual link -start
            return false;

        var iframe = $('<iframe src="../UCP/FinIQ_UCPDealEntry.aspx?WorkflowMode=UCPWFL&NoteMasterID=N:' + notemasterid + '&Master_Popup=POPUP#navpanes=0&toolbar=0&statusbar=0&scrollbar=1&pagenum=1&view=fitH,0"></iframe>');

        $("<div></div>").append(iframe).appendTo("body").dialog({
            height: 800,
            width: 1200,
            modal: false,
            resizable: true,
            draggable: true,
            autoOpen: true,
            bgiframe: true,
            close: function () { $('html').find('#collDialog').html(); },
            open: function () { $('html').find('#collDialog').html(''); }
        });

        element = $('body > .ui-dialog');
        if (element.length > 0) {
            element[element.length - 1].style.left = 40;
            element[element.length - 1].style.top = 20;
        }

        return false;
    }
    catch (error) {
        throw (error);
    }
}

//Function Added by MohiniM || 20-Jan-2021 ||For duplicate validation for fees tab - Feedescription -start
//Function Added by MohiniM || 14-Jan-2021 ||For duplicate validation for fees tab - Feedescription -start

//Function changes by MohiniM || 18-Jan-2021 ||For duplicate validation for fees tab - Feedescription -start
function Validateduplicate(ddlDescription) {
    
    var countduplicate = 0;
    //if (ddlDescription.includes("gvFees")) {
    if(ddlDescription.type == undefined){
    var gridview = document.getElementById(ddlDescription);
        if (gridview != null)
        {
            var inputlist = gridview.parentElement.getElementsByClassName("description");
            for (var i = 0; i < inputlist.length; i++) {
                if (inputlist[inputlist.length - 1].children[0].selectedOptions[0].value == inputlist[i].children[0].selectedOptions[0].value) {
                    countduplicate = countduplicate + 1;
                }
            }
        }  
    }
    else {
        var row = ddlDescription.parentNode.parentNode.parentNode;
        var inputlist = row.getElementsByClassName("description");  
        for (var i = 0; i < inputlist.length; i++) {
            if (ddlDescription.selectedOptions[0].value == inputlist[i].children[0].selectedOptions[0].value) {
                //if (ddlDescription.selectedOptions[0].text == inputlist[i].children[0].innerText) {
                countduplicate = countduplicate + 1;
            }
        }
        if (countduplicate <= 1)
        {
            if (ddlDescription.id.includes('FeesGrid1')) {
                if (ddlDescription.selectedOptions[0].value == $('#ctl00_MainContent_oUCPFeesTab_IDFeesGrid1_hdnresidencyTemplate').val()) {
                    if ($('#ctl00_MainContent_oUCPFeesTab_IDFeesGrid1_hdncustresidency').val() != 1) {
                        //$('#ctl00_MainContent_oUCPFeesTab_lblError').html('VAT is not applicable for Non Resident Customer.');
                        MsgDialog_Fees(this, "Warning", 0, "VAT is not applicable for Non Resident Customer.");
                        document.getElementById("ctl00_MainContent_oUCPFeesTab_btnSave").disabled = true;
                    }
                    else {
                        document.getElementById("ctl00_MainContent_oUCPFeesTab_btnSave").disabled = false;
                    }
                }
                else {
                    document.getElementById("ctl00_MainContent_oUCPFeesTab_btnSave").disabled = false;
                }
            }
            else {
                document.getElementById("ctl00_MainContent_oUCPFeesTab_btnSave").disabled = false;
            }
        }
    }
    if(countduplicate > 1)
    {
        //$('#ctl00_MainContent_oUCPFeesTab_lblError').html('Fee description already added.');
        MsgDialog_Fees(this, "Warning", 0, "Fee already exists.");

        document.getElementById("ctl00_MainContent_oUCPFeesTab_btnSave").disabled = true;
    }
    else
    {
        document.getElementById("ctl00_MainContent_oUCPFeesTab_btnSave").disabled = false;
    }
}
//Function changes by MohiniM || 14-Jan-2021 ||For duplicate validation for fees tab - Feedescription -End

function MsgDialog_Fees(obj, title, x, dialogText) {

    try {
        var activeElement = sessionStorage.getItem('focusItem');
        console.log(title);
        console.log(dialogText);

        if (!dialogConfirmed) {
            console.log("dialog1");

            if (x === 1) {
                if ($("#pageName").html() != null) {
                    title = "Information - " + $("#pageName").html();
                }
                console.log("x=1");
                //changes by  MohiniM || 18-Feb-2021 || Added for msg padding issue.
                //changes by  MohiniM || 19-Mar-2021 || Added for image alignment .-start
                $('html').append(String.Format("<div id='dialog1' title='{0}'><table cellpadding='2' cellspacing='0' style='padding-top:40px !important;'><tr><td style='padding:10px;padding-bottom: 35px;'><img src='../App_Themes/images/imgSuccess.png' style='width:18px;height:18px;'></td><td><p style='float:left;color:#008000;'><span style='float:left;margin:0 0 20px 0;'></span>{1}</p></td> </tr></table></div>",
                               title, dialogText));
                //changes by  MohiniM || 19-Mar-2021 || Added for image alignment .-End

                var x = $('html');


            }
            else if (x === 0) {
                if ($("#pageName").html() != null) {
                    title = "Warning - " + $("#pageName").html();
                }
                //changes by  MohiniM || 18-Feb-2021 || Added for msg padding issue.
                //changes by  MohiniM || 19-Mar-2021 || Added for image alignment .-start
                $('html').append(String.Format("<div id='dialog1' title='{0}'><table cellpadding='2' cellspacing='0' style='padding-top:40px !important;'><tr><td style='padding:10px;padding-bottom: 35px;'><img src='../App_Themes/images/Warning_Msg.png' style='width:18px;height:18px;'></td><td><p style='float:left;color:#0368b6;'><span style='float:left;margin:0 0 20px 0;'></span>{1}</p></td> </tr></table></div>",
                               title, dialogText));
                //changes by  MohiniM || 19-Mar-2021 || Added for image alignment .-End
                console.log("x=0");

            }
            $('#dialog1').dialog
                    ({
                        height: 180,
                        width: 350,
                        modal: true,
                        resizable: false,
                        draggable: true,
                        close: function (event, ui) {
                            $(document).find("#" + activeElement).focus();
                            $('html').find('#dialog1').remove();
                        },
                        buttons:
                        {

                            'OK': function () {
                                $(this).dialog('close');
                            }
                        }
                    });
        } $('button:last').focus();


        return dialogConfirmed;

        $(".ui-widget-overlay").height($("body").height());

    }
    catch (error) {
        console.log("Error: " + error);
    }
}
//Function Added by MohiniM || 14-Jan-2021 ||For duplicate validation for fees tab - Feedescription -start
//Function Added by MohiniM || 20-Jan-2021 ||For duplicate validation for fees tab - Feedescription -start

//Functions added for Entitlements tab || 03-Mar-2021 || Prachi --<start>
function LaunchPopupScreen(Path, Height, Width, Top, Left, OpenMode) {
    try {
        if (OpenMode === "IFRAME") {
            var iframe = $('<iframe src="' + Path + '"OpenPopup","height="' + Height + '", width="' + Width + '", status="no",resizable="yes",toolbar="no",scrollbars="no",menubar="no", frameborder="0", marginwidth="0", marginheight="0"></iframe>');

            $("<div></div>").append(iframe).appendTo("body").dialog({
                height: Height,
                width: Width,
                modal: true,
                resizable: true,
                draggable: true,
                autoOpen: true,
                bgiframe: true,
                close: function () { $('html').find('#collDialog').html(); },
                open: function () { $('html').find('#collDialog').html(''); }
            });

            element = $('body > .ui-widget-overlay');
            if (element.length > 0) {
                element[0].style.height = $(window).height();
            }

            element = $('body > .ui-dialog');
            if (element.length > 0) {
                element[element.length - 1].style.left = Left;
                element[element.length - 1].style.top = Top;
            }
        }
        else {
            window.open(Path, 'PopupScreen' + Math.random(), 'top=' + Top + ',left=' + Left + ',status= no, resizable=yes, scrollbars=yes, toolbar=no,width=' + Width + ',height=' + Height + '');
        }
    } catch (e) {
        throw (e);
    }
}

var dialogConfirmed = false;

function confirmationDialog(obj, title, dialogText) {
    try {
        if ($("#pageName").html() != null) {
            title = "Confirmation - " + $("#pageName").html();
        }

        $('body').find("#dialog").remove();

        if (!dialogConfirmed) {

            $('html').append(String.Format("<div id='dialog' title='{0}'><p style='float:left;'><span class='ui-icon ui-icon-alert' style='float:left; margin:0 5px 20px 0;'></span>{1}</p></div>",
                title, dialogText));

            $('#dialog').dialog
                ({
                    height: 180,
                    width: 350,
                    modal: true,
                    resizable: false,
                    draggable: true,
                    close: function () { $('html').find('#dialog').remove(); },
                    buttons:
                    {
                        'Yes': function () {
                            $(this).dialog('close');
                            dialogConfirmed = true;
                            if (typeof obj === 'string' || obj instanceof String) {
                                if (obj) $('[id$="' + obj + '"]').click();
                                dialogConfirmed = false;
                            }
                            else {

                                if (obj) obj.click();
                                dialogConfirmed = false;

                            }
                        },
                        'No': function () {
                            $(this).dialog('close');
                        }
                    }
                });
        }

        return dialogConfirmed;
    }
    catch (error) {
        console.log("Error: " + error);
    }
}
//Functions added for Entitlements tab || 03-Mar-2021 || Prachi --<end>

//Functions Added by MohiniM || 18-Oct-2021 || MASINT-2249 -start
//Functions Added by MohiniM || 13-May-2021 || Checkbox Functions -start
function Check_Click(chkBox) {
    //debugger;
    var row = chkBox.parentNode.parentNode.parentNode;
    var GridView = row.parentNode;
    var selectedCustomer = chkBox.parentNode.parentNode.getElementsByClassName("customerId")[0].innerText.replace(/[ \n]/g, '');
    var inputList = GridView.getElementsByTagName("input");
    var chkcount = 0;
    var totalchkcount = 0;
    for (var i = 0; i < inputList.length; i++) {
        if (inputList[i].id.includes("txtCIFSearch")) {
            if (inputList[i].value == chkBox.parentNode.parentNode.getElementsByTagName("input")[1].value) {
                if (inputList[i - 1].type == "checkbox" && !inputList[i - 1].id.includes("chkAll")) {
                    inputList[i - 1].checked = chkBox.checked;
                    chkcount = chkcount + 1;
                }
            }
            totalchkcount = totalchkcount + 1;
        }
    }

    if (inputList[0].id.includes("chkAll")) {
        if (totalchkcount == chkcount) {
            if (chkBox.checked) {
                inputList[0].checked = true;
            }
            else {
                inputList[0].checked = false;
            }
        }
        else {
            inputList[0].checked = false;
        }
    }
}

function checkAll(chkAll) {
    debugger;
    var GridView = chkAll.parentNode.parentNode.parentNode.parentNode;
    var inputList = GridView.getElementsByTagName("input");

    for (var i = 0; i < inputList.length; i++) {

        var row = inputList[i].parentNode.parentNode;
        if (inputList[i].type == "checkbox" && chkAll != inputList[i]) {
            if (chkAll.checked) {
                inputList[i].checked = true;
            }
            else {
                inputList[i].checked = false;
            }
        }
    }
}

//Functions Added by MohiniM || 18-Oct-2021 || MASINT-2249 -End
//Functions Added by MohiniM || 13-May-2021 || Checkbox Functions -End

//Functions Added by MohiniM || 16-Aug-2021 || Remove Fee Function -start
//function RemoveFees(btnremove) {
    function RemoveFees() {
    try {
        //debugger;
        //var feedescriptionID = btnremove.id.replace("btnDelete", "ddlFeeDescription");
        //var selectedFeeDesc = document.getElementById(feedescriptionID).selectedOptions[0].value   
        //document.getElementById("ctl00_MainContent_oUCPFeesTab_hdnremoveFeedesc").value = selectedFeeDesc
        //document.getElementById("ctl00_MainContent_oUCPFeesTab_btnremove").click();
        document.getElementById("ctl00_MainContent_oUCPFeesTab_btnLoad").click();
    }
    catch (ex) {
        throw ex;
    }
}
//Functions Added by MohiniM || 16-Aug-2021 || Remove Fee Function -End
    

//Function Added by MohiniM || 1-Sep-21 || Remove Fees Ref.MASCLI-2102 || Start;

    function confirmationBoxFees(btnremove) {
        try {
            debugger;
            var feedescriptionID = btnremove.id.replace("btnDelete", "ddlFeeDescription");
            var selectedFeeDesc = document.getElementById(feedescriptionID).selectedOptions[0].value   
            document.getElementById("ctl00_MainContent_oUCPFeesTab_hdnremoveFeedesc").value = selectedFeeDesc
            var dialogText = ""
            dialogText = dialogText.concat("Do you want to delete this record?")
            //if ($("#pageName").html() != null) {
            title = "Confirmation - Fees";
            //}

            if (!dialogConfirmed) {
                $('html').append(String.Format("<div id='dialog1' title='{0}'><p style='float:left;'><img src='../App_Themes/images/Warning_Msg.png' style='width:13px;height:15px;margin-right:10px;padding-top: 20px;'><span   style='float:left;margin:0 5px 20px 0;'></span>{1}</p></div>",
                            title, dialogText));
                //alert("hi " + title);
                $('#dialog1').dialog
                        ({
                            height: 180,
                            width: 350,
                            modal: true,
                            resizable: false,
                            draggable: true,
                            close: function (event, ui) { $('html').find('#dialog1').remove(); },
                            buttons:
                            {
                                'Yes': function () {
                                    document.getElementById("ctl00_MainContent_oUCPFeesTab_btnremove").click();
                                    dialogConfirmed = false;
                                    $(this).dialog('close');
                                },
                                'No': function () {
                                    $(this).dialog('close');
                                    dialogConfirmed = false;
                                }
                            }
                        });
            }

            return dialogConfirmed;
        }
        catch (error) {
            console.log("Error: " + error);
        }
    }

//Function Added by MohiniM || 1-Sep-21 || Remove Fees Ref.MASCLI-2102 || End

$(document).keydown(function (e) {//<Rohit Padole || Added on 12-Oct-2021 || to close UCP dealentry popup on Alt+x JIRA BOCISSINT-663>
    if (e.altKey && e.keyCode == 88) {
        //$("#ctl00_MainContent_lnkCloseUCPPopUP").click();
        CloseWindow();
    }
});