/******************************************************************************************

1. ¼³¸í: FCKeditor ³»¿ë ÀÔ·Â Ã¼Å©

******************************************************************************************/
function chk_editor()
{
    var s = content___Frame.document.eEditorArea.document.body.innerText;
    if(isNull(s)){
        alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä.");
        content___Frame.focus();
        return false;
    }
    else{
        return true;
    }
}


/******************************************************************************************

1. ¼³¸í: ¿øº» ÀÌ¹ÌÁö º¸±â

******************************************************************************************/
function viewOriginIMG(img_url)
{
    Popup('/module/Article/Article_Sub/view_image.php?img_url='+img_url,400,300,1);
}



/******************************************************************************************

1. ¼³¸í: ¼ýÀÚÀÎÁö Ã¼Å©

******************************************************************************************/
function isNumeric(s)
{
  for(i=0; i<s.length; i++)
  {
    c = s.substr(i, 1);

    if(c < "0" || c > "9")
      return false;
   }
   return true;
}


/******************************************************************************************

1. ¼³¸í: ÀÔ·Â ±ÛÀÚ¼ö(±æÀÌ)

******************************************************************************************/
function checklen(obj1,obj2)
{
    var msgtext

    msgtext = eval(obj1).value

    /*
    var i=0,l=0
    var temp

    //±æÀÌ¸¦ ±¸ÇÑ´Ù.
    while(i < msgtext.length)
    {
        temp = msgtext.charAt(i)

        if (escape(temp).length > 4)
            l+=2
        else if (temp!='\r')
            l++

        i++
    }
    */

    l = msgtext.length

    eval(obj2).value=l
}


function checklen_innerHTML(obj1,obj2)
{
    var msgtext

    msgtext = eval(obj1).value

    l = msgtext.length

    eval(obj2).innerHTML=l
}

/******************************************************************************************
1. ¼³¸í: ÆË¾÷
2. »ç¿ë¿¹:

    ex)

        ±âº» = <a href="javascript:Popup('/index.php',400,300)
        scroll = <a href="javascript:Popup('/index.php',400,300,1)
        resizable = <a href="javascript:Popup('/index.php',400,300,0,1)
        scroll,resizable = <a href="javascript:Popup('/index.php',400,300,1,1)
******************************************************************************************/
function Popup(url,width,height,scroll,resizable)
{
    /*
    var pname = url.split('?')

    if(pname[1])
        var pop_name = pname[1].substring(0,-4)
    else
        var pop_name = 'popup'
    */

    var pop_name = url
    pop_name = pop_name.replace('\/','')
    pop_name = pop_name.replace('.','')
    var pop_name = pop_name.substring(0,4)

    var optsrt;

    if( !scroll )       scroll= 0;

    if( !resizable )    resizable= 0;

    optstr="height="+height+",width="+width+",location=0,menubar=0,resizable="+resizable+",scrollbars="+scroll+",status=0,titlebar=0,toolbar=0,screeny=0,left=0,top=0";
    window.open(url, pop_name, optstr);

}


/******************************************************************************************
*
* Å×ÀÌºí ¼û±â±â/º¸¿©ÁÖ±â
* ·¹ÀÌ¾î ¼û±â±â/º¸¿©ÁÖ±â
*
******************************************************************************************/
function display_table(id){
    var style = document.getElementById(id).style;
    style.display = (style.display=="none"?"block":"none");
}
function display_layer(layer){
    var style = document.getElementById(layer).style;
    style.visibility = (style.visibility=="hidden"?"visible":"hidden");
}

/******************************************************************************************
*
* ³¯Â¥ °è»êÇÏ±â
*
******************************************************************************************/
function dayCalc(d1,d2){
    var date1 = new Date(d1);
    var newdate = new Date();
    var newtime = date1.getTime() + (d2*24*60*60*1000);

    newdate.setTime(newtime);

    var date = newdate.getDate();
    var month = newdate.getMonth()+1;
    var year = newdate.getFullYear()

    if(month<10){
        month = "0" + month;
    }
    if(date<10){
        date = "0" + date;
    }
    return year + "-" + month + "-" + date;
}

/******************************************************************************************
*
* ¹®ÀÚ¿­ °ø¹é ÀÚ¸£±â
*
******************************************************************************************/
function Trim(str)
{
    var count = str.length, len = count, st = 0
    while ((st < len) && (str.charAt(st) <= ' ')) st++
    while ((st < len) && (str.charAt(len - 1) <= ' ')) len--

    return ((st > 0) || (len < count)) ? str.substring(st, len) : str
}

/******************************************************************************************

1. ¼³¸í: form³»¿¡ <select>°¡ ÀÖ°Å³ª, <select>¿¡ °³º°Àû ID¸¦ ºÎ¿©ÇÑ °æ¿ì <option>ÀÌ ÀÚµ¿À¸·Î ¼±ÅÃµÇ°Ô
2. »ç¿ë¿¹:

    ex 1)
        <form name=aa>
            <select name=bb>
                <option value=1>1</option>
                <option value=1>2</option>
            </select>
        </form>
        <script>
            select_option( document.aa.bb, '1')
        </script>

    ex2)
        <select ID=bb>
            <option value=1>1</option>
            <option value=1>2</option>
        </select>
        <script>
            select_option( document.getElementById('bb'), '1')
        </script>

******************************************************************************************/
function select_option(el, value){
    for(i = 0; i < el.options.length; i++){
        if(el.options[i].value == value){
            el.options[i].selected = true;
            break;
        }
    }
}

/******************************************************************************************
1. ¼³¸í: ¸ñ·ÏÀÇ Ç×¸ñµé¿¡ ´ëÇØ ÀüÃ¼ÀûÀÎ ¼±ÅÃ, ¹ÝÀüÀ» ÇØ¾ßÇÒ °æ¿ì
2. »ç¿ë¿¹:

    ex)
        <form name=aa>
            <input type=button value=' toggle '  onClick="toggle(document.aa.elements['id[]'])">
            <input type=checkbox  value='1' name='id[]'>
            <input type=checkbox  value='2' name='id[]'>
            <input type=checkbox  value='3' name='id[]'>
        </form>

******************************************************************************************/
function toggle(element)
{
    if( element)
    {
        if(element.length)
        {
            for(var i=0; i< element.length; i++)
                swap_checkbox(element[i])
        }
        else
            swap_checkbox(element)
    }
    else
        alert("¼±ÅÃÇÒ Ç×¸ñÀÌ ¾ø½À´Ï´Ù")
}

function swap_checkbox(element)
{
    if( !element.disabled)
        element.checked= ! element.checked
}

/******************************************************************************************
1. ¼³¸í: <select>ÀÇ <option>Áß ¼±ÅÃµÈ °ÍÀÌ ÇÏ³ª¶óµµ ÀÖ´Â°¡
2. »ç¿ë¿¹:

    <form name=aa>
        <select name=bb>
            <option value=1>1</option>
            <option value=2>2</option>
        </select>
    </form>

    <script>
    if( selected_option( document.aa.bb))
        alert('¼±ÅÃµÇ¾ú½À´Ï´Ù')
    </script>

******************************************************************************************/
function selected_option(el)
{
    for(var i=1; i<el.length; i++)
        if(el[i].selected)
            break

    if( i== el.length )
        return false
    else
        return true
}


/******************************************************************************************
1. ¼³¸í: <input type=radio or type=checkbox>°¡ ÇÏ³ª¶óµµ ¼±ÅÃÀÌ µÇ¾î ÀÖ´Â°¡
2. »ç¿ë¿¹:

    <form name=aa>
        <input type=radio name=bb value=1>
        <input type=radio name=bb value=2>
        <input type=radio name=bb value=3>
    </form>

    <script>
    if( checked_box( document.aa.bb))
        alert('¼±ÅÃµÇ¾ú½À´Ï´Ù.')
    </script>

******************************************************************************************/
function checked_box(el)
{
    re= false
    if( el)
    {
        if( el.length)
        {
            for(var i=0; i< el.length; i++)
                if(el[i].checked)
                {
                    re= true
                    break
                }
        }
        else
            re= el.checked
    }
    else
        re= false

    return re
}


/******************************************************************************************
1. ¼³¸í: Ã¼Å©ÇÑ value°¡ ¹«¾ùÀÎ°¡?
2. »ç¿ë¿¹:

    <form name=aa>
        <input type=radio name=bb value=1>
        <input type=radio name=bb value=2>
        <input type=radio name=bb value=3>
    </form>

    <script>
        checked_value( document.aa.elements['bb'])
    </script>

******************************************************************************************/
function checked_value(el)
{
    re = 0
    if( el){
        if( el.length)  {
            for(var i=0; i< el.length; i++){
                if(el[i].checked) {
                    re= i+1
                    break
                }
            }
        }
    }
    return re
}
function checked_value2(el)
{
    re = 0
    if(el){

        if(el.length){
            if(el.length > 1){
                for(var i=0; i< el.length; i++){
                    if(el[i].checked) {
                        re= el[i].value;
                        break
                    }
                }
            }
        }else{
            re= el.value;
        }
    }

    return re
}
/******************************************************************************************
1. ¼³¸í: checkbox¸¦ ÀÚµ¿À¸·Î Ã¼Å©ÇÏ°í ½ÍÀº °æ¿ì( µ¥ÀÌÅ¸¼öÁ¤½Ã) ÀÚµ¿À¸·Î Ã¼Å©µÇ°Ô ÇÑ´Ù.
2. »ç¿ë¿¹:

    <form name=aa>
        <input type=checkbox name=correct_answer[] value=1>
        <input type=checkbox name=correct_answer[] value=2>
        <input type=checkbox name=correct_answer[] value=3>
    </form>

    <script>
    var correct= new Array()
    correct= [1,2,]
    for(var i in correct)
        check_box( document.aa.elements['correct_answer[]'], correct[i])
    </script>

******************************************************************************************/
function check_box(el, value)
{

    if(el)
    {
        if(el.length)
        {
            for(var i=0; i< el.length; i++)
            {
                if(el[i].value==value)
                {
                    el[i].checked= true
                    break
                }
            }
        }
        else
        {
            if(el.value==value)
                el.checked= true
        }
    }
}

/******************************************************************************************
1. ¼³¸í: <textarea>¿¡¼­ ±Û ¼ö°¡ ÁöÁ¤ÇÑ ¹ÙÀÌÆ®¼ö¸¦ ÃÊ°úÇÏÁö ¾Ê°Ô ÁöÁ¤
2. »ç¿ë¿¹:
    <form name=aa>
        <textarea name=bb></textarea>
    </form>
    <script>
    if( check_over_flow(document.aa.bb, 2000))
        alert('2000 ¹ÙÀÌÆ® ¹Ì¸¸ÀÔ´Ï´Ù.')
    </script>

******************************************************************************************/

function check_over_flow(el,check_byte_num){
    var str = el.value;
    var str_byte = 0;
    for(i = 0; i<str.length; i++){
        var code = str.charCodeAt(i);
        var ch = str.substr(i,1).toUpperCase();
        code = parseInt(code);
        if((ch<"0"||ch>"9") && (ch<"A"||ch>"Z") && ((code>255)||code<0)){
            str_byte = str_byte + 2;
        }else{
            str_byte = str_byte + 1;
        }
    }
    //alert(str_byte);
    if(str_byte > check_byte_num){
        //el.value = str.substr(0,Math.ceil(check_byte_num/2));
        el.focus()
        alert((check_byte_num/2)+'ÀÚ ÀÌ³»·Î ÀÔ·ÂÇÏ¼¼¿ä.')
        return false;
    }else{
        return true;
    }
}

/******************************************************************************************
1. ¼³¸í: Form ³»ÀÇ  text,textarea, password ¿ä¼Ò Áß¿¡ ºó °ªÀÌ ÀÖÀ» °æ¿ì
2. »ç¿ë¿¹:

function check()
{
    f= document.BBS
    // ÃÖ¼ÒÇÑ  bbs_id, bbs_name, bbs_comment ¼¼ °³ÀÇ Æû¿ä¼Ò °ªÀº Ã¤¿öÁ® ÀÖ¾î¾ß ÇÑ´Ù
    return blank_check( f.bbs_id) && blank_check( f.bbs_name) && blank_check( f.bbs_comment)
}

******************************************************************************************/
function blank_check(el)
{
    if (el.type == null || el.type == undefined)
    {
        return false;
    }
    if( el.type=='text' || el.type=='textarea' || el.type=='password')
        if( Trim(el.value).length < 1)
            return false;

    return true
}


/******************************************************************************************
1. ¼³¸í: °æ°í ÈÄ Æ÷Ä¿½º ¿Å±â±â
******************************************************************************************/
function warning(el, msg)
{
    el.focus()
    alert(msg)
    return false
}

/******************************************************************************************
 1.¼³¸í: Æ¯Á¤ÇÑ ÆÄÀÏ È®ÀåÀÚ¸¸ ¹Þ¾ÆµéÀÌ°í ½ÍÀº °æ¿ì

  2. »ç¿ë¿¹:

        target='11.hwp'
        arr= new Array( 'hwp','doc')
        // arr= 'hwp' È®ÀåÀÚ°¡ ÇÏ³ªÀÏ°æ¿ì ¹®ÀÚ¿­·Î °ªÀ» ³Ñ°Üµµ µÈ´Ù.
        if( proper_file(target, arr))
            alert('È®ÀåÀÚ°¡ ÀÏÄ¡ÇÕ´Ï´Ù.')

******************************************************************************************/
function proper_file(target, arr)
{
    var exts=''

    if( target=='')
        return false

    if( typeof arr == 'string')
        exts= arr
    else
        var exts= '(' + arr.join('|') + ')'

    var pattern= new RegExp(exts)
    return target.match(pattern)
}

/******************************************************************************************
*
* Files Å×ÀÌºíÀ» ÅëÇØ ¾÷·ÎµåµÈ ÆÄÀÏµéÀ» »èÁ¦ÇÒ ¶§ °øÅëÀ¸·Î »ç¿ëÇÏ´Â ÇÔ¼ö
*
******************************************************************************************/
function upfile_delete(file_code)
{
    if( confirm('ÆÄÀÏÀ» »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?'))
        location.href= "/lib/Upload/filedelete.php?file_code="+file_code
}

/******************************************************************************************
1. ¼³¸í: ÀÌ¸ÞÀÏÀÌ Çü½Ä¿¡ ¸Â´Â°¡

2.»ç¿ë¿¹:
    <form name=aa>
        <input type=text name=email>
    </form>

    <script>
    if( !isEMailAddr(document.aa.email.value))
        return warning(document.aa.email, 'ÀÌ¸ÞÀÏÀÌ Çü½Ä¿¡ ¸ÂÁö ¾ÊÀÝ¾Æ')
    </script>

******************************************************************************************/
function isEMailAddr(email)
{
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/
//  var no_mail = /@hanmail.net|@daum.net/i
    return email.match(re)
}

/******************************************************************************************
1. ¼³¸í: ÁÖ¹Îµî·Ï¹øÈ£°¡ Çü½Ä¿¡ ¸Â´Â°¡

2.»ç¿ë¿¹:
    <form name=aa>
        <input type=text name=jumin1>
        <input type=text name=jumin2>
    </form>

    <script>
    if( !isValidSSN(document.aa.jumin1.value, document.aa.jumin2,value))
        return warning(document.aa.jumin1, 'ÁÖ¹Î¹øÈ£°¡ Çü½Ä¿¡ ¸ÂÁö ¾ÊÀÝ¾Æ')
    </script>

******************************************************************************************/
function isValidSSN( ssn1, ssn2)
{
    var sum=0;

    if( isNaN(ssn1) || isNaN(ssn2))
        return false


    if( ssn1.length<6 || ssn2.length<7)
        return false

    // 1~6 ÀÚ¸®´Â °¢ÀÚ¸®¿¡ 2¾¿ ´õÇØ¼­ ´©Àû
    for(var i=0;i<ssn1.length;i++)
        sum += (i+2) * ssn1.charAt(i);

    // 7,8 ÀÚ¸®´Â ÀÚ¸®¿¡ 8À» ´õÇØ ´©Àû
    for(i=0;i<2;i++)
        sum = sum + (i+8) * ssn2.charAt(i);

    // 9~12 ÀÚ¸®´Â ÀÚ½ÅÀ» °öÇÑ´Ù.
    for(i=2;i<6;i++)
        sum += i * ssn2.charAt(i);

    // º¯¼öÇÏ³ª¸¦ ÇÒ´çÇÑ ÈÄ ´©Àû°ªÀ» 11·Î ³ª´©¾î ³ª¸ÓÁö°¡ 0ÀÌ¸é ±× º¯¼ö¿¡ 10, 1ÀÌ¸é 11, ³ª¸ÓÁø ³ª¸ÓÁö°ªÀ» ±×³É ÇÒ´çÇÑ´Ù.  ³ª¸ÓÁö ±¸ÇÏ±â
    var checkSum = 0;
    var checkCode = 0;

    checkSum = sum % 11;
    if(checkSum == 0)
        checkCode = 10;
    else if(checkSum == 1)
        checkCode = 11;
    else
        checkCode = checkSum;

    // 11¿¡¼­ À§°ªÀ» »« °ªÀ» ±¸ÇÏ°í ÀÌ°ª°í ÁÖ¹Î¹øÈ£ ¸¶Áö¸· °ª°ú ºñ±³ÇÑ´Ù.. Æ²¸®¸é ÁÖ¹Î¹øÈ£ ¿À·ù..
    var check1 = parseInt(11 - checkCode);
    var check2 = parseInt(ssn2.charAt(6)) ;

    return check1 == check2
}


// ¿Ü±¹ÀÎ ÁÖ¹Î¹øÈ£ Ã¼Å©
function isValidSSN_fr( ssn1, ssn2)
{    
    var sum = 0;
    var odd = 0;
     var fgn_no = ssn1+ssn2 ;
                         
    buf = new Array(13);
    for (i = 0; i < 13; i++) buf[i] = parseInt(fgn_no.charAt(i));
    //for (i = 6; i < 13; i++) buf[i] = parseInt(ssn2.charAt(i));


    odd = buf[7]*10 + buf[8];
    
    if (odd%2 != 0) {
      return false;
    }

    if ((buf[11] != 6)&&(buf[11] != 7)&&(buf[11] != 8)&&(buf[11] != 9)) {
      return false;
    }
    	
    multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
    for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);


    sum=11-(sum%11);
    
    if (sum>=10) sum-=10;

    sum += 2;

    if (sum>=10) sum-=10;

    if ( sum != buf[12]) {
        return false;
    }
    else {
        return true;
    }	

}


/******************************************************************************************

1. ¼³¸í: Null ÀÎ°¡?

******************************************************************************************/
function isNull( s )
{
    if( s == null ) return true;

    var result = s.replace(/(^\s*)|(\s*$)/g, "");

    if( result )
        return false;
    else
        return true;
}


/******************************************************************************************
1. ¼³¸í: ÅëÈ­ ¸¸µé±â

2.»ç¿ë¿¹:
    setComma(100000) => 100,000

******************************************************************************************/
function setComma(str)
{
    str = ""+str+"";
    var retValue = "";
    for(i=0; i<str.length; i++)
    {
        if(i > 0 && (i%3)==0)
            retValue = str.charAt(str.length - i -1) + "," + retValue;
        else
            retValue = str.charAt(str.length - i -1) + retValue;
    }
    return retValue
}


/******************************************************************************************
1. ¼³¸í: ¾ÆÀÌÇÁ·¹ÀÓ ³ôÀÌ ÀÚµ¿ Á¶Àý

2.»ç¿ë¿¹:


******************************************************************************************/
function calcHeight(frm_name)
{
    //find the height of the internal page
    var the_height= document.getElementById(frm_name).contentWindow.document.body.scrollHeight;

    //change the height of the iframe
    document.getElementById(frm_name).height=the_height;
}


/******************************************************************************************
1. ¼³¸í: °Ë»ö¹Ù¿¡¼­ ³¯Â¥ ¼¼ÆÃ

2.»ç¿ë¿¹: ´çÀÏ,1ÁÖÀÏ,15ÀÏ µî ¹öÆ°À» ´©¸£¸é ½ÃÀÛÀÏ°ú Á¾·áÀÏ¿¡ ³¯Â¥¸¦ ÀÚµ¿ ¼¼ÆÃÇÑ´Ù.


******************************************************************************************/
function Set_SearchDate(fname,el1,el2,mode)
{
    f = eval("document."+fname)

    var today = new Date()
    ty = today.getFullYear()
    tm = today.getMonth()+1
    td = today.getDate()

    switch (mode)
    {
        case '1':
            var dt = dayCalc(today,0)
            break;
        case '3':
            var dt = dayCalc(today,-3)
            break;
        case '7':
            var dt = dayCalc(today,-7)
            break;
        case '15':
            var dt = dayCalc(today,-15)
            break;
        case '30':
            var dt = dayCalc(today,-30)
            break;
    }

    if(tm<10)   tm='0'+tm
    if(td<10)   td='0'+td

    eval('f.'+el1).value = dt
    eval('f.'+el2).value = ty + '-' + tm + '-' + td
}



/******************************************************************************************

 1.¼³¸í: Max °³¼ö ÀÌ»ó Ã¼Å© ¸øÇÏ°Ô ÇÏ±â

******************************************************************************************/
function MaxClick(str, limit)
{
    var el = document.RESEARCH.elements[str]
    var chkcnt = 0

    for(var i=0; i< el.length; i++)
    {
        if(el[i].checked)   {
            chkcnt++
            if(chkcnt > limit)
            {
                alert(limit+'±îÁö¸¸ ¼±ÅÃ°¡´ÉÇÕ´Ï´Ù.')
                el[i].checked=false
                break;
            }
        }
    }
}



/******************************************************************************************

 1.¼³¸í: ´ÙÀ½ ¹®Ç× È°¼ºÈ­ / ºñÈ°¼ºÈ­ ½ÃÅ°±â

******************************************************************************************/
function EnableNext(str, val)
{
    var el = document.RESEARCH.elements[str]

    if(val == 'enable')
    {
        el.disabled = false
        el.style.backgroundColor = '#ffffff'
    }
    else{
        el.disabled = true
        el.style.backgroundColor = '#cccccc'
    }
}
function EnableNextAll(str, val)
{
    var el = document.RESEARCH.elements[str]

    if(val == 'enable'){
        for(var i=0;i<el.length;i++)
            el[i].disabled = false
    }else{
        for(var i=0;i<el.length;i++)
            el[i].disabled = true
    }
}

/******************************************************************************************

 1.¼³¸í: Target È°¼ºÈ­ / ºñÈ°¼ºÈ­ ½ÃÅ°±â

******************************************************************************************/
function DisableTarget(str)
{
    var el = document.RESEARCH.elements[str]

    el.disabled = true
    el.style.backgroundColor = '#cccccc'
}
function EnableTarget(str)
{
    var el = document.RESEARCH.elements[str]

    el.disabled = false
    el.style.backgroundColor = '#ffffff'
}



/******************************************************************************************

 1.¼³¸í: È°¼ºÈ­ / ºñÈ°¼ºÈ­ ½ÃÅ°±â

******************************************************************************************/
function swapEnable(str)
{
    var el = document.RESEARCH.elements[str]

    if(el.disabled == false){
        el.disabled = true
        el.style.backgroundColor = '#cccccc'
    }else{
        el.disabled = false
        el.style.backgroundColor = '#ffffff'
    }
}



/******************************************************************************************
*
* indexOf function added to Array using prototype by Kim
*
******************************************************************************************/
Array.prototype.indexOf= function (value){
    var idx=-1;
    for(var i=0; i< this.length; i++)
        if( this[i] == value)
        {
            idx= i
            break
        }

    return idx
}

String.prototype.just= function(direction, space, value){
    if( typeof space == 'undefined' || typeof space != 'number')
        return -1
    if( typeof value == 'undefined' || typeof value != 'string')
        value = 0

    var how_many= space - this.length
    var ext= ''
    for(var i=0; i< how_many; i++)
        ext+= value
    return direction ?  this+ext : ext+this
}

String.prototype.ljust= function(space, value){
    return this.just(false, space, value)
}

String.prototype.rjust= function(space, value){

    return this.just(true, space, value)
}

String.prototype.setComma= function(){
    str = ""+this+"";
    var retValue = "";
    for(i=0; i<str.length; i++)
    {
        if(i > 0 && (i%3)==0)
            retValue = str.charAt(str.length - i -1) + "," + retValue;
        else
            retValue = str.charAt(str.length - i -1) + retValue;
    }
    return retValue
}

String.prototype.ChangeToTime = function(mode)
{
    if(mode == 'hms')
    {
        var acc_hour = parseInt( parseInt(this,10)/3600,10);
        var acc_hour_mod = parseInt(this,10)%3600;
        var acc_min = parseInt(acc_hour_mod/60,10);
        var acc_sec = parseInt(this,10)%60;

        var change_to_time = acc_hour.toString().ljust(2,'0') + ":" + acc_min.toString().ljust(2,'0') + ":" + acc_sec.toString().ljust(2,'0')

    }else if(mode == 'sec')
    {
        var r_diff_hour = parseInt(this.substr(0,2),10)
        var r_diff_min = parseInt(this.substr(3,2),10)
        var r_diff_sec = parseInt(this.substr(6,2),10)

        var change_to_time = r_diff_hour*3600+r_diff_min*60+r_diff_sec

    }
    return change_to_time
}
/******************************************************************************************

 1.¼³¸í: ÆË¾÷Ã¢ Å¬¸¯ÇßÀ»¶§ ¿øÇÏ´Â ÆäÀÌÁö ÀÌµ¿

******************************************************************************************/
function gogoPage(url,depth)
{

    if (depth == '2')
    {
            parent.opener.location.href=url;
    }else{
            parent.parent.opener.location.href=url;
    }
}

/******************************************************************************************

 ¼ýÀÚ¸¦ ÀÔ·ÂÇß´ÂÁö Ã¼Å©
* onKeyPress="isNum()"
******************************************************************************************/
function isNum(){

    if(((event.keyCode<48) || (event.keyCode>57)) && (event.keyCode != 46)) {
        event.returnValue=false;
        return false;
    }
    return true;

}

/******************************************************************************************

Å×ÀÌºí ¸ð¼­¸®¸¦ µÕ±Û°Ô!

»ç¿ë¿¹ ) Å×ÀÌºí ÅÂ±×¿¡ ´ÙÀ½°ú °°ÀÌ »ðÀÔÇÑ´Ù.
<table width="90" height='10'
  rbgcolor="white" border="0" cellpadding="0" cellspacing="0"
  id="ta1" radius="2" rborder="white">
******************************************************************************************/
function roundTable(objID) {
   var obj = document.getElementById(objID);
   var Parent, objTmp, Table, TBody, TR, TD;
   var bdcolor, bgcolor, Space;
   var trIDX, tdIDX, MAX;
   var styleWidth, styleHeight;

   Parent = obj.parentNode;
   objTmp = document.createElement('SPAN');
   Parent.insertBefore(objTmp, obj);
   Parent.removeChild(obj);

   bdcolor = obj.getAttribute('rborder');
   bgcolor = obj.getAttribute('rbgcolor');
   radius = parseInt(obj.getAttribute('radius'));
   if (radius == null || radius < 1) radius = 1;
   else if (radius > 6) radius = 6;

   MAX = radius * 2 + 1;

   Table = document.createElement('TABLE');
   TBody = document.createElement('TBODY');

   Table.cellSpacing = 0;
   Table.cellPadding = 0;

   for (trIDX=0; trIDX < MAX; trIDX++) {
          TR = document.createElement('TR');
          Space = Math.abs(trIDX - parseInt(radius));
          for (tdIDX=0; tdIDX < MAX; tdIDX++) {
                 TD = document.createElement('TD');

                 styleWidth = '1px'; styleHeight = '1px';
                 if (tdIDX == 0 || tdIDX == MAX - 1) styleHeight = null;
                 else if (trIDX == 0 || trIDX == MAX - 1) styleWidth = null;
                 else if (radius > 2) {
                        if (Math.abs(tdIDX - radius) == 1) styleWidth = '2px';
                        if (Math.abs(trIDX - radius) == 1) styleHeight = '2px';
                 }

                 if (styleWidth != null) TD.style.width = styleWidth;
                 if (styleHeight != null) TD.style.height = styleHeight;

                 if (Space == tdIDX || Space == MAX - tdIDX - 1) TD.style.backgroundColor = bdcolor;
                 else if (tdIDX > Space && Space < MAX - tdIDX - 1)  TD.style.backgroundColor = bgcolor;

                 if (Space == 0 && tdIDX == radius) TD.appendChild(obj);
                 TR.appendChild(TD);
          }
          TBody.appendChild(TR);
   }
   Table.appendChild(TBody);
   Parent.insertBefore(Table, objTmp);
}


/******************************************************************************************

¿¡µðÅÍ »ý¼ºÇÏ±â

»ç¿ë¿¹)
        <script>Namoeditor_create(10,'intention','lec_rg',400);</script>
         10: Object id
         intention:ÇÊµåÀÌ¸§
         lec_rg:ÆûÀÌ¸§
         400: ¿¡µðÅÍ ±æÀÌ
******************************************************************************************/

function Namoeditor_create(id_num,ob_nm,form_nm,height){

    if (!height)
    {
        var height = 250;
    }
    if (id_num == 1)
    {
        var cont = '<OBJECT WIDTH=0 HEIGHT=0 CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">'
        +'<PARAM NAME="LPKPath" VALUE="/lib/NamoWec6_Trial/NamoWec6_Trial.lpk">'
        +'</OBJECT>'
        +'<OBJECT ID="Wec" WIDTH="100%" HEIGHT="'+height+'" '
        +'CLASSID="CLSID:F1F33E02-DD6B-4a7c-9C29-D02A95500CB0" CODEBASE="/lib/NamoWec6_Trial/NamoWec.cab#version=6,0,0,49">'
        +'<param name="UseNamoNet" value="0">'
        +'<param name="InitFileURL" value="/lib/NamoWec6_Trial/kor/namowec.env">'
        +'<param name="InstallSourceURL" value="http://www.namo.co.kr/activesquare/products/update">'
        +'</OBJECT>'
        +'<SCRIPT language="javascript" FOR="Wec" EVENT="OnInitCompleted()">'
        +'document.Wec.value = document.'+form_nm+'.'+ob_nm+'.value;'
        +'</SCRIPT>';

    }else{
        var cont ='<OBJECT WIDTH=0 HEIGHT=0 CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">'
        +'<PARAM NAME="LPKPath" VALUE="/lib/NamoWec6_Trial/NamoWec6_Trial.lpk">'
        +'</OBJECT>'
        +'<OBJECT ID="Wec'+id_num+'" WIDTH="100%" HEIGHT="'+height+'" '
        +'CLASSID="CLSID:F1F33E02-DD6B-4a7c-9C29-D02A95500CB0" CODEBASE="/lib/NamoWec6_Trial/NamoWec.cab#version=6,0,0,49">'
        +'</OBJECT>'
        +'<SCRIPT language="javascript" FOR="Wec'+id_num+'" EVENT="OnInitCompleted()">'
        +'document.Wec'+id_num+'.value = document.'+form_nm+'.'+ob_nm+'.value;'
        +'</SCRIPT>';
    }
    document.write(cont);
}



/******************************************************************************************
*
*³×ÀÌ¹ö »çÀü
*: µå·¡±×ÇÑ ¿µ¿µ/¿µÇÑ ´Ü¾î¸¦ ³×ÀÌ¹ö »çÀüÀ» ÀÌ¿ëÇÏ¿© Ã£¾Æº¼¼ö ÀÖ´Â ±â´É
*
******************************************************************************************/
function Search_Dic(mode)
{
    // »ç¿ëÀÚ°¡ ¼±ÅÃÇÑ ÅØ½ºÆ®¸¦ ¾Ë¾Æ³»±â À§ÇØ ³Ý½ºÄÉÀÌÇÁ´Â getSelection()À» Áö¿øÇÏ°í, ÀÎÅÍ³Ý ÀÍ½ºÇÃ·Î·¯´Â selection °´Ã¼ÀÇ createRange()¸¦ ÀÌ¿ëÇÑ´Ù
    R=(document.getSelection)?document.getSelection():document.selection.createRange();
    T=(document.getSelection)?R:R.text;
    if(T=='')
        T=prompt('Ã£°í ½ÍÀº ´Ü¾î¸¦ ÀÔ·ÂÇÏ¼¼¿ä!','');
    if(T&&T!='')
    {
            switch (mode)
            {
                case 'eng' :
                    window.open('http://dic.naver.com/endic?query='+T, 'selectedText');
                    break;
                case 'hanja':
                    window.open('http://hanja.naver.com/search.naver?dic_where=hanja&query='+T, 'selectedText');
                    break;
                case 'kr':
                    window.open('http://krdic.naver.com/search.nhn?dic_where=krdic&kind=all&query='+encodeURI(T), 'selectedText');
                    break;
            }
    }
}



/******************************************************************************************

Clipboard Copy Alert

******************************************************************************************/
var  clipboard_yes = "0";
function contents_cp()
{
    if (window.event && clipboard_yes=="0")
    {
		clipboard_yes = "1";
        window.event.returnValue = true;
        window.setTimeout('attach_kinref()', 10);
    }
}
function attach_kinref()
{
    if (window.clipboardData) // IE
    {
        // get data from clipboard
		var txt = "";
        txt = window.clipboardData.getData('Text');

        // attach the source at the end of text
        txt = txt + "\r\n\r\nÃâÃ³ : µ¿¾ÆºñÁî´Ï½º¸®ºä(www.dongabiz.com)\r\n\r\n";

        // set data to clibboard
        var result = window.clipboardData.setData('Text', txt);

		clipboard_yes = "0";
    }
}

function clean_clipboard()
{

	window.clipboardData.setData('Text','');
}



/******************************************************************************************
*
* ¸ÂÃã¹ý °Ë»ç±â 2007-03-05 Á¶ÀÎ¿µ Ãß°¡
*
* ¹öÆ°¿¡ spellcheck(document.TOPIC.content)¸¦ È£Ãâ½Ã ¸ÂÃã¹ý °Ë»çÃ¢ ÆË¾÷
*
******************************************************************************************/

String.prototype.trim = function () {
    return this.replace(/^\s*/g, "").replace(/\s*$/g, "");
}

function urimalSpellCheck_Start(str1,str2,str3,str4) {
    if(str1.trim() == "") {
        alert("³»¿ëÀÌ ¾ø½À´Ï´Ù.");
        return false;
    }

    width = 450;
    height = 500;
    left = 0;
    itop = 148;

    var tempWin=window.open("about:blank", "tempWindow", "width="+width+", height="+height+", left="+left+",top="+itop+", scrollbars=yes,status=yes");
    tempWin.focus();

    var formObj = document.createElement('form');
    formObj.setAttribute('name','spellCheckForm');
    formObj.setAttribute('action',str2);
    formObj.setAttribute('method','post');
    formObj.setAttribute('target','tempWindow');

    var spellText1 = document.createElement('input');
    spellText1.setAttribute('type', 'hidden');
    spellText1.setAttribute('name', 'text1');
    spellText1.setAttribute('value', str1.trim());

    var spellText2 = document.createElement('input');
    spellText2.setAttribute('type', 'hidden');
    spellText2.setAttribute('name', 'text2');
    spellText2.setAttribute('value', str3);

    formObj.appendChild(spellText1);
    formObj.appendChild(spellText2);
    document.body.appendChild(formObj);
    formObj.submit();
}


function spellcheck(el) {
    var content = el.value;
    if(content.trim() == "") { alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä."); return; }
    var path = "/tempaction.php";
    var actionkey = "http://164.125.36.47/WebSpell_ISAPI.dll?Check";
    var tempurl = "http://164.125.36.47/urimal-spellcheck.html";
    Popup('/tempaction_banner.html',450,100);
    urimalSpellCheck_Start(content,path,actionkey,tempurl);
}



/******************************************************************************************
*
* ÆÄÀÏ´Ù¿î·Îµå Ãß°¡ (2007-05-18)
* ÅØ½ºÆ® ÆÄÀÏ ´Ù¿î·Îµå½Ã ÀÌ ÇÔ¼ö »ç¿ë.
*
******************************************************************************************/
function Add_filedown(file_type,file_code,service_code,user_id)
{
    if(user_id == ''){
        alert('·Î±×ÀÎÇØ ÁÖ¼¼¿ä.');
    }else{
        var url = "/lib/Upload/filedown.php?file_type="+file_type+"&file_code="+file_code+"&service_code="+service_code;
        location.href = url;
    }

}


/******************************************************************************************
*
* java ½ºÅ©¸³Æ® ÀÎÄÚµù ÇÔ¼ö
* ¿¹)
* var afternote = encodeURIComponent(f.content.value);
******************************************************************************************/

// First things first, set up our array that we are going to use.
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + //all caps
   "abcdefghijklmnopqrstuvwxyz" + //all lowercase
   "0123456789+/="; // all numbers plus +/=
//Heres the encode function
function encode64(inp)
{
 var out = ""; //This is the output
 var chr1, chr2, chr3 = ""; //These are the 3 bytes to be encoded
 var enc1, enc2, enc3, enc4 = ""; //These are the 4 encoded bytes
 var i = 0; //Position counter
 do //Set up the loop here
 {
  chr1 = inp.charCodeAt(i++); //Grab the first byte
  chr2 = inp.charCodeAt(i++); //Grab the second byte
  chr3 = inp.charCodeAt(i++); //Grab the third byte
  //Here is the actual base64 encode part.
  //There really is only one way to do it.
  enc1 = chr1 >> 2;
  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  enc4 = chr3 & 63;
  if (isNaN(chr2))
  {
   enc3 = enc4 = 64;
  }
  else if (isNaN(chr3))
  {
   enc4 = 64;
  }
  //Lets spit out the 4 encoded bytes
  out = out + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) +
  keyStr.charAt(enc4);
  // OK, now clean out the variables used.
  chr1 = chr2 = chr3 = "";
  enc1 = enc2 = enc3 = enc4 = "";
 } while (i < inp.length);
 //And finish off the loop
 //Now return the encoded values.
 return out;
}
//Heres the decode function
function decode64(inp)
{
 var out = ""; //This is the output
 var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
 var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
 var i = 0; //Position counter
 // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
 var base64test = /[^A-Za-z0-9+/=]/g;
 if (base64test.exec(inp)) //Do some error checking
 {
  alert("There were invalid base64 characters in the input text.n" +
  "Valid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?n" +
  "Expect errors in decoding.");
 }
 inp = inp.replace(/[^A-Za-z0-9+/=]/g, "");
 do //Here¡¯s the decode loop.
 {
  //Grab 4 bytes of encoded content.
  enc1 = keyStr.indexOf(inp.charAt(i++));
  enc2 = keyStr.indexOf(inp.charAt(i++));
  enc3 = keyStr.indexOf(inp.charAt(i++));
  enc4 = keyStr.indexOf(inp.charAt(i++));
  //Heres the decode part. There¡¯s really only one way to do it.
  chr1 = (enc1 << 2) | (enc2 >> 4);
  chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  chr3 = ((enc3 & 3) << 6) | enc4;
  //Start to output decoded content
  out = out + String.fromCharCode(chr1);
  if (enc3 != 64)
  {
   out = out + String.fromCharCode(chr2);
  }
  if (enc4 != 64)
  {
   out = out + String.fromCharCode(chr3);
  }
  //now clean out the variables used
  chr1 = chr2 = chr3 = "";
  enc1 = enc2 = enc3 = enc4 = "";
 } while (i < inp.length); //finish off the loop
 //Now return the decoded values.
 return out;
}




/*
    »ý°¢ ³ëÆ®¿¡ Áñ°ÜÃ£±â Ãß°¡
*/
function add_ideanote_favorite(category_id){
    if(confirm("¼±ÅÃÇÏ½Å °­ÁÂ¸¦ Áñ°ÜÃ£±â¿¡ Ãß°¡ÇÏ½Ã°Ú½À´Ï±î?") == true){
            var JSON_url = "/module/Lecture/Subject/add_ideanote_favorite.php?category_id="+category_id;

            retrive_text = dynamic.loadText(JSON_url);

            result       = JSON.decode(retrive_text);
            alert(result['message']);
            return result;

    }
}

/*

    ½ºÅ©·¦ ¹öÆ° ½ÃÀÛ
    - fScrap('Å×ÀÌºí¸í', 'ÆÄ¶ó¹ÌÅÍ')
            ÆÄ¶ó¹ÌÅÍ´Â '|' ±¸ºÐÀÚ·Î ¿¬°á°¡´ÉÇÏ¸ç ÇÊ¿äÇÑ ÆÄ¶ó¹ÌÅÍµéÀ» ±¸ºÐÀÚ·Î ¿¬°áÇØ¼­ fScrap()¸¦ È£ÃâÇÏ¸é
             /module/ideanote_scrap/scrap.php ÆäÀÌÁö¿¡ Àü´ÞµÇ¾î °¡°øµÈ µÚ Ã³¸®µÈ´Ù.

*/
function fScrap(tablename, param){
    if(confirm("½ºÅ©·¦ÇÏ½Ã°Ú½À´Ï±î?") == true){
            var JSON_url = "/module/IdeaNote_Scrap/scrap.php?tablename="+tablename+"&param="+param;

            retrive_text = dynamic.loadText(JSON_url);
            //alert(retrive_text);
            result       = JSON.decode(retrive_text);
            alert(result['message']);
            if(result['result'] == 1){
                if(opener != null){
                    opener.document.location.reload();
                }
            }
    }
}


/**
* string String::cut(int len)
* ±ÛÀÚ¸¦ ¾Õ¿¡¼­ºÎÅÍ ¿øÇÏ´Â ¹ÙÀÌÆ®¸¸Å­ Àß¶ó ¸®ÅÏÇÕ´Ï´Ù.
* ÇÑ±ÛÀÇ °æ¿ì 2¹ÙÀÌÆ®·Î °è»êÇÏ¸ç, ±ÛÀÚ Áß°£¿¡¼­ Àß¸®Áö ¾Ê½À´Ï´Ù.
*/
String.prototype.cut = function(len) {
        var str = this;
        var l = 0;
        for (var i=0; i<str.length; i++) {
                l += (str.charCodeAt(i) > 128) ? 2 : 1;
                if (l > len) return str.substring(0,i) + "...";
        }
        return str;
}



/*
    function Valid_Date(datein)
        - ÀÔ·ÂµÈ ³¯Â¥¸¦ °ËÁõÇÏ¿© À¯È¿ÇÑÁö ÆÇ´ÜÇÑ´Ù.
            À¯È¿ÇÒ°æ¿ì true¸¦ ¹ÝÈ¯
            À¯ÇÏÁö¾ÊÀ» °æ¿ì false¸¦ ¹ÝÈ¯
*/
function Valid_Date(datein)
{

        var indate=datein;

        if (indate.indexOf("-")!=-1){
                var sdate = indate.split("-");
        }


        var chkDate=new Date(sdate[0], parseInt(sdate[1])-1, sdate[2]);
   //     alert(chkDate);
        var cmpDate=(chkDate.getYear())+"-"+(chkDate.getMonth()+1)+"-"+(chkDate.getDate());
        //alert(cmpDate);
        var indate2=(Math.abs(sdate[0]))+"-"+(Math.abs(sdate[1]))+"-"+(Math.abs(sdate[2]));
        //alert(indate2);
        if (indate2!=cmpDate){
                //alert("ÀÔ·ÂÇÑ ³¯Â¥°¡ ¾È¸ÂµçÁö ÀÔ·ÂÇü½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù. \n\n³¯Â¥¸¦ Á¤È®È÷ ÀÔ·ÂÇß´ÂÁö ¶Ç´Â yyyy-mm-dd Çü½ÄÀ¸·Î ÀÔ·ÂÇß´ÂÁö È®ÀÎÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.");
                return false;
        }
        else {
                if (cmpDate=="NaN-NaN-NaN"){
                        //alert("ÀÔ·ÂÇÑ ³¯Â¥°¡ ¾È¸ÂµçÁö ÀÔ·ÂÇü½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù. \n\n³¯Â¥¸¦ Á¤È®È÷ ÀÔ·ÂÇß´ÂÁö ¶Ç´Â yyyy-mm-dd Çü½ÄÀ¸·Î ÀÔ·ÂÇß´ÂÁö È®ÀÎÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.");
                        return false;
                }
                else {
                        return true;
                }
        }

}



/*****
    function resizeWindow()
    ÆË¾÷Ã¢ ¸®»çÀÌÁî ÇÔ¼ö
    »ç¿ë ¿¹:
        <script>
            resizeWindow(0, 0);
        </script>

*****/
function resizeWindow(margin_width, margin_height){
    if(margin_width == null){
        margin_width = 0;
    }
    if(margin_height == null){
        margin_height = 0;
    }

  var innerBody = document.body;
  var innerHeight = innerBody.scrollHeight;
  resizeTo(200,innerHeight);
  var innerWidth = innerBody.scrollWidth+(innerBody.offsetWidth - innerBody.clientWidth);
  innerHeight = (innerBody.scrollHeight) * 2 - innerBody.offsetHeight;
  resizeTo(innerWidth+margin_width,innerHeight+margin_height);
}

/*
    function rtrim(str, chars)
        rtrim advance version
        »ç¿ë¹ý
            str = rtrim(str, '-');

*/
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}