// Global º¯¼ö¼±¾ð
var GLB_MONTH_IN_YEAR   = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var GLB_DAY_IN_WEEK     = ["Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"];

/**
 * @type   : prototype_function
 * @access : public
 * @desc   : ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ ³»Àå °´Ã¼ÀÎ String °´Ã¼¿¡ toDate ¸Þ¼Òµå¸¦ Ãß°¡ÇÑ´Ù. toDate ¸Þ¼Òµå´Â ³¯Â¥¸¦ Ç¥ÇöÇÏ´Â
 *           ½ºÆ®¸µ °ªÀ» ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ ³»Àå °´Ã¼ÀÎ Date °´Ã¼·Î º¯È¯ÇÑ´Ù.
 * <pre>
 *     var date = "2002-03-05".toDate("YYYY-MM-DD")
 * </pre>
 * À§ÀÇ ¿¹¿¡¼­ date º¯¼ö´Â ½ÇÁ¦·Î 2002³â 3¿ù 5ÀÏÀ» Ç¥ÇöÇÏ´Â Date ¿ÀºêÁ§Æ®¸¦ °¡¸£Å²´Ù.
 * @sig    : [pattern]
 * @param  : pattern optional Date¸¦ Ç¥ÇöÇÏ°í ÀÖ´Â ÇöÀçÀÇ StringÀ» patternÀ¸·Î Ç¥ÇöÇÑ´Ù. (default : YYYYMMDD)
 * <pre>
 *     # syntex
 *
 *       YYYY : year(4ÀÚ¸®)
 *       YY   : year(2ÀÚ¸®)
 *       MM   : month in year(number)
 *       DD   : day in month
 *       HH   : hour in day (0~23)
 *       mm   : minute in hour
 *       ss   : second in minute
 *       SS   : millisecond in second
 *
 *     <font color=red>ÁÖÀÇ)</font> YYYY(YY)´Â ¹Ýµå½Ã ÀÖ¾î¾ß ÇÑ´Ù. YYYY(YY) ¸¸ »ç¿ëÇÒ °æ¿ì´Â 1¿ù 1ÀÏÀ» ±âÁØÀ¸·Î
 *     ÇÏ°í YYYY¿Í MM ¸¸»ç¿ëÇÒ °æ¿ì´Â 1ÀÏÀ» ±âÁØÀ¸·Î ÇÑ´Ù.
 * </pre>
 * @return : º¯È¯µÈ Date Object.
 */
String.prototype.toDate = function(pattern) {
        var index = -1;
        var year;
        var month;
        var day;
        var hour = 0;
        var min  = 0;
        var sec  = 0;
        var ms   = 0;

        if (pattern == null) {
                pattern = "YYYYMMDD";
        }

        if ((index = pattern.indexOf("YYYY")) == -1 ) {
                index = pattern.indexOf("YY");
                year = "20" + this.substr(index, 2);
        } else {
                year = this.substr(index, 4);
        }

        if ((index = pattern.indexOf("MM")) != -1 ) {
                month = this.substr(index, 2);
        } else {
                month = 1;
        }

        if ((index = pattern.indexOf("DD")) != -1 ) {
                day = this.substr(index, 2);
        } else {
                day = 1;
        }

        if ((index = pattern.indexOf("HH")) != -1 ) {
                hour = this.substr(index, 2);
        }

        if ((index = pattern.indexOf("mm")) != -1 ) {
                min = this.substr(index, 2);
        }

        if ((index = pattern.indexOf("ss")) != -1 ) {
                sec = this.substr(index, 2);
        }

        if ((index = pattern.indexOf("SS")) != -1 ) {
                ms = this.substr(index, 2);
        }

        return new Date(year, month - 1, day, hour, min, sec, ms);
}



/**
 * @type   : prototype_function
 * @object : Date
 * @access : public
 * @desc   : ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ ³»Àå °´Ã¼ÀÎ Date °´Ã¼¿¡ format ¸Þ¼Òµå¸¦ Ãß°¡ÇÑ´Ù. format ¸Þ¼Òµå´Â Date °´Ã¼°¡ °¡Áø ³¯Â¥¸¦
 *           ÁöÁ¤µÈ Æ÷¸äÀÇ ½ºÆ®¸µÀ¸·Î º¯È¯ÇÑ´Ù.
 * <pre>
 *     var dateStr = new Date().format("YYYYMMDD");
 *
 *     Âü°í : Date ¿ÀºêÁ§Æ® »ý¼ºÀÚµé - dateObj = new Date()
 *                                   - dateObj = new Date(dateVal)
 *                                   - dateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]])
 * </pre>
 * À§ÀÇ ¿¹¿¡¼­ ¿À´Ã³¯Â¥°¡ 2002³â 3¿ù 5ÀÏÀÌ¶ó¸é dateStrÀÇ °ªÀº "20020305"°¡ µÈ´Ù.
 * default patternÀº "YYYYMMDD"ÀÌ´Ù.
 * @sig    : [pattern]
 * @param  : pattern optional º¯È¯ÇÏ°íÀÚ ÇÏ´Â ÆÐÅÏ ½ºÆ®¸µ. (default : YYYYMMDD)
 * <pre>
 *     # syntex
 *
 *       YYYY : hour in am/pm (1~12)
 *       MM   : month in year(number)
 *       MON  : month in year(text)  ¿¹) "January"
 *       DD   : day in month
 *       DAY  : day in week  ¿¹) "Sunday"
 *       hh   : hour in am/pm (1~12)
 *       HH   : hour in day (0~23)
 *       mm   : minute in hour
 *       ss   : second in minute
 *       SS   : millisecond in second
 *       a    : am/pm  ¿¹) "AM"
 * </pre>
 * @return : Date¸¦ Ç¥ÇöÇÏ´Â º¯È¯µÈ String.
 */
Date.prototype.format = function(pattern) {
    var year      = this.getFullYear();
    var month     = this.getMonth() + 1;
    var day       = this.getDate();
    var dayInWeek = this.getDay();
    var hour24    = this.getHours();
    var ampm      = (hour24 < 12) ? 0 : 1;
    var hour12    = (hour24 > 12) ? (hour24 - 12) : hour24;
    var min       = this.getMinutes();
    var sec       = this.getSeconds();
    var YYYY = "" + year;
    var YY   = YYYY.substr(2);
    var MM   = (("" + month).length == 1) ? "0" + month : "" + month;
    var MON  = GLB_MONTH_IN_YEAR[month-1];
    var DD   = (("" + day).length == 1) ? "0" + day : "" + day;
    var DAY  = GLB_DAY_IN_WEEK[dayInWeek];
    var HH   = (("" + hour24).length == 1) ? "0" + hour24 : "" + hour24;
    var hh   = (("" + hour12).length == 1) ? "0" + hour12 : "" + hour12;
    var mm   = (("" + min).length == 1) ? "0" + min : "" + min;
    var ss   = (("" + sec).length == 1) ? "0" + sec : "" + sec;
    var SS   = "" + this.getMilliseconds();
    var a    = (a == 0) ? "AM" : "PM";

    var dateStr;
    var index = -1;

    if (typeof(pattern) == "undefined") {
            dateStr = "YYYYMMDD";
    } else {
            dateStr = pattern;
    }

        dateStr = dateStr.replace(/a/g,    a);
        dateStr = dateStr.replace(/YYYY/g, YYYY);
        dateStr = dateStr.replace(/YY/g,   YY);
        dateStr = dateStr.replace(/MM/g,   MM);
        dateStr = dateStr.replace(/MON/g,  MON);
        dateStr = dateStr.replace(/DD/g,   DD);
        dateStr = dateStr.replace(/DAY/g,  DAY);
        dateStr = dateStr.replace(/hh/g,   hh);
        dateStr = dateStr.replace(/HH/g,   HH);
        dateStr = dateStr.replace(/mm/g,   mm);
        dateStr = dateStr.replace(/ss/g,   ss);

        return dateStr;
}

/**
 * @type   : prototype_function
 * @object : Date
 * @access : public
 * @desc   : ÇöÀç Date °´Ã¼ÀÇ ³¯Â¥º¸´Ù ÀÌÈÄ³¯Â¥¸¦ °¡Áø Date °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
 *           ¿¹¸¦ µé¾î ³»ÀÏ ³¯Â¥¸¦ ¾òÀ¸·Á¸é ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µÈ´Ù.
 * <pre>
 *     var oneDayAfter = new Date.after(0, 0, 1);
 * </pre>
 * @sig    : [years[, months[, dates[, hours[, minutes[, seconds[, mss]]]]]]]
 * @param  : years   optional ÀÌÈÄ ³â¼ö
 * @param  : months  optional ÀÌÈÄ ¿ù¼ö
 * @param  : dates   optional ÀÌÈÄ ÀÏ¼ö
 * @param  : hours   optional ÀÌÈÄ ½Ã°£¼ö
 * @param  : minutes optional ÀÌÈÄ ºÐ¼ö
 * @param  : seconds optional ÀÌÈÄ ÃÊ¼ö
 * @param  : mss     optional ÀÌÈÄ ¹Ð¸®ÃÊ¼ö
 * @return : ÀÌÈÄ³¯Â¥¸¦ Ç¥ÇöÇÏ´Â Date °´Ã¼
 */
Date.prototype.after = function(years, months, dates, hours, miniutes, seconds, mss) {
    if (years == null)    years    = 0;
    if (months == null)   months   = 0;
    if (dates == null)    dates    = 0;
    if (hours == null)    hours    = 0;
    if (miniutes == null) miniutes = 0;
    if (seconds == null)  seconds  = 0;
    if (mss == null)      mss      = 0;

        return new Date(this.getFullYear() + years,
                        this.getMonth() + months,
                        this.getDate() + dates,
                        this.getHours() + hours,
                        this.getMinutes() + miniutes,
                        this.getSeconds() + seconds,
                        this.getMilliseconds() + mss
                       );
}
// alert(new Date().after(1, 1, 1, 1, 1, 1).format("YYYYMMDD HHmmss"));

/**
 * @type   : prototype_function
 * @object : Date
 * @access : public
 * @desc   : ÇöÀç Date °´Ã¼ÀÇ ³¯Â¥º¸´Ù ÀÌÀü³¯Â¥¸¦ °¡Áø Date °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
 *           ¿¹¸¦ µé¾î ¾îÁ¦ ³¯Â¥¸¦ ¾òÀ¸·Á¸é ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µÈ´Ù.
 * <pre>
 *     var oneDayBefore = new Date.before(0, 0, 1);
 * </pre>
 * @sig    : [years[, months[, dates[, hours[, minutes[, seconds[, mss]]]]]]]
 * @param  : years   optional ÀÌÀüÀ¸·Î µ¹¾Æ°¥ ³â¼ö
 * @param  : months  optional ÀÌÀüÀ¸·Î µ¹¾Æ°¥ ¿ù¼ö
 * @param  : dates   optional ÀÌÀüÀ¸·Î µ¹¾Æ°¥ ÀÏ¼ö
 * @param  : hours   optional ÀÌÀüÀ¸·Î µ¹¾Æ°¥ ½Ã°£¼ö
 * @param  : minutes optional ÀÌÀüÀ¸·Î µ¹¾Æ°¥ ºÐ¼ö
 * @param  : seconds optional ÀÌÀüÀ¸·Î µ¹¾Æ°¥ ÃÊ¼ö
 * @param  : mss     optional ÀÌÀüÀ¸·Î µ¹¾Æ°¥ ¹Ð¸®ÃÊ¼ö
 * @return : ÀÌÀü³¯Â¥¸¦ Ç¥ÇöÇÏ´Â Date °´Ã¼
 */
Date.prototype.before = function(years, months, dates, hours, miniutes, seconds, mss) {
    if (years == null)    years    = 0;
    if (months == null)   months   = 0;
    if (dates == null)    dates    = 0;
    if (hours == null)    hours    = 0;
    if (miniutes == null) miniutes = 0;
    if (seconds == null)  seconds  = 0;
    if (mss == null)      mss      = 0;

        return new Date(this.getFullYear() - years,
                        this.getMonth() - months,
                        this.getDate() - dates,
                        this.getHours() - hours,
                        this.getMinutes() - miniutes,
                        this.getSeconds() - seconds,
                        this.getMilliseconds() - mss
                       );
}
//alert(new Date().before(1, 1, 1, 1, 1, 1).format("YYYYMMDD HHmmss"));



/* ------------------------------------------------------------------
Function ID  : rsetScrollBarPop
Description  : ÆË¾÷¿¡¼­ »ç¿ëÇÏ¸ç µ¥ÀÌÅ¸¸¦ Ãâ·ÂÈÄ µ¥ÀÌÅ¸ °Ç¼ö¿¡ µû¶ó divList ÀÇ »çÀÌÁî¸¦ Á¶ÀýÇØÁØ´Ù.
Argument     : non
Return Value : non
ÀÛ  ¼º  ÀÚ   : EZFARM
ÀÛ¼º  ÀÏÀÚ   : 2003 - 04 - 17
ÀÛ¼º  ³»¿ë   :
-------------------------------------------------------------------- */
function rsetScrollBarPop( divObj, tblListObj, nWidth )
{
    if ( nWidth == null )
    {
        nWidth = 404;
    }

    if ( gettblObjWidth( tblListObj ) <= nWidth )
    {
        // °¡·Î ½ºÅ©·ÑÀÌ ¾ø´Â°æ¿ì
        if ( gettblObjHight( tblListObj ) > parseInt( divObj.style.height.substring( 0, divObj.style.height.indexOf( "p" ) ) ) )
        {
            divObj.style.height = parseInt( divObj.style.height.substring( 0, divObj.style.height.indexOf( "p" ) ) ) + 1;
        }
        else
        {
            divObj.style.width = ( nWidth ) + "px";
            divObj.style.height = gettblObjHight( tblListObj ) + 2;
        }
    }
    else
    {
        // °¡·Î ½ºÅ©·ÑÀÌ ÀÖ´Â°æ¿ì
        if ( gettblObjHight( tblListObj ) < parseInt( divObj.style.height.substring( 0, divObj.style.height.indexOf( "p" ) ) ) )
        {
            divObj.style.width = ( nWidth - 2 ) + "px";
            divObj.style.height = gettblObjHight( tblListObj ) + 18;
        }
        else
        {
            divObj.style.width = ( nWidth + 18 ) + "px";
        }
    }
}


/* ------------------------------------------------------------------
Function ID  : gettblObjWidth
Description  : ¸®½ºÆ®Ãâ·ÂºÎ¿¡¼­ »ç¿ëÇÏ¸ç ÇØ´ç Ãâ·Â¸®½ºÆ®ÀÇ
ÀüÃ¼ ³ÐÀÌ¸¦ ±¸ÇÏ±â À§ÇØ »ç¿ëÇÑ´Ù.
Argument     : tblObj       : Object
Return Value : non
ÀÛ  ¼º  ÀÚ   : EZFARM
ÀÛ¼º  ÀÏÀÚ   : 2003 - 04 - 17
ÀÛ¼º  ³»¿ë   : Ãâ·Â¸®½ºÆ®ÀÇ ³ÐÀÌ¸¦ ¾Ë¾Æ¾ß ¼¼·Î½ºÅ©·ÑÀÇ À§Ä¡¸¦
°áÁ¤ÇÒ¼ö ÀÖ´Ù.
-------------------------------------------------------------------- */
function gettblObjWidth( tblObj )
{
    var nLoop   = 0;
    var nWidth  = 0;

    for ( nLoop = 0; nLoop < tblObj.length ; nLoop ++ )
    {
        nWidth = tblObj[nLoop].scrollWidth;
        break;
    }

    if ( nWidth == 0 ) nWidth = tblObj.scrollWidth;
    return nWidth;
}
/* ------------------------------------------------------------------
Function ID  : gettblObjHight
Description  : ¸®½ºÆ®Ãâ·ÂºÎ¿¡¼­ »ç¿ëÇÏ¸ç ÇØ´ç Ãâ·Â¸®½ºÆ®ÀÇ
ÀüÃ¼ ³ôÀÌ¸¦ ±¸ÇÏ±â À§ÇØ »ç¿ëÇÑ´Ù.
Argument     : tblObj       : Object
Return Value : non
ÀÛ  ¼º  ÀÚ   : EZFARM
ÀÛ¼º  ÀÏÀÚ   : 2003 - 04 - 17
ÀÛ¼º  ³»¿ë   : ¸®½ºÆ®Å×ÀÌºíÀ» ¸î°Ç¾¿ ³ª´©¾î Ãâ·ÂÇÏ¹Ç·Î ¹è¿­·Î
ÀâÈú¼öµµ ÀÖ°í ÇÏ³ª·Î ½áÁú¼öµµ ÀÖÀ¸¹Ç·Î
ÇÏ´Ü¿¡¼­ ¹è¿­¿©ºÎ¸¦ È®ÀÎÇØ Ã³¸®ÇÑ´Ù.
-------------------------------------------------------------------- */
function gettblObjHight( tblObj )
{
    var nLoop   = 0;
    var nHeight = 0;
    for ( nLoop = 0; nLoop < tblObj.length ; nLoop ++ )
    {
        nHeight = nHeight + tblObj[nLoop].scrollHeight;
    }
    if ( nHeight == 0 ) nHeight = tblObj.scrollHeight;

    return nHeight;
}
