var Els;
var DP_now		= new Date();
var DP_year		= "";
var DP_month	= "";

var bNets4plus = (navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) >= "4");
var bExpl4plus = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(0,1) >= "4");

function chk(ymd) {
	if(document.mainForm.chkDate.length > 0) {
		for(ii = 0; ii < document.mainForm.chkDate.length; ii++) {
			var sp = document.mainForm.chkDate[ii].value.split("|");
			if((ymd >= sp[0] && ymd <= sp[1]) && sp[2] > 0) {
				return true;
			}
		}
	}
	return false;
}

function DP_start(){
	if(DP_yearS == "") 
		DP_year = DP_now.getFullYear();
	else 
		DP_year = DP_yearS;

	if(DP_yearS == "") 
		DP_month = DP_now.getMonth();
	else 
		DP_month = DP_monthS;


	var tmp = "<style type='text/css'>\
	.calTitle {width:45px;height:24px;background-Color:#9e9d98;color:#ffffff;font-size:9pt}\
	.dayfont {text-align:right;width:40px;height:19px;padding:5px 5px 0px 0px;font-size:8pt;background-Color:#ffffff;cursor:hand}\
	.nofont {text-align:right;width:40px;height:19px;padding:5px 5px 0px 0px;font-size:8pt;background-Color:#ffffff;}\
	.today {text-align:right;width:40px;height:19px;padding:5px 5px 0px 0px;font-size:8pt;background-Color:#f0f3de;cursor:hand}\
	.selday {text-align:right;width:40px;height:19px;padding:5px 5px 0px 0px;font-size:8pt;background-Color:#eee4e3;cursor:hand}\
	.evtday {text-align:right;width:40px;height:19px;padding:5px 5px 0px 0px;font-size:8pt;background-Color:#e5e8ef;cursor:hand}\
	</style>\
	<table id='frm' name='frm' border='0' cellpadding='0' cellspacing='1' bgcolor='fffff7'><tr><td>\
	<table cellpadding='0' cellspacing='0'>\
	<form>\
	<tr height='25'>\
		<td align='left'>\
			<a href='javascript:DP_direc(-1)' onfocus='blur()' class='DPwhite'><img src=/images/event/icon_pre.gif align=absmiddle border=0 alt=ÀÌÀü/></a>\
			<select id'yearS' name='yearS' onChange='DP_chg_date()' style='font-size:8pt'></select>\
			<select id='monthS' name='monthS' onChange='DP_chg_date()' style='font-size:8pt'>\
			<option value='0'> 1¿ù</option>\
			<option value='1'> 2¿ù</option>\
			<option value='2'> 3¿ù</option>\
			<option value='3'> 4¿ù</option>\
			<option value='4'> 5¿ù</option>\
			<option value='5'> 6¿ù</option>\
			<option value='6'> 7¿ù</option>\
			<option value='7'> 8¿ù</option>\
			<option value='8'> 9¿ù</option>\
			<option value='9'> 10¿ù</option>\
			<option value='10'> 11¿ù</option>\
			<option value='11'> 12¿ù</option>\
			</select>\
			<a href='javascript:DP_direc(1)' onfocus='blur()' class='DPwhite'><img src=/images/event/icon_next.gif align=absmiddle border=0 alt=´ÙÀ½/></a>\
		</td>\
	</tr>\
	</form>\
	<tr>\
		<td colspan=3>\
		<table id='oTable' name='oTable' width='100%' cellpadding='0' cellspacing='1' bgcolor='#dcdbe0'>\
			<tr>\
				<th class='calTitle'>ÀÏ</th>\
				<th class='calTitle'>¿ù</th>\
				<th class='calTitle'>È­</th>\
				<th class='calTitle'>¼ö</th>\
				<th class='calTitle'>¸ñ</th>\
				<th class='calTitle'>±Ý</th>\
				<th class='calTitle'>Åä</th>\
			</tr>\
		</table>\
		</td>\
	</tr>\
	</table>\
	</td></tr></table>";
	document.write("<div id='calendar' name='calendar' style=''>"+tmp+"</div>");
	DP_print_cal(DP_year,DP_month);
}

function DP_get_lastDate(year,month){
	var leap;
	var last = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (year%4==0)		leap = true;
	if (year%100==0)	leap = false;
	if (year%400==0)	leap = true;
	if (leap) last[1] = 29;
	return last[month];
}

function DP_get_firstDay(year,month){
	var ici	= new Date(year,month);
	return ici.getDay();
}

function chageMonth(year,month) {
	DP_year = year;
	DP_month = month;
	document.mainForm.yearS.length = 7;
	for (i=0;i<7;i++){
		document.mainForm.yearS.options[i].value = year - 3 + i;
		document.mainForm.yearS.options[i].text = year - 3 + i + "³â";
	}
	document.mainForm.yearS.selectedIndex = 3;
	document.mainForm.monthS.selectedIndex = month;
}

function DP_print_cal(year,month){
	DP_del();
	DP_year = year;
	DP_month = month;

	chageMonth(DP_year,DP_month);

	var firstDay = DP_get_firstDay(year,month);
	var lastDate = DP_get_lastDate(year,month);
	var oTr1 = document.getElementById('oTable');
	var cnt = 0;
	if (firstDay){
		oTr = oTr1.insertRow(1);
		for (i=0;i<firstDay;i++) {
			oTd = oTr.insertCell(i);
			oTd.innerHTML = "<div class='nofont'>&nbsp;</div>";

		}
		cnt = i;
	}
	var cht2 = 2;

	for (i=0;i<lastDate;i++){
		if (cnt%7==0) {
			if (i == 0) cht2--;
			oTr = oTr1.insertRow(cht2);
			cht2++;
		}


		var m = "";
		var d = "";
		if(String(parseInt(month)+1).length == 1) {
			m = "0"+String(parseInt(month)+1);
		} else {
			m = parseInt(month)+1;
		}
		if(String((i+1)).length == 1) {
			d = "0"+String((i+1));
		} else {
			d = (i+1);
		}
		oTd = oTr.insertCell(cnt%7);


		var str = "";
		var strnum = ((cnt%7) == 0 || (cnt%7) == 6) ? "<span style='color:#cd3333;font-weight:bold'>" + (i+1) + "</span>":"<span>" + (i+1) + "</span>";



		if (DP_now.getFullYear()==year && DP_now.getMonth()==month && DP_now.getDate()==i+1) {
			str += "<div class='today'>" + strnum + "</div>";
		} else if(year + "-" + m + "-" + d == DP_date) {
			str += "<div class='selday'>" + strnum + "</div></a>";
		} else if(chk(year + "-" + m + "-" + d)) {
			str += "<div class='evtday'>" + strnum + "</div>";
		} else {
			if (DP_now.getFullYear()==year && DP_now.getMonth()==month && DP_now.getDate()==i+1) {
				str += "<div class='today'>" + strnum + "</div>";
			} else {
				str += "<div class='dayfont'>" + strnum + "</div>";
			}
		}
		oTd.innerHTML = "<a href=\"javascript:DP_set(" + year + "," + (parseInt(month)+1) + "," + (i+1) +")\">"+str+"</a>";
		cnt++;
	}

	if (cnt%7 > 0) {
		for (i=cnt%7;i<7;i++) {
			oTd = oTr.insertCell(i);
			oTd.innerHTML = "<div class='nofont'>&nbsp;</div>";

		}
	}
}

function DP_del(){ 
    for (i=document.getElementById('oTable').rows.length;i>1;i--) document.getElementById('oTable').deleteRow(i-1); 
}

function DP_direc(x){
	DP_month = parseInt(DP_month) + x;
	if (DP_month>11){
		DP_month = DP_month - 12;
		DP_year++;
	} else if (DP_month<0){
		DP_month = DP_month + 12;
		DP_year--;
	}
	chageMonth(DP_year,DP_month);

	var obj = document.mainForm;
	obj.target = "";
	obj.action = "event_event.jsp";
	obj.submit();
}

function DP_set(year,month,date){
	if (month<10) month = "0" + month;
	if (date<10) date = "0" + date;
	var obj = document.mainForm;
	obj.selDate.value = year + "-" + month + "-" + date;
	obj.target = "";
	obj.action = "event_event.jsp";
	obj.submit();
}

function DP_chg_date(){
	DP_year = parseInt(document.mainForm.yearS.value);
	DP_month = parseInt(document.mainForm.monthS.value);
	var obj = document.mainForm;
	obj.target = "";
	obj.action = "event_event.jsp";
	obj.submit();
}