// calendar helper function needed on profile pages & mypage
// or wherever our calendar needs to be displayed

function CalendarHelper() {

	this.bas_cal = '';
	this.dp_cal = ''
	this.ms_cal = '';  
	this.calendarMap = new Object();
	this.profile = 'false';
	
	this.createCalendarMap = function(tempList) {
		// profileCalendar object is available globally
		// it is defined on the page (mypage and profile page)
		for(var i=0; i<tempList.length; i++) {	
			var schedule = eval(tempList[i]);
			var startTime = eval(schedule['startTime']);
			var startDate = new Date();
			startDate.setTime(startTime);
			var tempArray = this.calendarMap[startDate.formatDate("m/d/Y")];
			if(tempArray) {
				tempArray.push(tempList[i]);	
			} else {
				tempArray = new Array();
				tempArray.push(tempList[i]);
				this.calendarMap[startDate.formatDate("m/d/Y")] = tempArray;
			}
		}	
	}
	
	this.loadCalendar = function() {
	    while ($("multi_container").hasChildNodes()) {
	        $("multi_container").removeChild($("multi_container").lastChild);
	    }
		this.ms_cal  = new Epoch('epoch_multi','flat',$('multi_container'),true, profileCalendar.profile);
	}
	
	this.showSchedule = function(key, profile) {
		var scheduleList = eval(this.calendarMap[key]);
		var detailsDiv = document.getElementById('calDetails');	
		var resultString = '';
		
		if(scheduleList != null) {
			for(var i=0; i < scheduleList.length; i++) {
			
				var startTime = eval(scheduleList[i]['startTime']);
				var startDate = new Date();
				startDate.setTime(startTime);
				
				var endTime = eval(scheduleList[i]['endTime']);
				var endDate = new Date();
				endDate.setTime(endTime);						

				if (profile == 'true') {
					resultString += '<div class="date">';
					resultString += createAddScheduleButtonStr(scheduleList[i]['scheduleId']);
					resultString += startDate.formatDate("m/d/Y");
					resultString += ': <span class="time">';
					resultString += startDate.formatDate("g:i a") + ' - ' + endDate.formatDate("g:i a");
					resultString += '</span></div><div class="title">';
					resultString += scheduleList[i]['title'];
					resultString += '</div><div class="description">';
					resultString += scheduleList[i]['description'];
					resultString += '</div>';
				} else {
					resultString += '<div class="calEvent"><div class="lBox">';
					resultString += '<div class="profileImage"><a href="/profile/' + scheduleList[i]['userName'] +'">';
					resultString += '<img src="' + scheduleList[i]['profileImageUrl'] + '"></a></div>';
					resultString += '<div class="userName"><a href="/profile/' + scheduleList[i]['userName'] + '">' + scheduleList[i]['screenName'] + '</a></div></div>';
					resultString += '<div class="rBox"><div class="removeEvent"><a href="javascript:removeUserSchedule(\'' + scheduleList[i]['scheduleId'] + '\',\'' + scheduleList[i]['mySchedule'] + '\')"><img title="Remove Event" src="/images/en/member/mypage_062007/minusicon.gif"></a></div>';
					resultString += '<div class="date">' + startDate.formatDate("m/d/Y");
					resultString += '<span class="time"> ' + startDate.formatDate("g:i a") + ' - ' + endDate.formatDate("g:i a") + '</span></div>';
					resultString += '<div class="title">' + scheduleList[i]['title'] + '</div>';
					resultString += '<div class="description">' + scheduleList[i]['description'] + '</div></div></div>';
				}
			}
		} else {
			resultString = 'No Scheduled Shows';
		}
		
		detailsDiv.innerHTML = resultString;
	}
}
