<!--
/******************************* ´Þ·Â ½ºÅ©¸³Æ® *******************************/
//	ÃÖÁ¾¼öÁ¤ÀÚ : ÀÌÈ£Ã¶
//	ÃÖÁ¾¼öÁ¤ÀÏ : 2005-08-25
//	- ÄÚµå ÁÙÀÌ±â.... »ç¿ë½Ã ÇÔ¼ö È£Ãâ·Î ¼îºÎ
//	- year¸ðµå Ãß°¡
//  - ¼¿·ºÆ® ¹Ú½º ¼û±â±â
//	- <div> LA_printCal() È£Ãâ½Ã Ãâ·Â
/*****************************************************************************/

var gcGray = "#CCCCCC";
var gcToggle = "#7397D2";
var gcBG = "#FFFFFF";
var yearMode	=	0; //³â ¼¿·ºÆ® ¹Ú½º¸®½ºÆ® =>  0 : °ú°Å~¹Ì·¡, 1 : °ú°Å~ÇöÀç, 2: ÇöÀç~¹Ì·¡

var gdCurDate;
var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();
var VicPopCal = new Object();

var gMonths = new Array("1","2","3","4","5","6","7","8","9","10","11","12");


var target_field;
var target_button;
var target_div;

function setCal(){
	//target_field,target_button,target_div,target_day
	if(arguments.length < 3){
		alert('ÀÎÀÚ°¡ ÇÊ¿äÇÕ´Ï´Ù~!');
		return;
	} else if(arguments.length > 3){
		this.giYear		=	parseInt(arguments[3][0]); 
		this.giMonth	=	parseInt(arguments[3][1]); 
		this.giDay		=	parseInt(arguments[3][2]); 
	}
	
	this.target_field	=	arguments[0];
	this.target_button	=	arguments[1];
	this.target_div		=	arguments[2];
}



function fSetDate(iYear, iMonth, iDay){
	
	if(iMonth < 10)		iMonth = '0' + iMonth;
	if(iDay < 10)		iDay = '0' + iDay;

	target_field.value = iYear+'-'+iMonth+"-"+iDay;		//Here, you could modify the locale as you need !!!!
	target_div.style.display = "none";
	target_button.value = '¡å';
	clickBtn = false;
	selectbox_visible();
}

function fSetSelected(aCell){
	var iOffset = 0;
	var iYear = parseInt(document.all.tbSelYear.value);
	var iMonth = parseInt(document.all.tbSelMonth.value);

	aCell.bgColor = gcBG;

	with (aCell.children["cellText"]){
		var iDay = parseInt(innerText);

		if(color.toUpperCase() == gcGray.toUpperCase())	iOffset = (iDay>10)?-1:1;

		iMonth += iOffset;

		if(iMonth<1) {
			iYear--;
			iMonth = 12;
		} else if (iMonth>12){
			iYear++;
			iMonth = 1;
		}
	}
	
	fSetDate(iYear, iMonth, iDay);
}

function fBuildCal(iYear, iMonth) {
	var aMonth=new Array();
	for(i=1;i<7;i++)
		aMonth[i]=new Array(i);

	var dCalDate=new Date(iYear, iMonth-1, 1);
	var iDayOfFirst=dCalDate.getDay();
	var iDaysInMonth=new Date(iYear, iMonth, 0).getDate();
	var iOffsetLast=new Date(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1;
	var iDate = 1;
	var iNext = 1;

	for (d = 0; d < 7; d++)
		aMonth[1][d] = (d<iDayOfFirst)?-(iOffsetLast+d):iDate++;
	for (w = 2; w < 7; w++)
		for (d = 0; d < 7; d++)
			aMonth[w][d] = (iDate<=iDaysInMonth)?iDate++:-(iNext++);
	return aMonth;
}

function fDrawCal(iYear, iMonth) {
	var WeekDay = new Array("Su","Mo","Tu","We","Th","Fr","Sa");
	var styleTD = " bgcolor='"+gcBG+"' valign='middle' align='center' style='cursor:hand;color:#999999;' ";            //Coded by Liming Weng(Victor Won)  email:victorwon@netease.com

	with (document) {
		write("<tr height='"+100/7+"%'>");
		for(i=0; i<7; i++){
			if(i==0)		fontColor = 'red';
			else if(i==6)	fontColor = 'blue';
			else			fontColor = '#333333';
			write("<td valign='middle' align='center' bgcolor='"+gcBG+"' width='"+100/7+"%' style='color:"+fontColor+";'><B>" + WeekDay[i] + "</B></td>");
		}
		write('</tr>');

		for (w = 1; w < 7; w++) {
			write("<tr height='"+100/7+"%'>");
			for (d = 0; d < 7; d++) {

					write("<td id=calCell "+styleTD+" onMouseOver='this.bgColor=gcToggle;this.style.fontWeight=\"bold\";' onMouseOut='this.bgColor=gcBG;this.style.fontWeight=\"\";' onclick='fSetSelected(this)'>");
					write("<font id=cellText Victor='Liming Weng'> </font>");
					write("</td>");
			}
			write("</tr>");
		}
	}
}


function fUpdateCal(iYear, iMonth) {
	var objYear = document.getElementById('selYear');

	for(i=0;i<objYear.options.length;i++)	objYear.options[i] = null;


  // ³â ¼³Á¤
	// °ú°Å ~ ÇöÀç
	if(yearMode == 1){
		var tmpDate = new Date();
		var tmpYear = tmpDate.getFullYear();
		var limitYearCnt = tmpYear-1900;

		for(i=0;i<=limitYearCnt;i++){
			objYear.options[i] = new Option(parseInt(tmpYear)-i,parseInt(tmpYear)-i);
			if(objYear.options[i].value==iYear)	objYear.options[i].selected = true;
		}
	// ÇöÀç ~ ¹Ì·¡
	} else if(yearMode == 2){
		var tmpDate = new Date();
		var tmpYear = tmpDate.getFullYear();
		var limitYearCnt = 100;

		for(i=0;i<=limitYearCnt;i++){
			objYear.options[i] = new Option(parseInt(tmpYear)+limitYearCnt-i,parseInt(tmpYear)+limitYearCnt-i);
			if(objYear.options[i].value==iYear)	objYear.options[i].selected = true;
		}
	// °ú°Å ~ ¹Ì·¡
	} else {
		var limitYearCnt	=	20;

		for(i=0;i<limitYearCnt;i++){
			objYear.options[i] = new Option(parseInt(iYear)-i+limitYearCnt/2,parseInt(iYear)-i+limitYearCnt/2);
			if(objYear.options[i].value==iYear)	objYear.options[i].selected = true;
		}
	}


	var objMonth = document.getElementById('selMonth');

	for(i=0;i<objMonth.options.length;i++)	objMonth.options[i] = null;

	for(i=0;i<12;i++){
		objMonth.options[i] = new Option(1+i,1+i);
		if(i==iMonth-1)	objMonth.options[i].selected = true;
	}	

	myMonth = fBuildCal(iYear, iMonth);


	var i = 0;
	var cellObj	=	document.getElementsByName('cellText');
	for (var w = 0; w < 6; w++){
		for (var d = 0; d < 7; d++){
			
			//cellObj		=	cellText[(7*w)+d];

			with (cellObj[(7*w)+d]) {
				getAttribute("Victor").value = i++;
				
				if (myMonth[w+1][d]<0) {
						color = gcGray;
						innerHTML = -myMonth[w+1][d];
				} else {
					
					if(d==0) {
							color = "red";
							innerHTML = myMonth[w+1][d];
					} else if(d==6) {
							color = "blue";
							innerHTML = myMonth[w+1][d];
					} else {
							color = "#333333";
							innerHTML = myMonth[w+1][d];
					}
				}

				if(giDay == i+1 ){
							
				}
				

				if(myMonth[w+1][d] == giDay) {
					color = "#FFFFFF";
					innerHTML = "<b>"+myMonth[w+1][d]+"</b>";
					
					calCell[(7*w)+d].style.backgroundColor = '#999999';

				} else {
					calCell[(7*w)+d].style.backgroundColor = gcBG;
				}

			}
		}
	}
	
}

function fSetYearMon(iYear, iMon){
  document.all.tbSelMonth.options[iMon-1].selected = true;
  for (i = 0; i < document.all.tbSelYear.length; i++)
        if (document.all.tbSelYear.options[i].value == iYear)
                document.all.tbSelYear.options[i].selected = true;
  fUpdateCal(iYear, iMon);
}

function fPrevMonth(){

  var iMon = document.all.tbSelMonth.value;
  var iYear = document.all.tbSelYear.value;

  if (--iMon<1) {
          iMon = 12;
          iYear--;
  }

  fSetYearMon(iYear, iMon);
}

function fNextMonth(){
  var iMon = document.all.tbSelMonth.value;
  var iYear = document.all.tbSelYear.value;

  if (++iMon>12) {
          iMon = 1;
          iYear++;
  }

  fSetYearMon(iYear, iMon);
}





function LA_printCal(){

	var nowDate = new Date();
	var nowYear = nowDate.getFullYear();
	var nowMonth = nowDate.getMonth()+1;
	var nowDay = nowDate.getDate();


	with (document) {
	write("<div id='divCal' style=\"display:'none'; position:absolute;\">");
	write("<table border='0' width='200' cellpadding='0' cellspacing='1' bgcolor='#BBBBBB'><tr><td>");
	write("<table id='popTable' cellpadding='5' cellspacing='0'  border='0' bgcolor='#FFFFFF' width='100%'>");
	write("  <TR>");
	write("    <td valign='middle' align='center'>");
	write("		 <nobr>");
	write("		 <input type='button'	name='PrevMonth'	value='<' style='border:1 solid #999999;background-color:#FFFFFF;height:20;width:20;FONT:16 Fixedsys;font-weight:bold;color:#333333;' onClick='fPrevMonth()'>");
	write("		 <select id='selMonth'	name='tbSelMonth'	onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'></SELECT>");
	write("		 <SELECT id='selYear'	name='tbSelYear'	onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won' style='border:1 solid #999999;background-color:#FFFFFF;'></SELECT>");
	write("		 <input type='button'	name='PrevMonth'	value='>' style='border:1 solid #999999;background-color:#FFFFFF;height:20;width:20;FONT:16 Fixedsys;font-weight:bold;color:#333333;' onclick='fNextMonth()'>");
	write("		 </nobr>");
	write("	   </td>");
	write("  </TR>");
	write("  <TR>");
	write("    <td align='center'>");
	write("      <DIV style='background-color:#FFFFFF;'>");
	write("			<table width='100%' border='0' cellpadding='1' cellspacing='1' bgcolor='#AAAAAA'>");
						fDrawCal(giYear, giMonth);
	write("			</table>");
	write("		  </DIV>");
	write("		</td>");
	write("	  </TR>");
	write("	  <TR>");
	write("		<TD align='center'>");
	write("		  <font style='cursor:hand;font:12 Fixedsys' onclick='fSetDate("+nowYear+","+nowMonth+","+nowDay+")' onMouseOver='this.style.color=\"#4576B1\"' onMouseOut='this.style.color=\"#666666\"'>Today:  "+nowMonth+" "+nowDay+", "+nowYear+"</font>");
	write("		</TD>");
	write("	  </TR>");
	write("</TABLE>");
	write("</TD></TR></TABLE>");
	write("</div>");
	fUpdateCal(giYear, giMonth);
	}
}

// °´Ã¼ ÁÂÇ¥±¸ÇÏ±â
function LA_getObjTop(obj){

	if (obj.offsetParent == document.body){
		return obj.offsetTop;
	} else{
		return obj.offsetTop + LA_getObjTop(obj.offsetParent);
	}
}
function LA_getObjLeft(obj){
	
	
	if (obj.offsetParent == document.body){
		return obj.offsetLeft;
	} else{
		return obj.offsetLeft + LA_getObjLeft(obj.offsetParent);
	}
}

// È£Ãâ ½ºÅ©¸³Æ®
var clickBtn = false;
function LA_controlCal(btn_field,target_field,mode){
	
	// ¸ðµå ¼¼ÆÃ 
	yearMode	=	mode;

	var objCal = document.getElementById('divCal');

	if(!clickBtn){
		var dateArr	=	target_field.value.split('-');

		objCal.style.display	=	'';
		
		// À§Ä¡ Á¤ÇØÁÖ±â
		objCal.style.top	=	document.body.clientTop + btn_field.offsetHeight + LA_getObjTop(btn_field) + 2;
		objCal.style.left	=	document.body.clientLeft - objCal.offsetWidth + btn_field.offsetWidth + LA_getObjLeft(btn_field);	
		
		// ÃÊ±âÈ­ setCal(³¯Â¥ÀÔ·ÂµÉ ÅØ½ºÆ®ÇÊµå°´Ã¼, Å¬¸¯µÈ ¹öÆ°°´Ã¼, ´Þ·Â·¹ÀÌ¾î °´Ã¼,³¯Â¥¹è¿­ - arr[0]:³â,arr[1]:¿ù,arr[2]ÀÏ(ÀÌºÎºÐÀÌ ¾øÀ¸¸é ÇöÀç ³¯Â¥·Î ÃÊ±âÈ­));

		if(dateArr.length == 3){
			setCal(target_field,btn_field,objCal,dateArr);
			// ³¯Â¥ °»½Å
			fUpdateCal(dateArr[0], dateArr[1]);
		} else {
			setCal(target_field,btn_field,objCal);
			var now	=	new Date();
			fUpdateCal(giYear,giMonth);
		}			
		clickBtn = true;
		btn_field.value = '¡ã';
		selectbox_hidden('divCal');
	} else {

		objCal.style.display	=	'none';
		clickBtn = false;
		btn_field.value = '¡å';
		selectbox_visible();
	}
}
function selectbox_hidden(layer_id){ 
	var ly = eval(layer_id); 

	// ·¹ÀÌ¾î ÁÂÇ¥ 
	var ly_left  = ly.offsetLeft; 
	var ly_top    = ly.offsetTop; 
	var ly_right  = ly.offsetLeft + ly.offsetWidth; 
	var ly_bottom = ly.offsetTop + ly.offsetHeight; 

	// ¼¿·ºÆ®¹Ú½ºÀÇ ÁÂÇ¥ 
	var el; 

	for (i=0; i<document.forms.length; i++) { 
		for (k=0; k<document.forms[i].length; k++) { 
			el = document.forms[i].elements[k];
			if (el.type == "select-one" || el.type == "select-multiple") {	// 2005-08-26 multiple Çü½ÄÀÏ¶§µµ
				var el_left = el_top = 0; 
				var obj = el; 
				if (obj.offsetParent) { 
					while (obj.offsetParent) { 
						el_left += obj.offsetLeft; 
						el_top  += obj.offsetTop; 
						obj = obj.offsetParent; 
					} 
				} 
				el_left  += el.clientLeft; 
				el_top    += el.clientTop; 
				el_right  = el_left + el.clientWidth; 
				el_bottom = el_top + el.clientHeight; 

				// ÁÂÇ¥¸¦ µûÁ® ·¹ÀÌ¾î°¡ ¼¿·ºÆ® ¹Ú½º¸¦ Ä§¹üÇßÀ¸¸é ¼¿·ºÆ® ¹Ú½º¸¦ hidden ½ÃÅ´
				if ( (el_left >= ly_left && el_top >= ly_top && el_left <= ly_right && el_top <= ly_bottom) || 
					(el_right >= ly_left && el_right <= ly_right && el_top >= ly_top && el_top <= ly_bottom) || 
					(el_left >= ly_left && el_bottom >= ly_top && el_right <= ly_right && el_bottom <= ly_bottom) || 
					(el_left >= ly_left && el_left <= ly_right && el_bottom >= ly_top && el_bottom <= ly_bottom) ) 
					el.style.visibility = 'hidden'; 
			} 
		} 
	} 
} 

// °¨Ãß¾îÁø ¼¿·ºÆ® ¹Ú½º¸¦ ¸ðµÎ º¸ÀÌ°Ô ÇÔ 
function selectbox_visible(){ 
	for (i=0; i<document.forms.length; i++) { 
		for (k=0; k<document.forms[i].length; k++) { 
			el = document.forms[i].elements[k];    
			if ((el.type == "select-one" || el.type == "select-multiple") && el.style.visibility == 'hidden') 
				el.style.visibility = 'visible'; 
		} 
	} 
} 



//-->


/*	º»¹®¿¡ µé¾î°¥ ÅÂ±×
<SCRIPT LANGUAGE="JavaScript" src='calendar.js'></SCRIPT>
°Ë»ö : 
<INPUT TYPE="text" NAME="searchStart" value='' size='10' style='height:18;'><INPUT TYPE="button" value='¡å' onclick='LA_controlCal(this,this.form.searchStart,0);' style='border : 1 solid #999999;height:18;width:17; background-color:#FFFFFF;font-weight:bold;color:#000099;'  onfocus='this.blur();'>
~
<INPUT TYPE="text" NAME="searchEnd" value='' size='10' style='height:18;'><INPUT TYPE="button" value='¡å'  onclick='LA_controlCal(this,this.form.searchEnd,0);' style='border : 1 solid #999999;height:18;width:17; background-color:#FFFFFF;font-weight:bold;color:#000099' onfocus='this.blur();'>

<!-- ´Þ·Â -->
<SCRIPT LANGUAGE="JavaScript">LA_printCal();</SCRIPT>
*/