function renderHoliday(cal, cell) {
	YAHOO.util.Dom.addClass(cell, "holiday");
}

function renderReserved(cal, cell) {
	YAHOO.util.Dom.addClass(cell, "reserved");
	YAHOO.calendar.cal.renderOutOfBoundsDate(cal, cell);
	return YAHOO.widget.Calendar.STOP_RENDER;
}

function renderClosed(cal, cell) {
	YAHOO.util.Dom.addClass(cell, "closed");
	YAHOO.calendar.cal.renderOutOfBoundsDate(cal, cell);
	return YAHOO.widget.Calendar.STOP_RENDER;
}

function toggle() {
	var obj = document.getElementById("calendarWrapper");
	var display = obj.style.display.toLowerCase();
	if(display == "block") {
		obj.style.display = "none";
	} else {
		obj.style.display = "block";
	}
}

function handleSelect(type, args, obj) {
	var dates = args[0];
	var date = dates[0];
	var year = date[0]
	var month = date[1]
	var day = date[2];
	
	var selYear = document.getElementById("year");
	var selMonth = document.getElementById("month");
	var selDay = document.getElementById("day");
	
	for (var y=0; y<selYear.options.length; y++) {
		if (selYear.options[y].value == year) {
			selYear.selectedIndex = y;
			break;
		}
	}
	
	for (var m=0; m<selMonth.options.length; m++) {
		if (selMonth.options[m].value == month) {
			selMonth.selectedIndex = m;
			break;
		}
	}
	selDay.selectedIndex = day;
	
	document.getElementById("calendarWrapper").style.display = "none";
}

// YUI Calendar

YAHOO.namespace("calendar");

YAHOO.calendar.init = function() {
	var yearLabelSuffix, monthsLong, weekdaysShort, titleString;
	if(location.href.match(/_e\.php$/)) {
		yearLabelSuffix = "/";
		monthsLong = ["1","2","3","4","5","6","7","8","9","10","11","12"];
		weekdaysShort = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
		titleString = "<span class='reserved'>&nbsp;&nbsp;&nbsp;</span> Reserved day&nbsp;&nbsp;&nbsp;&nbsp;<span class='closed'>&nbsp;&nbsp;&nbsp;</span> Closed day";
	} else {
		yearLabelSuffix = "年";
		monthsLong = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
		weekdaysShort = ["日", "月", "火", "水", "木", "金", "土"];
		titleString = "<span class='reserved'>&nbsp;&nbsp;&nbsp;</span> 貸し切り日&nbsp;&nbsp;&nbsp;&nbsp;<span class='closed'>&nbsp;&nbsp;&nbsp;</span> クローズ日";
	}
	YAHOO.calendar.cal = new YAHOO.widget.CalendarGroup("cal", "calendar", {
		pages : 3,
		pagedate : startMonth,
		mindate : startDay,
		maxdate : endDay,
		hide_blank_weeks : true,
		MY_LABEL_YEAR_POSITION :  1,
		MY_LABEL_MONTH_POSITION :  2,
		MY_LABEL_YEAR_SUFFIX :  yearLabelSuffix,
		MONTHS_LONG : monthsLong,
		WEEKDAYS_SHORT : weekdaysShort,
		title: titleString
	});
	
	YAHOO.calendar.cal.deselect("3/21/2008");
	
	for(var i=0; i<holiday.length; i++) {
		YAHOO.calendar.cal.addRenderer(holiday[i], renderHoliday);
	}
	
	for(var i=0; i<reservedDay.length; i++) {
		YAHOO.calendar.cal.addRenderer(reservedDay[i], renderReserved);
	}
	
	for(var i=0; i<closedDay.length; i++) {
		YAHOO.calendar.cal.addRenderer(closedDay[i], renderClosed);
	}
	
	YAHOO.calendar.cal.selectEvent.subscribe(handleSelect, YAHOO.calendar.cal, true);
	
	YAHOO.calendar.cal.render();
}

YAHOO.util.Event.onDOMReady(YAHOO.calendar.init);

