(function($) {
    $.cookie = function(name, value, options) {
        if (typeof value === 'undefined') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var c = $.trim(cookies[i]).split('=');
                if (c[0] === name) {
                    return decodeURIComponent(c[1]);
                }
            }
            return null;
        } else {
            document.cookie = [
                name + '=' + encodeURIComponent(value),
                options.expires ?
                        '; expires=' + (typeof options.expires === 'number' ?
                                new Date((new Date()).getTime() + options.expires * 1000 * 60 * 60 * 24) :
                                options.expires).toUTCString() :
                        '',
                options.path ? '; path=' + options.path : '',
                options.domain ? '; domain=' + options.domain : ''
            ].join('');
        }
    },

    $.removeCookie = function(name, options) {
        document.cookie = [
            name + '=',
            '; expires=' + (new Date()).toUTCString(),
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : ''
        ].join('');
    }
})(jQuery);
