<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/FiniqAppMasterPage.Master" CodeBehind="HolidaySetupJS.aspx.vb" Inherits="FinIQWebApp.HolidaySetupJS" %>


<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
     <%-- Added by AniruddhaJ | 04Mar2022 Start--%>
    
<link href="HolidaySetup.css" type="text/css" rel="stylesheet"/>
    
    <script>
  
        var ccyHolidaysObject = {};

        Date.prototype.toShortFormat = function () {
            try {

                var month_names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                var day = this.getDate();
                var month_index = this.getMonth();
                var year = this.getFullYear();

                if (day.toString().length > 1) {

                } else {
                    day = "0" + day;
                }

                return "" + day + "-" + month_names[month_index] + "-" + year;

            } catch (error) {
                console.log(error.message());
                $(".lblError").html(error.message())
            }
        }


        $(document).ready(function () {
            console.log('UC_HolidaySetup loaded')

            $("#DefaultYearSelector").text(new Date().getFullYear());


            $("#btnAddHoliday").click(function () {
                $("#dialogAddHoliday").dialog();
                //    $("#dialogAddHoliday").parent().show();
            })
          


            $("#btnOpenGridView").click(function () {
                $("#dialogGridHoliday").dialog();
            })
            
            fillEntity();


            var ccycodelist = [];
            var strCcy = '';
            var strddl = ''

            $('#txtFromDate').val(new Date().toShortFormat());
            callAPIAsync("HolidaySetupJS.aspx/getHolidayCcyList", {}).then(data => {

                console.log('getHolidayCcyList', JSON.parse(data.d));
                ccycodelist = JSON.parse(data.d).filter(function (e) {
                    return e.code != '' && e.code != 'ALL' 
                })
                for (let c of ccycodelist) {

                    strCcy = strCcy + `<div class='divccy' onclick='ccyCheckChanged(this)'>${c.code}</div>`;
                    strddl = strddl + `<option value='${c.code}'>${c.code}</option>`;

                }
                //console.log('strccy console', strCcy);//ApurvaK
                $(`#trCcyList`).append(strCcy);

                $(`#ddlccy`).append(strddl);

                var ConfigBasedDefaultCcy = $("#ctl00_MainContent_HiddenBankBaseCcy").val() != undefined && $("#ctl00_MainContent_HiddenBankBaseCcy").val() != "" ? $("#ctl00_MainContent_HiddenBankBaseCcy").val():"USD" // Make this config based

                ccyHolidaysObject[ConfigBasedDefaultCcy] = [];
                var selectedccy = ConfigBasedDefaultCcy
                let paramsObject = { 'strCCY': selectedccy, 'strType': '', 'strFromDate': `01-Jan-${Number($("#DefaultYearSelector").text())}`, 'strToDate': `31-Dec-${Number($("#DefaultYearSelector").text())}` };

                $("#trCcyList").find("div.divccy").each(function () {
                    if ($(this).text() == selectedccy) {
                        $(this).addClass('Hactive');

                    }
                })

                callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {
                    if (JSON.parse(data.d).length > 0) {
                        $("#divRightTD1").empty();

                        ccyHolidaysObject[JSON.parse(data.d)[0].Currency] = JSON.parse(data.d);

                        console.log('after adding object prop', ccyHolidaysObject);
                        //    $("#info").html(ccyHolidaysObject[JSON.parse(data.d)[0].Currency]);
                        plotCalendar(ccyHolidaysObject, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()))
                    } else {
                        $("#info").html('Holidays not found for ' + selectedccy);
                        $("#info").show();

                    }


                })

            })

        })

        function fillEntity() {
            try {
                callAPIAsync("HolidaySetupJS.aspx/GetEntity", { "LoginID": $("#ctl00_MainContent_HiddenUserName").val() }).then(data => {
                    
                    console.log('GetEntity ', data);
                    let strEntity = '';

                    for (let E of data.d.CVPData) {
                        strEntity = strEntity + `<option value=${E.Code}>${E.Value}</option>`;


                    }
                    $("#ddlEntity").append(strEntity);


                }).catch(err => {
                    console.log(err)
                })
            } catch (err) {
                console.log(err.message);

            }
        }
        function ccyCheckChanged(_this) {


            $("#trCcyList>div").each(function (i, divElement) {
                $(divElement).removeClass('Hactive');
            })

            if ($(_this).hasClass('Hactive')) {
                $(_this).toggleClass('Hactive')
                delete ccyHolidaysObject[$(_this).text()];
                console.log('after delete object prop', ccyHolidaysObject);
                $("#info").html("");
                //    $("#info").html().replace($(_this).text(), "");
                $("#divRightTD1").empty();
                plotCalendar(ccyHolidaysObject, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()));

            } else {

                $(_this).toggleClass('Hactive')
                $("#info").html("");
                ccyHolidaysObject = {};

                ccyHolidaysObject[$(_this).text()] = [];
                var selectedccy = $(_this).text()
                let paramsObject = { 'strCCY': $(_this).text(), 'strType': '', 'strFromDate': `01-Jan-${Number($("#DefaultYearSelector").text())}`, 'strToDate': `31-Dec-${Number($("#DefaultYearSelector").text())}` };

                callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {
                    if (JSON.parse(data.d).length > 0) {
                        $("#divRightTD1").empty();

                        ccyHolidaysObject[JSON.parse(data.d)[0].Currency] = JSON.parse(data.d);

                        console.log('after adding object prop', ccyHolidaysObject);
                        //    $("#info").html(ccyHolidaysObject[JSON.parse(data.d)[0].Currency]);
                        plotCalendar(ccyHolidaysObject, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()))
                    } else {
                        $("#info").html('Holidays not found for ' + selectedccy);
                        $("#info").show();
                        plotDefaultCalendar("", Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()));

                    }


                })

            }
        }

        function callAPIAsync(url, params) {
            $("#dvLoader").show();

            return new Promise((resolve, reject) => {

                $.ajax({
                    type: 'POST',
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: JSON.stringify(params),
                    crossDomain: true,
                    async: true,
                    success: function (data) {
                        resolve(data);
                        $("#dvLoader").hide();

                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        console.log(xhr.responseText);
                        $("#dvLoader").hide();
                        $("#info").html(xhr.responseText);
                        $("#info").show();

                    }
                });

            })
        }

        function plotDefaultCalendar(_selectedDate, startYear, endYear) {
            try {
                
                var month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                var str = ``;
                if (startYear === undefined && endYear === undefined) {
                    var startYear = new Date().getFullYear();
                    var endYear = new Date().getFullYear();
                } else {
                    startYear = startYear;
                    endYear = endYear;

                }
                $("#divRightTD1").empty();

                var tempEventDate = [];

                tempEventDate[new Date(_selectedDate)] = {
                    "Date": new Date(_selectedDate)
                }

                for (var y = startYear; y <= endYear; y++) {

                    for (var i = 0; i < 12; i++) {

                        str = `<div class='RMWdatepicker' id='RMWdatepicker_${y}_${i}'> </div>`;

                        $("#divRightTD1").append(str);

                        $('#RMWdatepicker_' + y + "_" + i).datepicker({

                            dateFormat: "dd-M-yy",
                            defaultDate: new Date(`01-${month[i]}-${y}`),
                            showOtherMonths: false,
                            selectOtherMonths: false,
                            changeMonth: false,
                            changeYear: false,
                            beforeShowDay: function (date) {

                                var highlight = tempEventDate[date];
                                if (highlight) {
                                    return [true, `event`, tempEventDate[date].Date.toString()];
                                } else {
                                    return [true, '', ''];
                                }
                            },

                            onSelect: function (dateText) {

                                console.log("Selected date: " + dateText + "; input's current value: " + this.value);

                                if ($("#ctl00_MainContent_HiddenMode").val() === "VIEWER") {
                                    ccyHolidaysObject = {};
                                    plotDefaultCalendar(this.value, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()))

                                    let paramsObject = { 'strCCY': "", 'strType': "", 'strFromDate': this.value, 'strToDate': this.value };
                                    var selectedDate = this.value;

                                    callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {

                                        if (JSON.parse(data.d).length > 0) {

                                            console.log('highlight ccy ', JSON.parse(data.d))

                                            $("#trCcyList>div").each(function (i, divElement) {

                                                $(divElement).removeClass('Hactive');

                                                for (let Obj of JSON.parse(data.d)) {

                                                    if (Obj.Currency === $(divElement).text().trim()) {
                                                        $(divElement).addClass('Hactive');

                                                    }
                                                }

                                            })


                                        } else {
                                            $("#trCcyList>div").each(function (i, divElement) {

                                                $(divElement).removeClass('Hactive');

                                            })

                                            $("#info").html('Holidays not found for date ' + selectedDate);
                                            $("#info").show();

                                        }


                                    })

                                } else {// MAKER BLOCK


                                }
                            }

                        });
                        str = "";

                    }

                }

            } catch (err) {
                console.log(err.message);

            }
        }

        function plotCalendar(datesDataObject, startYear, endYear) {
            try {
                if (startYear === undefined && endYear === undefined) {
                    var startYear = new Date().getFullYear();
                    var endYear = new Date().getFullYear();
                } else {
                    var startYear = startYear;
                    var endYear = endYear;

                }
                var eventDates = {};
                /*            var keys = Object.keys(datesDataObject)*/

                if (Object.keys(datesDataObject).length == 0) {
                    $("#divRightTD1").empty();
                    $("#info").html("");
                } else {
                    for (let a in datesDataObject) {
                        for (let c of datesDataObject[a]) {
                            //  eventDates[new Date(datesDataObject[keys[c]])] = new Date(datesDataObject[keys[c]]);
                            eventDates[new Date(parseInt(c.HolidayDate.substr(6)))] = {
                                "Date": new Date(new Date(parseInt(c.HolidayDate.substr(6)))),
                                 <%--Added by ApurvaK for BBVAORINT-285 UI change(Changed Currency to Calendar) as discussed with DJ| 06 JUN 2022--%> 
                                "Event": `Calendar - ${c.Currency} | Holiday Type - ${c.HolidayType} | Description - ${c.Misc == "" ? "NA" : c.Misc} | Holiday Name - ${c.HolidayName == "" ? "NA" : c.HolidayName} `,
                                "ID": `${c.Currency}`,
                                "EventValues": `${c.Currency},${c.HolidayType},${c.Misc == "" ? "NA" : c.Misc},${c.HolidayName == "" ? "NA" : c.HolidayName},${c.ID}`
                            }
                        }
                    }


                    var month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                    var str = ``;
               
                    for (var y = startYear; y <= endYear; y++) {

                        for (var i = 0; i < 12; i++) {

                            str = `<div class='RMWdatepicker' id='RMWdatepicker_${y}_${i}'> </div>`;

                            $("#divRightTD1").append(str);

                            $('#RMWdatepicker_' + y + "_" + i).datepicker({
                                dateFormat: "dd-M-yy",
                                defaultDate: new Date(`01-${month[i]}-${y}`),
                                showOtherMonths: false,
                                selectOtherMonths: false,
                                changeMonth: false,
                                changeYear: false,
                                beforeShowDay: function (date, inst) {

                                    var highlight = eventDates[date];
                                    if (highlight) {
                                        return [true, `event WithValues,${eventDates[date].EventValues.replace(/['"]+/g, '')}`, eventDates[date].Event];
                                    } else {
                                        return [true, '', ''];
                                    }
                                },
                                onSelect: function (dateText) {


                                    console.log("Selected date: " + dateText + "; input's current value: " + this.value);
                                  
                                    if ($("#ctl00_MainContent_HiddenMode").val() === "VIEWER") {
                                        ccyHolidaysObject = {};
                                        plotDefaultCalendar(this.value, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()));

                                        let paramsObject = { 'strCCY': "", 'strType': "", 'strFromDate': this.value, 'strToDate': this.value };
                                        var selectedDate = this.value;

                                        callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {
                                            if (JSON.parse(data.d).length > 0) {

                                                console.log('highlight ccy ', JSON.parse(data.d))
                                                $("#trCcyList>div").each(function (i, divElement) {

                                                    $(divElement).removeClass('Hactive');

                                                    for (let Obj of JSON.parse(data.d)) {
                                                        if (Obj.Currency === $(divElement).text().trim()) {
                                                            $(divElement).addClass('Hactive');

                                                        }
                                                    }

                                                })

                                            } else {

                                                $("#trCcyList>div").each(function (i, divElement) {

                                                    $(divElement).removeClass('Hactive');

                                                })

                                                $("#info").html('Holidays not found for date' + selectedDate);
                                                $("#info").show();

                                            }


                                        })

                                    } else {  // MAKER BLOCK
                                        if (event.currentTarget.className.trim() != "" && event.currentTarget.className.trim().includes(",")) {

                                            let holidayDeatilsArray = [];
                                            holidayDeatilsArray = event.currentTarget.className.split(",")
                                            $("#ddlccy").val(holidayDeatilsArray[1])
                                            $("#txtHolidayType").val(holidayDeatilsArray[2])
                                            $("#txtHolidayName").val(holidayDeatilsArray[4])
                                            $("#txtEvent").val(holidayDeatilsArray[3])
                                            $("#txtFromDate").val(this.value);
                                            //  if (holidayDeatilsArray[0].includes("-today")) {  // today date click 
                                            //   $("#hdnCCYID").val(0);
                                            // } else
                                            if (holidayDeatilsArray[5].includes("today") || holidayDeatilsArray[5].trim().includes("-current-day")) {
                                                $("#hdnCCYID").val(holidayDeatilsArray[5].split(" ")[0]);
                                            } else {
                                                $("#hdnCCYID").val(holidayDeatilsArray[5]);
                                            }
                                            $("#btnDeleteHoliday").prop("disabled", false);
                                            $("#btnInsertHoliday").val("Update Holiday");



                                            $("#dialogAddHoliday").dialog();


                                        } else {
                                            $("#hdnCCYID").val();
                                            $("#ddlccy").val("");
                                            $("#ddlccy").val("")
                                            $("#txtHolidayType").val("")
                                            $("#txtHolidayName").val("")
                                            $("#txtEvent").val("")
                                            $("#txtFromDate").val(this.value);

                                            $("#txtFromDate").val(this.value);

                                            $("#btnDeleteHoliday").prop("disabled", true);
                                            $("#btnInsertHoliday").val("Add Holiday");



                                            $("#dialogAddHoliday").dialog();


                                        }
                                    }
                                }

                            });
                            str = "";

                        }

                    }

                    $("td.event").tooltip({
                        show: null,
                        position: {
                            my: "left top",
                            at: "left bottom"
                        },
                        open: function (event, ui) {

                            ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast");
                            $(ui.tooltip).addClass("userInfotip");
                        }
                    });

                    

                }
                console.log('Holidays ', eventDates);

            } catch (error) {
                console.log(error.message)
            }
        }
        function openGridView() {
            try {
            
                var strTable = `<table id="gridHolidaySetup" class="gridHolidaySetup" style="">`;
                var strHeader = `<tr class='rowHeader1'>`;

                 <%--Added by ApurvaK for BBVAORINT-285 UI change(Changd Currency to Calendar) as discussed with DJ| 06 JUN 2022--%> 
                strHeader = strHeader + `<td>ID</td><td>Calendar</td><td>Holiday Date</td><td>Holiday Name</td><td>Holiday Type</td><td>Event</td><td>Updated At</td><td>Updated By</td>`;


                strHeader = strHeader + `</tr>`;


                strTable = strTable + strHeader
                for (let o in ccyHolidaysObject) {

                    ccyHolidaysObject[o].sort((a, b) => (a.ID > b.ID) ? 1 : ((b.ID > a.ID) ? -1 : 0))

                    for (let row of ccyHolidaysObject[o]) {
                        <%--Added by ApurvaK for BBVAORINT-285 UI change(Changd Currency to Calendar) as discussed with DJ| 06 JUN 2022--%>
                        strTable = strTable + `<tr class=''><td>${row.ID}</td><td style='text-align:center;'>${row.Currency}</td> <td>${new Date(parseInt(row.HolidayDate.substr(6))).toShortFormat()}</td>
                              <td>${row.HolidayName}</td><td>${row.HolidayType}</td><td>${row.Misc}</td>
                              <td>${row.Updated_At == null ? "" : row.Updated_At}</td><td>${row.Updated_By == null ? "" : row.Updated_By}</td>
                              </tr>`;

                    }
                }
                strTable = strTable + `</table>`;

                $(document).find("#divTable").empty().append(strTable);

            } catch (err) {
                console.log(err.message);

            }
        }
        function InsertHoliday() {
            try {

                var hdnEditCcy = $("#ddlccy").val();
                var holidayInsertUpdateFlag = $("#btnInsertHoliday").val().trim().toUpperCase() == "ADD HOLIDAY" ? "I" : "U"
                let InsertHolidayObj = {
                    'ID': $("#hdnCCYID").val().trim() == "" ? 0 : $("#hdnCCYID").val().trim(), 'holidayCcy_': $("#ddlccy").val(), 'holidayType': $("#txtHolidayType").val(), 'holidayDate_': $("#txtFromDate").val(), 'holidayName': $("#txtHolidayName").val(), 'misc': $("#txtEvent").val(), 'insertOrUpdate': holidayInsertUpdateFlag, 'strCcyAllorNot': $("#ddlccy").val(), 'userName': $("#ctl00_MainContent_HiddenUserName").val(), 'ipAdress': ""
                }
                console.log('to insert ', InsertHolidayObj);

                callAPIAsync("HolidaySetupJS.aspx/saveHolidayCalendar", InsertHolidayObj).then(data => {
                    console.log(data);
                    if (data.d == "true") {
                        // $("#dialogAddHoliday").parent().hide();

                        $("#info").html("Holiday Saved Successfully!")
                        $("#info").show();

                        $('#dialogAddHoliday').dialog('close');

                        delete ccyHolidaysObject[hdnEditCcy];
                        ccyHolidaysObject[hdnEditCcy] = [];
                        var selectedccy = hdnEditCcy
                        let paramsObject = { 'strCCY': hdnEditCcy, 'strType': '', 'strFromDate': `01-Jan-${Number($("#DefaultYearSelector").text())}`, 'strToDate': `31-Dec-${Number($("#DefaultYearSelector").text())}` };

                        callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {
                            if (JSON.parse(data.d).length > 0) {
                                $("#divRightTD1").empty();

                                ccyHolidaysObject[JSON.parse(data.d)[0].Currency] = JSON.parse(data.d);

                                console.log('after adding object prop', ccyHolidaysObject);
                                //    $("#info").html(ccyHolidaysObject[JSON.parse(data.d)[0].Currency]);
                                plotCalendar(ccyHolidaysObject, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()))
                            } else {
                                $("#info").html('Holidays not found for ' + selectedccy);
                                $("#info").show();
                            }
                        })


                    } else {
                        //  $("#dialogAddHoliday").parent().hide();

                        $("#info").html("Holiday Not Saved!")
                        $("#info").show();
                        $('#dialogAddHoliday').dialog('close');

                    }
                })

            } catch (err) {

                console.log(err.message)
            }


        }
        function deleteHoliday() {
            try {


                let DeleteHolidayObj = {
                    'strid': $("#hdnCCYID").val().trim() == "" ? 0 : $("#hdnCCYID").val().trim(), 'AppUserName': $("#ctl00_MainContent_HiddenUserName").val(), 'I_StrIPAddress': ""
                }
                console.log('to delete ', DeleteHolidayObj);

                callAPIAsync("HolidaySetupJS.aspx/DeleteRecords", DeleteHolidayObj).then(data => {

                    console.log(data);

                    if (data.d == "true") {

                        //   $("#dialogAddHoliday").parent().hide();
                        $("#info").html("Holiday Deleted Successfully!")
                        $("#info").show();
                        $('#dialogAddHoliday').dialog('close');
                        var hdnEditCcy = $("#ddlccy").val();

                        delete ccyHolidaysObject[hdnEditCcy];
                        ccyHolidaysObject[hdnEditCcy] = [];
                        var selectedccy = hdnEditCcy
                        let paramsObject = { 'strCCY': hdnEditCcy, 'strType': '', 'strFromDate': `01-Jan-${Number($("#DefaultYearSelector").text())}`, 'strToDate': `31-Dec-${Number($("#DefaultYearSelector").text())}` };

                        callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {
                            if (JSON.parse(data.d).length > 0) {
                                $("#divRightTD1").empty();

                                ccyHolidaysObject[JSON.parse(data.d)[0].Currency] = JSON.parse(data.d);

                                console.log('after adding object prop', ccyHolidaysObject);
                                //    $("#info").html(ccyHolidaysObject[JSON.parse(data.d)[0].Currency]);
                                plotCalendar(ccyHolidaysObject, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()))
                            } else {
                                $("#info").html('Holidays not found for ' + selectedccy);
                                $("#info").show();
                            }
                        })

                    } else {

                        //        $("#dialogAddHoliday").parent().hide();
                        $("#info").html("Holiday Not Deleted!")
                        $("#info").show();
                        $('#dialogAddHoliday').dialog('close');

                    }


                })


            } catch (err) {
                console.log(err.message);

            }
        }
        function loadNextYear() {
            try {
                debugger
            let currentYear = Number($("#DefaultYearSelector").text());
            $("#DefaultYearSelector").text(currentYear + 1);

            $("#info").html("");
                ccyHolidaysObject = {};
                let selectedccy = [];
            

                selectedccy  = $("#trCcyList>div").filter((index,element) => {
                    if ($(element).hasClass("Hactive"))
                        return $(element)

                })
                let strselectedccy = selectedccy[0].innerText

                ccyHolidaysObject[strselectedccy] = [];
          
                let paramsObject = {
                    'strCCY': strselectedccy, 'strType': '',
                    'strFromDate': `01-Jan-${Number($("#DefaultYearSelector").text())}`,
                    'strToDate': `31-Dec-${Number($("#DefaultYearSelector").text())}`
                };

            callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {
                if (JSON.parse(data.d).length > 0) {
                    $("#divRightTD1").empty();

                    ccyHolidaysObject[JSON.parse(data.d)[0].Currency] = JSON.parse(data.d);

                    console.log('after adding object prop', ccyHolidaysObject);
                    //    $("#info").html(ccyHolidaysObject[JSON.parse(data.d)[0].Currency]);
                    plotCalendar(ccyHolidaysObject, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()))
                } else {
                    $("#info").html('Holidays not found for ' + selectedccy);
                    $("#info").show();
                    plotDefaultCalendar("", Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()));

                }


            })
            } catch (err) {
                console.log(err.message);

            }

        }
        function loadPrevYear() {
            try {
                debugger
                let currentYear = Number($("#DefaultYearSelector").text());
                $("#DefaultYearSelector").text(currentYear - 1);

                $("#info").html("");
                ccyHolidaysObject = {};
                let selectedccy = [];


                selectedccy = $("#trCcyList>div").filter((index, element) => {
                    if ($(element).hasClass("Hactive"))
                        return $(element);

                })

                let strselectedccy = selectedccy[0].innerText

                ccyHolidaysObject[strselectedccy] = [];

                let paramsObject = { 'strCCY': strselectedccy, 'strType': '', 'strFromDate': `01-Jan-${Number($("#DefaultYearSelector").text())}`, 'strToDate': `31-Dec-${Number($("#DefaultYearSelector").text())}` };

                callAPIAsync("HolidaySetupJS.aspx/getHolidayByCcyCode", paramsObject).then(data => {
                    if (JSON.parse(data.d).length > 0) {
                        $("#divRightTD1").empty();

                        ccyHolidaysObject[JSON.parse(data.d)[0].Currency] = JSON.parse(data.d);

                        console.log('after adding object prop', ccyHolidaysObject);
                        //    $("#info").html(ccyHolidaysObject[JSON.parse(data.d)[0].Currency]);
                        plotCalendar(ccyHolidaysObject, Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()))
                    } else {
                        $("#info").html('Holidays not found for ' + selectedccy);
                        $("#info").show();
                        plotDefaultCalendar("", Number($("#DefaultYearSelector").text()), Number($("#DefaultYearSelector").text()));

                    }


                })

            } catch (err) {
                console.log(err.message);

            }
        }
    </script>
    <table class="tblHolidaySetup">

        <tr>
            <td colspan="2" style="padding-left:7px;">
                <span> Entity </span>
                
           
                <select id="ddlEntity" class="ddl" style="margin-left:10px;width:160px">

                    </select>

                </td>
            </tr>
        <tr id="">

            <td id="trCcyList"></td>
			<%--//Added by Apurva K for currency grid filling css issue|| As discussed with Anirddha J|| 06 June 2022--%>
            <td id="" style="padding-left:6vw" class="divHolydayCaledar">
                <table style="width:100%;">
                    <tr>
                        <td style="width:50%;">
                           <table class="yearSeletcorContainer">
                               <tr>
                                   <td> <span class="yearMover" onclick="loadPrevYear()"><</span>
                                       </td>
                                    
                                   <td>

                                          <div id="DefaultYearSelector" class="yearMover"></div>
                                       </td>
                             <td>
                                    <span class="yearMover" onclick="loadNextYear()">></span>
                                 </td>
                                </tr>
                               </table>
                       
                            
                            <div id="info" title="Information" >
                            </div>

                            

                         <asp:Label ID="lblError" runat="server" Text="" CssClass="lblError"></asp:Label>
                            </td>
                        <td>
                            <div style="float:right">
                            
                                <input type="button" id="btnAddHoliday" class="btn" value="Add" style="display:none"/>
<%--                                <input type="button" id="btnDeleteHoliday" class="btn" value="Filter By Date"/>--%>
                                <input type="button" id="btnOpenGridView"  onclick="openGridView()" class="btn" value="Grid View"/>

                          </div>
                                </td>
                        </tr>
                    <tr>
                         <td id="divRightTD1" colspan="2">

                            </td>
                        
                        </tr>
                    </table>
              
            </td>

        </tr>

   <tr>
            <td colspan="2">
               <div id="dialogAddHoliday" title="Add Holiday" style="display:none">
 <table style="width:100%" class="tblAddHoliday">
     <tr>
         <td>
            <%--Added by ApurvaK for BBVAORINT-285 UI change as discussed with DJ|| 06 JUN 2022--%> 
             Calendar
             </td>
          <td>
              <select id="ddlccy" style="width:157px">
                
              </select>
             </td>
         <tr>
          <td>
              Holiday Name
             </td>
          <td>
                   <input type="text" style="" id="txtHolidayName" class="txt" value =""/>
             </td>
             </tr>
     <tr>
         <td>
              Holiday Type
             </td>
          <td>
                   <input type="text" style="" id="txtHolidayType" class="txt" value =""/>
             </td>
         </tr>
     <tr>
          <td>
            Event
             </td>
          <td>
                   <input type="text" style="" id="txtEvent" class="txt" value =""/>
             </td>
     </tr>
                      
                    <tr>           
         <td>
              <span>Date</span>
             </td>
          <td>
              <input type="text" style="" id="txtFromDate" class="txt" value ="" readonly/>
             </td>
                        </tr>
         <tr>
          <td colspan="2">
             
      <input type="text" style="display:none" id="hdnCCYID"/ value="0">
             </td>
         </tr>
     <tr>
          <td style="text-align:center" colspan="2">
            
               <input type="button" id="btnInsertHoliday" onclick="InsertHoliday()" class="btn" style='width:90px' value="Add Holiday"/>
               <input type="button" id="btnDeleteHoliday" onclick="deleteHoliday()" class="btn" style='width:90px' value="Delete Holiday"/>

             </td>
         </tr>
     </table>
</div>
                </td>
            </tr>

        <tr>
            <td>
                     <div id='dialogFilterHoliday' style="display:none">
                         some filter pop up 
                     </div>
                </td>
            </tr>
   
                 <tr>
            <td>
                 <div id='dialogGridHoliday' style="display:none">
                      <table id="divTable">

                      </table>

                     </div>
                      
                </td>
            </tr>



        <asp:HiddenField ID="HiddenUserName" runat="server" />
          <asp:HiddenField ID="HiddenMode" runat="server" />

          <asp:HiddenField ID="HiddenBankBaseCcy" runat="server" />

             

    </table>

<%--    End--%>

</asp:Content>
