/*
* ¡¡¡¡¡¡¡¡G calendar v0.5
* (°øÈÞÀÏ ¹× ±¹°æÀÏ Ã¼Å©±â´É¾øÀ½)
*
*¡¡¡¡¡¡By Çàº¹ÇÑ°í´Ï(gonom9@empal.com)
*/

var action_global = ""; //actionÀÇ Àü¿ªº¯¼ö
var now = new Date();
var now_year = now.getYear();
var now_month = now.getMonth()+1;
var now_day = now.getDate();

function calendar(action){
	cal(now_year,now_month,now_day,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();
                    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 width=160 height=140 border=0 cellpadding=0 cellspacing=0 bgcolor=#DADADA>\n";
    outStr += "<tr><td colspan=7 height=9><img src='../images/calendar.gif' width='160'></td></tr>\n";
    outStr += "<tr><td bgcolor=#ffffff align=center>\n";
	outStr += "<table width=100% height=100% border=0 cellpadding=0 cellspacing=1 bgcolor=#DADADA>\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'>ÀÏ<td class=calendar>¿ù<td class=calendar>È­<td class=calendar>¼ö<td class=calendar>¸ñ<td class=calendar>±Ý<td class=calendar style='color:blue'>Åä</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("{y}", year);
                    action_script = action_script.replace("{m}",(month < 10)?"0"+month:month);
                    action_script = action_script.replace("{d}", (date_array[j][i]<10)?"0"+date_array[j][i]:date_array[j][i]);
            }
            else action_script = "";
            today=date_array[j][i];

            if(today=="") today="&nbsp;";
            //³¯Â¥º°·Î ½ºÅ©¸³Æ® Ãâ·Â
			//if(now_year==year && now_month==month && now_day>today) {
//	            if(now_year==year && now_month==month && now_day==today) today="<b>"+today+"</b>";
			//	if(i==0){ outStr += "<td style='font-size:9pt;font-family:±¼¸²;color=#A7A7A7;background=#FBF8F5'>"+today+"</td>"; continue; }
	        //    if(i==6){ outStr += "<td style='font-size:9pt;font-family:±¼¸²;color=#A7A7A7;background=#FBF8F5'>"+today+"</td>"; continue; }
	        //   outStr += "<td style='font-size:9pt;font-family:±¼¸²;color=#A7A7A7;background=#FBF8F5'>"+today+"</td>";
			//} else {
	            if(now_year==year && now_month==month && now_day==today) today="<b>"+today+"</b>";
				if(i==0){ outStr += "<td class=calendar style='color:ED1C24;cursor:hand' onMouseover=this.style.backgroundColor='#DEDEDE' onMouseout=this.style.backgroundColor='' onClick=\""+action_script+"\">"+today+"</td>"; continue; }
	            if(i==6){ outStr += "<td class=calendar style='color:0000FF;cursor:hand' onMouseover=this.style.backgroundColor='#DEDEDE' onMouseout=this.style.backgroundColor='' onClick=\""+action_script+"\">"+today+"</td>"; continue; }
	            outStr += "<td class=calendar style='cursor:hand' onMouseover=this.style.backgroundColor='#DEDEDE' onMouseout=this.style.backgroundColor='' onClick=\""+action_script+"\">"+today+"</td>";
			//}
		}
        outStr += "</tr>\n";
    }
    outStr += "</table></td></tr></table>";

	if(now_year==year && now_month==month) {
	    month_link = (month > 1)? "<font style='text-decoration:none;color:#474747;'>¢·</font> <font color=#474747>ÀÌµ¿":"<a onClick=\"cal("+(year-1)+",12,"+day+",'')\" style='text-decoration:none; color:#474747; cursor:hand'>¢·</a> <font color=#474747>ÀÌµ¿";
	} else {
		month_link = (month > 1)? "<a onClick=\"cal("+year+","+(month-1)+","+day+",'')\" style='text-decoration:none; color:#474747; cursor:hand'>¢·</a> <font color=#474747>ÀÌµ¿":"<a onClick=\"cal("+(year-1)+",12,"+day+",'')\" style='text-decoration:none; color:#474747; cursor:hand'>¢·</a> <font color=#474747>ÀÌµ¿";
	}
    month_link += (month < 12)? "</font> <a onClick=\"cal("+year+","+(month+1)+","+day+",'')\" style='text-decoration:none; color:#474747; cursor:hand'>¢¹</a>":"</font> <a onClick=\"cal("+(year+1)+",1,"+day+",'')\" style='text-decoration:none; color:#474747; 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_year.innerHTML = "<b><font color=#F26522>"+year+"³â "+month+"¿ù</font></b> &nbsp;";
    document.all.G_cal_month.innerHTML = month_link;
}

function onoff_Gcal(){
    document.all.G_cal.style.top = event.clientY+window.document.body.scrollTop+10;
    document.all.G_cal.style.left = event.clientX+window.document.body.scrollLeft-50;
    document.all.G_cal.style.visibility = (document.all.G_cal.style.visibility=="hidden")?"":"hidden";
}

document.writeln("<style>td.calendar{font-size:9pt;font-family:±¼¸²;color:4B4B4B; background-color:white}</style>");
document.writeln(""
+"<div id=G_cal style='width=160;position:absolute;visibility:hidden;z-index:100;'>"
+"<table bgcolor=#EEEEEE width=160 height=22 border=0 cellpadding=3 cellspacing=0 style='border:1x solid #DADADA'>"
+" <tr><td style='font-size:9pt;font-family:±¼¸²;background:#ffffff'><span id=G_cal_year></span></td>"
+" <td style='font-size:9pt;font-family:±¼¸²;background:#ffffff;text-align:right'><span id=G_cal_month></span>"
+" </td></tr>"
+"</table>"
+"<div id=G_cal_body style='width:160'>"
+"</div></div>");

