let turnOffYearSpan = false;     // true = Only show This Year and Next, false = show +/- 5 years
let weekStartsOnSunday = false;  // true = Start the week on Sunday, false = start the week on Monday
let showWeekNumber = true;  // true = show week number,  false = do not show week number

let languageCode = 'en'; // Possible values: en, ge, no, nl, es, pt-br, fr

let calendarDisplayTime = true;

// Format of current day at the bottom of the calendar
let todayStringFormat = '[todayString] [UCFdayString]. [day]. [monthString] [year]';
let pathToImages = '../js/dhtmlgoodies_calendar/images/'; // Relative to your HTML file

let speedOfSelectBoxSliding = 200; // Milliseconds between changing year and hour when holding mouse over "-" and "+" - lower value = faster
let intervalSelectBoxMinutes = 5; // Minute select box - interval between each option (5 = default)

let calendarOffsetTop = 0; // Offset - calendar placement - adjust this based on your layout
let calendarOffsetLeft = 0;

let calendarDiv = false;

let MSIE = /*@cc_on!@*/false; // Detect Internet Explorer (legacy support)
let Opera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; // Detect Opera browser

// Adjust the language settings dynamically
switch (languageCode) {
    case "en":
        var monthArray = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var monthArrayShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
        var dayArray = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
        var weekString = 'Week';
        var todayString = 'Today';
        break;
    // Add cases for other languages (ge, no, etc.)
    //...
}

// Adjust start of the week logic
if (weekStartsOnSunday) {
    let tempDayName = dayArray[6];
    for (let i = 6; i > 0; i--) {
        dayArray[i] = dayArray[i - 1];
    }
    dayArray[0] = tempDayName;
}

// Utility function for leap year calculation
function isLeapYear(year) {
    return (year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0));
}

// Utility function to create month dropdown div
function createMonthDiv() {
    const div = document.createElement('DIV');
    div.className = 'monthYearPicker';
    for (let i = 0; i < monthArray.length; i++) {
        const subDiv = document.createElement('DIV');
        subDiv.innerHTML = monthArray[i];
        subDiv.onmouseover = highlightMonthYear;
        subDiv.onmouseout = highlightMonthYear;
        subDiv.onclick = selectMonth;
        subDiv.id = 'monthDiv_' + i;
        subDiv.style.width = '56px';
        subDiv.onselectstart = cancelCalendarEvent;
        div.appendChild(subDiv);
        if (currentMonth && currentMonth === i) {
            subDiv.style.color = selectBoxHighlightColor;
            activeSelectBoxMonth = subDiv;
        }
    }
    return div;
}

// Utility function to handle selection of the month
function selectMonth() {
    document.getElementById('calendar_month_txt').innerHTML = this.innerHTML;
    currentMonth = this.id.replace(/[^\d]/g, '');
    document.getElementById('monthDropDown').style.display = 'none';
    updateCalendar();
}

// Function to update the calendar content
function updateCalendar() {
    // Your calendar content update logic
    writeCalendarContent(); // Ensures calendar updates accordingly
}

// Function to cancel any calendar-related events
function cancelCalendarEvent() {
    return false;
}

// Feature detection for modern and deprecated features
if (typeof Promise === "undefined") {
    console.warn("Your browser does not support modern JavaScript features like Promises. Some functionality may not work as expected.");
}

// Main initialization of the calendar
function initCalendar() {
    // IE-specific handling (legacy support)
    if (MSIE) {
        iframeObj = document.createElement('IFRAME');
        iframeObj.style.filter = 'alpha(opacity=0)';
        iframeObj.style.position = 'absolute';
        iframeObj.border = '0px';
        iframeObj.style.backgroundColor = '#FF0000';

        iframeObj2 = document.createElement('IFRAME');
        iframeObj2.style.position = 'absolute';
        iframeObj2.border = '0px';
        iframeObj2.style.height = '1px';
        iframeObj2.style.width = '1px';

        document.body.appendChild(iframeObj2);
        document.body.appendChild(iframeObj);
    }

    // Create the calendar div and append it to the document
    calendarDiv = document.createElement('DIV');
    calendarDiv.id = 'calendarDiv';
    calendarDiv.style.zIndex = 1000;

    slideCalendarSelectBox();
    document.body.appendChild(calendarDiv);

    writeBottomBar();
    writeTopBar();

    if (!currentYear) {
        const d = new Date();
        currentMonth = d.getMonth();
        currentYear = d.getFullYear();
    }
    writeCalendarContent();
}
