/**
	ÆÄÀÏ¸í : common.js 
	¸ñ  Àû : 
	ÀÛ¼ºÀÚ : ÀÌ¼º¿ø
	³»  ¿ë : 
	----------------------------------------------------------------------------

	[Function Category]

		A.  Object °ü·Ã ÇÔ¼ö.
		B.  String °ü·Ã ÇÔ¼ö.
		C.  Numeric °ü·Ã·ÃÇÔ¼ö.
		D.  Date °ü·Ã ÇÔ¼ö.
		E.  Form °ü·Ã ÇÔ¼ö.
		F.  Cookie °ü·Ã ÇÔ¼ö.
		G.  URI¹× Window °ü·Ã ÇÔ¼ö.



    [Function List]

		A-1.  showProps	         ÀÔ·Â °´Ã¼¿¡ ¼ÓÇÑ ¸ðµç ¼Ó¼º°ú ÇÔ¼ö¸¦ º¸¿©ÁØ´Ù.
		A-2.  isObject		     ÀÔ·Â °´Ã¼°¡ ½ÇÁ¦·Î ÆäÀÌÁö»ó¿¡ Á¸ÀçÇÏ´Â HTML°´Ã¼ÀÎÁö¸¦ °Ë»çÇÑ´Ù.
		A-3.  isArray			 ÀÔ·Â °´Ã¼°¡ Array ÇüÅÂÀÎÁö °Ë»çÇÑ´Ù.


		B-1.  isNullString       ÀÔ·Â ¹®ÀÚ¿­ÀÇ °ªÀÌ ³Î(null)ÀÎÁö¸¦ °Ë»çÇÑ´Ù.								 
		B-2.  trim               ÀÔ·Â ¹®ÀÚ¿­ÀÇ ¾ÕµÚ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
		B-3.  trimByFront        ÀÔ·Â ¹®ÀÚ¿­ÀÇ ¾Õ¿¡¼­ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
		B-4.  trimByBack         ÀÔ·Â ¹®ÀÚ¿­ÀÇ µÚ¿¡¼­ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
		B-5.  strlen             ÀÔ·Â °´Ã¼ÀÇ ¹ÙÀÌÆ®´ÜÀ§ÀÇ ±æÀÌ¸¦ ±¸ÇÑ´Ù.
		B-6.  removeSpace        ¹®ÀÚ¿­ÀÇ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
		B-7.  insertComma        ¹®ÀÚ¿­À» µÚ¿¡¼­ºÎÅÍ 3ÀÚ¸®¾¿ ,(comma)·Î  ²÷´Â´Ù.
		B-8.  removeComma        ,(comma)¸¦ »èÁ¦ÇÑ´Ù.
		B-9.  replace            ¹®ÀÚ¿­À» ±³È¯ÇÑ´Ù.
        B-10. removeString       ÀÔ·Â ¹®ÀÚ¿­ÀÇ ÁöÁ¤¹®ÀÚ¸¦ Á¦°ÅÇÑ´Ù.

		C-1.  getRandom          ÁöÁ¤ÇÑ ÀÚ¸®¼öÀÇ ³­¼ö¸¦ ¹ß»ý½ÃÅ²´Ù.
		C-2.  toInteger          ¼Ò¼öÁ¡À» Æ÷ÇÔÇÑ ¼ýÀÚ¸¦ ¼Ò¼öÁ¡À» Á¦°ÅÇÑ Á¤¼ö·Î º¯È¯ÇÑ´Ù.
		C-3.  toReal             ¼Ò¼öÁ¡À» Æ÷ÇÔÇÏÁö ¾ÊÀº ¼ýÀÚ¸¦ ¼Ò¼öÁ¡À» Æ÷ÇÔÇÑ ½Ç¼ö·Î º¯È¯ÇÑ´Ù.


		D-1.  toTimeString       ÀÚ¹Ù½ºÅ©¸³Æ® Date °´Ã¼¸¦ Time ¹®ÀÚ¿­·Î º¯È¯ÇÑ´Ù.
		D-2.  toTimeObject       Time ½ºÆ®¸µÀ» ÀÚ¹Ù½ºÅ©¸³Æ® Date °´Ã¼·Î º¯È¯ÇÑ´Ù.
		D-3.  getCurrentTime     ÇöÀç ½Ã°¢À» Time Çü½ÄÀ¸·Î ¸®ÅÏÇÑ´Ù.
		D-4.  getYear            ÇöÀç Ò´À» YYYYÇü½ÄÀ¸·Î ¸®ÅÏ
		D-5.  getMonth           ÇöÀç êÅÀ» MMÇü½ÄÀ¸·Î ¸®ÅÏ
		D-6.  getDay             ÇöÀç ìíÀ» DDÇü½ÄÀ¸·Î ¸®ÅÏ
		D-7.  getDayOfWeek       ¿À´Ã³¯Â¥¿¡ ÇØ´çÇÏ´Â ¿äÀÏÀ» ±¸ÇÑ´Ù.
		D-8.  shiftTime          ÁÖ¾îÁø Time °ú y³â m¿ù dÀÏ h½Ã Â÷ÀÌ³ª´Â TimeÀ» ±¸ÇÑ´Ù.
		D-9.  getHourBefore      ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü½Ã°£À» ±¸ÇÑ´Ù.
		D-10. getDayBefore       ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀüÀÏÀ» ±¸ÇÑ´Ù.
		D-11. getMonthBefore     ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü¿ùÀ» ±¸ÇÑ´Ù.
		D-12. getYearBefore      ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü¿¬µµ¸¦ ±¸ÇÑ´Ù.
		D-13. getHourAfter       ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ½Ã°£À» ±¸ÇÑ´Ù.
		D-14. getDayAfter        ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄÀÏ¸¦ ±¸ÇÑ´Ù.
		D-15. getMonthAfter      ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ¿ùÀ» ±¸ÇÑ´Ù.
		D-16. getYearAgter       ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ¿¬µµ¸¦ ±¸ÇÑ´Ù.
		D-17. getMonthInterval   µÎ ½Ã°£ÀÌ ¸î °³¿ù Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù.
		D-18. getDayInterval     µÎ ½Ã°£ÀÌ ¸îÀÏ Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù.
		D-19. getHourInterval    µÎ ½Ã°£ÀÌ ¸î½Ã°£ Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù.
		D-20. isLeapYear         À±³â¿©ºÎ¸¦ ³ªÅ¸³½´Ù.
		D-21. ValidFormattedDate °ªÀÌ YYYY-MM-DD Çü½ÄÀÌ ¸Â´ÂÁö °Ë»çÇÑ´Ù.

		F-1.  setCookie          ÄíÅ°°ªÀ» ÁöÁ¤ÇÑ´Ù.
		F-2.  getCookie          ÄíÅ°°ªÀ» °¡Á®¿Â´Ù.
		F-3.  deleteCookie       ÁöÁ¤ÇÑ ÄíÅ°ÀÌ¸§ÀÇ ÄíÅ°¸¦ »èÁ¦ÇÑ´Ù.
*/

var gFunctionName;
//disableRightButton();
enableEnterKey();

/**
 * A-1. ÀÔ·Â °´Ã¼¿¡ ¼ÓÇÑ ¸ðµç ¼Ó¼º°ú ÇÔ¼ö¸¦ º¸¿©ÁØ´Ù.
 *
 * @param obj	HTML °´Ã¼ id ¶Ç´Â °´Ã¼ name
 * @return
 */
function showProps(obj) {
	var element = this.getObject(obj);
	var msg = "°´Ã¼ÀÇ ¼Ó¼º\n\n";
	var i = 0;

	if(obj) {
		for(prop in obj) {
			i++;
			msg += i + ". " + prop+'=' + obj[prop] + "\n";
			if(i % 10 ==0) {
				msg = "";
			}
		}
		if(msg) 
			window.alert(msg);
	}
}

/**
 * A-2. ÀÔ·Â °´Ã¼°¡ ½ÇÁ¦·Î ÆäÀÌÁö»ó¿¡ Á¸ÀçÇÏ´Â HTML°´Ã¼ÀÎÁö¸¦ °Ë»çÇÑ´Ù.
 *
 * @param obj	°´Ã¼ ID
 * @return
 */
function isObject(obj) {
	if(typeof(obj) == "undefined") {
//		window.alert("°´Ã¼°¡ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù. °´Ã¼ÀÇ Ã¶ÀÚ¸¦ È®ÀÎÇÏ¼¼¿ä.");
		return false;
	}

	return true;
}

/**
 * A-3. ÀÔ·Â °´Ã¼°¡ Array ÇüÅÂÀÎÁö °Ë»çÇÑ´Ù.
 *
 * @param obj	°´Ã¼ ID
 * @return
 */
function isArray(obj) {
	if((typeof(obj) != "object") || (typeof(obj[0]) != "object")) {
//		window.alert("element(checkbox)°¡ Array°¡ ¾Æ´Õ´Ï´Ù.");
		return false;
	}

	return true;
}

/**
 * B-1. ÀÔ·Â ¹®ÀÚ¿­ÀÇ °ªÀÌ ³Î(null)ÀÎÁö¸¦ °Ë»çÇÑ´Ù.
 *
 * @param str ¹®ÀÚ¿­
 * @return
 */
function isNull(obj) {
    var str = obj.value;

	if(strlen(str) == 0) {
		return true;
	}

	return false;
}

/**
 * B-2. ÀÔ·Â ¹®ÀÚ¿­ÀÇ ¾ÕµÚ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function trim(str) {
	var n = str.length;

	var i;
	for(i=0; i<n; i++) {
		if(str.charAt(i) != " ") {
			break;
		}
	}

	var j;
	for(j=n-1; j>=0; j--) {
		if(str.charAt(j) != " ") {
			break;
		}
	}

	if(i>j) {
		return "";
	}
	else {
		return str.substring(i,j+1);
	}
}

/**
 * B-3. ÀÔ·Â ¹®ÀÚ¿­ÀÇ ¾Õ¿¡¼­ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function trimByFront(str) {
	var n = str.length;

	var i;
	for(i=0; i<n; i++) {
		if(str.charAt(i) != " ") {
			break;
		}
	}

    return str.substring(i);
}

/**
 * B-4. ÀÔ·Â ¹®ÀÚ¿­ÀÇ µÚ¿¡¼­ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function trimByBack(str) {
	var n = str.length;

	var j;
	for(j=n-1; j>=0; j--) {
		if(str.charAt(j) != " ") {
			break;
		}
	}

	return str.substring(0,j+1);
}

/**
 * B-5. ÀÔ·Â °´Ã¼ÀÇ ¹ÙÀÌÆ®´ÜÀ§ÀÇ ±æÀÌ¸¦ ±¸ÇÑ´Ù.
 *
 * @param obj	°´Ã¼ ID
 * @return
 */
function strlen(str) {
	var j = 0;
	for(var i=0; i<str.length; i++) {
		if(escape(str.charAt(i)).length == 6)
			j++;
		j++;
	}

	return(j);
}

/**
 * B-6. ¹®ÀÚ¿­ÀÇ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function removeSpace(str) {
	return removeString(str, " ");
}

/**
 * B-7. ¹®ÀÚ¿­À» µÚ¿¡¼­ºÎÅÍ 3ÀÚ¸®¾¿ ,(comma)·Î  ²÷´Â´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return		,(comma)°¡ »ðÀÔµÈ ¹®ÀÚ¿­
 */
function insertComma(str) {
	str = removeComma(str);

	var strIdx = str.indexOf(".");
	if(strIdx == -1) {
		return insertCharacterByBack(str, ",", 3);
	}
	else {
		var str1 = str.substring(0, strIdx);
		var str2 = str.substring(strIdx);

		return insertCharacterByBack(str1, ",", 3) + str2;
	}
}

/**
 * B-8. ,(comma)¸¦ »èÁ¦ÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function removeComma(str) {
	return removeString(str, ",");
}



/**
 * B-9. ¹®ÀÚ¿­À» ±³È¯ÇÑ´Ù.
 *
 * @param source	ÀüÃ¼ ¹®ÀÚ¿­
 * @param target	¹Ù²Ù±æ ¿øÇÏ´Â ¹®ÀÚ¿­
 * @param replace	¹Ù²Ü ¹®ÀÚ¿­
 * @return
 */
function replace( source,  target,  replace) {
    var sourceData="";
    sourceData=source;

    if(sourceData==null) return "";
    if(target==null||target=="") return source;

    iTargetLen = target.length;

    sbfReplace="";
    i = 0;
    j = 0;

    while (j > -1)
    {
      j = sourceData.indexOf(target,i);
      if (j > -1)
      {

        sbfReplace+=sourceData.substring(i,j);
        sbfReplace+=replace;
        i = j + iTargetLen;
      }
    }
    sbfReplace+=sourceData.substring(i,sourceData.length);

    return sbfReplace;
}

/**
 * B-10. ÀÔ·Â ¹®ÀÚ¿­ÀÇ ÁöÁ¤¹®ÀÚ¸¦ Á¦°ÅÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function removeString(str, delStr) {
	var oldVal = str;
	var newVal = "";


	var n = oldVal.length;

	for(var i=0; i<n; i++) {
		if(oldVal.charAt(i) == delStr) {
			continue;
		}
		else {
			newVal += oldVal.charAt(i);
		}
	}
	
	return newVal;
}


function getObject(obj) {
	if(!isObject(obj))
		return false;

	if(typeof(window.document.all[obj]) == "object")
		return window.document.all[obj];
	else
		return null;
}

/**
 * C-1. ÁöÁ¤ÇÑ ÀÚ¸®¼öÀÇ ³­¼ö¸¦ ¹ß»ý½ÃÅ²´Ù.
 *
 * @param size	³­¼ö Å©±â
 * @return
 */
function getRandom(size) {
	var random;
	while((random = Math.random() * Math.pow(10, size) - 1) < Math.pow(10, size - 1))
		;
	return(parseInt(random));
}



/**
 * C-2. ¼Ò¼öÁ¡À» Æ÷ÇÔÇÑ ¼ýÀÚ¸¦ ¼Ò¼öÁ¡À» Á¦°ÅÇÑ Á¤¼ö·Î º¯È¯ÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function toInteger(str) {
	if(str.indexOf(".") == -1)
		return str;
	else
		return str.substring(0,  str.indexOf("."));
}

/**
 * C-3. ¼Ò¼öÁ¡À» Æ÷ÇÔÇÏÁö ¾ÊÀº ¼ýÀÚ¸¦ ¼Ò¼öÁ¡À» Æ÷ÇÔÇÑ ½Ç¼ö·Î º¯È¯ÇÑ´Ù.
 *
 * @param str	¹®ÀÚ¿­
 * @return
 */
function toReal(str) {
	var strIdx = str.indexOf(".")

	if(strIdx == -1)
		return str + ".0";
	else if(strIdx == str.length-1)
		return str + "0";
	else
		return str;
}



/**
 * D-1. ÀÚ¹Ù½ºÅ©¸³Æ® Date °´Ã¼¸¦ Time ¹®ÀÚ¿­·Î º¯È¯ÇÑ´Ù.
 *
 * @param date	Date °´Ã¼
 * @return
 */
function toTimeString(date) {
  var year  = date.getFullYear();
  var month = date.getMonth() + 1; // 1¿ù=0, 12¿ù=11
  var day   = date.getDate();
  var hour  = date.getHours();
  var min   = date.getMinutes();
  var sec   = date.getSeconds();

  if(("" + month).length == 1) {month = "0" + month;}
  if(("" + day).length == 1) {day = "0" + day;}
  if(("" + hour).length == 1) {hour = "0" + hour;}
  if(("" + min).length == 1) {min = "0" + min;}
  if(("" + sec).length == 1) {sec = "0" + sec;}

  return("" + year + month + day + hour + min + sec)
}

/**
 * D-2. Time ½ºÆ®¸µÀ» ÀÚ¹Ù½ºÅ©¸³Æ® Date °´Ã¼·Î º¯È¯ÇÑ´Ù.
 *
 * @param time	Time ¹®ÀÚ¿­
 * @return
 */
function toTimeObject(time) {
  var year  = time.substr(0,4);
  var month = time.substr(4,2) - 1; // 1¿ù=0, 12¿ù=11
  var day   = time.substr(6,2);
  var hour  = time.substr(8,2);
  var min   = time.substr(10,2);

  return new Date(year,month,day,hour,min);
}

/**
 * D-3. ÇöÀç ½Ã°¢À» Time Çü½ÄÀ¸·Î ¸®ÅÏÇÑ´Ù.
 *
 * @return
 */
function getCurrentTime() {
  return toTimeString(new Date());
}

/**
 * D-4. ÇöÀç Ò´À» YYYYÇü½ÄÀ¸·Î ¸®ÅÏ
 *
 * @return
 */
function getYear() {
  return getCurrentTime().substr(0,4);
}

/**
 * D-5. ÇöÀç êÅÀ» MMÇü½ÄÀ¸·Î ¸®ÅÏ
 *
 * @return
 */
function getMonth() {
  return getCurrentTime().substr(4,2);
}

/**
 * D-6. ÇöÀç ìíÀ» DDÇü½ÄÀ¸·Î ¸®ÅÏ
 *
 * @return
 */
function getDay() {
  return getCurrentTime().substr(6, 2);
}

/**
 * D-7. ¿À´Ã³¯Â¥¿¡ ÇØ´çÇÏ´Â ¿äÀÏÀ» ±¸ÇÑ´Ù.
 *
 * @return
 */
function getDayOfWeek() {
  var now = new Date();

  var day = now.getDay();
  var week = new Array("ÀÏ", "¿ù", "È­", "¼ö", "¸ñ", "±Ý", "Åä");

  return week[day];
}

/**
 * D-8. ÁÖ¾îÁø Time °ú y³â m¿ù dÀÏ h½Ã Â÷ÀÌ³ª´Â TimeÀ» ±¸ÇÑ´Ù.
 *
 * @param time	Time °´Ã¼
 * @param y		y³â Â÷ÀÌ
 * @param m		m¿ù Â÷ÀÌ
 * @param d		dÀÏ Â÷ÀÌ
 * @param h		h½Ã Â÷ÀÌ
 * @return
 */
function shiftTime(time, y, m, d, h) {
  var date = toTimeObject(time);

  date.setFullYear(date.getFullYear() + y); // y³âÀ» ´õÇÔ
  date.setMonth(date.getMonth() + m); // m¿ùÀ» ´õÇÔ
  date.setDate(date.getDate() + d); // dÀÏÀ» ´õÇÔ
  date.setHours(date.getHours() + h); // h½Ã¸¦ ´õÇÔ

  return toTimeString(date);
}

/**
 * D-9. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü½Ã°£À» ±¸ÇÑ´Ù.
 *
 * @param   nHour   ½Ã°£
 * @return
 */
function getHourBefore(nHour) {
	nHour = eval(nHour);
	return shiftTime(getCurrentTime(), 0, 0, 0, -nHour);
}

/**
 * D-10. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀüÀÏÀ» ±¸ÇÑ´Ù.
 *
 * @param   nDay    ÀÏ
 * @return
 */
function getDayBefore(nDay) {
	nDay = eval(nDay);
	return shiftTime(getCurrentTime(), 0, 0, -nDay, 0);
}

/**
 * D-11. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü¿ùÀ» ±¸ÇÑ´Ù.
 *
 * @param nMonth    ¿ù
 * @return
 */
function getMonthBefore(nMonth) {   
    nMonth = eval(nMonth);
	return shiftTime(getCurrentTime(), 0, -nMonth, 0, 0);
}

/**
 * D-12. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü¿¬µµ¸¦ ±¸ÇÑ´Ù.
 *
 * @param nYear     ¿¬
 * @return
 */
function getYearBefore(nYear) {
	nYear = eval(nYear);
	return shiftTime(getCurrentTime(), -nYear, 0, 0, 0);
}

/**
 * D-13. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ½Ã°£À» ±¸ÇÑ´Ù.
 *
 * @param nHour     ½Ã°£
 * @return
 */
function getHourAfter(nHour) {
	nHour = eval(nHour);
	return shiftTime(getCurrentTime(), 0, 0, 0, nHour);
}

/**
 * D-14. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄÀÏ¸¦ ±¸ÇÑ´Ù.
 *
 * @param nDay      ÀÏ
 * @return
 */
function getDayAfter(nDay) {
	nDay = eval(nDay);
	return shiftTime(getCurrentTime(), 0, 0, nDay, 0);
}

/**
 * D-15. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ¿ùÀ» ±¸ÇÑ´Ù.
 *
 * @param nMonth    ¿ù
 * @return
 */
function getMonthAfter(nMonth) {
	nMonth = eval(nMonth);
	return shiftTime(getCurrentTime(), 0, nMonth, 0, 0);
}

/**
 * D-16. ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ¿¬µµ¸¦ ±¸ÇÑ´Ù.
 *
 * @param nYear     ¿¬
 * @return
 */
function getYearAfter(nYear) {
	nYear = eval(nYear);
	return shiftTime(getCurrentTime(), nYear, 0, 0, 0);
}

/**
 * D-17. µÎ ½Ã°£ÀÌ ¸î °³¿ù Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù.
 *
 * @param time1
 * @param time2
 * @return
 */
function getMonthInterval(time1,time2) {
  var date1 = toTimeObject(time1);
  var date2 = toTimeObject(time2);

  var years  = date2.getFullYear() - date1.getFullYear();
  var months = date2.getMonth() - date1.getMonth();
  var days   = date2.getDate() - date1.getDate();

  return years * 12 + months + ((days >= 0)?0:-1);
}

/**
 * D-18. µÎ ½Ã°£ÀÌ ¸îÀÏ Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù.
 *
 * @param time1
 * @param time2
 * @return
 */
function getDayInterval(time1, time2) {
  var date1 = toTimeObject(time1);
  var date2 = toTimeObject(time2);
  var day   = 1000 * 3600 * 24;

  return parseInt((date2 - date1) / day, 10);
}

/**
 * D-19. µÎ ½Ã°£ÀÌ ¸î½Ã°£ Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù.
 *
 * @param time1
 * @param time2
 * @return
 */
function getHourInterval(time1, time2) {
  var date1 = toTimeObject(time1);
  var date2 = toTimeObject(time2);
  var hour  = 1000 * 3600;

  return parseInt((date2 - date1) / hour, 10);
}


/**
* D-20.  À±³â¿©ºÎ¸¦ ³ªÅ¸³½´Ù.
**/
function isLeapYear(aYear) {
    if ((aYear % 4 == 0) && ((aYear % 100 != 0) || (aYear % 400 == 0)))
    {
        return true;   // À±³â
    }    
    else
    {
        return false;  // Æò³â
    }
}


/**
 * D-21. °ªÀÌ YYYY-MM-DD Çü½ÄÀÌ ¸Â´ÂÁö °Ë»çÇÑ´Ù.
 * 
 * @param str1	¹®ÀÚ¿­1
 * @return 
 */
function validFormattedDate(strDate) {
	
	if(strDate.length != 10 ) return false;
    var str1 = replace( strDate, '-', '');
    var yyyy = str1.substring(0, 4); 
    var mm   = str1.substring(4, 6); 
    var dd   = str1.substring(6, 8);
    
	if(!ValidDate(yyyy, mm, dd)) {
		return false;
	}
	return true;
}


/**
 * F-1. ÄíÅ°°ªÀ» ÁöÁ¤ÇÑ´Ù.
 *
 * @param name		 ÄíÅ°¸í
 * @param value		 ÄíÅ°°ª
 * @param expiredays ¸¸·áÀÏ
 * @return
 */
function setCookie( name, value, expiredays ) {
    var today = new Date();
    var nextDate = today.getDate() + (expiredays  - 1)
    today.setDate(nextDate);
    var newDate = new Date( today.getYear(), today.getMonth(), today.getDate(), 23, 59, 59 );
    document.cookie = name + "=" + escape( value ) + "; domain=kbstar.com; path=/; expires=" + newDate.toGMTString() + ";";
}

/**
 * F-2. ÄíÅ°°ªÀ» °¡Á®¿Â´Ù.
 *
 * @param name		ÄíÅ°¸í
 * @return
 */
function getCookie( name ){
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length ) {
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
				endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 )
			break;
	}
	return "";
}


/**
 * F-3. ÁöÁ¤ÇÑ ÄíÅ°ÀÌ¸§ÀÇ ÄíÅ°¸¦ »èÁ¦ÇÑ´Ù.
 *
 * @param name	ÄíÅ° ÀÌ¸§
 * @param name	ÄíÅ° °ª
 * @return
 */
function deleteCookie(name) {
	var expire = new Date();
	expire.setTime(expire.getTime() - 1);
	var value = GetCookie(name);
	document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
}

////////////////////////////////////////////////////////////////////////////////
//  Window °ü·Ã ÇÔ¼ö
////////////////////////////////////////////////////////////////////////////////

function openWindow(url, name, W, H, scroll, resize, option) {
    var X = 0;
    var Y = 0;

    if(option == 8) {
        X = (window.screen.width - W) / 2;
        Y = window.screen.height - H - 83;
    }
    else {
		if(parseInt(W) <= 400 && parseInt(H) <= 400) {
    //        X = (window.screen.width/2) - (W/2+10);
    //        Y = (window.screen.height/2) - (H/2+50);
            if(window.screen.width < W + window.event.screenX)
                X = window.event.screenX - W - 10;
            else
                X = window.event.screenX;

            if(window.screen.height < H + window.event.screenY)
                Y = window.event.screenY - H - 30;
            else
                Y = window.event.screenY;
        }
    }

	var win = window.open(url, name, "status=no, height=" + H + ",width=" + W + ", left=" + X + ", top=" + Y + ", screenX=" + X + ", screenY=" + Y + ", scrollbars=" + scroll + ", resizable=" + resize);
	
	win.focus();
	return win;
}

////////////////////////////////////////////////////////////////////////////////
//  Select °ü·Ã ÇÔ¼ö
////////////////////////////////////////////////////////////////////////////////

/**
 * SELECT °´Ã¼°¡  ÃÊ±â»óÅÂ(index == 0)¿¡¼­ º¯°æµÇ¾ú´ÂÁö °Ë»çÇÑ´Ù.
 *
 * @param obj	°´Ã¼ ID
 * @param msg	°´Ã¼ ÀÌ¸§
 * @return
 */
function isSelected(obj, msg) {
	if(!isObject(obj))
		return false;

	if(obj.selectedIndex == 0) {
		if(msg) {
			window.alert("[" + msg + "]ÀÌ(°¡) ¼±ÅÃµÇÁö ¾Ê¾Ò½À´Ï´Ù.");
		}
		
		obj.focus();
		return false;
	}

	return true;
}

function compareOptionValues(a, b) {
	// Radix 10: for numeric values
	// Radix 36: for alphanumeric values
	var sA = parseInt(a.value, 36);
	var sB = parseInt(b.value, 36);

	return sA - sB;
}

function compareOptionText(a, b) {
	// Radix 10: for numeric values
	// Radix 36: for alphanumeric values
	var sA = parseInt(a.text, 36);
	var sB = parseInt(b.text, 36);
	return sA - sB;
}

/**
 * SELECT ¸®½ºÆ®¿¡¼­ ´Ù¸¥ ¸®½ºÆ®·Î Ç×¸ñÀ» ÀÌµ¿ÇÑ´Ù.
 *
 * @param srcList	¿øº» ¸®½ºÆ®
 * @param tarList	´ë»ó ¸®½ºÆ®
 * @param moveAll	true : ÀüÃ¼ Ç×¸ñ, false : ¼±ÅÃÇÑ Ç×¸ñ
 * @return
 */
function moveDualList(srcList, tarList, moveAll) {
	if(srcList.length == 0) {
		window.alert("ÀÌµ¿ÇÒ Ç×¸ñÀÌ ¾ø½À´Ï´Ù.");
		return false;
	}

	if((srcList.selectedIndex == -1) && (moveAll == false)) {
		window.alert("ÀÌµ¿ÇÒ Ç×¸ñÀ» ¼±ÅÃÇÏ¼¼¿ä.");
		return false;
	}

	newtarList = new Array(tarList.options.length);

	var len = 0;

	for(len = 0; len < tarList.options.length; len++) {
		if(tarList.options[ len ] != null) {
			newtarList[ len ] = new Option(tarList.options[ len ].text, tarList.options[ len ].value, tarList.options[ len ].defaultSelected, tarList.options[ len ].selected);
		}
	}

	for(var i = 0; i < srcList.options.length; i++) {
		if(srcList.options[i] != null && (srcList.options[i].selected == true || moveAll)) {
			newtarList[ len ] = new Option(srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected);
			len++;
		}
	}

	newtarList.sort(compareOptionValues);   // BY VALUES
	//newtarList.sort(compareOptionText);   // BY TEXT

	for(var j = 0; j < newtarList.length; j++) {
		if(newtarList[ j ] != null) {
			tarList.options[ j ] = newtarList[ j ];
		}
	}

	for(var i = srcList.options.length - 1; i >= 0; i--) {
		if(srcList.options[i] != null && (srcList.options[i].selected == true || moveAll)) {
		   srcList.options[i] = null;
		}
	}
}


/**
 * ÀÔ·Â ¹®ÀÚ¿­À» µÚ¿¡¼­ºÎÅÍ ÁöÁ¤ÇÑ Å©±â¸¸Å­ ±¸ºÐ¹®ÀÚ·Î ²÷´Â´Ù. (»èÁ¦´ë»ó)
 *
 * @param strMain	¹®ÀÚ¿­
 * @param strIns	±¸ºÐ ¹®ÀÚ
 * @param size		»ðÀÔ ´ÜÀ§
 * @return
 */
function insertCharacterByBack(strMain, strIns, size) {
	var returnStr = "";
	var tempStrMain = strMain + "";
	var tempStrIns = strIns + "";
	var strMainLength = tempStrMain.length;

	if (strMainLength < size) {
		return tempStrMain;
	}
	else {
		var strLengthDiv = parseInt(strMainLength / size);
		var strLengthRemnant = parseInt(strMainLength % size);

		if (strLengthRemnant > 0) {
			returnStr = tempStrMain.substring(0, strLengthRemnant) + strIns;
		}

		for (i = 0; i < strLengthDiv; i++) {
			if (i == 0) {
				returnStr = returnStr + tempStrMain.substring(strLengthRemnant, strLengthRemnant + size);
			}
			else {
				returnStr = returnStr + tempStrIns + tempStrMain.substring(strLengthRemnant + (size * i), strLengthRemnant + (size * i) + size);
			}
		}

		return returnStr;
	}
}

/**
 * ÀÌº¥Æ® ÃÊ±âÈ­
 */
function disableRightButton() {

	if(window.Event)
		document.captureEvents(Event.MOUSEUP);

	function nocontextmenu() {
		window.event.cancelBubble = true
		window.event.returnValue = false;
		return false;
	}

	function norightclick(e) {
		if(window.Event) {
			if(e.which == 2 || e.which == 3)
			return false;
		}
		else if(window.event.button == 2 || window.event.button == 3) {
			window.event.cancelBubble = true
			window.event.returnValue = false;
			return false;
		}
	}

	document.oncontextmenu = nocontextmenu;
	document.onmousedown = norightclick;
}

function enableEnterKey() {
	function onkeypress(e) {
        if(window.event.keyCode == 13 && window.event.srcElement.type != "textarea" && window.event.srcElement.type != "button") { // 13 : Enter
			__submit();
			
			if(window.event.srcElement.type == "text" || window.event.srcElement.type == "password")
				return false;
        }
	}

    document.onkeypress = onkeypress;
}

function jsOpenMainFileManagerWindow(mgrId, bbsId, oldFilePath, oldFileName) {
	openWindow("/common/commonMainFileManager.jsp?mgrId=" + mgrId + "&bbsId=" + bbsId + "&filePKey=" + oldFileName + "&filePath=" + oldFilePath, "BBS_MAIN_FILE_MANAGER", 620, 200);
}

function jsOpenClubFileManagerWindow(clubId, mgrId, bbsId, oldFilePath, oldFileName) {
	openWindow("/common/commonClubFileManager.jsp?clubId=" + clubId + "&mgrId=" + mgrId + "&bbsId=" + bbsId + "&filePKey=" + oldFileName + "&filePath=" + oldFilePath, "CLUB_FILE_MANAGER", 620, 200);
}

function jsOpenClubImageManagerWindow(clubId, columnName, oldFilePath, oldFileName) {
	openWindow("/common/commonClubImageManager.jsp?clubId=" + clubId + "&columnName=" + columnName + "&filePKey=" + oldFileName + "&filePath=" + oldFilePath, "CLUB_FILE_MANAGER", 620, 200);
}

function jsOpenMainFileDownloadWindow(fileId) {
	location.href = "/common/commonMainFileDownload.jsp?fileId=" + fileId;
}

function jsOpenMapFileDownloadWindow(mapId, flag) {
	location.href = "/common/commonMapFileDownload.jsp?mapId=" + mapId+"&flag="+flag;
}


function jsOpenCorpFileDownloadWindow(corpId, fileId) {
	location.href = "/common/commonCorpFileDownload.jsp?corpId=" + corpId + "&fileId=" + fileId;
}

function jsOpenCpmsFileDownloadWindow(fileId) {
	location.href = "/common/commonCpmsFileDownload.jsp?fileId=" + fileId;
}


function jsOpenClubFileDownloadWindow(fileId, mgrName) {
        location.href = "/common/commonClubFileDownload.jsp?fileId=" + fileId + "&mgrName=" + mgrName;
}

function jsOpenBbsFileDownloadWindow(fileId, mgrId) {
	location.href = "/common/commonBbsFileDownload.jsp?fileId=" + fileId +  "&mgrId=" + mgrId;
}

function jsOpenCalendarWindow(fName) {
	gFunctionName = fName;
	openWindow("/common/commonShowCalendar.jsp", "CALENDAR", 180, 220);
}

function jsOpenEstiFileDownloadWindow(bbsId, no) {
	location.href = "/common/commonEstiFileDownload.jsp?bbsId=" + bbsId + "&no="+no;
}

function jsOpenFixedFileDownloadWindow(bbsId, no, service) {
	location.href = "/common/commonFixedFileDownload.jsp?bbsId="+bbsId+"&no="+no+"&service="+service;
}

function jsOpenEstimateFileDownloadWindow(bbsId) {
	location.href = "/common/commonEstimateFileDownload.jsp?bbsId=" + bbsId ;
}

function jsOpenEstimateFileDownloadWindow(bbsId, tab) {
	location.href = "/common/commonEstimateFileDownload.jsp?bbsId=" + bbsId + "&service="+tab ;
}

function jsOpenServiceFileDownloadWindow(bbsId, no) {
	location.href = "/common/commonServiceFileDownload.jsp?bbsId=" + bbsId + "&no="+no;
}


function jsOpenFileWindow(fileId) {
	location.replace("/demo/standard1/common/commonDownloadFile.php?fileId=" + fileId);
}
