
/* ING-alert-message */

var expireDay = 30; 

/* To hide the banner make bannerMessageEnabled variable as false and to show make as true */ 
var bannerMessageEnabled = false; 

/* Don't use special character in alertMessage text field as it causing issue. */
var alertMessage = {
    version: "14032025",
    messages: [
        {
            type: "alert",
            text: "<a target='_blank' href='https://www.ing.com.au/faq-result.html?faqid=what-to-do-if-youre-impacted-by-cyclone-alfred'>Read our</a> guide on what to do if you're impacted by Cyclone Alfred. We're here to help. For the fastest way to make a Car and/or Home Insurance claim go online <a target='_blank' href='https://ing.disconline.com.au/myaccount/#/signin'>Log in | ING Online Policy Manager</a>. For helpful resources <a target='_blank' href='https://www.ing.com.au/faq-result.html?faqid=need-help-to-prepare-for-cyclone-alfred'>click here</a>."
        }
    ] 
};


/* ING-alert-message functions */

var cookieName = "ING-alert-message";
if (bannerMessageEnabled) {
    if (typeof $.cookie(cookieName) === 'undefined') {
        showAlertMessage(alertMessage);
    } else {
        var oldMessage = JSON.parse($.cookie(cookieName));
        var oldVersion = parseInt(oldMessage.version, 10);
        var newVersion = parseInt(alertMessage.version, 10);
        if (newVersion > oldVersion) {
            showAlertMessage(alertMessage);
        }
    }
}


function showAlertMessage(message) {

    var messageBox = $('<div/> </a>').addClass('ING-messagebox').attr('id', 'additional-info-box').css('display', 'none').prependTo('body');
    var container = $('<div/>').addClass('container').appendTo(messageBox);
    var list = $('<ul/>').appendTo(container);

    for (var index in message.messages) {
        var row = $('<li/>').appendTo(list);
        var rawMessage = message.messages[index].text;
        var oneMessage = $('<div/>').addClass('message').html('<span>' + rawMessage + '</span>');
        oneMessage.appendTo(row);
    }

    var closeButton = $('<div/>').addClass('close-button').appendTo(messageBox);
    closeButton.on('click', function() {

        $.cookie(cookieName, JSON.stringify(message), { expires: expireDay });

        messageBox.slideUp(function() {
            $(this).remove();
        });
    });

    messageBox.slideDown();
}

