/****************************************************************
 * isExceedMax(form.field) : 입력값의 길이가 입력객체의 최대길이를 넘는지 확인
 * examples  :
 *
 * if( isExceedMax(form.field) ) {
 *     alert('입력값을 초과했네요.');
 * }
 *
 * return : 입력값이 해당 입력객체의 최대길이를 넘으면 TURE
 * date   : 2002-10-28
 ****************************************************************/
function isExceedMax(input) {
    if(input.value.length <= input.maxLength ) {
        return false;
    }
    return true;
}


/****************************************************************
 * isNull(form.field) : 입력값이 NULL인지 체크
 * examples  :
 *
 * if( isNull(form.field) ) {
 *     alert('입력값이 없네요.');
 * }
 *
 * return : 입력값이 Null or 값이 없으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isNull(input) {
    if (input.value == null || input.value == "") {
        return true;
    }
    return false;
}


/****************************************************************
 * isEmpty(form.field) : 입력값이 비어있는지 체크
 * examples  :
 *
 * if( isEmpty(form.field) ) {
 *     alert('입력값이 없네요.');
 * }
 *
 * return : 입력값에 아무것도 없으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isEmpty(input) {
    if (input.value == null || input.value.replace(/ /gi,"") == "") {
        return true;
    }
    return false;
}


/****************************************************************
 * containsChars(form.field, chars) :
 * 입력값에 특정 문자가 있는지 체크
 * 특정 문자를 허용하지 않으려 할 때 사용
 * examples  :
 *
 * if( containsChars(form.field, "!,*&^%$#@~;") ) {
 *     alert('입력값에 특수문자가 포함되었네요.');
 * }
 *
 * return : 입력값에 지정한 특정문자가 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function containsChars(input, chars) {
    for (var inx = 0; inx < input.value.length; inx++) {
       if (chars.indexOf(input.value.charAt(inx)) != -1)
           return true;
    }
    return false;
}



/****************************************************************
 * containsCharsOnly(form.field, chars) :
 * 입력값이 특정 문자만으로 되어있는지 체크
 * examples  :
 *
 * if( containsCharsOnly(form.field, "ABO") ) {
 *     alert('입력값이 A or B or O 문자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 지정한 특정문자로만 되어 잇으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function containsCharsOnly(input,chars) {
    for (var inx = 0; inx < input.value.length; inx++) {
       if (chars.indexOf(input.value.charAt(inx)) == -1)
           return false;
    }
    return true;
}


/****************************************************************
 * isAlphabet(form.field) : 입력값이 알파벳으로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isAlphabet(form.field) ) {
 *     alert('입력값이 알파벳으로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 알파벳으로만 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isAlphabet(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isUpperCase(form.field) : 입력값이 알파벳 대문자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isUpperCase(form.field) ) {
 *     alert('입력값이 알파벳 대문자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 알파벳 대문자로만 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isUpperCase(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    return containsCharsOnly(input, chars);
}


/****************************************************************
 * isLowerCase(form.field) : 입력값이 알파벳 소문자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isLowerCase(form.field) ) {
 *     alert('입력값이 알파벳 소문자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 알파벳 소문자로만 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isLowerCase(input) {
    var chars = "abcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isNumber(form.field) : 입력값이 숫자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 숫자 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isNumber(form.field) ) {
 *     alert('입력값이 숫자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 숫자로만 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isNumber(input) {
    var chars = "0123456789";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isAlphaNum(form.field) : 입력값이 알파벳과 숫자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isAlphaNum(form.field) ) {
 *     alert('입력값이 알파벳과 숫자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 알파벳과 숫자로만 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isAlphaNum(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * hasHangul(form.field) : 문자열에 한글이 포함되어 있는지 여부 체크
 * 현재 단순히 ascii코드가 255 보다 크면 한글이 존재하는 걸루 여김.
 * examples  :
 *
 * if( hasHangul(form.field) ) {
 *     alert('입력값에 한글이 포함되어 있네요.');
 * }
 *
 * return : 입력값에 한글이 포함되어 있다면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function hasHangul(input) {
    var strParam = input.value;
    var i;
    for(i=0; i<strParam.length; i++) {
        if(strParam.charCodeAt(i) > 255) return true;
    }
    return false;
}


/****************************************************************
 * isNumDash(form.field) : 입력값이 숫자,대시(-)로만 되어있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isNumDash(form.field) ) {
 *     alert('입력값이 숫자와 대시로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 숫자,대시(-)로만 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isNumDash(input) {
    var chars = "-0123456789";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isNumComma(form.field) : 입력값이 숫자,콤마(,)로만 되어있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isNumComma(form.field) ) {
 *     alert('입력값이 숫자와 콤마로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 숫자,콤마(,) 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isNumComma(input) {
    var chars = ",0123456789";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isNumComma(form.field) : 입력값에서 콤마를 제거한다.
 * 같은 방법으로 다양한 캐릭터에 대한 응용이 가능하다.
 * examples  :
 *
 * var val = removeComma(form.field) : "2222,2222" -> 22222222
 *
 * return : 입력값에서 콤마(,)를 제거한 문자열.
 * date   : 2002-10-28
 ****************************************************************/
function removeComma(input) {
    return input.value.replace(/,/gi,"");
}



/****************************************************************
 * isNumComma(form.field, format) :
 * 입력값이 사용자가 정의한 포맷 형식인지 체크
 * 자세한 format 형식은 자바스크립트의 'regular expression(정규식)'을 참조
 * 정규식에 대한 내용은 검색엔진을 통해 찾아보면 나옴.
 * examples  :
 *
 * if (isValidFormat(form.field, "[xyz]")) {
 *        alert('x-z 까지의 문자가 존재하네요.');
 * }
 *
 * return : 입력값이 지정한 올바른 포맷으로 되어 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isValidFormat(input, format) {
    if (input.value.search(format) != -1) {
        return true;
    }
    return false;
}


/****************************************************************
 * isValidEmail(form.field) : 입력값이 이메일 형식인지 체크
 * examples  :
 *
 * if (isValidEmail(form.field)) {
 *        alert('입력값이 이메일 형식이네요.');
 * }
 *
 * return : 입력값이 이메일 형식으로 되어있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isValidEmail(input) {
    /*--
    var format = /^(\S+)@(\S+)\.([A-Za-z]+)$/;
    --*/
    var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
    return isValidFormat(input,format);
}



/****************************************************************
 * isValidPhone(form.field) : 입력값이 전화번호 형식(숫자-숫자-숫자)인지 체크
 * examples  :
 *
 * if (isValidPhone(form.field)) {
 *        alert('입력값이 전화번호 형식이네요.');
 * }
 *
 * return : 입력값이 전화번호 형식(숫자-숫자-숫자)이면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isValidPhone(input) {
    var format = /^(\d+)-(\d+)-(\d+)$/;
    return isValidFormat(input,format);
}

/****************************************************************
 * openWindow(url, name, width, height)
 * : 주어진 값에 따라 새창을 오픈한다. (화면 중앙에 위치함)
 *
 * @PARAM URL    WINDOW의 URL
 * @PARAM NAME   WINDOW의 명
 * @PARAM WIDHT  WINDOW폭 (픽셀)
 * @PARAM HEIGHT WINDOW높이 (픽셀)
 *
 * examples  :
 *
 * var win = openWindow("http://localhost/", localhost, 300, 300);
 *
 * return : 해당 윈도우 객체.
 * date   : 2002-10-28
 ****************************************************************/
function openWindow(url, name, width, height)   {

    var top  = screen.height / 2 - height / 2 - 50;
    var left = screen.width / 2 - width / 2 ;
    var win = open(url, name,
            'width=' + width + ', height=' + height + ', top=' + top +
            ', left=' + left + ', scrollbars=yes, resizable=no, status=yes, toolbar=no, menubar=no');

    win.focus();
    return win;
}


function openWindowOpt(url, name, width, height, etcOpt)   {

    if (etcOpt.length > 0) {
    
        var top  = screen.height / 2 - height / 2 - 50;
        var left = screen.width / 2 - width / 2 ;
        var win = open(url, name,
                'width=' + width + ', height=' + height + ', top=' + top +
                ', left=' + left + ', scrollbars=auto, resizable=no, status=yes, toolbar=no, menubar=no, ' + etcOpt);

        win.focus();
        return win;
    } 
    else {
        return openWindow(url, name, width, height);
    }
}

function openWindowNoCenter(url, name, width, height, etcOpt)   {

    var win = open(url, name,
            'width=' + width + ', height=' + height + 
            ', scrollbars=auto, resizable=no, status=yes, toolbar=no, menubar=no, ' + etcOpt);

    win.focus();
    return win;
}

/****************************************************************
 * alertMsg(form.field) : 주어진 문자열로 경고창을 띄운 뒤 입력객체에 포커스 됨.
 * examples  :
 *
 * if (isValidPhone(form.field)) {
 *        alertMsg(form.field, '입력값이 전화번호 형식이네요.');
 * }
 *
 * return : 항상 False. -> 의미 없음.
 * date   : 2002-10-28
 ****************************************************************/
function alertMsg( input, msg ) {
    alert( msg );
    input.focus();
    // input.select();
    return false;
}


/****************************************************************
 * hasCheckedRadio(form.field) : 선택된 라디오버튼이 있는지 체크
 * examples  :
 *
 * if (hasCheckedRadio(form.field)) {
 *        alert('선택된 라디오 버튼이 있네요.');
 * }
 *
 * return : 선택된 라디오버튼이 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function hasCheckedRadio(input) {
    if (input.length > 1) {
        for (var inx = 0; inx < input.length; inx++) {
            if (input[inx].checked) return true;
        }
    } else {
        if (input.checked) return true;
    }
    return false;
}


/****************************************************************
 * getCheckedRadio(form.field) : 선택된 라디오버튼의 값을 리턴
 * examples  :
 *
 * var value = getCheckedRadio(form.field);
 *
 * return : 선택된 라디오버튼의 값
 * date   : 2002-10-28
 ****************************************************************/
function getCheckedRadio(input) {

    if (hasCheckedRadio(input)) {
        for (var inx = 0; inx < input.length; inx++) {
            if (input[inx].checked) return input[inx].value;
        }
    }
}


/****************************************************************
 * hasCheckedBox(form.field) : 선택된 체크박스가 있는지 체크
 * examples  :
 *
 * if (hasCheckedBox(form.field)) {
 *        alert('선택된 체크박스가 있네요.');
 * }
 *
 * return : 선택된 체크박스가 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function hasCheckedBox(input) {
    return hasCheckedRadio(input);
}

/****************************************************************
 * hasSelectedIndex(form.field) : 선택된 선택박스의 값이 있는지 체크
 *
 * return : 선택된 선택박스의 값이 있으면 TRUE
 * date   : 2005-04-04
 ****************************************************************/
function hasSelectedIndex(input) {
    for (i=1 ; i < input.options.length ; i++) {
        if (input.options[i].selected == true) {
            return true;
        }
    }

    return false;
}

/****************************************************************
 * hasSelectedIndex(form.field) : 선택된 선택박스의 값이 있는지 체크
 *
 * return : 선택된 선택박스의 값이 있으면 TRUE
 * date   : 2005-04-04
 ****************************************************************/
function hasSelectedIndexValue(input) {
    if (input.value != '') {
        return true;
    }

    return false;
}

/****************************************************************
 * getSelectedValue(form.field) : 선택된 선택박스의 값을 얻는다.
 * examples  :
 *
 * var value = getSelectedValue(form.field);
 *
 * return :  선택된 선택박스의 값.
 * date   : 2002-10-28
 ****************************************************************/
function getSelectedValue(input) {

    if ( input == null )
        return null;

    return input.options[input.selectedIndex].value;
}


/****************************************************************
 * getSelectedValue(form.field) : 선택된 선택박스의 텍스트를 얻는다.
 * examples  :
 *
 * var value = getSelectedText(form.field);
 *
 * return :  선택된 선택박스의 텍스트.
 * date   : 2002-10-28
 ****************************************************************/
function getSelectedText(input) {

    if ( input == null )
        return null;

    return input.options[input.selectedIndex].text;
}


/****************************************************************
 * getIndexByValue(form.field, value)
 *  : 지정한 값과 일치하는 선택박스의 인덱스를 얻는다.
 * examples  :
 *
 * var index = getIndexByValue(form.field, "값");
 *
 * return : 지정한 값과 일치하는 선택박스의 인덱스. 없으면 -1 리턴.
 * date   : 2002-10-28
 ****************************************************************/
function getIndexByValue(input, value) {

    if ( input == null )
        return;

    for ( var i = 0; i < input.options.length; i++ ) {
        if ( input.options[i].value == value )
            return i;
    }
    return -1;  // not found.
}


/****************************************************************
 * removeOptionByValue(form.field, value)
 *  : 지정한 값과 일치하는 선택박스의 인덱스를 삭제한다.
 * examples  :
 *
 * if (removeOptionByValue(form.field, "값")) {
 *        alert('해당 인덱스가 삭제되었어요.');
 * }
 *
 * return : 해당 인덱스가 지워지면 TRUE.
 * date   : 2002-10-28
 ****************************************************************/
function removeOptionByValue(input, value) {

    if ( input == null )
        return false;

    var index = getIndexByValue( input, value );
    var srcC = 0, destC = 0;

    if ( index == -1 ) return false; // not found

    // else value was found, shift all elemenets which are after index

    while ( srcC < input.options.length) {
        input.options[destC] = input.options[srcC];
        if ( srcC == index ) destC--;
        srcC++;
        destC++;
    }

    input.options.length -= 1;

    return true;
}


/****************************************************************
 * makeBlur(form.field)
 *  : 값이 입력안되게 하기
 * examples  :
 *
 * <input type=text onfocus = "MakeBlur(input)">
 *
 * return : 해당없음.
 * date   : 2002-10-28
 ****************************************************************/
function makeBlur(input) {
    input.blur();
}



/*-------------------------------------------------------------------------------
 * [3] 문자열 관련 함수
 *-------------------------------------------------------------------------------
 */


/****************************************************************
 * removeToken(form.field, char) : 지정한 캐릭터 제거하기.
 * examples  :
 *
 * form.field = '1111,11'일 경우....
 * removeToken(form.field, ',');
 *        -> 1111,11 -> 111111
 *
 * return : 입력값에서 지정한 캐릭터를 제거한 문자열.
 * date   : 2002-10-28
 ****************************************************************/
function removeToken(input, _char) {
    val = input.value;
    str = "";
    strr = val.split(_char);
    for (i=0 ; i < strr.length ; i++) {
        str += strr[i];
    }
    input.value = str;
}


/****************************************************************
 * getByteLength(form.field) : 입력값의 바이트 길이를 얻는다.
 * examples  :
 *
 * form.field = 'hi한글'일 경우....
 * getByteLength(form.field); -> 6
 *
 * return : 입력값의 바이트 길이 (한글은 2Byte)
 * date   : 2002-10-28
 ****************************************************************/
function getByteLength(input) {
    var byteLength = 0;
    for (var inx = 0; inx < input.value.length; inx++) {
        var oneChar = escape(input.value.charAt(inx));
        if ( oneChar.length == 1 ) {
            byteLength ++;
        } else if (oneChar.indexOf("%u") != -1) {
            byteLength += 2;
        } else if (oneChar.indexOf("%") != -1) {
            byteLength += oneChar.length/3;
        }
    }
    return byteLength;
}


/****************************************************************
 * fillSpace(form.field, len, positionOfSpace)
 *    : 입력값의 앞이나 뒤에 총 바이트가 지정한 길이가 되도록 공백을 추가한다.
 * examples  :
 *
 * form.field = 'hi한글'일 경우....
 * fillSpace(form.field, 4, 'head') -> '    hi한글'
 * fillSpace(form.field, 4, 'tail') -> 'hi한글    '
 *
 * return : 지정한 길이의 공백이 추가된 새로운 문자열
 * date   : 2002-10-28
 ****************************************************************/
function fillSpace(input, len, positionOfSpace) {
    var str = input.value;
    var newStr = input.value;

    if( positionOfSpace == "head" )
        for(var i=0;i<(len-str.length);i++)
            newStr = " " + newStr ;
    else
        for(var i=0;i<(len-str.length);i++)
            newStr = newStr + " ";

    return newStr;
}


/****************************************************************
 * replaceString(form.field, old, new)
 *  : 입력값의 모든 문자열중에서 old를 new로 대체함.
 * examples  :
 *
 * form.field = 'hahohi'일 경우....
 * replaceString(form.field, 'ho','한글') -> 'ha한글hi'
 *
 * return : 대체된 새로운 문자열
 * date   : 2002-10-28
 ****************************************************************/
function replaceString(input, strOld, strNew) {

    var str = input.value;
    var index = 0;
    var oldLen = strOld.length;
    var newLen = strNew.length;
    var strPre = "";

    if( strOld == null || strOld == "") return str;

    while (true) {
        if ((index = str.indexOf(strOld)) != -1) {
            strPre= strPre + str.substring(0, index) + strNew;
            str = str.substring(index + oldLen);
        }
        else
            break;
    }
    return strPre + str;
}


/****************************************************************
 * trim(form.field)
 *  : 문자열 앞뒤의 공백을 지움 (' ', '\r', '\n', '\t')
 * examples  :
 *
 * form.field = ' ha한글 '일 경우....
 * trim(form.field) -> 'ha한글'
 *
 * return : 대체된 새로운 문자열
 * date   : 2002-10-28
 ****************************************************************/
function trim(input) {
    var str     = input.value;
    var len     = str.length;
    var iFrom    = 0;
    var iTo        = len;

    for(var i=0 ; i < len ; i++) {
        if( str.charAt(i) == ' ' || str.charAt(i) == '\r' || str.charAt(i) == '\n' || str.charAt(i) == '\t' )
            iFrom = i+1;
        else break;
    }
    for(var i=len-1 ; i > iFrom ; i--) {
        if( str.charAt(i) == ' ' || str.charAt(i) == '\r' || str.charAt(i) == '\n' || str.charAt(i) == '\t' )
            iTo = i;
        else break;
    }
    return str.substring(iFrom, iTo);
}


/****************************************************************
 * formatString(strParam, strFormat, cMark)
 *  : 지정한 문자열을 지정한 포맷으로 변환한다.
 * examples  :
 *
 * formatString("20010305", "4-2-2", '/') -> 2001/03/05
 * formatString("7011011101417", "6-7", '-') -> 701101-1101417
 *
 * return : 포맷된 새로운 문자열
 * date   : 2002-10-28
 ****************************************************************/
function formatString(strParam, strFormat, cMark) {
    var formatArray, strData, nLength, nCurPos;
    nLength = nCurPos = 0;
    strData = "";

    formatArray = strFormat.split("-");
    for(i=0; i < formatArray.length; i++) {
        nLength = parseInt(formatArray[i]);
        strData += strParam.substr(nCurPos, nLength);
        if(i < (formatArray.length-1)) strData += cMark;
        nCurPos += nLength;
    }
    return strData;
}


/****************************************************************
 * numFormat(form.field)
 *  : 입력값을 금액표시로 전환
 * examples  :
 *
 * form.field = '99999'일 경우....
 * numFormat(form.field) -> 99,999
 *
 * form.field = '-12345.001'일 경우....
 * numFormat(form.field) -> -123,45.001
 *
 * return : 대체된 새로운 금액 문자열
 * date   : 2002-10-28
 ****************************************************************/
function numFormat(obj) {

    var str  = String(obj.value);
    var len  = str.length;
    var tmp  = "";
    var tm2  = "";

    /* 소수점 두개 이상 에러 표시 */
    count = 0;

    for( j=0 ; j < len ; j++) {
        if( obj.value.charAt(j) == '.') count++;
    }

    if (count > 1) {
        var text = "소수점이 둘 이상 포함되었습니다.";
        alert(text);
        obj.focus();
    }

    if (str.charAt(0) == '-') {
        tmp = '-' ;
        str = str.substring(1,len);
    }

    if (str.indexOf('-',0) != -1) {
        obj.focus();
        return;
    }

    if ((sit=str.indexOf('.',0)) != -1) {
        tm2 = str.substring(sit,len);
        str = str.substring(0,sit);
    }

    var i    = 0;

    while (str.charAt(i) == '0') i++;

    str = str.substring(i,len);
    len = str.length;

    if(len < 3) {
        obj.value = str;
        return;
    }
    else {
        var sit = len % 3;
        if (sit > 0) {
            tmp = tmp + str.substring(0,sit) + ',';
            len = len - sit;
        }

        while (len > 3) {
            tmp = tmp + str.substring(sit,sit+3) + ',';
            len = len - 3;
            sit = sit + 3;
        }

        tmp = tmp + str.substring(sit,sit+3) + tm2;
        obj.value = tmp;
    }
}



/*-------------------------------------------------------------------------------
 * [4] 쿠키 관련 함수
 *-------------------------------------------------------------------------------
 */


/****************************************************************
 * setCookie(name, value, expiredays)
 *  : 지정한 값으로 쿠키를 설정한다.
 * examples  :
 *
 * setCookie( "is_end", "done" , 1); -> 쿠키보관일 : 하루
 *
 * return : 해당 없음.
 * date   : 2002-10-28
 ****************************************************************/
function setCookie(name, value, expiredays){
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

/****************************************************************
 * getCookie(name)
 *  : 지정한 값에 따른 쿠키를 얻는다.
 * examples  :
 *
 * if (getCookie( "is_end" ) == "done") {
 *        alert('쿠키가 만료되었습니다.');
 * }
 *
 * examples  :
 * return : 쿠키정보 문자열.
 * date   : 2002-10-28
 ****************************************************************/
function getCookie(uName) {
    var flag = document.cookie.indexOf(uName+'=');
    if (flag != -1) {
        flag += uName.length + 1
        end = document.cookie.indexOf(';', flag)

        if (end == -1) end = document.cookie.length
        return unescape(document.cookie.substring(flag, end))
    }
}


/****************************************************************
 * isImage(name)
 *  : 첨부파일 포맷이 이미지 형식인지 확인한다.
 * examples  :
 *
 * if ( !isImage(name) ) {
 *        alert('이미지 형식이 아닙니다.');
 * }
 *
 * examples  :
 * date   : 2004-02-26
 ****************************************************************/
function isImage(input) {

    if (input.value != '') {
        var file = input.value;
        var idx = file.indexOf('.');
        file = file.substring(idx + 1);
        if ( file == 'jpg' || file == 'jpeg' || file == 'gif' || file == 'png' || file == 'bmp' ||
             file == 'JPG' || file == 'JPEG' || file == 'GIF' || file == 'PNG' || file == 'BMP'
        ) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return true;
    }
}

function isXls(input) {

    if (input.value != '') {
        var file = input.value;
        var idx = file.indexOf('.');
        file = file.substring(idx + 1);
        if ( file == 'xls' || file == 'xlsx' ) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return true;
    }
}

/****************************************************************
 * getlayer(name)
 *  : 브라우져에 따른 레이어를 얻는다.
 *
 * date   : 2005-11-17
 ****************************************************************/
function getlayer(name) {

    if (document.layers) { // NN
        pop = document.layers[name];
        pop_br=1;
    }
    else if(document.all) { // IE
        pop = document.all[name];
        pop_br=2;
    } else { // Standard
        pop = document.getElementById(name);
        pop_br=3;
    }
}

/****************************************************************
 * hiddenLayer(name)
 *  : 브라우져에 따른 레이어를 감춘다.
 *
 * date   : 2005-11-17
 ****************************************************************/
function hiddenLayer(layers) {

    getlayer(layers);
    
    if (pop_br == 1) {
        pop.visibility='hidden';
    }
    else if (pop_br == 2) {
        pop.style.display='none';
    }
    else if (pop_br == 3) {
        pop.style.visibility='hidden';
    }
}

/****************************************************************
 * showLayer(name)
 *  : 브라우져에 따른 레이어를 표시한다.
 *
 * date   : 2005-11-17
 ****************************************************************/
function showLayer(layers) {

    getlayer(layers);

    if (pop_br == 1) {
        pop.visibility = 'visible';
        pop.left = window.innerWidth/2-pop.width.replace("px","")/2;
        pop.top = window.innerHeight/2-pop.height.replace("px","")/2;
    }
    else if (pop_br == 2) {
        pop.style.visibility = 'visible';
        pop.style.left = document.body.scrollLeft+document.body.offsetWidth/2-pop.style.width.replace("px","")/2;
        pop.style.top = document.body.scrollTop+document.body.offsetHeight/2-pop.style.height.replace("px","")/2;
    }
    else if (pop_br == 3) {
        pop.style.visibility = 'visible';
        pop.style.left=document.body.offsetWidth/2-pop.style.width.replace("px","")/2;
        pop.style.top=document.body.offsetHeight/2-pop.style.height.replace("px","")/2;
    }   
}

/****************************************************************
 * jsResize(obj)
 *  : iFrame 리사이즈
 *
 * date   : 2005-11-21
 ****************************************************************/
function jsResize(obj) { 
    
    // document.getElementById("iFresize").style.height = document.getElementById("foaFrame").offsetHeight;
    // document.getElementById("iFresize").style.width = document.getElementById("foaFrame").offsetWidth;
    // alert(obj.contentWindow);

    var Body; 
    var H, Min; 
    Min = 100; 
    // alert( document.getElementById("iFresize").offsetHeight );
    // alert(obj.contentWindow+'\n'+ obj.contentWindow.document+'\n'+ obj.contentWindow.document.getElementsByTagName('BODY'));
    Body = (obj.contentWindow.document.getElementsByTagName('BODY'))[0]; 

    H = parseInt(Body.scrollHeight) + 5; 
    obj.style.height = (H<Min?Min:H) + 'px'; 

    // alert(Body.scrollHeight +'\n'+ H +'\n'+ obj.style.height);

    window.scrollTo(1, 1);  
} 

/****************************************************************
 * hasHangulName(obj)
 *  : 업로드 파일 이름에 한글이 포함되었는지 여부
 *
 * date   : 2005-11-21
 ****************************************************************/
function hasHangulName(obj) {

    var fileName = obj.value;
    var idx = fileName.lastIndexOf('\\');
    fileName = fileName.substring(idx + 1);

    var i;
    for(i=0; i<fileName.length; i++) {
        if(fileName.charCodeAt(i) > 255) return true;
    }    
    return false;
}

/****************************************************************
 * jsToggleMenu(obj)
 *  : xmlMenu.js를 대체하는 인트라넷 좌측 메뉴 관련 스크립트
 *
 * date   : 2005-11-25
 ****************************************************************/
function jsToggleMenu(currMenu) {
    var subMenu = document.getElementById(currMenu);
    if (subMenu != null) {
        if (subMenu.style.display == 'none') {
            subMenu.style.display = 'block';
        }
        else {
            subMenu.style.display = 'none';
        }
    }
}

/****************************************************************
 * jsProcess()
 *  : 요청을 제출하는 동안 이미지 표시
 *
 * <span id='upload' style='display:block'>
 * ....
 * <span id='tranimg' style='display:none'>
 *     <img src="$CTX_ROOT/resource/images/processing.gif">
 * ....
 *
 * date   : 2005-11-25
 ****************************************************************/
function jsProcess() {
    try {
        document.getElementById('submitBt').style.display  = 'none';
        document.getElementById('processBt').style.display = 'block';
    }
    catch (Exception) {
    }
}
function jsProcessOpt(hdnVal, shwVal) {
    try {
        document.getElementById(hdnVal).style.display  = 'none';
        document.getElementById(shwVal).style.display = 'block';
    }
    catch (Exception) {
    }
}

/****************************************************************
 * jsTextAreaResize()
 *  : TextArea필드 리사이즈
 *
 * date   : 2006-08-11
 ****************************************************************/
function jsTextAreaResize(que, elementName) {
    var area = document.getElementById(elementName);
    if (que == '-') {
        if ( area.rows != 8 ) {
            area.rows = area.rows - 4;
        }
    }
    else if (que == '+') {
        area.rows = area.rows + 4;
    }
    else {
        area.rows = 8;
    }

    jsResize( this.parent.document.getElementById('detailFrame') );
}

/****************************************************************
 * jsClipBoard('클립보드에 담길 내용')
 *  : IE / FF 모두 동작하는 클립보드 복사 함수
 *  : _clipboard.swf 파일의 경로에 주의할 것
 *  
 * date   : 2009-09-14
 ****************************************************************/
function jsClipBoard(str) { 
    if (document.selection) { 
        bResult = window.clipboardData.setData("Text", str); 
        //if (bResult) alert('클립보드에 저장되었습니다.'); 
    } 
    else { 
        str = encodeforFlash(str); 
        var flashcopier = 'flashcopier'; 
        if (!document.getElementById(flashcopier)) { 
            var divholder = document.createElement('div'); 
            divholder.id = flashcopier; 
            document.body.appendChild(divholder); 
        } 
        document.getElementById(flashcopier).innerHTML = ''; 
        var divinfo = '<embed src="../../swf/clipboard.swf" FlashVars="clipboard='+str+'" width="1" height="1" type="application/x-shockwave-flash"></embed>'; 
        document.getElementById(flashcopier).innerHTML = divinfo; 
        //alert('클립보드에 저장되었습니다.'); 
    } 
};
function encodeforFlash(str) { 
    var SAFECHARS = "0123456789" + 
                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + 
                  "abcdefghijklmnopqrstuvwxyz" + 
                  "-_.!~*'()"; 

    var HEX = "0123456789ABCDEF"; 

    var plaintext = str; 
    var encoded = ""; 
    for (var i = 0; i < plaintext.length; i++ ) { 
        var ch = plaintext.charAt(i); 
        if (ch == " ") { 
            encoded += "+"; 
        } 
        else if (SAFECHARS.indexOf(ch) != -1) { 
            encoded += ch; 
        } 
        else { 
            var charCode = ch.charCodeAt(0); 
            if (charCode > 255) { 
                encoded += ch; 
            } else { 
                encoded += "%"; 
                encoded += HEX.charAt((charCode >> 4) & 0xF); 
                encoded += HEX.charAt(charCode & 0xF); 
            } 
        } 
    } 
    return encoded; 
}; 
