/**
 * @author Tamada
 */

var sPath = './';
var sFolder = '';

document.write('<script type="text/javascript" src="'+sPath+'calendar/js/xml_read.js"></script>');
// 月日HTML配置
function setMonthHtml() {
	
	calHtml = '<ul class="tabnav">';
	calHtml += '<li class="this"><a href="./calendar/?yr='+nYear+'&mt='+nMonth+'">'+nYear+'年'+nMonth+'月</a></li>';
	nowDate = new Date( nowYear, nowMonth, 1 );
	deffDate1 = new Date( nYear, nMonth, 1 );		// 表示月
	deffDate2 = new Date( nowYear, nowMonth+6, 1 );		// 6カ月後
	if( nowDate.getTime() >= deffDate1.getTime() ) {
		calHtml += '<li><img src="images/home/btn_cal_prev.gif" alt="前月" /></li>';
	}
	else {
		calHtml += '<li><a href="javascript:void(0);" onclick="setPrev();return false;"><img src="images/home/btn_cal_prev.gif" alt="前月" /></a></li>';
	}
	if( deffDate1.getTime() >= deffDate2.getTime() ) {
		calHtml += '<li class="next"><img src="images/home/btn_cal_next.gif" alt="次月" /></li>';
	}
	else {
		calHtml += '<li class="next"><a href="javascript:void(0);" onclick="setNext();return false;"><img src="images/home/btn_cal_next.gif" alt="次月" /></a></li>';
	}
	calHtml += '</ul>';
	$('div.con_calendar div.month').html(calHtml);
	
	/*
				<ul class="tabnav">
					<li class="this"><a href="#this">2011年11月</a></li>
					<li><a href="#prev"><img src="images/home/btn_cal_prev.gif" alt="前月" /></a></li>
					<li><a href="#next"><img src="images/home/btn_cal_next.gif" alt="次月" /></a></li>
				</ul>
	 */
}

// カレンダーHTML配置
function setCalendarHtml(xml) {
	calHtml = '';
	calHtml += '<table cellspacin="0" cellpadding="0" border="0" summary="イベントカレンダー">';
	
	// xmlから曜日、日付を取得
	arrWeek = new Array( "", "日", "月", "火", "水", "木", "金", "土" );
	tmpWeek = '';
	tmpDay = '';
	$(xml).find("day").each(function(idx){
		xmlWeek = $(this).find("week_id").text();
		xmlDay = $(this).find("event_day").text();
		xmlEvent = $(this).find("event_disp").text();
		end = parseInt(xmlWeek);
		if( idx == 0 ) {
			// 開始のtd
			for( i = 0; i < end; i++ ) {
				tmpDay += '<td class="tb_day">&nbsp;</td>';
			}
		}
		if( end == 0 ) {
			tmpDay += '</tr>';
			tmpDay += '<tr>';
		}
		clsDate = 'tb_day';
		switch(xmlWeek){
			case '6':
				clsDate = 'tb_sat';
				break;
			case '0':
				clsDate = 'tb_sun';
				break;
		}
		// 本日
		xmlYr = $(this).find('event_year').text();
		xmlMt = $(this).find('event_month').text();
		xmlDy = $(this).find('event_day').text();
		def1Date = new Date(xmlYr, parseInt(xmlMt)-1, xmlDy);
		def2Date = new Date(objDate.getFullYear(), objDate.getMonth(), objDate.getDate());
		if( def1Date.getTime() == def2Date.getTime() ){
			clsDate = "today";
		}
		// イベント
		if( xmlEvent == "t" ) {
			//nDate = nYear + "-" + nMonth + "-" + xmlDay;
			clsDate += " event";
			tmpDay += '<td class="'+clsDate+'"><a href="./calendar/?yr='+nYear+'&mt='+nMonth+'&dy='+xmlDay+'">'+xmlDay+'</a></td>';
		}
		else {
			tmpDay += '<td class="'+clsDate+'">'+xmlDay+'</td>';
		}
		// 最終日
		var lastDate = new Date(xmlYr, xmlMt, 0);
		if( lastDate.getDate() == def1Date.getDate() ){
			// 開始のtd
			for(var l = xmlWeek; l < 6; l++ ) {
				tmpDay += '<td class="tb_day">&nbsp;</td>';
			}
		}
	});
	
	// 曜日
	calHtml += '</tbody>';
	calHtml += '<tr>';
	calHtml += tmpDay;
	calHtml += '</tr>';
	calHtml += '</table>';
	
	$('div.con_calendar div.box_cal').html(calHtml);
	
				/*
				<table cellspacing="0" cellpadding="0" border="0" summary="イベントカレンダー">
					<tbody>
						<tr>
							<td class="tb_sun">1</td>
							<td class="tb_day">2</td>
							<td class="tb_day">3</td>
							<td class="tb_day">4</td>
							<td class="tb_day today">5</td>
							<td class="tb_day">6</td>
							<td class="tb_sat">7</td>
						</tr>
						<tr>
							<td class="tb_sun">8</td>
							<td class="tb_day">9</td>
							<td class="tb_day">10</td>
							<td class="event"><a href="#">11</a></td>
							<td class="tb_day">12</td>
							<td class="tb_day">13</td>
							<td class="tb_sat">14</td>
						</tr>
					</tbody>
				</table>
				*/
}

// カレンダー取得失敗
function setCalendarFalse() {
	$('div.con_calendar div.box_cal').html('<p>準備中です</p>');
}

// イベントHTML配置
function setEventHtml(xml) {
}

// イベント取得失敗
function setEventFalse() {
	
}

