//  ´Þ¾È¿¡¼­ ³¯Â¥¸¦ »Ì¾Æ³»´Â ÇÔ¼ö
function DaysInMonth(WhichYear, WhichMonth)
{
        var DaysInMonth = 31;
        if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11") DaysInMonth = 30;
        if (WhichMonth == "02" && (WhichYear/4) != Math.floor(WhichYear/4))        DaysInMonth = 28;
        if (WhichMonth == "02" && (WhichYear/4) == Math.floor(WhichYear/4))        DaysInMonth = 29;
        return DaysInMonth;
}


//  ÆË¾÷ÀÌ ¶á ºÎºÐÀÇ ¸Ç À§¿¡ ³ªÅ¸³ª´Â ³âµµ¿Í ¿ù Á¤º¸¸¦ º¸¿©ÁØ´Ù.
function drawHead(title,objName,year,month,day, job) {
	monthArray = Array("","01","02","03","04","05","06","07","08","09","10","11","12");
	var stringMonth;

	var prevYear = year - 1;
	var nextYear = year + 1;
	var prevMonth = month - 1;
	var nextMonth = month + 1;
	var drawML = "";

	if (month < 10) {
		stringMonth = "0" + month;
	} else {
		stringMonth = month;
	}

	drawML = "<table border='0' cellspacing='0' cellpadding='7'><tr align='center'>";

	// Áö³­ ¿¬µµ Ãâ·Â
	drawML += "<td><a href=\"javascript:opener.writeCalendar(\'" + title + "\',\'" + objName + "\'," + prevYear + "," + month + "," + day + "," + null +",\'" + job + "\');\"><img src='/shopping/image/button/cal_prevyear.gif' alt='ÀÌÀü ³âµµ' border='0' /></a></td>";

	// Áö³­ ´Þ Ãâ·Â
	if (prevMonth > 0) {
		drawML += "<td><a href=\"javascript:opener.writeCalendar(\'" + title + "\',\'" + objName + "\'," + year + "," + prevMonth + "," + day + "," + null +",\'" + job +"\');\"><img src='/shopping/image/button/cal_prevmon.gif' alt='ÀÌÀü ´Þ' border='0' /></a></td>";
	}
	else {
		drawML += "<td><a href=\"javascript:opener.writeCalendar(\'" + title + "\',\'" + objName + "\'," + prevYear + ",12," + day +"," + null +",\'" + job + "\');\"><img src='/shopping/image/button/cal_prevmon.gif' alt='ÀÌÀü ´Þ' border='0' /></a></td>";
	}

	// ÇöÀç ¿¬¿ù Ãâ·Â
	drawML += "<td><b>" + year + "/" + stringMonth + "</b></td>";

	// ´ÙÀ½ ´Þ Ãâ·Â
	if (nextMonth <13) {
		drawML += "<td><a href=\"javascript:opener.writeCalendar(\'" + title + "\',\'" + objName + "\'," + year + "," + nextMonth + "," + day + "," + null +",\'" + job +"\');\"><img src='/shopping/image/button/cal_nextmon.gif' alt='´ÙÀ½ ´Þ' border='0' /></a></td>";
	}
	else {
		drawML += "<td><a href=\"javascript:opener.writeCalendar(\'" + title + "\',\'" + objName + "\'," + nextYear + ",1," + day + "," + null +",\'" + job +"\');\"><img src='/shopping/image/button/cal_nextmon.gif' alt='´ÙÀ½ ´Þ' border='0' /></a></td>";
	}

	// ´ÙÀ½ ¿¬µµ Ãâ·Â
	drawML += "<td><a href=\"javascript:opener.writeCalendar(\'" + title + "\',\'" + objName + "\'," + nextYear + "," + month + "," + day + "," + null +",\'" + job +"\');\"><img src='/shopping/image/button/cal_nextyear.gif' alt='ÀÌÀü ³âµµ' border='0' /></a></td>";


	drawML += "</tr></table>";

	return drawML;
}

//  ÆË¾÷ ¶á ºÎºÐ¿¡¼­ ½ÇÁ¦ÀÇ ³¯Â¥¸¦ º¸¿©ÁÖ´Â ÇÔ¼ö
function drawTable(title,objName,year,month,useCurrentSetting, job) {
  var htmlBuffer;
  var stringMonth;
  var stringYear;
  var date = new Date();
  date.setYear(year);
  date.setMonth(month-1);
  date.setDate(1);
  var tempDay;

  if (month < 10) {
  	stringMonth = "0" + month;
  } else {
  	stringMonth = month;
  }

  ajuste = date.getDay();

  htmlBuffer  = "<table border='0' cellpadding='5' cellspacing='1' bgcolor='#DBDBDB'>";
  htmlBuffer += "<tr align='center' bgcolor='#E6E6E6'>";
  htmlBuffer += "<td bgcolor='#ECDADA'>ÀÏ</td>";
  htmlBuffer += "<td bgcolor='#DDE3E6'>¿ù</td>";
  htmlBuffer += "<td bgcolor='#DDE3E6'>È­</td>";
  htmlBuffer += "<td bgcolor='#DDE3E6'>¼ö</td>";
  htmlBuffer += "<td bgcolor='#DDE3E6'>¸ñ</td>";
  htmlBuffer += "<td bgcolor='#DDE3E6'>±Ý</td>";
  htmlBuffer += "<td bgcolor='#DDE3E6'>Åä</td>";
  htmlBuffer += "</tr><TR>";

  // ºñÄ­ ¸¸µé±â
  for (var j=1; j<=ajuste; j++) {
    htmlBuffer += "<td align='center' bgcolor='#FFFFFF'>&nbsp;</td>";
  }
  // ¼ýÀÚ Ã¤¿ì±â
  var i;
  for (i=1; i<=DaysInMonth(year,month); i++) {
  	tempDay = i;

  	if (i < 10) {
  		tempDay = "0" + tempDay;   //  ¾Õ¿¡ 0 À» ºÙ¿©¼­ ³¯Â¥¸¦ ¸¸µç´Ù.
  	}

    htmlBuffer += "\r\n    <td align='center' ";
	if ((i == getCurrentDay()) && (month == getCurrentMonth()) && (year == getCurrentYear())) {
		htmlBuffer += " bgcolor='#EDEDED'";
	}
	else {
		htmlBuffer += " bgcolor='#FFFFFF'";
	}

	if(useCurrentSetting == '2'){
		var totalDate = year+""+stringMonth+""+tempDay;
	}else{
		var totalDate = year+"/"+stringMonth+"/"+tempDay;	
	}

    htmlBuffer += "><font color='black' face='tahoma, verdana' size='2'>";


	htmlBuffer += "<a href='javascript:opener.document.all." + objName + ".value=\"" + totalDate + "\"; ";
        htmlBuffer += "self.close();'";
        htmlBuffer += ">" + tempDay + "</a></font></td>";

    if (((i+ajuste) % 7)==0) {
		htmlBuffer += "</tr>";
    	if (i + 1 <= DaysInMonth(year,month)) {
			htmlBuffer += "<tr>";
		}
	}
  }

  // ³²Àº Ä­ Ã¤¿ì±â
  for (; (i + ajuste) % 7 != 1; i++) {
    htmlBuffer += "<td align='center' bgcolor='#FFFFFF'>&nbsp;</td>";
  }

  htmlBuffer += "</tr></table>";

  return htmlBuffer;
}


function writeCalendar(title,objName,year,month,day,useCurrentSetting, job ) {

  var html = "";
  html += "<html><head><title>" + title + "</title><meta http-equiv='Content-Type' content='text/html; charset=euc-kr' />";
  html += "<style>";
  html += "a:link    {color: #446998; font-family:Arial, Helvetica, sans-serif; font-size:11px; text-decoration: none;}";
  html += "a:visited {color: #446998; font-family:Arial, Helvetica, sans-serif; font-size:11px; text-decoration: none;}";
  html += "a:active  {color: #446998; font-family:Arial, Helvetica, sans-serif; font-size:11px; text-decoration: none;}";
  html += "a:hover   {color: #BD9D64; font-family:Arial, Helvetica, sans-serif; font-size:11px; text-decoration: underline;}";
  html += "</style>";
  html += "</head>";

  html += "<link href='style.css' rel='stylesheet' type='text/css' /></head>";
  html += "<body> <center>";

  html += drawHead(title,objName,year,month,day, job);

  html += drawTable(title,objName,year,month,useCurrentSetting, job);

  html += "</center></body></html>";
  ventana = open("","calendario","width=230,height=255");

  ventana.document.open();

  ventana.document.writeln(html);

  ventana.document.close();

  ventana.focus();

}

function getInitDate(objName)
{
	var initDate = eval("document.all."+objName+"value");
	return initDate;
}


// ÇöÀçÀÇ ³âµµ
function getCurrentYear() {
	var w = new Date();
	if (navigator.appName == "Netscape") return w.getYear() + 1900;
 	else return w.getYear();
}


//  ÇöÀçÀÇ ¿ù
function getCurrentMonth() {
	var w = new Date();
	return w.getMonth()+1;
}


// ÇöÀçÀÇ ³¯Â¥
function getCurrentDay() {
	var w = new Date();
	return w.getDate();
}

// ±âÁ¸¿¡ ÀÛ¼ºµÈ ³¯Â¥°¡ ¾øÀ¸¸é..  else ¹®ÀÌ ½ÇÇàµÇ°í
// Ã³À½ ³¯Â¥¸¦ ÀÛ¼ºÇÒ °æ¿ì¿¡..  if ¹®ÀÌ ½ÇÇà

function openCalendar(obj) {

	var year = getCurrentYear();
	var month = getCurrentMonth();
	var day = getCurrentDay();

	writeCalendar("³¯ÀÚ¼±ÅÃ",obj.name, year,month,day, null, "on_select");

}




