
function planner(cid, mid_list, type) {
	this.cid = cid;
	this.mid_list = mid_list;
	this.type = type;

	this.date = new Date();

	this._calendar;
	this.icon_path;
}


function setLifepod() {
	this.entries = new Array();

	switch(this.type) {
		case('mini'):
			this._calendar = new CalendarMini(this.cid);
			break;
		case('nano'):
			this._calendar = new CalendarNano(this.cid);
			break;
		default:
			this._calendar = new Calendar(this.cid);
			this._calendar.addControl(new Calendar.Control.View);
			this._calendar.addControl(new Calendar.Control.Move);
			this._calendar.attachEvent('entryClick', entryClick, this);
			break;
	}

	this._calendar.attachEvent('drawFinish', this.getEntries);
	this._calendar.attachEvent('cal_obj', this._calendar);
	this._calendar.attachEvent('planner_obj', this);
	this._calendar.draw();
}
planner.prototype = Calendar;
planner.prototype.setLifepod = setLifepod;
planner.prototype.getEntries = getEntries;
planner.prototype.quickAdd = quickAdd;
planner.prototype.setEntry = setEntry;


function getEntries() {
	var params = new Array();
	params['mid_list'] = this.planner_obj.mid_list;
	params['year'] = this.cal_obj.date.getFullYear();
	params['month'] = this.cal_obj.date.getMonth()+1;
	if(this.month != params['month'] || this.year != params['year']) {
		this.year = params['year'];
		this.month = params['month'];

		var response_tags = new Array('error','message','entries','iconpath');
		exec_xml('planner', 'getPlannerEntriesXml', params, completeGetEntries, response_tags, params, this);
	} else {
		this.planner_obj.setEntry(null, this);
	}
}


function completeGetEntries(ret_obj, response_tags, params, obj) {
	if(ret_obj['iconpath']) {
		obj.icon_path = ret_obj['iconpath'];
	}
	if(ret_obj['entries']) {
		var entry_obj = eval(ret_obj['entries']);
		this.setEntry(entry_obj, obj);
		if(!entry_obj) return;
	}
}


function setEntry(entries, obj) {
	if(entries) {
		for(i=0; i < entries.length; i++) {
			var entry = entries[i];
			var dv = entries[i].id;
			var userData = Object();

			if(entry.comment >= 1) {
				entry.title = entry.title + ' ['+entry.comment+']';
			}
			if(entry.icons && entry.icons.length >= 1) {
				var icons = '';
				for(k = 0; k < entry.icons.length; k++) {
					icons += '<img src="' + obj.icon_path + entry.icons[k] + '.gif" style="vertical-align: top;" />';
				}
				if(icons) {
					entry.title = icons + entry.title;
				}
			}
			userData.grant = entry.grant;
			userData.icons = icons;

			obj.planner_obj.entries[entry.id] = new Calendar.Entry(entry.id, entry.category, Calendar.str2date(entry.start), Calendar.str2date(entry.end), entry.type, entry.title, entry.description, entry.color, entry.bg, entry.icon, entry.allowTag, userData);
		}
	}
	obj.cal_obj.addEntries(obj.planner_obj.entries);
}


function entryClick(entry) {
	if(entry.userData.grant == 'Y') {
		var url = request_uri.setQuery('mid', current_mid).setQuery('document_srl', entry.id);
		location.href = url;
	}
}


function quickAdd(start, end) {
	alert(start+', '+end);
}
