﻿// JSLint Config:
/*jslint browser: true */
/*global cc, jQuery, cc_resx_TR_You_Using_Unsupported_Browser, cc_resx_TR_close,  */

//  
//  Author: Kevin Burkitt
//  Date:   2010-05-06
//
//  See: http://think2loud.com/build-an-unsupported-browser-warning-with-jquery/
//
//  Checks if the Browser is supported and if not displays a message - if user clicks CLOSE a cookie
//  is saved so that the message is not displayed again
//
cc.badbrowser = function() {
    return {

        init: function() {
            if (cc.badbrowser.badBrowser() && cc.badbrowser.getBadBrowser('browserWarning') !== 'seen') {
                var html = "<div id=\"browserWarning\" class=\"top-notify\"><div class=\"page-center clearfix\"><div class=\"left\">";
                html += "<h3>" + cc_resx_TR_You_Using_Unsupported_Browser + "</h3>";
                html += "</div><div class=\"right\"><a href='#' id='browser-warning-close'>" + cc_resx_TR_close + "</a>";
                html += "</div></div></div>";

                jQuery(html).prependTo("body");

                jQuery('#browser-warning-close').click(function() {
                    cc.badbrowser.setBadBrowser('browserWarning', 'seen');
                    jQuery('#browserWarning').slideUp(500);
                    return false;
                });
            }
        },


        badBrowser: function() {
            if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
                return true;
            }

            return false;
        },

        getBadBrowser: function(c_name) {
            if (document.cookie.length > 0) {
                var c_start = document.cookie.indexOf(c_name + "=");
                if (c_start !== -1) {
                    c_start = c_start + c_name.length + 1;
                    var c_end = document.cookie.indexOf(";", c_start);
                    if (c_end === -1) {
                        c_end = document.cookie.length;
                    }
                    return unescape(document.cookie.substring(c_start, c_end));
                }
            }
            return "";
        },

        setBadBrowser: function(c_name, value, expiredays) {
            var exdate = new Date();
            exdate.setDate(exdate.getDate() + expiredays);
            document.cookie = c_name + "=" + escape(value) + ((expiredays === null) ? "" : ";expires=" + exdate.toGMTString());
        }

    };
} ();

