/*
* 파일명 : Calendar.js
* 원본출처 : 인터넷(원작자 알수 없음. 있다면 메일 주시기 바랍니다.)
* 수정자 : 손대관(pinerest@naver.com)
* 프로그램 설명 : createPopup을 이용한 달력 출력 자바스크립트.
* 2008. 2. 7 : CSS의 분리, 코드 최적화, 버그 수정 및 프로젝트에 적합하게 하기 위해 수정작업이 있었습니다.
* 2008. 2 .16 : IE6에서 주석으로 야기되는 오류로 인해 모든 주석 삭제. 주석버전은 메일주시면 드리겠습니다.
* 2008. 2. 18 : 변수 명 규격화
* 2008. 2. 20 : 날짜 형식 8자리에서 10자리로 변경
* 2008. 2. 25 : IE6에서 오류로 인해 GetObjectTop, GetObjectLeft함수의 재귀호출 구조에서 반복문구조로 변경
* 2008. 2. 26 : IE6에서 오류로 인해 GetObjectTop, GetObjectLeft함수의 객체비교구문에서 객체명 비교로 변경
*/
var g_target;
var g_cal_Day;
var g_calShow = 0;
function openCalendar(arg_obj)
{
g_target = arg_obj;
if(g_calShow == 1)
{
var CalDiv = document.getElementById("calendar1");
CalendarFormDiv.removeChild(CalDiv);
g_calShow = 0;
return;
}
g_calShow = 1;
var l_now = arg_obj.value.split('-');
if (l_now.length == 3 && arg_obj.value.length == 10)
{
if(checkNumber(l_now[0] + l_now[1] + l_now[2]) == true)
{
g_cal_Day = arg_obj.value;
Show_cal(l_now[0], l_now[1], l_now[2]);
}
}
else
{
l_now = new Date();
g_cal_Day = l_now.getFullYear() + "-" + day2(l_now.getMonth()+1) + "-" + day2(l_now.getDate());
Show_cal(l_now.getFullYear(), l_now.getMonth()+1, l_now.getDate());
}
}
function checkNumber(arg_obj)
{
var l_str = arg_obj;
if(l_str.length == 0)
return false;
for(var i=0; i < l_str.length; i++)
{
if(!('0' <= l_str.charAt(i) && l_str.charAt(i) <= '9'))
return false;
}
return true;
}
function Calendar_Click(arg_e)
{
g_cal_Day = arg_e.title;
if (g_cal_Day.length == 10)
g_target.value = g_cal_Day;
var CalendarFormDiv = document.getElementById("CalendarFormDiv");
var CalDiv = document.getElementById("calendar1");
CalendarFormDiv.removeChild(CalDiv);
g_calShow = 0;
}
function day2(arg_d)
{
var l_str = new String();
if (parseInt(arg_d) < 10)
l_str = "0" + parseInt(arg_d);
else
l_str = "" + parseInt(arg_d);
return l_str;
}
function fnChangeYearD(arg_sDay)
{
sYear = document.getElementById("selYear").value;
sMonth = document.getElementById("selMonth").value;
var CalendarFormDiv = document.getElementById("CalendarFormDiv");
var CalDiv = document.getElementById("calendar1");
CalendarFormDiv.removeChild(CalDiv);
Show_cal(sYear, sMonth, arg_sDay);
}
function fnChange(sYear, sMonth, sDay)
{
var CalendarFormDiv = document.getElementById("CalendarFormDiv");
var CalDiv = document.getElementById("calendar1");
CalendarFormDiv.removeChild(CalDiv);
Show_cal(sYear, sMonth, sDay);
}
function Show_cal(arg_sYear, arg_sMonth, arg_sDay)
{
var CalendarFormDiv = document.getElementById("CalendarFormDiv");
var l_intaMonths_day = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
var l_straMonth_Val = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
var l_intThisYear = new Number();
var l_intThisMonth = new Number();
var l_intThisDay = new Number();
l_intThisYear = parseInt(arg_sYear,10);
l_intThisMonth = parseInt(arg_sMonth,10);
l_intThisDay = parseInt(arg_sDay,10);
var l_datToday = new Date();
if (l_intThisYear == 0)
l_intThisYear = l_datToday.getFullYear();
if (l_intThisMonth == 0)
l_intThisMonth = parseInt(l_datToday.getMonth(),10)+1;
if (l_intThisDay == 0)
l_intThisDay = l_datToday.getDate();
switch(l_intThisMonth)
{
case 1:
l_intPrevYear = l_intThisYear -1;
l_intPrevMonth = 12;
l_intNextYear = l_intThisYear;
l_intNextMonth = 2;
break;
case 12:
l_intPrevYear = l_intThisYear;
l_intPrevMonth = 11;
l_intNextYear = l_intThisYear + 1;
l_intNextMonth = 1;
break;
default:
l_intPrevYear = l_intThisYear;
l_intPrevMonth = parseInt(l_intThisMonth,10) - 1;
l_intNextYear = l_intThisYear;
l_intNextMonth = parseInt(l_intThisMonth,10) + 1;
break;
}//close switch
l_datFirstDay = new Date(l_intThisYear, l_intThisMonth-1, 1);
l_intFirstWeekday = l_datFirstDay.getDay();
if ((l_intThisYear % 4) == 0)
if ((l_intThisYear % 100) == 0)
if ((l_intThisYear % 400) == 0)
l_intaMonths_day[2] = 29;
else
l_intaMonths_day[2] = 29;
l_firstPrintDay = 1;
l_intLastDay = l_intaMonths_day[l_intThisMonth];
var l_strCal_HTML = "<table id='Cal_Table'>";
l_strCal_HTML += "<tr id='Cal_Header'><td colspan=7>";
l_strCal_HTML += "<select name='selYear' id='Cal_Select' OnChange='fnChangeYearD("+l_intThisDay+")';>";
for (var l_optYear=(l_intThisYear-3); l_optYear<(l_intThisYear+4); l_optYear++)
{
l_strCal_HTML += "<option value='"+l_optYear+"' ";
if (l_optYear == l_intThisYear)
l_strCal_HTML += " selected>";
else
l_strCal_HTML += ">";
l_strCal_HTML += l_optYear+"</option>";
}
l_strCal_HTML += "</select>";
l_strCal_HTML += " <a style='cursor:hand;' OnClick='fnChange("+l_intPrevYear+","+l_intPrevMonth+","+l_intThisDay+");'><img src='/admin/js/image/btn_before.gif' align='absmiddle' alt='이전달' /></a> ";
l_strCal_HTML += "<select name='selMonth' id='Cal_Select' OnChange='fnChangeYearD("+l_intThisDay+")';>";
for (var i=1; i<13; i++)
{
l_strCal_HTML += "<option value='"+l_straMonth_Val[i-1]+"' ";
if (l_intThisMonth == parseInt(l_straMonth_Val[i-1],10))
l_strCal_HTML += " selected>";
else
l_strCal_HTML += ">";
l_strCal_HTML += l_straMonth_Val[i-1]+"</option>";
}
l_strCal_HTML += "</select> ";
l_strCal_HTML += "<a style='cursor:hand;' OnClick='fnChange("+l_intNextYear+","+l_intNextMonth+","+l_intThisDay+");'><img src='/admin/js/image/btn_next.gif' align='absmiddle' alt='다음달' /></a>";
l_strCal_HTML += "</td></tr>";
l_strCal_HTML += "<tr id='Cal_Week'>";
l_strCal_HTML += " <td class='Cal_Sunday'>일</td>";
l_strCal_HTML += " <td class='Cal_Weekday'>월</td>";
l_strCal_HTML += " <td class='Cal_Weekday'>화</td>";
l_strCal_HTML += " <td class='Cal_Weekday'>수</td>";
l_strCal_HTML += " <td class='Cal_Weekday'>목</td>";
l_strCal_HTML += " <td class='Cal_Weekday'>금</td>";
l_strCal_HTML += " <td class='Cal_Saturday'>토</td>";
l_strCal_HTML += "</tr>";
for (l_intLoopWeek=1; l_intLoopWeek <= 6; l_intLoopWeek++)
{
l_strCal_HTML += "<tr id='Cal_Day'>"
for (l_intLoopDay=1; l_intLoopDay <= 7; l_intLoopDay++)
{
if (l_intFirstWeekday > 0)
{
l_strCal_HTML += "<td class='Cal_EmptyDay'> ";
l_intFirstWeekday--;
}
else
{
if (l_firstPrintDay > l_intLastDay)
l_strCal_HTML += "<td class='Cal_Empty'> ";
else
{
var l_strID = "";
var l_strClass = "";
if (l_intThisDay==l_firstPrintDay && l_intThisMonth==parseInt(g_cal_Day.split('-')[1], 10) && l_intThisYear==parseInt(g_cal_Day.split('-')[0], 10))
l_strID = "Cal_Today";
switch(l_intLoopDay)
{
case 1:
l_strClass = "Cal_Sunday";
break;
case 7:
l_strClass = "Cal_Saturday";
break;
default:
l_strClass = "Cal_Weekday";
}
l_strCal_HTML += "<td style='cursor:hand;' id='" + l_strID + "' class='" + l_strClass + "' onClick='Calendar_Click(this);' title=" + l_intThisYear + "-" + day2(l_intThisMonth).toString() + "-" + day2(l_firstPrintDay).toString() + " onmouseover=\"this.id='Cal_MouseOver'\" onmouseout=\"this.id='" + l_strID + "'\">" + l_firstPrintDay;
}
l_firstPrintDay++;
}
l_strCal_HTML += "</td>";
}
l_strCal_HTML += "</tr>";
if (l_firstPrintDay > l_intLastDay)
break;
}
l_strCal_HTML += "</table>";
// 추가할 폼(에 들어갈 HTML)
var addedDiv = document.createElement("div"); // 폼 생성
addedDiv.id = "calendar1"; // 폼 Div에 ID 부 여 (삭제를 위해)
addedDiv.innerHTML = l_strCal_HTML; // 폼 Div안에 HTML삽입
CalendarFormDiv.appendChild(addedDiv); // 삽입할 DIV에 생성한 폼 삽입
}
function GetObjectTop(arg_obj)
{
var l_intTopSum = arg_obj.offsetTop;
while(arg_obj.nodeName.indexOf('HTML') != 0 && arg_obj.nodeName.indexOf('BODY') != 0)
{
arg_obj = arg_obj.offsetParent;
l_intTopSum += arg_obj.offsetTop;
}
return l_intTopSum;
}
function GetObjectLeft(arg_obj)
{
var l_intLeftSum = arg_obj.offsetLeft;
while(arg_obj.nodeName.indexOf('HTML') != 0 && arg_obj.nodeName.indexOf('BODY') != 0)
{
arg_obj = arg_obj.offsetParent;
l_intLeftSum += arg_obj.offsetLeft;
}
return l_intLeftSum;
}