jQuery(document).ready(function() {
    showAlert();    
});

/**
 * Display a FancyBox alert if a) the redirect is coming from acresso.com 
 * and b) the user hasn't already seen the message
 */
function showAlert() 
{
    var url = document.location.href;
    if ((url.indexOf("#acresso") != -1) && ($.cookie('HasSeenAcressoMsg') != 1)) {
        // Show message
        $("body").after('<a id="alert-link" href="#alert-msg" style="display: none;">Show alert</a>');
        $("body").after('<div id="alert-msg" style="display: none;"><div id="acresso-message" style="background-color: #FFF; height: 250px; margin: 0 auto; width: 450px;"><img src="/webdocuments/logo-acresso-flexera.png" style="margin-top: 60px;" /><p style="color: #666; font-size: 14px; line-height: 130%; margin: 15px;">The acresso.com URL will soon be expiring.  Please take a moment to update your bookmarks to flexerasoftware.com.  If you have cookies enabled, this message will not be shown again.</p></div></div>');
        $("a#alert-link").fancybox({ 
            'overlayOpacity': 0.4,
            'overlayColor': '#000000',
            'frameHeight':    250,
            'frameWidth': 450,
            'padding': 0,
            'zoomSpeedIn': 600,
            'zoomSpeedOut': 300
        });
        $("a#alert-link").click().remove();
        
        // Set "has viewed" flag
        setCookie();
    }
}

/**
 * Store a "has viewed" flag for the alert
 */
function setCookie() 
{
    $.cookie('HasSeenAcressoMsg', '1', { 
        expires: 365, 
        path: '/', 
        domain: 'flexerasoftware.com' 
    });
}

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};