﻿
var objFetchCalendar = null;

function init_Calendar(_moduleid, _iseditable) {
    
    var options = {
        height: 750,
        width: 600,
        navHeight: 25,
        labelHeight: 25,
        onMonthChanging: function(dateIn) {
            loadEvents(_moduleid, dateIn, "Month");
        },
        onEventLinkClick: function(event) {
            return false
        },
        onEventBlockClick: function(event) {
            return false;
        },
        onEventBlockOver: function(event) {
            return false;
        },
        onEventBlockOut: function(event) {
            return false;
        },
        onDayLinkClick: function(date) {
            return false;
        },
        onDayCellClick: function(date) {
            return false;
        }
    };
    
    $.jMonthCalendar.Initialize(options, []);

    loadEvents(_moduleid, Date.today().moveToFirstDayOfMonth(), "Month");
    
    //SetEditControls(_iseditable, _moduleid, 'calendar');
}

function loadEvents(_moduleid, dateIn, mode) {

    // clear all dates on the calendar
    $.jMonthCalendar.ReplaceEventCollection([]);
    
    // if ajax call is in process, cancel it        
    if (objFetchCalendar) {
        objFetchCalendar.abort();
    }
    
    // fetch the data from the webservice
    objFetchCalendar = $.ajax({
        type: "POST",
        url: "/desktopmodules/sitebuilder/components/WebService.asmx/FetchCalendar_Current",
        // pass parameters to webmethod
        data: "{PortalID: " + _PortalID + ", ModuleID: " + _moduleid + ", StartDate: '" + dateIn.toString('MM/dd/yyyy') + "', View: 'Month', URL: '" + dnn.getVar('publicurl') + "?skin=" + _SiteSkin + "&mode=calendar_detail&itemid={0}'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            // add new dates to the calendar
        $.jMonthCalendar.AddEvents(msg);
            
            return true;
        }
    });
}