window.Partials = window.Partials || {};

$(function () {
    Globalize.culture(navigator.language || navigator.browserLanguage);

    DevExpress.data.utils.odata.keyConverters.DateTime = function (value) {
        return new DevExpress.data.EdmLiteral("datetime'" + moment(value).format('YYYY-MM-DDTHH:mm:ss') + "'");
    }

    ko.subscribable.fn.subscribeChanged = function (callback) {
        var previousValue;
        this.subscribe(function (_previousValue) {
            previousValue = _previousValue;
        }, undefined, 'beforeChange');
        this.subscribe(function (latestValue) {
            callback(latestValue, previousValue);
        });
    };

    Date.prototype.nextMonth = function () {
        var thisMonth = this.getMonth();
        this.setMonth(thisMonth + 1);
        if (this.getMonth() != thisMonth + 1 && this.getMonth() != 0)
            this.setDate(0);
    };

    Date.prototype.prevMonth = function () {
        var thisMonth = this.getMonth();
        this.setMonth(thisMonth - 1);
        if (this.getMonth() != thisMonth - 1 && (this.getMonth() != 11 || (thisMonth == 11 && this.getDate() == 1)))
            this.setDate(0);
    };

    Partials.app = new DevExpress.framework.html.HtmlApplication({
        namespace: Partials,
        layoutSet: DevExpress.framework.html.layoutSets[Partials.config.layoutSet],
        navigation: Partials.config.navigation,
        commandMapping: Partials.config.commandMapping
    });
    Partials.app.router.register(":view/:id", { view: "home", id: undefined });
    Partials.app.navigate();
});