﻿var days = new Array("sun", "mon", "tue", "wed", "thu", "fri", "sat");
function showCalendar(year, month, date, flag){
	var oDateOfCurrent;
	if(year != null && month != null && date != null){
		oDateOfCurrent = new Date(year, month, date);
	}else{
		oDateOfCurrent = new Date();//인수가 없을때
	}

	var currentYear = oDateOfCurrent.getFullYear(); // 년
	var currentMonth = oDateOfCurrent.getMonth(); // 월
	var currentDate = oDateOfCurrent.getDate(); // 일

	var oDateTemp;
	var tmpeYear;
	var tempMonth;
	var tempDate = 1;
	var tempDay;

	var calendar = "<table width=\"100%\"  class=\"calendar\" \n" +
					"	<colgroup><col width='33' /><col width='33' /><col width='33' /><col width='33' /><col width='33' /><col width='33' /><col width='33' /></colgroup>\n" +
					"	<thead><tr class=\"year\">\n" +
					"		<th colspan=\"7\">\n" + 
					"			<span onclick=\"javascript:showCalendar(" + currentYear + "," + (currentMonth-1) + "," + currentDate + ", 0)\" style='cursor:pointer;'><img src='http://static.ndolfin.com/201012/images/btn/btn_calendar_before.gif' alt='이전' /></span>\n" +
					"			<span class='date'>" + currentYear + ".\n" + 
					"			" + (currentMonth + 1) +"\n" +
					"			</span> \n" +
					"			<span onclick=\"javascript:showCalendar(" + currentYear + "," + (currentMonth+1) + "," + currentDate + ", 0)\" style='cursor:pointer;'><img src='http://static.ndolfin.com/201012/images/btn/btn_calendar_next.gif' alt='이후' /></span>\n" +
					"		</th>\n" +
					"	</tr>\n" +
					"	<tr class='header'>\n" +
					"		<td style='border-left:1px solid #d8d8d8;'><img src='http://static.ndolfin.com/201012/images/contents/tit_calendar1.gif' alt='SUN' /></td>\n" +
					"		<td><img src='http://static.ndolfin.com/201012/images/contents/tit_calendar2.gif' alt='MON' /></td>\n" +
					"		<td><img src='http://static.ndolfin.com/201012/images/contents/tit_calendar3.gif' alt='TUE' /></td>\n" +
					"		<td><img src='http://static.ndolfin.com/201012/images/contents/tit_calendar4.gif' alt='WEB' /></td>\n" +
					"		<td><img src='http://static.ndolfin.com/201012/images/contents/tit_calendar5.gif' alt='THR' /></td>\n" +
					"		<td><img src='http://static.ndolfin.com/201012/images/contents/tit_calendar6.gif' alt='FRI' /></td>\n" +
					"		<td class='last'><img src='http://static.ndolfin.com/201012/images/contents/tit_calendar7.gif' alt='SAT' /></td>\n" +
					"	</tr></thead><tbody>\n";
	for(var row = 0; row < 6; row++){
		calendar += "	<tr>\n";

		for(var col = 0; col < 7; col++){
			oDateTemp = new Date(currentYear, currentMonth, tempDate); // 달력 시작 년,월,일
			tempDay = oDateTemp.getDay();
			tempMonth = oDateTemp.getMonth();
			if(tempDay <= col && tempMonth == currentMonth){ // 해당 월, 요일과 맞는 일자만출력
				tempYear = oDateTemp.getFullYear();


               var d = new Date();

                var nowDay = d.getFullYear() + "-" + d.getMonth() + "-" + d.getDate();
                var tDay = tempYear + "-" + tempMonth + "-" + tempDate;

                var showDay = year + "-" + month + "-" + date;

                // ********* 여기서 일정이 있을 경우 td class="note" *************
                //if (tempDate == currentDate) {

                if (flag == 1) {
                    if (tDay == showDay) {
                        calendar += "		<td class=\"note\">";
                    } else if (tDay == nowDay) {
                        calendar += "		<td class=\"note\">";
                    } else {
                        calendar += "		<td>";
                    }
                } else {
                    if (tDay == nowDay) {
                        calendar += "		<td class=\"note\">";
                    } else {
                        calendar += "		<td>";
                    }
                }
// event
				calendar += "<span onclick=showPlan('" + currentYear + "','" + (currentMonth + 1) + "','" + tempDate + "');>" + (tempDate++) + "</span>";
// empty 
			}else{ 
				calendar += "		<td class='blank'>&nbsp;";
			}
			calendar += "</td>\n";
		}
		calendar += "	</tr>\n";
	}
	calendar += "</tbody></table>\n";
	
	document.getElementById("calendar").innerHTML = calendar;
}


function showPlan(year,month,date){
	GetList(year,month, date);
	showCalendar(year, month-1, date, 1);
	document.getElementById('plan_date').innerHTML = "<strong>" + year + "." + month + "." + date + "</strong>의 일정입니다.";
	document.getElementById('plan').style.display = "block";
}
