/**
 * systemÀÇ ÇöÀç³¯Â¥¸¦ °¡Á®¿Â´Ù
 * @return string ¿À´Ã³¯Â¥ (yyyy-MM-dd)
 */
function getStrToday() {
 	 var today=new Date();
 	 var strToDay = today.getYear();
 	 if (today.getMonth()+1 < 10)
 	 	strToDay += "-0"+ (parseInt(today.getMonth())+1);
 	 else
 	 	strToDay += "-" + (parseInt(today.getMonth())+1);

 	 if (today.getDate() < 10)
 	 	strToDay += "-0"+today.getDate();
 	 else
 	 	strToDay += "-" + today.getDate();

 	 return strToDay;
}

/**
 * <pre>
 * javascript dateÇüÀ» ¾Æ·¡ÀÇ Æ÷¸ËÀ¸·Î º¯°æ (dwr¿¡¼­ ÁÖ·Î »ç¿ë)
 * transDateToStr(grpMasterTmp.reg_time, 'date')  <==== yyyy-mm-dd
 * transDateToStr(grpMasterTmp.reg_time, 'time')  <==== yyyy-mm-dd hh:mm:ss.0
 * </pre>
 * @param p_date DateÇü
 * @param p_add_time ¹®ÀÚ¿­ key (date, time)
 * @return ³¯Â¥ÇüÅÂÀÇ ¹®ÀÚ¿­
 */
function transDateToStr( p_date, p_add_time ){
	var strToDay = "";
	if(p_date != null){

		strToDay = p_date.getYear();

		if (p_date.getMonth()+1 < 10){
			strToDay += "-0"+ (parseInt(p_date.getMonth())+1);
		} else {
			strToDay += "-" + (parseInt(p_date.getMonth())+1);
		}

		if (p_date.getDate() < 10){
			strToDay += "-0"+p_date.getDate();
		} else {
			strToDay += "-" + p_date.getDate();
		}

		if(p_add_time !=null){

			if (p_date.getHours() < 10){
				strToDay += " 0"+p_date.getHours()+ ":";
			} else {
				strToDay += " "+p_date.getHours()+ ":";
			}

			if (p_date.getMinutes() < 10){
			strToDay += "0"+p_date.getMinutes()+ ":";
			} else {
				strToDay += ""+p_date.getMinutes()+ ":";
			}

			if (p_date.getSeconds() < 10){
				strToDay += "0"+p_date.getSeconds();
			} else {
				strToDay += ""+p_date.getSeconds()+".0";
			}
		}
	}
	return strToDay;
}

/**
 * ÁÖ¾îÁø 8ÀÚ¸® ¹®ÀÚ¿­À» ³¯Â¥Æ÷¸Ë(YYYY-MM-DD or YYYY/MM/DD)·Î ¹Ù²Ù¾îÁØ´Ù.
 *
 * @param	source		º¯È¯ÇÒ 8ÀÚ¸® ³¯Â¥¹®ÀÚ¿­
 * @param	format		³¯Â¥Çü½Ä
 * @return	string		º¯È¯µÈ ³¯Â¥ ¹®ÀÚ¿­
 **/
function dateFormat(source, format)
{
	ret = "";
	delimiter = "";

	if (format.indexOf("-") != -1)
		delimiter = "-";
	else if (format.indexOf("/") != -1)
		delimiter = "/";
	else
	{
		alert("ÀÔ·ÂµÈ ³¯Â¥Æ÷¸ËÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.");
		return;
	}

	if (source.length == 8)
	{
		ret = source.substring(0, 4) + delimiter + source.substring(4, 6) + delimiter + source.substring(6, 8);
	} else if (source.length == 10)
	{
		ret = source.substring(0, 4) + delimiter + source.substring(5, 7) + delimiter + source.substring(8, 10);
	} else
	{
		alert("ÀÔ·ÂµÈ ³¯Â¥Çü½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.");
		return;
	}
	return ret;
}

/**
 * ³¯Â¥Çü½ÄÀÌ ¿Ã¹Ù¸¥Áö °Ë»ç
 *
 * @param astrValue ³¯Â¥Æ÷¸Ë(yyyymmdd, yyyy/mm/dd, yyyy-mm-dd)
 * @param astrNotNull	nn:not null, "": null Çã¿ë
 * @return boolean true/false
 **/
function blnOkDate(astrValue, astrNotNull)
{
	var arrDate;

	if (astrValue=='')
	{
		if (astrNotNull == "nn")
			return false;
		else
			return true;
	}else{
		if (astrValue.indexOf("-") != -1)
			arrDate = astrValue.split("-");
		else if (astrValue.indexOf("/") != -1)
			arrDate = astrValue.split("/");
		else
		{
			if (astrValue.length != 8) return false;
			astrValue = astrValue.substring(0,4)+"/"+astrValue.substring(4,6)+"/" +astrValue.substring(6,8);
			arrDate = astrValue.split("/");
		}

		if (arrDate.length != 3) return false;

		var chkDate = new Date(arrDate[0] + "/" + arrDate[1] + "/" + arrDate[2]);
		if (isNaN(chkDate) == true ||
			(arrDate[1] != chkDate.getMonth() + 1 || arrDate[2] != chkDate.getDate()))
		{
			return false;
		}
	}
	return true;
}


/**
 * ±×¸®µå ³¯Â¥ ¼¿¿¡¼­ ³¯Â¥¸¦ ÀÔ·Â¹Þ°í¼­ À¯È¿ÇÑÁö Ã¼Å©(yyyymmdd or yyyy-mm-dd or yyyy/mm/dd)ÈÄ Æ²¸®¸é Calendar Popup
 *
 * @param	fgName	±×¸®µå°´Ã¼¸í
 * @param	row		Çà¼ö
 * @param	col		¿­¼ö
 **/
function openCalendarInGrid(fgName, row, col)
{
	var fg = document.all(fgName);
	if (!blnOkDate(fg.TextMatrix(row, col), "nn"))
	{
		fg.TextMatrix(row, col) = "";
		showDateCalendarGrid(fgName + ", " + row + ", " + col);
	}
	else
		fg.TextMatrix(row, col) = dateFormat(fg.TextMatrix(row, col), "YYYY-MM-DD");

}

/**
 * INPUT field¿¡¼­ ³¯Â¥¸¦ ÀÔ·Â¹Þ°í¼­ À¯È¿ÇÑÁö Ã¼Å©(yyyymmdd or yyyy-mm-dd or yyyy/mm/dd)ÈÄ Æ²¸®¸é Calendar Popup
 *
 * @param field INPUT °´Ã¼
 **/
function openCalendar(dateField)
{
 var obj = eval("document." + dateField);

 if (obj.value == "")
  return;
 if (!blnOkDate(obj.value, "nn"))
 {
  obj.value = "";
  showDateCalendar(dateField);
 }
 else
  obj.value = dateFormat(obj.value, "YYYY-MM-DD");

}

/**
 * systemÀÇ ÇöÀç³¯Â¥ + stValue ³¯ÀÚ¸¦ ¹ÝÈ¯ÇÑ´Ù.
 * @param stDate yyyy-MM-dd Çü½ÄÀÇ string
 * @param stType ³â,¿ù,ÀÏ {Year|Month|Day}
 * @param stValue int ´õÇÒ ¼ýÀÚ
 * @return string yyyy-MM-dd
 */
function addDate(stDate, stType, stValue) {
	var CurYear = stDate.substring(0,4);
	var CurMonth = stDate.substring(5,7);
	var CurDate = stDate.substring(8);

	var TDate = new Date();

	if (stType == 'Year') {
		CurYear = eval(CurYear) + eval(stValue);
		TDate.setFullYear(CurYear);
	} else if (stType == 'Month') {
		CurMonth = eval(CurMonth) + eval(stValue-1);
		TDate.setMonth(CurMonth);
	} else {
		CurDate = eval(CurDate) + eval(stValue);
		TDate.setDate(CurDate);
	}

	CurYear = TDate.getFullYear();
	CurMonth = TDate.getMonth()+1;
	CurDate = TDate.getDate();
	if (CurMonth<10) CurMonth = '0' + CurMonth;
	if (CurDate<10) CurDate = '0' + CurDate;

	return  (CurYear.toString() + '-' + CurMonth.toString() + '-' + CurDate.toString());
}