var sUserAgent = navigator.userAgent;
var fAppVersion = parseFloat(navigator.appVersion);

function compareVersions(sVersion1, sVersion2) {

    var aVersion1 = sVersion1.split(".");
    var aVersion2 = sVersion2.split(".");

    if (aVersion1.length > aVersion2.length) {
        for (var i=0; i < aVersion1.length - aVersion2.length; i++) {
            aVersion2.push("0");
        }
    } else if (aVersion1.length < aVersion2.length) {
        for (var i=0; i < aVersion2.length - aVersion1.length; i++) {
            aVersion1.push("0");
        }
    }
    for (var i=0; i < aVersion1.length; i++) {

        if (aVersion1[i] < aVersion2[i]) {
            return -1;
        } else if (aVersion1[i] > aVersion2[i]) {
            return 1;
        }
    }
    return 0;

}

var isOpera = sUserAgent.indexOf("Opera") > -1;
var isMinOpera4 = isMinOpera5 = isMinOpera6 = isMinOpera7 = isMinOpera7_5 = false;

if (isOpera) {
    var fOperaVersion;
    if(navigator.appName == "Opera") {
        fOperaVersion = fAppVersion;
    } else {
        var reOperaVersion = new RegExp("Opera (\\d+\\.\\d+)");
        reOperaVersion.test(sUserAgent);
        fOperaVersion = parseFloat(RegExp["$1"]);
    }

    isMinOpera4 = fOperaVersion >= 4;
    isMinOpera5 = fOperaVersion >= 5;
    isMinOpera6 = fOperaVersion >= 6;
    isMinOpera7 = fOperaVersion >= 7;
    isMinOpera7_5 = fOperaVersion >= 7.5;
}

var isKHTML = sUserAgent.indexOf("KHTML") > -1
              || sUserAgent.indexOf("Konqueror") > -1
              || sUserAgent.indexOf("AppleWebKit") > -1;

var isMinSafari1 = isMinSafari1_2 = false;
var isMinKonq2_2 = isMinKonq3 = isMinKonq3_1 = isMinKonq3_2 = false;
var isSafari = false;
if (isKHTML) {
    isSafari = sUserAgent.indexOf("AppleWebKit") > -1;
    isKonq = sUserAgent.indexOf("Konqueror") > -1;

    if (isSafari) {
        var reAppleWebKit = new RegExp("AppleWebKit\\/(\\d+(?:\\.\\d*)?)");
        reAppleWebKit.test(sUserAgent);
        var fAppleWebKitVersion = parseFloat(RegExp["$1"]);
        isMinSafari1 = fAppleWebKitVersion >= 85;
        isMinSafari1_2 = fAppleWebKitVersion >= 124;
        isMinSafari3 = fAppleWebKitVersion >= 510;
    } else if (isKonq) {

        var reKonq = new RegExp("Konqueror\\/(\\d+(?:\\.\\d+(?:\\.\\d)?)?)");
        reKonq.test(sUserAgent);
        isMinKonq2_2 = compareVersions(RegExp["$1"], "2.2") >= 0;
        isMinKonq3 = compareVersions(RegExp["$1"], "3.0") >= 0;
        isMinKonq3_1 = compareVersions(RegExp["$1"], "3.1") >= 0;
        isMinKonq3_2 = compareVersions(RegExp["$1"], "3.2") >= 0;
    }

}

var isIE = sUserAgent.indexOf("compatible") > -1
           && sUserAgent.indexOf("MSIE") > -1
           && !isOpera;

var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6 = isMinIE7 = isMinIE8 = false;

if (isIE) {
    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    reIE.test(sUserAgent);
    var fIEVersion = parseFloat(RegExp["$1"]);

    isMinIE4 = fIEVersion >= 4;
    isMinIE5 = fIEVersion >= 5;
    isMinIE5_5 = fIEVersion >= 5.5;
    isMinIE6 = fIEVersion >= 6.0;
    isMinIE7 = fIEVersion >= 7.0;
    isMinIE8 = fIEVersion >= 8.0;        
}

var isMoz = sUserAgent.indexOf("Gecko") > -1
            && !isKHTML;

var isMinMoz1 = sMinMoz1_4 = isMinMoz1_5 = false;

if (isMoz) {
    var reMoz = new RegExp("rv:(\\d+\\.\\d+(?:\\.\\d+)?)");
    reMoz.test(sUserAgent);
    isMinMoz1 = compareVersions(RegExp["$1"], "1.0") >= 0;
    isMinMoz1_4 = compareVersions(RegExp["$1"], "1.4") >= 0;
    isMinMoz1_5 = compareVersions(RegExp["$1"], "1.5") >= 0;
}

var isNS4 = !isIE && !isOpera && !isMoz && !isKHTML
            && (sUserAgent.indexOf("Mozilla") == 0)
            && (navigator.appName == "Netscape")
            && (fAppVersion >= 4.0 && fAppVersion < 5.0);

var isMinNS4 = isMinNS4_5 = isMinNS4_7 = isMinNS4_8 = false;

if (isNS4) {
    isMinNS4 = true;
    isMinNS4_5 = fAppVersion >= 4.5;
    isMinNS4_7 = fAppVersion >= 4.7;
    isMinNS4_8 = fAppVersion >= 4.8;
}

var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC")
            || (navigator.platform == "Macintosh");

var isUnix = (navigator.platform == "X11") && !isWin && !isMac;

var isWin95 = isWin98 = isWinNT4 = isWin2K = isWinME = isWinXP = false;
var isMac68K = isMacPPC = false;
var isSunOS = isMinSunOS4 = isMinSunOS5 = isMinSunOS5_5 = false;

if (isWin) {
    isWin95 = sUserAgent.indexOf("Win95") > -1
              || sUserAgent.indexOf("Windows 95") > -1;
    isWin98 = sUserAgent.indexOf("Win98") > -1
              || sUserAgent.indexOf("Windows 98") > -1;
    isWinME = sUserAgent.indexOf("Win 9x 4.90") > -1
              || sUserAgent.indexOf("Windows ME") > -1;
    isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1
              || sUserAgent.indexOf("Windows 2000") > -1;
    isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1
              || sUserAgent.indexOf("Windows XP") > -1;
    isWinNT4 = sUserAgent.indexOf("WinNT") > -1
              || sUserAgent.indexOf("Windows NT") > -1
              || sUserAgent.indexOf("WinNT4.0") > -1
              || sUserAgent.indexOf("Windows NT 4.0") > -1
              && (!isWinME && !isWin2K && !isWinXP);
}

if (isMac) {
    isMac68K = sUserAgent.indexOf("Mac_68000") > -1
               || sUserAgent.indexOf("68K") > -1;
    isMacPPC = sUserAgent.indexOf("Mac_PowerPC") > -1
               || sUserAgent.indexOf("PPC") > -1;
}

if (isUnix) {
    isSunOS = sUserAgent.indexOf("SunOS") > -1;

    if (isSunOS) {
        var reSunOS = new RegExp("SunOS (\\d+\\.\\d+(?:\\.\\d+)?)");
        reSunOS.test(sUserAgent);
        isMinSunOS4 = compareVersions(RegExp["$1"], "4.0") >= 0;
        isMinSunOS5 = compareVersions(RegExp["$1"], "5.0") >= 0;
        isMinSunOS5_5 = compareVersions(RegExp["$1"], "5.5") >= 0;
    }
}

function toggleMoreLess(obj, num, txtMore, txtLess)
{
//        oMore = document.getElementById('more' + num);
        oMore = document.getElementById('fold' + num);
        oContent = document.getElementById('content' + num);

        /* if (txtMore.Length == 0) txtMore = 'more...'; */
        /* if (txtLess.Length == 0) txtLess = 'less...'; */

        if (oContent.style.display == 'none') {
                oContent.style.display = 'block';
                oMore.className = "moreless_top";
                obj.innerHTML = txtLess;

                oLess = document.createElement("P");
                oLess.id = "less" + num;
                oLess.className = "moreless_bottom";
                var txtMore2 = txtMore.replace(/&/g,'&amp;');
                var txtLess2 = txtLess.replace(/&/g,'&amp;');

                oLess.innerHTML = '<span style="cursor: pointer;" onclick="toggleMoreLess(this, \'' + num + '\', \'' + txtMore2 + '\', \'' + txtLess2 + '\'); return false;">' + txtLess + '<\/span>';

                after = oContent.nextSibling;
                oContent.parentNode.insertBefore(oLess, after);
        } else {
                oContent.style.display = 'none';
                oMore.className = "moreless_fold";
//                oMore.childNodes[0].innerHTML = txtMore;
                obj.innerHTML = txtMore;
                oLess = document.getElementById('less' + num);
                oContent.parentNode.removeChild(oLess);
        }
    }

    function toggleMoreLess2(obj, num, txtMore, txtLess) {
        //        oMore = document.getElementById('more' + num);
        oMore = document.getElementById('fold' + num);
        oContent = document.getElementById('content' + num);

        /* if (txtMore.Length == 0) txtMore = 'more...'; */
        /* if (txtLess.Length == 0) txtLess = 'less...'; */

        if (oContent.style.display == 'none') {
            oContent.style.display = 'block';
            oMore.className = "moreless_top2";
            obj.innerHTML = txtLess;

            oLess = document.createElement("P");
            oLess.id = "less" + num;
            oLess.className = "moreless_bottom";
            var txtMore2 = txtMore.replace(/&/g, '&amp;');
            var txtLess2 = txtLess.replace(/&/g, '&amp;');

            oLess.innerHTML = '<span style="cursor: pointer;" onclick="toggleMoreLess2(this, \'' + num + '\', \'' + txtMore2 + '\', \'' + txtLess2 + '\'); return false;">' + txtLess + '<\/span>';

            after = oContent.nextSibling;
            oContent.parentNode.insertBefore(oLess, after);

            
        } else {
            oContent.style.display = 'none';
            oMore.className = "moreless_fold2";
            //                oMore.childNodes[0].innerHTML = txtMore;
            obj.innerHTML = txtMore;
            oLess = document.getElementById('less' + num);
            oContent.parentNode.removeChild(oLess);
        }
    }

/*
' ------------------------------------------------------------------
' Function    : fc_chk_byte(aro_name)
' Description : ÀÔ·ÂÇÑ ±ÛÀÚ¼ö¸¦ Ã¼Å©
' Argument    : Object Name(±ÛÀÚ¼ö¸¦ Á¦ÇÑÇÒ ÄÁÆ®·Ñ)
' Usage       : onkeyup="fc_chk_byte(this,10);"
' ------------------------------------------------------------------
*/
function fc_chk_byte(aro_name,ari_max)
{

   var ls_str     = aro_name.value; // ÀÌº¥Æ®°¡ ÀÏ¾î³­ ÄÁÆ®·ÑÀÇ value °ª
   var li_str_len = ls_str.length;  // ÀüÃ¼±æÀÌ

   // º¯¼öÃÊ±âÈ­
   var li_max      = ari_max; // Á¦ÇÑÇÒ ±ÛÀÚ¼ö Å©±â
   var i           = 0;  // for¹®¿¡ »ç¿ë
   var li_byte     = 0;  // ÇÑ±ÛÀÏ°æ¿ì´Â 2 ±×¹Ü¿¡´Â 1À» ´õÇÔ
   var li_len      = 0;  // substringÇÏ±â À§ÇØ¼­ »ç¿ë
   var ls_one_char = ""; // ÇÑ±ÛÀÚ¾¿ °Ë»çÇÑ´Ù
   var ls_str2     = ""; // ±ÛÀÚ¼ö¸¦ ÃÊ°úÇÏ¸é Á¦ÇÑÇÒ¼ö ±ÛÀÚÀü±îÁö¸¸ º¸¿©ÁØ´Ù.

   for(i=0; i< li_str_len; i++)
   {
      // ÇÑ±ÛÀÚÃßÃâ
      ls_one_char = ls_str.charAt(i);

      // ÇÑ±ÛÀÌ¸é 2¸¦ ´õÇÑ´Ù.
      if (escape(ls_one_char).length > 4)
      {
         li_byte += 2;
      }
      // ±×¹ÜÀÇ °æ¿ì´Â 1À» ´õÇÑ´Ù.
      else
      {
         li_byte++;
      }

      // ÀüÃ¼ Å©±â°¡ li_max¸¦ ³ÑÁö¾ÊÀ¸¸é
      if(li_byte <= li_max)
      {
         li_len = i + 1;
      }
   }
   
   // ÀüÃ¼±æÀÌ¸¦ ÃÊ°úÇÏ¸é
   if(li_byte > li_max)
   {
      alert("Limitation Error(max:"+li_max+" letters)");
      ls_str2 = ls_str.substr(0, li_len);
      aro_name.value = ls_str2;
      
   }
   aro_name.focus();   
}

/*
' ------------------------------------------------------------------
' Function    : fc_chk2()
' Description : EnterÅ°¸¦ ¸øÄ¡°ÔÇÑ´Ù.
' Argument    : 
' Usage       : onkeypress="fc_chk2()"
' ------------------------------------------------------------------
*/
function fc_chk2()
{
   if(event.keyCode == 13)
      event.returnValue=false;
}

function getParameter(qs) {
          var value = '';
          var address = unescape(location.href);
          var param= (address.slice(address .indexOf('?') + 1, address .length)).split('&'); 
          for (var i = 0; i < param.length; i++) {
              var name = param[i].split('=')[0];
              if (name.toUpperCase() == qs.toUpperCase()) {
                  value = param[i].split('=')[1];
                  break;
              }
          }
          return value ;
}


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 "";
}
