/*
 * IE6 Detection & Deprecation Message
 *
 */

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;

function setCookie(c_name,value,exdays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++) {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name) {
            return unescape(y);
        }
    }
}

document.observe('dom:loaded', function() {
    var ie_mesg = getCookie('ie6_mesg');
    if (Prototype.Browser.IE6 == true) {
        if (ie_mesg == null || ie_mesg == "") {
            blackOut = new Element('div', { 'id': 'blackOut'});
            detectionMsg = "<h3>" + gettext('IE6 Browser Detected') + "</h3>";
            detectionMsg += "<p>" + gettext('You are using an outdated version of Internet Explorer.') + "</p>";
            detectionMsg += "<p>" + gettext('We are no longer supporting IE6 on our website. Please upgrade today to ensure that you can view and use our website properly.') + "</p>";
            detectionMsg += "<p><a href='http://www.theie6countdown.com/'>" + gettext('Internet Explorer 6 Countdown') + "</a></p>";
            redirectClose = new Element('a', {href: 'javascript://', 'id': 'redirectClose'}).update('X');
            redirectWrapper = new Element('div', {'id': 'redirectWrapper'});
            redirectTop = new Element('div', {'id': 'redirectTop'}).update(gettext(detectionMsg));
            redirectBottom = new Element('div', {'id': 'redirectBottom'});


            redirectWrapper.insert(redirectTop, { position: 'bottom'});
            redirectTop.insert(redirectClose, {position: 'bottom'});
            redirectWrapper.insert(redirectBottom, { position: 'bottom'});
            redirectClose.observe('click', function(e) {
                blackOut.hide();
                redirectWrapper.hide();
                setCookie('ie6_mesg', 'True', 1);
            });
            $('footer').insert(blackOut, {position: 'after'});
            $('footer').insert(redirectWrapper, {position: 'after'});
            
            var windowHeightSize = parseInt(redirectWrapper.getStyle('height')) / 2;
            var topAmt = parseInt((document.documentElement.clientHeight / 2)) - windowHeightSize;
            var leftAmt = parseInt((document.documentElement.clientWidth / 2) - 200);
            redirectWrapper.setStyle({'top': topAmt + 'px', 'left': leftAmt + 'px'}); 
            blackOut.setStyle({'height': document.body.clientHeight + 'px'});
        }
    }
});

