//var ShamsiWeekView = kendo.ui.MultiDayView.extend({
//    nextDate: function () {
//        return kendo.date.nextDay(this.startDate());
//    },
//    options: {
//        selectedDateFormat: "{0:D} - {1:D}"
//    },
//    name: "ShamsiWeekView",
//    calculateDateRange: function () {
//        //create a range of dates to be shown within the view
//        //var selectedDate = this.options.date,
//            // start = kendo.date.dayOfWeek(selectedDate, this.calendarInfo().firstDay, -1),
//            var start = GetStartDateOfWeek(this.options.date),
//            idx, length,
//            dates = [];

//        for (idx = 0, length = 7; idx < length; idx++) {
//            dates.push(start);
//            start = kendo.date.nextDay(start);
//        }
//        this._render(dates);
//    }
//});

//var ShamsiMonthView = kendo.ui.MonthView.extend({
//    name: "ShamsiMonthView",
//    _renderLayout: function (date) {
//        var that = this;

//        this._firstDayOfMonth = GetStartDateOfMonth(date);

//        this._lastDayOfMonth = GetLastDateOfMonth(date);

//        this._startDate = GetStartDateOfWeek(GetStartDateOfMonth(date));

//        this.createLayout(KendoShamsilayout(this));

//        this._content();

//        this.refreshLayout();

//        this.content.on("click" + ".kendo", ".k-nav-day,.k-more-events", function (e) {
//            var offset = $(e.currentTarget).offset();
//            var slot = that._slotByPosition(offset.left, offset.top);

//            e.preventDefault();
//            that.trigger("navigate", { view: "day", date: slot.startDate() });
//        });
//    }
//});

function KendoShamsilayout(kendoObject) {
    //var calendarInfo = this.calendarInfo();
    var calendarInfo = kendo.cultures["fa-IR"].calendars.standard;
    var weekDayNames = kendoObject._isMobile() ? calendarInfo.days.namesShort : calendarInfo.days.names;
    var names = shiftArray(weekDayNames, calendarInfo.firstDay);
    var columns = $.map(names, function(value) { return { text: value }; });
    var resources = kendoObject.groupedResources;
    var rows;

    if (resources.length) {
        if (kendoObject._isVerticallyGrouped()) {
            var inner = []; //add hidden cells in order to sync the content rows
            for (var idx = 0; idx < 6; idx++) {
                inner.push({ text: "<div>&nbsp;</div>", className: "k-hidden k-slot-cell" });
            }

            rows = kendoObject._createRowsLayout(resources, inner, kendoObject.groupHeaderTemplate);
        } else {
            columns = kendoObject._createColumnsLayout(resources, columns, kendoObject.groupHeaderTemplate);
        }
    }

    return {
        columns: columns,
        rows: rows
    };
}
function GetStartDateOfMonth(DateObg) {
    var date = new JalaliDate().gregorianToJalali(DateObg.getFullYear(), DateObg.getMonth() + 1, DateObg.getDate())[2];
    diff = DateObg.getDate() - date + 1;
    var startOfWeek = new Date(DateObg.setDate(diff));
    return startOfWeek;
}
function GetLastDateOfMonth(DateObg) {
    var date = new JalaliDate().gregorianToJalali(DateObg.getFullYear(), DateObg.getMonth() + 1, DateObg.getDate());
    diff = DateObg.getDate() - date[2] + GetShamsiDayCountOfMonth(date);
    var startOfWeek = new Date(DateObg.setDate(diff));
    return startOfWeek;
}
function FirstShamsiVisibleMonthDay(DateObg) {
    var date = GetStartDateOfWeek(GetStartDateOfMonth(DateObg));
    diff = DateObg.getDate() - date + 31;
    var startOfWeek = new Date(DateObg.setDate(diff));
    return startOfWeek;
}
function GetStartDateOfWeek(DateObg) {
    var day = DateObg.getDay(),
    diff = DateObg.getDate() - day - (DateObg.getDate() == 6 ? -6 : 1);
    var startOfWeek = new Date(DateObg.setDate(diff));
    return startOfWeek;
}
function GetShamsiDayCountOfMonth(JalaliDateArrayItem) {
    return new JalaliDate(JalaliDateArrayItem[0], JalaliDateArrayItem[1], 0).jalalidate[2];
}

function shiftArray(array, idx) {
    return array.slice(idx).concat(array.slice(0, idx));
}