var action_global = ""; //actionÀÇ Àü¿ªº¯¼ö

function cal(year, month, day, action){
	var i, j, day_num=1;
	var last_week, month_link="";
	var calDate = new Date(year, month-1, day_num);
	var checkDate = new Date();
	var date_array = new Array(6);

	for(i=0;i<6;i++) date_array[i] = new Array("","","","","","","");

	//½ºÅ©¸³Æ® ÃßÃâ ¹× º¯È¯, ³»¿ëÀÌ ¾øÀ¸¸é ¸¶Áö¸· action »ç¿ë
	if(action == ""){
		script = action_global;
	}else{
		var script = action;
		var action_mode = action.substring(0,3);
		if(action_mode.toLowerCase()=="url") script = "document.location.href='"+action.substring(4,action.length)+"'";
		action_global = script;
	}

	for(j=0;j<6;j++){
		for(i=0;i<7;i++){
			if(j==0 && i==0)i = calDate.getDay();
			
			//day_num = day_num + "";
			//if(day_num.length < 2) {day_num = "0"+day_num; }

				date_array[j][i]=day_num+"";
				day_num++;
				
				//ÇØ´ç ³¯Â¥°ª¿¡ ´ëÇÑ À¯È¿¼º °Ë»ç
				checkDate.setFullYear(year, month-1, day_num);
				if(checkDate.getDate() != day_num) break;
		}
		if(checkDate.getDate() != day_num) break;
	}
	last_week = (date_array[5][0])?6:5;

	

	outStr = "<table bgcolor=#CCCCCC width=160 height=160 border=0 cellpadding=0 cellspacing=0 style='border:1 solid black'><tr><td>\n";
	outStr += "<table width=100% height=100% border=0 cellpadding=0 cellspacing=1 style='border:1 solid black'>\n";
	outStr += "<col width=20 align=center></col><col width=20 align=center></col><col width=20 align=center></col><col width=20 align=center></col><col width=20 align=center></col><col width=20 align=center></col><col width=20 align=center></col>\n";
	outStr += "<tr><td class=calendar style='color:red'>S<td class=calendar>M<td class=calendar>T<td class=calendar>W<td class=calendar>T<td class=calendar>F<td class=calendar style='color:blue'>S</tr>\n";
	for(j=0;j<last_week;j++){
		outStr += "<tr>";
		for(i=0;i<7;i++){
			//½ºÅ©¸³Æ® ÀÚ·áº¯È¯
			if(date_array[j][i]!=""){
				action_script = script.replace("{year}", year);
				action_script = action_script.replace("{month}",month);
				action_script = action_script.replace("{day}", date_array[j][i]);
			}
			else action_script = "";


			//³¯Â¥º°·Î ½ºÅ©¸³Æ® Ãâ·Â
			if(i==0){ outStr += "<td class=calendar style='color:red;cursor:hand' onMouseover=this.style.backgroundColor='#FFEEEE' onMouseout=this.style.backgroundColor='' onClick=\""+action_script+"\">"+date_array[j][i]+"</td>"; continue; }
			if(i==6){ outStr += "<td class=calendar style='color:blue;cursor:hand' onMouseover=this.style.backgroundColor='#EEEEFF' onMouseout=this.style.backgroundColor='' onClick=\""+action_script+"\">"+date_array[j][i]+"</td>"; continue; }
			outStr += "<td class=calendar style='cursor:hand' onMouseover=this.style.backgroundColor='#EEEEEE' onMouseout=this.style.backgroundColor='' onClick=\""+action_script+"\">"+date_array[j][i]+"</td>";
		}
		outStr += "</tr>\n";
	}
	outStr += "</table></td></tr></table>";

	month_link = (month > 1)? "<a onClick=\"cal("+year+","+(month-1)+","+day+",'')\" style='text-decoration:none; color:#909090; cursor:hand'>¢·</a> <font color=black>"+month:"<a onClick=\"cal("+(year-1)+",12,"+day+",'')\" style='text-decoration:none; color:#909090; cursor:hand'>¢·</a> <font color=black>"+month;
	month_link += (month < 12)? "</font> <a onClick=\"cal("+year+","+(month+1)+","+day+",'')\" style='text-decoration:none; color:#909090; cursor:hand'>¢¹</a>":"</font> <a onClick=\"cal("+(year+1)+",1,"+day+",'')\" style='text-decoration:none; color:#909090; cursor:hand'>¢¹</a>";

	//HTML ´ëÀÔ
	document.all.G_cal_body.innerHTML = outStr;
	document.all.G_cal_year.innerHTML = "<a onClick=\"cal("+(year-1)+","+month+","+day+",'')\" style='text-decoration:none; color:#909090; cursor:hand'>¢·</a> <font color=black>"+year+"</font> <a onClick=\"cal("+(year+1)+","+month+","+day+",'')\" style='text-decoration:none; color:#909090; cursor:hand'>¢¹</a>";
	document.all.G_cal_month.innerHTML = month_link;

	document.all.G_close.innerHTML = "<a onClick=\"onoff_Gcal();\" style='text-decoration:none; color:#909090; cursor:hand'><img src='http://echosting.cafe24.com/image/admin/cal/close.gif' border=0'></a>";
}

function onoff_Gcal( year, month, day )
{
	cal(year, month, day, "set_date('{year}','{month}','{day}');onoff_Gcal();") ;

	//document.all.G_cal.style.top = event.clientY - 230;
	//document.all.G_cal.style.left = event.clientX -230;

	document.all.G_cal.style.visibility = (document.all.G_cal.style.visibility=="hidden")?"":"hidden";
}


