﻿function wrapButtons() {

    jQuery.each(jQuery(".buttons a"), function (i, val) {
        var b = jQuery(val);
        var BubuttonHTMLttonhtml;
        if (typeof (skinversion) != 'undefined') {
            if (skinversion == 3) {
                if (!b.parent().hasClass('button-wrapper')) {
                    if (!b.hasClass('button')) b.addClass('button');
                    jQuery("<span class='button-wrapper'><span class='button-l'> </span><span class='button-r'> </span></span>").insertBefore(b).append(b);
                    if (b.hasClass('active')) b.parent().addClass('active');
                }
                b.mouseover(function () { jQuery(this).parent().addClass("hover"); });
                b.mouseout(function () { var b = jQuery(this); b.parent().removeClass("hover"); if (!b.hasClass('active')) b.parent().removeClass('active'); });
                b.mousedown(function () { var b = jQuery(this); b.parent().removeClass("hover"); if (!b.hasClass('active')) b.parent().addClass('active'); });
                b.mouseup(function () { var b = jQuery(this); if (!b.hasClass('active')) b.parent().removeClass('active'); });
            }
        } else {
            if (!b.parent().hasClass('button-wrapper')) {
                if (!b.hasClass('button')) b.addClass('button');
                jQuery("<span class='button-wrapper'><span class='l'> </span><span class='r'> </span></span>").insertBefore(b).append(b);
                if (b.hasClass('active')) b.parent().addClass('active');
                //b.css('cursor', 'pointer');
            }
        }
    }).show();

    jQuery.each(jQuery(".RadMenu"), function (i, val) {

        var el = jQuery(val);
        if (!(el.hasClass("cpanel"))) {

            if (el.find('.rmRootGroup').length > 0) {
                el.find('.rmRootGroup').addClass("menu").removeClass("rmRootGroup").show();
                jQuery.each(jQuery(".rmItem a"), function (i, val) {
                    var b = jQuery(val);
                    if (b.siblings('.rmSlide').length > 0) b.parent('li').addClass('rmExpand');
                    b.html("<span class='l'></span><span class='r'></span><span class='t'>" + b.html() + "</span>");
                    if (b.hasClass('active')) b.parents('.rmItem').children('.rmLink').addClass('active');
                });
            }
        }
    }).show();
}

function initToolTip() {
    // clear default tooltip behavior. add custom animation  
    $(".cmdLblHelp").click(function () {
        var tip = $('#' + $(this).attr('id').replace('cmd', 'pnl'));
        if (tip.css('display') == 'none') {
            tip.fadeOut();
        } else {
            $('.ui-tooltip').hide();
            tip.fadeIn();
        }
        return false;
    }).children('img').attr('title', '');
}

/**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;
    }
};

// jGrowl
(function ($) {
    $.jGrowl = function (m, o) {
        if ($('#jGrowl').size() == 0)
            $('<div id="jGrowl"></div>').addClass((o && o.position) ? o.position : $.jGrowl.defaults.position).appendTo('body'); if($.cookie('notify_' + o.value) == null) $('#jGrowl').jGrowl(m, o);
    }; $.fn.jGrowl = function (m, o) {
        if ($.isFunction(this.each)) {
            var args = arguments; return this.each(function () {
                var self = this;  if ($(this).data('jGrowl.instance') == undefined) { $(this).data('jGrowl.instance', $.extend(new $.fn.jGrowl(), { notifications: [], element: null, interval: null })); $(this).data('jGrowl.instance').startup(this); }
                if ($.isFunction($(this).data('jGrowl.instance')[m])) { $(this).data('jGrowl.instance')[m].apply($(this).data('jGrowl.instance'), $.makeArray(args).slice(1)); } else { $(this).data('jGrowl.instance').create(m, o); } 
            });
        };
    }; $.extend($.fn.jGrowl.prototype, { defaults: { pool: 0, header: '', group: '', sticky: false, position: 'top-right', glue: 'after', theme: 'default', themeState: 'highlight', corners: '10px', check: 250, life: 3000, closeDuration: 'normal', openDuration: 'normal', easing: 'swing', closer: false, closeTemplate: '&times;', closerTemplate: '<div>[ close all ]</div>', log: function (e, m, o) { }, beforeOpen: function (e, m, o) { }, afterOpen: function (e, m, o) { }, open: function (e, m, o) { }, beforeClose: function (e, m, o) { }, close: function (e, m, o) { }, animateOpen: { opacity: 'show' }, animateClose: { opacity: 'hide'} }, notifications: [], element: null, interval: null, create: function (message, o) {
        var o = $.extend({}, this.defaults, o); if (typeof o.speed !== 'undefined') { o.openDuration = o.speed; o.closeDuration = o.speed; }
        this.notifications.push({ message: message, options: o }); o.log.apply(this.element, [this.element, message, o]);
    }, render: function (notification) {
        var self = this; var message = notification.message; var o = notification.options; var notification = $('<div class="jGrowl-notification ' + o.themeState + ' ui-corner-all' +
((o.group != undefined && o.group != '') ? ' ' + o.group : '') + '">' + '<div class="jGrowl-close">' + o.closeTemplate + '</div>' + '<div class="jGrowl-header">' + o.header + '</div>' + '<div class="jGrowl-message">' + message + '</div></div>').data("jGrowl", o).addClass(o.theme).children('div.jGrowl-close').attr('rel', o.value).bind("click.jGrowl", function () { $.cookie('notify_' + o.value, 'hide', { expires: .0416}); $(this).parent().trigger('jGrowl.close'); }).parent(); $(notification).bind("mouseover.jGrowl", function () { $('div.jGrowl-notification', self.element).data("jGrowl.pause", true); }).bind("mouseout.jGrowl", function () { $('div.jGrowl-notification', self.element).data("jGrowl.pause", false); }).bind('jGrowl.beforeOpen', function () { if (o.beforeOpen.apply(notification, [notification, message, o, self.element]) != false) { $(this).trigger('jGrowl.open'); } }).bind('jGrowl.open', function () {
    if (o.open.apply(notification, [notification, message, o, self.element]) != false) {
        if (o.glue == 'after') { $('div.jGrowl-notification:last', self.element).after(notification); } else { $('div.jGrowl-notification:first', self.element).before(notification); }
        $(this).animate(o.animateOpen, o.openDuration, o.easing, function () {
            if ($.browser.msie && (parseInt($(this).css('opacity'), 10) === 1 || parseInt($(this).css('opacity'), 10) === 0))
                this.style.removeAttribute('filter'); $(this).data("jGrowl").created = new Date(); $(this).trigger('jGrowl.afterOpen');
        });
    } 
}).bind('jGrowl.afterOpen', function () { o.afterOpen.apply(notification, [notification, message, o, self.element]); }).bind('jGrowl.beforeClose', function () {
    if (o.beforeClose.apply(notification, [notification, message, o, self.element]) != false)
        $(this).trigger('jGrowl.close');
}).bind('jGrowl.close', function () {
    $(this).data('jGrowl.pause', true); $(this).animate(o.animateClose, o.closeDuration, o.easing, function () {
        $(this).remove(); var close = o.close.apply(notification, [notification, message, o, self.element]); if ($.isFunction(close))
            close.apply(notification, [notification, message, o, self.element]);
    });
}).trigger('jGrowl.beforeOpen'); if (o.corners != '' && $.fn.corner != undefined) $(notification).corner(o.corners); if ($('div.jGrowl-notification:parent', self.element).size() > 1 && $('div.jGrowl-closer', self.element).size() == 0 && this.defaults.closer != false) { $(this.defaults.closerTemplate).addClass('jGrowl-closer ui-state-highlight ui-corner-all').addClass(this.defaults.theme).appendTo(self.element).animate(this.defaults.animateOpen, this.defaults.speed, this.defaults.easing).bind("click.jGrowl", function () { $(this).siblings().trigger("jGrowl.beforeClose"); if ($.isFunction(self.defaults.closer)) { self.defaults.closer.apply($(this).parent()[0], [$(this).parent()[0]]); } }); };
    }, update: function () {
        $(this.element).find('div.jGrowl-notification:parent').each(function () { if ($(this).data("jGrowl") != undefined && $(this).data("jGrowl").created != undefined && ($(this).data("jGrowl").created.getTime() + parseInt($(this).data("jGrowl").life)) < (new Date()).getTime() && $(this).data("jGrowl").sticky != true && ($(this).data("jGrowl.pause") == undefined || $(this).data("jGrowl.pause") != true)) { $(this).trigger('jGrowl.beforeClose'); } }); if (this.notifications.length > 0 && (this.defaults.pool == 0 || $(this.element).find('div.jGrowl-notification:parent').size() < this.defaults.pool))
            this.render(this.notifications.shift()); if ($(this.element).find('div.jGrowl-notification:parent').size() < 2) { $(this.element).find('div.jGrowl-closer').animate(this.defaults.animateClose, this.defaults.speed, this.defaults.easing, function () { $(this).remove(); }); } 
    }, startup: function (e) { this.element = $(e).addClass('jGrowl').append('<div class="jGrowl-notification"></div>'); this.interval = setInterval(function () { $(e).data('jGrowl.instance').update(); }, parseInt(this.defaults.check)); if ($.browser.msie && parseInt($.browser.version) < 7 && !window["XMLHttpRequest"]) { $(this.element).addClass('ie6'); } }, shutdown: function () { $(this.element).removeClass('jGrowl').find('div.jGrowl-notification').remove(); clearInterval(this.interval); }, close: function () { $(this.element).find('div.jGrowl-notification').each(function () { $(this).trigger('jGrowl.beforeClose'); }); } 
    }); $.jGrowl.defaults = $.fn.jGrowl.prototype.defaults;
})(jQuery);

$(document).ready(function () {

    initToolTip();

    wrapButtons();

});

function pageLoad() {
    initToolTip();

    wrapButtons();
}
