
// carry out initialization actions by attaching an extra function to any existing window.onload or window.onresize functions
if (window.addEventListener)                                    // W3C standard 
    window.addEventListener('load', CookieConfigOnLoadActions, false);
else if (window.attachEvent)                                    // IE
    window.attachEvent('onload', CookieConfigOnLoadActions);


// carry out extra initialization actions after page has loaded
function CookieConfigOnLoadActions()
{
    CreateBannerDiv();

    var cookie = ReadCookie();
    if (cookie == "1")
    {
        document.getElementById("cookies-wrapper").style.display = 'none';
        var cookiesPolicy = document.getElementById("cookies-policy");              // only present if no full page available
        if (cookiesPolicy != null)
            cookiesPolicy.style.display = 'block';
        wf24CookieConfigSet = true;
    }

    // carry out extra initialization actions by attaching an extra function to any existing document.body.onclick functions
    if (document.body.addEventListener)                                    // W3C standard 
        document.body.addEventListener('click', CookieConfigOnClickActions, false);
    else if (document.body.attachEvent)                                    // IE
        document.body.attachEvent('onclick', CookieConfigOnClickActions);
}


// uncomment for testing
//document.cookie = 'WF24CookieConfig=0; expires=-1; path=/';

var wf24CookieConfigSet = false;

function CookieConfigOnClickActions()
{
    document.getElementById("cookies-wrapper").style.display = 'none';
    var cookiesPolicy = document.getElementById("cookies-policy");              // only present if no full page available
    if (cookiesPolicy != null)
        cookiesPolicy.style.display = 'block';
    wf24CookieConfigSet = true;
}


// set cookie config cookie value whenever user clicks anywhere, if not already set
function CookieConfigOnClickActions()
{
    if (!wf24CookieConfigSet)
    {
        var expiry = new Date();
        expiry.setFullYear(expiry.getFullYear() + 1);
        document.cookie = 'WF24CookieConfig=1; expires=' + expiry.toUTCString() + '; path=/';
        wf24CookieConfigSet = true;

        document.getElementById("cookies-wrapper").style.display = 'none';
        var cookiesPolicy = document.getElementById("cookies-policy");              // only present if no full page available
        if (cookiesPolicy != null)
            cookiesPolicy.style.display = 'block';
    }
}


function ReadCookie()
{
    var nameEQ = "WF24CookieConfig=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++)
    {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return "";
}


function CreateBannerDiv()
{
    var bodytag = document.getElementsByTagName('body')[0];
    var div = document.createElement('div');
    div.setAttribute('id', 'cookies-wrapper');
    div.innerHTML = '<div id="cookies">' +
                    '<p id="cookies-title">Cookies</p>' +
                    '<p id="cookies-body">We use cookies to ensure that we give you the best experience on our website. ' +
                    'If you continue without changing your settings, we will assume that you are happy to receive all cookies on our website.</p>' +
                    '<ul id="cookies-ul">' +
                    '<li><a id="cookies-accept" href="javascript:void(0)" onclick="HideCookiePolicy()">Okay</a></li>' +
                    '<li><a id="cookies-info" href="/cookie-policy">Find Out More</a></li>' +
                    '</ul><div class="clear"></div></div>';
    bodytag.insertBefore(div, bodytag.firstChild);
}




function HideCookiePolicy()
{
    var cookiesPopoup = document.getElementById("cookies-wrapper");              // only present if no full page available
    if (cookiesPopoup != null)
        cookiesPopoup.style.display = 'none';
}

