dojo.declare("mf_eventCalendar", null, {
	calendar_identifier: "",
	
	AJAX_URL: "",
	
	selected_year: "",
	selected_month: "",
	object_identifier: "",
	
	constructor : function(
				calendar_identifier,
				selected_month,
				selected_year,
				AJAX_URL,
				object_identifier
			) {
		this.calendar_identifier = calendar_identifier;
		this.selected_year = selected_year;
		this.selected_month = selected_month;
		this.AJAX_URL = AJAX_URL;
		this.object_identifier = object_identifier;
	},

	nextMonth: function(){
		this._setMonth(this.selected_month + 1);
	},
	
	previousMonth: function(){
		this._setMonth(this.selected_month - 1);
	},
	
	setMonth: function(which){
		this._setMonth(which);
	},
	
	showContent: function(){
		var calendar_content_node = this._getCalendarContentNode();  
		
		calendar_content_node.innerHTML = this._getLoadingMsg();
		
		dojo.xhrGet({
			url: this.AJAX_URL,
			content: {
				object_identifier: this.object_identifier,
				month: this.selected_month,
				year: this.selected_year
			},
			handleAs: "text",	
			timeout: 60000,
			
			sync: false,
	
			load: function(rsp, ioargs) {

				calendar_content_node.innerHTML = rsp;

				return rsp;
			},
	
			error: function(error, ioargs){				
				console.debug("ERROR", error, ioargs);
			}
		});
		
	},

	_setMonth: function(which) {
		if(which==13) {
			which = 1;
			this.selected_year  = this.selected_year + 1;
		}
		if(which==0) {
			which = 12;
			this.selected_year  = this.selected_year - 1;
		}
		
		var show=0;
		this.selected_month=which;
		this.showContent();		
	},

	_getLoadingMsg: function() {
		return dojo.byId("calendar_loading_msg_"+this.calendar_identifier).innerHTML;
	},
	
	_getCalendarContentNode: function() {
		return dojo.byId("calendar_content_"+this.calendar_identifier);
	}
});

