c1.documentReady(function () {
    var wsNavBtn = document.querySelector('.header .list-icon.wide-screen'),
        nsNavBtn = document.querySelector('.header .list-icon.narrow-screen');

    wsNavBtn.addEventListener('click', function () {
        var body = document.querySelector('div.body');
        toggleClass(body, "collapsed");
        $(window).trigger("resize");
    });

    var dropdownNav = document.querySelector('.dropdown-nav.narrow-screen');
    new c1.sample.MultiLevelMenu(dropdownNav, nsNavBtn);
});

function hasClass(obj, cls) {
    return obj && obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}

function addClass(obj, cls) {
    if (obj && !this.hasClass(obj, cls)) obj.className += ' ' + cls;
}

function removeClass(obj, cls) {
    if (obj && hasClass(obj, cls)) {
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        obj.className = obj.className.replace(reg, ' ');
    }
}

function toggleClass(obj, cls) {
    if (hasClass(obj, cls)) {
        removeClass(obj, cls);
    } else {
        addClass(obj, cls);
    }
}

function refreshData(start, end, action, callback, data) {
    var startDate = new Date(start);
    var endDate = new Date(end);
    if (!data) {
        data = {};
    }
    if (start != null) {
        data.startDate = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getFullYear();
        data.start = start;
    }
    if (end != null) {
        data.endDate = (endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + endDate.getFullYear();
        data.end = end;
    }

    $.ajax(action, {
        success: function (data) {
            callback(data);
        },
        data: data,
        dataType: "json",
        type: "POST"
    });
}