
/****************************************************************
 * " aaaaaa ".trim() : 문자열 공백 제거
 ****************************************************************/
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}



/*-------------------------------------------------------------------------------
 * [1] 입력값 체크 함수
 *-------------------------------------------------------------------------------
 */

/****************************************************************
 * isIdAndPwPatternCheck(str) : 아이디, 입력값이 유효성 체크
 * examples  :
 ****************************************************************/
function isIdAndPwPatternCheck(str) {
	 var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9]{5,15}$/;
	 return pattern.test(str);
} 


/****************************************************************
 * isEmpty(form.field) : 입력값이 비어있는지 체크
 * examples  :
 ****************************************************************/
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('입력값에 특수문자가 포함되었네요.');
 * }
 ****************************************************************/
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.length; inx++) {
       if (chars.indexOf(input.value.charAt(inx)) == -1)
           return false;
    }
    return true;
}


/****************************************************************
 * isAlphabet(form.field) : 입력값이 알파벳으로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isAlphabet(form.field.value) ) {
 *     alert('입력값이 알파벳으로만 구성되어 있네요.');
 * }
 ****************************************************************/
function isAlphabet(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isUpperCase(form.field.value) : 입력값이 알파벳 대문자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isUpperCase(form.field.value) ) {
 *     alert('입력값이 알파벳 대문자로만 구성되어 있네요.');
 * }
 ****************************************************************/
function isUpperCase(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    return containsCharsOnly(input, chars);
}


/****************************************************************
 * isLowerCase(form.field.value) : 입력값이 알파벳 소문자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isLowerCase(form.field.value) ) {
 *     alert('입력값이 알파벳 소문자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 알파벳 소문자로만 이루어져 있으면 TRUE
 ****************************************************************/
function isLowerCase(input) {
    var chars = "abcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isNumber(form.field.value) : 입력값이 숫자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 숫자 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isNumber(form.field.value) ) {
 *     alert('입력값이 숫자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 숫자로만 이루어져 있으면 TRUE
 ****************************************************************/
function isNumber(input) {
    var chars = "0123456789";
    return containsCharsOnly(input,chars);
}


/****************************************************************
 * isAlphaNum(form.field.value) : 입력값이 알파벳과 숫자로만 되어 있는지 체크
 * 본 함수가 자주 호출될 경우에는 캐릭터 지역변수를 전역변수로
 * 사용해도 좋다.
 * examples  :
 *
 * if( isAlphaNum(form.field.value) ) {
 *     alert('입력값이 알파벳과 숫자로만 구성되어 있네요.');
 * }
 *
 * return : 입력값이 알파벳과 숫자로만 이루어져 있으면 TRUE
 * date   : 2002-10-28
 ****************************************************************/
function isAlphaNum(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    return containsCharsOnly(input,chars);
}

function isAlphaNum2(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    return containsCharsOnly(input,chars);
}

function isLowerCaseAlphaNum(input) {
    var chars = "abcdefghijklmnopqrstuvwxyz0123456789";
    return containsCharsOnly(input,chars);
}

/****************************************************************
 * hasHangul(form.field.value) : 문자열에 한글이 포함되어 있는지 여부 체크
 * 현재 단순히 ascii코드가 255 보다 크면 한글이 존재하는 걸루 여김.
 * examples  :
 *
 * if( hasHangul(form.field.value) ) {
 *     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;
}

function hasNumber(input){
	var strParam = input.value;
    var i;
    for(i=0; i<strParam.length; i++) {
        if(strParam.charCodeAt(i)<=57 && strParam.charCodeAt(i) >= 48) return true;
    }
    return false;
}

function hasAlpha(input){
	var strParam = input.value;
    var i;
    for(i=0; i<strParam.length; i++) {
        if(strParam.charCodeAt(i)<=122 && strParam.charCodeAt(i) >= 97) return true;
    }
    return false;
}


/****************************************************************
 * 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);
}

/****************************************************************
 * 회원 아이디 형식의 패턴을 체크
 * 아이디 형식은 영문, 숫자형식의 6~15자리이여야 하며 첫자리는 반드시 영문으로 시작 
 * return : 입력값이 패턴에 맞는 형식이면 TRUE
 * date : 2009-03-31
 ****************************************************************/
function isMemberIdPattern(str) {
	var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9]{5,15}$/;
	return pattern.test(str);
}

/*-------------------------------------------------------------------------------
 * [2] 폼 유틸 함수
 *-------------------------------------------------------------------------------
 */


/****************************************************************
 * setFocusToFirstTextField(form) : 폼의 첫번째 입력 텍스트 필드에 포커스를 줌.
 * examples  :
 *
 * <body onLoad='setFocusToFirstTextField(form);'>
 *
 * return : 의미 없음.
 * date   : 2002-10-28
 ****************************************************************/
function setFocusToFirstTextField(form) {

    if ( typeof form == 'undefined' ) return;  // if form is invalid, just return.

    var count = form.elements.length;

    for ( var i = 0; i < count; i++ ) {
        if ( form.elements[i].type == "text" || form.elements[i].type == "password" ) {
            form.elements[i].focus();
            return;
        }
    }
}



/****************************************************************
 * getCheckedValues(form.field) : 선택된 체크박스의 값을 지정 구분자로 연결하여 리턴
 * examples  :
 *
 * var value = getCheckedValues(form.field, '|');
 *
 * return : 선택된 체크박스의 배열 정보
 * date   : 2002-10-28
 ****************************************************************/
function getCheckedValues(input, sep) {

    if (sep == "")
        sep = "|";

    var fDels = "";
    var chk=0;
    if (input.length > 1) {
    	
        for (var inx = 0; inx < input.length; inx++) {
            if (input[inx].checked) {
            	if(chk==0){
            		 fDels += input[inx].value;
            	}else{
            		 fDels += sep+input[inx].value ;
            	}
               chk++;
            }
        }
    } else {
        if (input.checked)
            fDels = input.value;
    }

    return fDels.substring(0, fDels.length);
}

/****************************************************************
 * 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;
        }
    }
    return "";
}


/****************************************************************
 * 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;
}


/****************************************************************
 * 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;
}




/*-------------------------------------------------------------------------------
 * [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;
}


/****************************************************************
 * 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;
}



/*-------------------------------------------------------------------------------
 * [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;
    }
}

/****************************************************************
 * 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;
	}
}

/****************************************************************
 * hasHangulName(obj)
 *  : 업로드 파일 이름에 한글이 포함되었는지 여부
 *
 * date   : 2005-11-21
 ****************************************************************/
function hasHangulName(val) {

    var fileName = val;
    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;
}


/****************************************************************
 * Browser()
 *  : 브라우저 판단
 *
 * date   : 2006-12-27
 ****************************************************************/
 function Browser() {

    var ua, s, i;

    this.isIE    = false;
    this.isNS    = false;
    this.version = null;

    ua = navigator.userAgent;

    s = "MSIE";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isIE = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    s = "Netscape6/";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    // Treat any other "Gecko" browser as NS 6.1.
    s = "Gecko";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = 6.1;
        return;
    }
}
var browser = new Browser();


/**
 * 주어진 값(val)을 소수점이하 num자리수에서 반올림한값을 리턴
 *
 * @param val 반올림할 값
 * @param num 반올림할 자리수
 * @return number
 */
function round(val, num){
    val = val * Math.pow(10, num - 1);
    val = Math.round(val);
    val = val / Math.pow(10, num - 1);
    return val;
}

/**
 * 입력필드의 입력값 길이가 지정한 길이가 되면 다음 입력필드로 포커스를 이동한다.
 *
 * @param num (필수) 문자열 길이
 * @param fromform (필수) 입력필드
 * @param toform (필수) 다음 입력필드
 */
function moveFocus(num,fromform,toform)
{
    var str = fromform.value.length;
    if(str == num)
    toform.focus();
}


function showLayer(id) {
	var divObj = document.getElementById(id);

	if (divObj.style.visibility == "hidden")
		divObj.style.visibility="visible" ;
	if (divObj.style.display == "none")
		divObj.style.display = "block";
	return true;
}

function hideLayer(id) {
	var divObj = document.getElementById(id);

	if (divObj.style.visibility == "visible")
		divObj.style.visibility="hidden" ;
	if (divObj.style.display == "" || divObj.style.display == "block")
		divObj.style.display = "none";
	return true;
}
/*
 *  - 윈도 환경에 따라 사이즈가 다를 수 있습니다.
 *  - 팝업페이지의 스크립트 최하단에서 실행하십시오.
*/
function popupAutoResize() {
    var thisX = parseInt(document.body.scrollWidth);
    var thisY = parseInt(document.body.scrollHeight);
    var maxThisX = screen.width - 50;
    var maxThisY = screen.height - 50;
    var marginY = 0;
    //alert(thisX + "===" + thisY);
    //alert("임시 브라우저 확인 : " + navigator.userAgent);
    // 브라우저별 높이 조절. (표준 창 하에서 조절해 주십시오.)
    if (navigator.userAgent.indexOf("MSIE 6") > 0) marginY = 45;        // IE 6.x
    else if(navigator.userAgent.indexOf("MSIE 7") > 0) marginY = 75;    // IE 7.x
    else if(navigator.userAgent.indexOf("Firefox") > 0) marginY = 50;   // FF
    else if(navigator.userAgent.indexOf("Opera") > 0) marginY = 30;     // Opera
    else if(navigator.userAgent.indexOf("Netscape") > 0) marginY = -2;  // Netscape

    if (thisX > maxThisX) {
        window.document.body.scroll = "yes";
        thisX = maxThisX;
    }
    if (thisY > maxThisY - marginY) {
        window.document.body.scroll = "yes";
        thisX += 19;
        thisY = maxThisY - marginY;
    }
    window.resizeTo(thisX+10, thisY+marginY);

    // 센터 정렬
    // var windowX = (screen.width - (thisX+10))/2;
    // var windowY = (screen.height - (thisY+marginY))/2 - 20;
    // window.moveTo(windowX,windowY);
}


function reload(){
	location.reload();
}

/**
 * ,이 있는 숫자를 순수한 숫자로 바꿔준다. (+), (-) 허용
 *
 * @param num
 * @return number
 */
function removeComma( num ) {
    num = num.replace(/,/g, '');
    var args = Number(num);
    return args;
}

/****************************************************************
  숫자에 comma를 붙인다.
  @param	str
  2008-09-10 김상종
 ****************************************************************/

function addComma(str) {

	var num = "";
	var sign = "";

	if (str.charAt(0) == "+" || str.charAt(0) == "-") {
		sign = str.charAt(0);
		str = str.substr(1);
	}

	var index = str.indexOf('.');

	if (index != -1) {
		num = str.substr(index);
	} else {
		index = str.length;
	}
	for (var i = index - 3; i > 0; ) {
		num = ',' + str.substr(i, 3) + num;

		index = i;
		i -= 3;
	}

	num = sign + str.substr(0, index) + num;
	
	return	num;
}
/****************************************************************
날짜 표시(yyyy-mm-dd).
@param	str
2008-09-10 김상종
****************************************************************/

function formDate(date) {
	var dateData="";
	var dateDelm="-";

	dateData=date;
	dateData = replace(dateData.toString(),dateDelm,"");

	if(dateData==""){
		return "";
	}
	if(isNaN(dateData)||dateData.length!=8) {
		dateData = "";
		return dateData;
	}
	/*if(!isCorrectDate(dateData.substring(0,4),dateData.substring(4,6),dateData.substring(6,8))){
		return "";
	}*/
	dateData=dateData.substring(0,4)+dateDelm+dateData.substring(4,6)+dateDelm+dateData.substring(6,8);
	
	return dateData;	
}
/****************************************************************
문자열 교환
@param	str
2008-09-10 김상종
****************************************************************/
function replace( source,  target,  replace)
{
	var sourceData="";
	sourceData=source;

	if(sourceData==null) return "";
	if(target==null||target=="") return source;

	iTargetLen = target.length;

	sbfReplace="";
	i = 0;
	j = 0;

	while (j > -1)
	{
		j = sourceData.indexOf(target,i);
		if (j > -1)
		{
			
			sbfReplace+=sourceData.substring(i,j);
			sbfReplace+=replace;
			i = j + iTargetLen;
		}
	}
	sbfReplace+=sourceData.substring(i,sourceData.length);

	return sbfReplace;
}




/*************************************************************************
플래쉬 프린트
레이어 덮어 쓰는거 방지..
2008-10-02 김진혁
**************************************************************************/
function flashview(FlashIDName, FlashFileName, FlashWidth, FlashHeight, DNSSetting, WMODESetting, FlashBGColor, QSetting, FlashAlign)
{	
	document.write('<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	document.write('CODEBASE="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,22,0" ');
	document.write(' ID="'+FlashIDName+'" WIDTH="' + FlashWidth + '" HEIGHT="' + FlashHeight + '" ALIGN="wmode">');
	document.write('<PARAM NAME="movie" VALUE="'+ FlashFileName +'">');
	document.write('<PARAM NAME="quality" VALUE="high">');
	document.write('<PARAM NAME="bgcolor" VALUE="'+FlashBGColor+'">');
	document.write('<PARAM NAME="wmode" VALUE="transparent">');
	document.write('<PARAM NAME="allowScriptAccess" VALUE="always">');
	document.write('<EMBED SRC="'+ FlashFileName +'"  NAME="'+FlashIDName+'"');
	document.write(' WIDTH="' + FlashWidth + '" HEIGHT="' + FlashHeight + '" QUALITY="high" BGCOLOR="'+FlashBGColor+'"');
	document.write(' ALLOWSCRIPTACCESS="always" ALIGN="wmode" WMODE="transparent" TYPE="application/x-shockwave-flash" ');
	document.write(' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" >');
	document.write('</EMBED>');
	document.write('</OBJECT>');
}

/************************************************
 * 오토불러
 * 2008-10-02 김진혁
 *************************************************/
function autoBlur(){ 
	if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") 
	document.body.focus(); 
} 
document.onfocusin=autoBlur; 

/*************************************************
 * UTF-8 방식을 위한 URLencode
 * 2008-10-02 김진혁
 * ***********************************************/
function encodeURL(str){
	var s0, i, s, u;
	s0 = "";                // encoded str
	for (i = 0; i < str.length; i++){   // scan the source
	    s = str.charAt(i);
	    u = str.charCodeAt(i);          // get unicode of the char
	    if (s == " "){s0 += "+";}       // SP should be converted to "+"
	    else {
	        if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
	            s0 = s0 + s;            // don't escape
	        }
	        else {                  // escape
	            if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
	                s = "0"+u.toString(16);
	                s0 += "%"+ s.substr(s.length-2);
	            }
	            else if (u > 0x1fffff){     // quaternary byte format (extended)
	                s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
	                s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
	                s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
	                s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
	            }
	            else if (u > 0x7ff){        // triple byte format
	                s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
	                s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
	                s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
	            }
	            else {                      // double byte format
	                s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
	                s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
	            }
	        }
	    }
	}
	return s0;
}

/*************************************************
 * UTF-8 방식을 위한 URLDecode
 * 2008-10-02 김진혁
 * *************************************************/
function decodeURL(str){
	var s0, i, j, s, ss, u, n, f;
	s0 = "";                // decoded str
	for (i = 0; i < str.length; i++){   // scan the source str
	    s = str.charAt(i);
	    if (s == "+"){s0 += " ";}       // "+" should be changed to SP
	    else {
	        if (s != "%"){s0 += s;}     // add an unescaped char
	        else{               // escape sequence decoding
	            u = 0;          // unicode of the character
	            f = 1;          // escape flag, zero means end of this sequence
	            while (true) {
	                ss = "";        // local str to parse as int
	                    for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
	                        sss = str.charAt(++i);
	                        if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
	                            ss += sss;      // if hex, add the hex character
	                        } else {--i; break;}    // not a hex char., exit the loop
	                    }
	                n = parseInt(ss, 16);           // parse the hex str as byte
	                if (n <= 0x7f){u = n; f = 1;}   // single byte format
	                if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
	                if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
	                if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
	                if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
	                if (f <= 1){break;}         // end of the utf byte sequence
	                if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
	                else {break;}                   // abnormal, format error
	            }
	        s0 += String.fromCharCode(u);           // add the escaped character
	        }
	    }
	}
	return s0;
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
	alert("encode64")
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      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;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
	   var output = "";
	   var chr1, chr2, chr3;
	   var enc1, enc2, enc3, enc4;
	   var i = 0;

	   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	   do {
	      enc1 = keyStr.indexOf(input.charAt(i++));
	      enc2 = keyStr.indexOf(input.charAt(i++));
	      enc3 = keyStr.indexOf(input.charAt(i++));
	      enc4 = keyStr.indexOf(input.charAt(i++));

	      chr1 = (enc1 << 2) | (enc2 >> 4);
	      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	      chr3 = ((enc3 & 3) << 6) | enc4;

	      output = output + String.fromCharCode(chr1);

	      if (enc3 != 64) {
	         output = output + String.fromCharCode(chr2);
	      }
	      if (enc4 != 64) {
	         output = output + String.fromCharCode(chr3);
	      }
	   } while (i < input.length);

	   return output;
	}
function encode64Han(str) {
  return encode64(escape(str))
}
function decode64Han(str) {
  return unescape(decode64(str))
}


/************************************************
 * 폼내용을 URLEncode로 엔코드
 * 2008-10-02 김진혁
 *************************************************/
function formEncodeURL(form){
	alert('formEncodeURL')
	 for(i=0; i < form.length; i++) {
		 if (form.elements[i].type!="select") {
			 form.elements[i].value=encode64(form.elements[i].value);
			 alert(form.elements[i].value)
		 }else{
			 var size= form.elements[i].length;
			 for(ii=0;ii<size;ii++){
				 form.elements[i].options[i].value=encode64(form.elements[i].options[i].value);
				 alert(form.elements[i].value)
			 }
		 }
	 }
}

/************************************************
* 폼내용을 URLDecode로 디코드
* 2008-10-02 김진혁
 *************************************************/
function formDecodeURL(form){
	 for(i=0; i < form.length; i++) {
		 if (form.elements[i].type!="select") {
			 form.elements[i].value=decodeURL(form.elements[i].value);
		 }else{
			 var size= form.elements[i].length;
			 for(ii=0;ii<size;ii++){
				 form.elements[i].options[i].value=decodeURL(form.elements[i].options[i].value);
			 }
		 }
	 }
}

/* 숫자면 True*/
function isNum(num){
	x=num.length;
	for(i=0;i<x;i++){
		s=num.substring(i,i+1)
		if(s <'0' || s > '9') return false;
	}
	return true;
}
/************************************************
 *TextField나 TextArea 필드를 인자로 받으며 해당 필드의 Byte를 반환한다.
 *2008-10-02 김진혁
 *********************************************/
function getByte(obj)
{
	var byteSize = 0;
	var retValue = "";
	var aa = 0;
   
	if ( obj == null ) {
		return 0;
	} else {
		for( var i = 0; i < obj.length; i++ ) {
			var chr = escape(obj.charAt(i));		
			if ( chr.length == 1 ) {					
				byteSize ++;
				retValue += obj.charAt(i);
			} else if ( chr.indexOf("%u") != -1 ) {		
				byteSize += 2;
			} else if ( chr.indexOf("%") != -1 ) {		
				byteSize += chr.length/3;
				retValue += obj.charAt(i);
			}
		}
	}
			
	return byteSize;
}
/************************************
 * FORM FIELD를 받아 크기제한을 Byte로 체크 한다.
 * 2008-10-02 김진혁
 * ******************************/
function chkField(field,limit_min, limit_max){
	var msg="";
	//alert(typeof(field.rel)+"()"+typeof(field.title));
	//alert(typeof(field.rel) == 'string');
	if(typeof(field.rel)=='string') msg=field.rel;
	if(msg == ''){
		if(typeof(field.title)=='string') msg=field.title;
	}
	if(getByte(field.value.trim())==0){
		alert(msg+"을(를) 입력해주세요!");
		field.focus()
		return false;
	}
	len=getByte(field.value.trim());
	if(len<limit_min || len>limit_max){
		if(limit_min==limit_max){
			alert(msg+"은(는)\n\n"+limit_min+"자로 입력하셔야 합니다.");	
		}else{
			alert(msg+"은(는)\n\n"+limit_min+"자 이상 "+limit_max+"자 미만으로 입력하셔야 합니다.");
		}
		field.focus()
		return false;
	}
	return true;
}
function chkField1(field,limit_min, limit_max,msg){
	if(getByte(field.value.trim())==0){
		alert(msg+"을(를) 입력해주세요!");
		field.focus()
		return false;
	}
	len=getByte(field.value.trim());
	if(len<limit_min || len>limit_max){
		if(limit_min==limit_max){
			alert(msg+"은(는)\n\n"+limit_min+"자로 입력하셔야 합니다.");	
		}else{
			alert(msg+"은(는)\n\n"+limit_min+"자 이상 "+limit_max+"자 미만으로 입력하셔야 합니다.");
		}
		field.focus()
		return false;
	}
	return true;
}

function chkNumField(field,limit_min, limit_max){
	var msg="";
	//alert(typeof(field.rel)+"()"+typeof(field.title));
	if(typeof(field.rel)=='string') msg=field.rel;
	if(typeof(field.title)=='string') msg=field.title;
	if(getByte(field.value.trim())==0){
		alert(msg+"을(를) 입력해주세요!");
		field.focus()
		return false;
	}
	if(!isNum(field.value)){
		alert(msg+"은(는) 숫자만 입력가능합니다.")
		field.focus()
		return false;
	}
	if(field.value.length<limit_min || field.value.length>limit_max){
		if(limit_min==limit_max){
			alert(msg+"은(는)\n\n"+limit_min+"자로 입력하셔야 합니다.");	
		}else{
			alert(msg+"은(는)\n\n"+limit_min+"자 이상 "+limit_max+"자 미만으로 입력하셔야 합니다.");
		}
		field.focus()
		return false;
	}
	return true;
}
function chkNumField1(field,limit_min, limit_max,msg){
	if(getByte(field.value.trim())==0){
		alert(msg+"을(를) 입력해주세요!");
		field.focus()
		return false;
	}
	if(!isNum(field.value)){
		alert(msg+"은(는) 숫자만 입력가능합니다.")
		field.focus()
		return false;
	}
	if(field.value.length<limit_min || field.value.length>limit_max){
		if(limit_min==limit_max){
			alert(msg+"은(는)\n\n"+limit_min+"자로 입력하셔야 합니다.");	
		}else{
			alert(msg+"은(는)\n\n"+limit_min+"자 이상 "+limit_max+"자 미만으로 입력하셔야 합니다.");
		}
		field.focus()
		return false;
	}
	return true;
}

/**
* textarea 박스의 글자수를 체크한다.
* 사용법
* <form method='post' name='form'>
* <textarea name='smsMsg' value='' onkeyup="lengthWordCount(this, 80)" onchange="lengthWordCount(this, 80)" onfocus="lengthWordCount(this, 80)"  cols=16 rows=5></textarea><br>
* <span id='smsMsgCount'>0</span> 자 (80자까지 입력가능합니다.)
* </form>
* 표시될 글자수의  name (sapn의 name)은 textarea name + 'Count' 임
*
**/
function lengthWordCount(filed, max_count){
	//var str;
	var str_count = 0;
	var cut_count = 0;
	var str_length = filed.value.length;

	for(k=0; k < str_length; k++){
		//str = filed.value.charAt(k);
	    str_count++;

	    if(max_count < str_count){
	    	alert("입력은 최대 "+ max_count +"자로 입력하셔야 합니다.");
	    	str_count--;
		    filed.value = filed.value.substring(0,k);
		    break;
	    }
	}
	try{
		document.getElementById(filed.name+"Count").innerHTML = str_count;
	}catch(e){}
}

/************************************
 * 라디오버튼 필드 혹은 체크박스 필드의 선택된 값을 반환한다.
 * 2008-10-02 김진혁
 * ******************************/
function getVal(obj){
	if(obj==undefined){
		alert('객체가 잘못 되었습니다.')
		return "";
	}else{
		var len=obj.length;
		if(len!=0 && obj.length!=undefined){	
			for(i=0;i<len;i++){
				if(obj[i].checked){
					return obj[i].value;
				}
			}
			return "";
		}else{
			if(obj.checked){
				return obj.value;
			}else{
				return "";
			}
		}
	}
	return "";
}

/************************************
 * 셀렉트 박스의 선택된 값을 반환한다.
 * 2008-10-02 김진혁
 * ******************************/
function getSelVal(obj){
	if(obj==undefined){
		alert('객체가 잘못 되었습니다.')
		return "";
	}
	var val=obj.options[obj.selectedIndex].value;
	return val;
}

/************************************
 * 탭게시판 형식의 스크립트
 * 2008-10-02 김진혁
 * ******************************/
function BlockMenu(total_count, menu_name) {
	for(i=1;i<=total_count;i++){
		thiMenu = eval("document.getElementById('" + menu_name+digit2(i) + "').style");
	 	thiMenu.display = "none"
	}
}
/************************************
 * 현재 선택된 메뉴 번호, 총 메뉴, 숫자를 제외한 메뉴이름
 * 2008-10-02 김진혁
 * ******************************/
function toggleMenu(current_no, total_count, menu_name) {
	 BlockMenu(total_count, menu_name);
	 thiMenu = eval("document.getElementById('" + menu_name+digit2(current_no) + "').style");
	 thiMenu.display = "block"
}
/************************************
 * 숫자를 01, 02
 * 2008-10-02 김진혁
 * ******************************/
function digit2(num){
	if(num<10){
		return "0"+num;
	}else{
		return num;
	}
}

/************************************************
 * 날짜 차이를 구한다.
 *************************************************/ 
/*날짜 차이 구하기*/
function datediff(first,second){
	first=first.split("-").join("");
	first=first.split("/").join("");
	first=first.split(".").join("");
	second=second.split("-").join("");
	second=second.split("/").join("");
	second=second.split(".").join("");

	first=first.substring(0,8);
	second=second.substring(0,8);
	
	firstYear=first.substring(0,4);
	firstMonth=first.substring(4,6);
	firstDay=first.substring(6,8);
	
	secondYear=second.substring(0,4);
	secondMonth=second.substring(4,6);
	secondDay=second.substring(6,8);
	
	
	var nowTime = Date.UTC(firstYear, firstMonth-1, firstDay);  
	var thenTime = Date.UTC(secondYear, secondMonth-1, secondDay);
	var moFlag = 0;
	var dyFlag = 0;

	if (isNaN(firstYear) || isNaN(firstMonth) || isNaN(firstDay) || isNaN(secondYear) || isNaN(secondMonth) || isNaN(secondDay)) {
		window.alert("유효한 날짜가 아닙니다.");
		return -101010;
	}
	if (firstDay<1 || firstDay>31 || secondDay<1 || secondDay>31) {
		window.alert("유효한 날짜가 아닙니다.");
		return -101010;
	} else {
		dyFlag=1;
	}
	//alert(first+"]]]]]"+firstDay+"=="+firstMonth+"==")
	if (firstDay>30 && (firstMonth == 2 || firstMonth==4 || firstMonth==6 || firstMonth==9 || firstMonth==11)) {
		window.alert("유효한 날짜가 아닙니다.");
		return -101010;
	} else {
		dyFlag=1;
	}
	if (secondDay>30 && (secondMonth == 2 || secondMonth==4 || secondMonth==6 || secondMonth==9 || secondMonth==11)) {
		window.alert("유효한 날짜가 아닙니다");
		return -101010;
	} else {
		dyFlag=1;
	}
	if (firstDay>29 && firstMonth==2) {
		window.alert("유효한 날짜가 아닙니다");
		return -101010;
	} else {
		dyFlag=1;
	}
	if (firstMonth<1 || firstMonth>12 || secondMonth<1 || secondMonth>12) {
		window.alert("유효한 날짜가 아닙니다");
		return -101010;
	} else {
		moFlag=1;
	}
	return (thenTime-nowTime)/(3600000*24)
	
}

// 지정한 문자열왼쪽에 지정한 길이만큼 지정한 문자로 채운다. 지정한 문자가 없으면 공백
function leftPad(str, char, len){
	
  if (!char) {
	  char = " ";
  }
  
  var strFill = "";
  var i;
  if (str.length < len){
    for (i=0;i<(len - str.length);i++){
      strFill = strFill + char;
    }
  }
  strFill = strFill + str;
  return strFill;
}

//지정한 날짜로부터 몇일 후의 날짜를 반환하기
function addDate(dateStr, iDay)
{
	var offDate = null;
	
	if (dateStr && dateStr.length == 8) {
		
		var year = dateStr.substring(0, 4);
		var month = dateStr.substring(4, 6) - 1;
		var day = dateStr.substring(6, 8);
		
		var dateTmp = new Date(year, month, day);
		
		var oDate; // 리턴할 날짜 객체 선언
		
		var dd = dateTmp.getTime() + 1000*3600*24 * iDay; // 날짜 계산
	
		oDate = new Date(); // 계산된 날짜 객체 생성
		oDate.setTime(dd);
																// (객체에서 자동 계산)
		offDate = leftPad(String(oDate.getYear()),"0", 4)
				+ leftPad(String(oDate.getMonth() + 1),"0", 2)
				+ leftPad(String(oDate.getDate()),"0", 2);

	}
	
	return offDate;
}

//AJAX를 호출한다.
function callAjax(url,frmName,method,val){
	var param = "";
	if(frmName!=''){
		param=Form.serialize($(frmName));
	}
	try{
	   new Ajax.Request(url,
			            { method:'POST',
			              parameters:param,
			              onComplete : function(objAjax) {
						    	if( objAjax.readyState == 4 && objAjax.status == 200 ) { //--서버 처리 종료, 성공적인 처리
									msg=objAjax.responseText
						    		eval(val+"=msg;");
									
						    		eval(method);
						    		return msg;
								} else {
									Ext.MessageBox.alert('알림', '서버와의 통신이 원할하지 않습니다.\n다시 시도해 주십시오.');
									return "fail";
								}
									            			
							}
			            }
	   );//Ajax.Update	
	}catch(e){
		return "fail";
		//window.setTimeout(dataNext, 1000);
	}
}

//체크 박스 전체 선택.
var allChk=false;
function selAll(checkBox){
	allChk=allChk?false:true;
	if(checkBox!=undefined){
		if(checkBox.length!=undefined){
			for(i=0;i<checkBox.length;i++){
				checkBox[i].checked=allChk;
			}
		}else{
			checkBox.checked=allChk;
		}
	}	
}

//replaceAll 메소드
function replaceAll(str, oldStr, repStr){
	return str.split(oldStr).join(repStr);
}

// textarea 객체를 배열로 반환한다.
function getTextareas(form, name) {
    form = $(form);
    var inputs = form.getElementsByTagName('textarea');

    if (!name) return $A(inputs).map(Element.extend);

    for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
      var input = inputs[i];
      if ((name && input.name != name))
        continue;
      matchingInputs.push(Element.extend(input));
    }

    return matchingInputs;
  }
