/**
 * 입력 객체가 실제로 페이지상에 존재하는 HTML객체인지를 검사한다.
 *
 * @param obj	객체 ID
 * @return
 */
function isObject(obj)
{
	if(typeof(obj) != "object")
	{
		window.alert("객체가 존재하지 않습니다. 객체의 철자를 확인하세요.");
		return false;
	}

	return true;
}

﻿/**
 * 입력 객체의 값이 널(null)인지를 검사한다.
 *
 * @param obj	객체 ID
 * @return
 */
function isNull(obj)
{
	var str = trimString(obj.value);
	var msg = trimString(obj.alt);

	if(strlen(str) == 0)
	{
		if(msg)
		{
			window.alert(msg + "을(를) 입력하세요.");
			obj.value = str;
			obj.focus();
		}

		return true;
	}

	if(msg)
	{
		obj.value = str;
	}

	return false;
}

/*
 * 입력값에 공백문자가 있는지 체크 - 이름, 비밀번호
 * Parameter : value
 * Return : true / false
 */
 function custsay_check(objValue){

  var sp = /\s/;		// 공백문자

	  if (sp.exec(objValue) || objValue == "") {
		return true;
	  }
	  return false;
 }

/*
 * 입력값에 스페이스 이외의 의미있는 값이 있는지 체크
 * Parameter : value
 * Return : true / false
 */
function isEmpty(objValue)
{
    if(objValue == null || objValue.replace(/ /gi,"") == "")
        return true;

	return false;
}

/*
 * 입력값의 한글여부 체크
 * Parameter : value
 * Return : true / false
 */
function isKorean(str)
{


	for(i=0; i<str.length; i++)	 {
	  	if(!((str.charCodeAt(i) > 0x3130 && str.charCodeAt(i) < 0x318F) || (str.charCodeAt(i) >= 0xAC00 && str.charCodeAt(i) <= 0xD7A3))){
	   		return false;
	  	}
	  	else{

	  	}
	}
	return true;
}

function isKoreanAlphaNum(str){
	for(i=0; i<str.length; i++)	 {
	  	if(!((str.charCodeAt(i) > 0x3130 && str.charCodeAt(i) < 0x318F) || (str.charCodeAt(i) >= 0xAC00 && str.charCodeAt(i) <= 0xD7A3)
	  			|| isAlphaNum(str.charAt(i)) )){
	   		return false;
	  	}
	  	else{

	  	}
	}
	return true;
}
/**
 * 입력 객체의 바이트단위의 길이를 구한다.
 *
 * @param obj	객체 ID
 * @return
 */
function strlen(str)
{
	var j = 0;
	for(var i=0; i<str.length; i++)
	{
		if(escape(str.charAt(i)).length == 6)
			j++;
		j++;
	}

	return(j);
}


/**
 * 객체의 값이 주민번호에 적합한지 검사한다.
 *
 * @param obj1	객체1
 * @return
 */
function isResident(idnNo)	{
		var	strReturned;
		var	strInput;
		var	sum;
		var	mod;

		strInput = trimString(idnNo);
		var yy  = strInput.substring(0,2);
		var mm  = strInput.substring(2,4);
		var dd  =strInput.substring(4,6);
		var sex = strInput.substring(6,7);
		if(mm < 1 || mm > 12 || dd < 1 || dd > 31) {
			return false;
		}
		if(sex != 1 && sex != 2 && sex != 3 && sex != 4) {
			return false;
		}


		for(var i = 0, sum = 0;i<12;i++){
			sum += parseInt(strInput.charAt(i)) * ((i >7) ? (i - 6) : (i + 2));
		}


		mod = 11 - (sum % 11);

		if(mod >= 10) mod -= 10;

		if(mod != strInput.charAt(12)){
			return false;
		}

		return true;
}

/**
 * 객체의 값이 외국인 번호에 적합한지 검사한다.
 *
 * @param obj1	f.x.value
 * @return
 */
function isForeignJumin(fgn_reg_no) {

	if ((fgn_reg_no.charAt(6) == "5") || (fgn_reg_no.charAt(6) == "6")) {
		birthYear = "19";
	} else if ((fgn_reg_no.charAt(6) == "7") || (fgn_reg_no.charAt(6) == "8")) {
		birthYear = "20";
	} else if ((fgn_reg_no.charAt(6) == "9") || (fgn_reg_no.charAt(6) == "0")) {
		birthYear = "18";
	} else {
        return false;
	}

	birthYear += fgn_reg_no.substr(0, 2);
	birthMonth = fgn_reg_no.substr(2, 2) - 1;
	birthDate = fgn_reg_no.substr(4, 2);
	birth = new Date(birthYear, birthMonth, birthDate);

	if ( birth.getFullYear() % 100 != fgn_reg_no.substr(0, 2) || birth.getMonth() != birthMonth || birth.getDate() != birthDate) {
		return false;
	}

	if (fgn_no_chksum(fgn_reg_no) == false) {
        return false;
	} else {
		return true;
	}
}


function fgn_no_chksum(reg_no) {
    var sum = 0;
    var odd = 0;

    buf = new Array(13);
    for (i = 0; i < 13; i++) buf[i] = parseInt(reg_no.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;
    }
}
/*
 *
 * 만나이를 계산하여 14세 이상이면 true, 미만이면 false 반환
 *
 */
 function fnGetAge(idn) {

	if ((idn.charAt(6) == "1") || (idn.charAt(6) == "2")) {
		birthYear = "19";
	} else if ((idn.charAt(6) == "3") || (idn.charAt(6) == "4")) {
		birthYear = "20";
	}  else {
        return false;
	}
	birthYear += idn.substr(0, 2);
	birthMonth = idn.substr(2, 2);
	birthDate = idn.substr(4, 2);

	now = new Date();
	nowAge = now.getFullYear() - birthYear;
	//alert("birthYear:"+birthYear+"birthMonth:"+birthMonth+"birthDate:"+birthDate+"nowAge:"+nowAge);


	if(nowAge <= 0 ) {
		result = 0;
	}else {
		if((now.getMonth()+1) > birthMonth) {
			result = nowAge;
		}else if((now.getMonth()+1) == birthMonth) {
			if((now.getDate()) >= birthDate) {
				result = nowAge;
			}else{
				result = nowAge - 1;
			}
		}else if((now.getMonth()+1) < birthMonth) {
			result = nowAge - 1;
		}

	}
	if(result > 13)	{
		return true;
	}else{
		return false;// 14세 미만
	}
}

/*
 * 에러 메시지 처리 후 포커스를 넘김
 * Parameter : object, message
 */
function ErrMsg(obj, msg)
{
	alert(msg);
	obj.select();
	obj.focus();
}
/**
 * 입력값이 특정 문자(chars)만으로 되어있는지 체크 (String값을 체크한다.)
 * 특정 문자만 허용하려 할 때 사용
 * ex) if (!containsCharsOnly(form.blood.value ,"ABO"))
 *     {
 *         alert("혈액형 필드에는 A,B,O 문자만 사용할 수 있습니다.");
 *     }
 * Parameter : value, chars
 * Return : true / false
 */
function containsCharsOnly(objValue, chars)
{
    for (inx=0; inx<objValue.length; inx++)
	{
       if (chars.indexOf(objValue.charAt(inx)) == -1)
	   return false;
    }
    return true;
}

/**
 * 입력값에 특정 문자(chars)가 들어있는지 체크 (String값을 체크한다.)
 * 특정 문자만 거부하려 할 때 사용
 * ex) if (containsChars(form.blood.value ,"'%_"))
 *     {
 *         alert("검색 필드에는 ', %, _ 문자를 사용할 수 없습니다.");
 *     }
 * Parameter : value, chars
 * Return : true  - ', %, _ 문자가 들어 있는 경우
 *          false - ', %, _ 문자가 없는 경우
 */
function containsChars(objValue, chars)
{
    for (inx=0; inx<objValue.length; inx++)
	{
       if (chars.indexOf(objValue.charAt(inx)) != -1)
	   	return true;
    }
    return false;
}

/**
 *	공백문자 제거
 *
 */
function trimString(inString) {
/*
	var str = inString;
	str.replace(/(^\s*)|(\s*$)/g,"");
	return str;
*/

	var outString;
	var startPos;
	var endPos;
	var ch;

	// where do we start?
	startPos = 0;
	ch = inString.charAt(startPos);
	while ((ch == " ") || (ch == "\b") || (ch == "\f") || (ch == "\n") || (ch == "\r") || (ch == "\n"))
    {
		startPos++;
		ch = inString.charAt(startPos);
	}

	// where do we end?
	endPos = inString.length - 1;
	ch = inString.charAt(endPos);
	while ((ch == " ") || (ch == "\b") || (ch == "\f") || (ch == "\n") || (ch == "\r") || (ch == "\n"))
    {
		endPos--;
		ch = inString.charAt(endPos);
	}

	// get the string
	outString = inString.substring(startPos, endPos + 1);

	return outString;
}

/*   js_tab_order        :   입력필드에 입력이 끝나면 자동으로 focus이동
 *                           (입력필드의 onkeyup event에 사용할것)
 *          js_tab_order("1","2","3")
 *          --> 1: Input Box object
 *              2: focus를 이동시킬 object name
 *              3: focus 이동위해 1번 object에 입력되어야 할 자리수
 */
function js_tab_order(arg,nextname,len) {
  if (arg.value.length == len) {
      nextname.focus() ;
      return;
  }
}
//
/*
 * isInteger	: 숫자와 길이 체크
 *
 */
	function isInteger(st,maxLength)	{
		if (st.length == maxLength) {
			for (j=0; j < maxLength ;j++){
				if ((st.substring(j, j+1) < "0") || (st.substring(j, j+1) > "9"))
					return false;
			}
		}else {
			  return false;
		}
		 return true;
	}
/*
 * businChk	: 사업자 번호 체크
 *
 */
	function businChk(obj1, obj2, obj3) {
		 var frm=document.f;
		 var strCk1=obj1.value;
		 var strCk2=obj2.value;
		 var strCk3=obj3.value;
		 var arrCkValue = new Array(10);

		  arrCkValue[0] = ( parseFloat(strCk1.substring(0 ,1))  * 1 ) % 10;
		  arrCkValue[1] = ( parseFloat(strCk1.substring(1 ,2))  * 3 ) % 10;
		  arrCkValue[2] = ( parseFloat(strCk1.substring(2 ,3))  * 7 ) % 10;
		  arrCkValue[3] = ( parseFloat(strCk2.substring(0 ,1))  * 1 ) % 10;
		  arrCkValue[4] = ( parseFloat(strCk2.substring(1 ,2))  * 3 ) % 10;
		  arrCkValue[5] = ( parseFloat(strCk3.substring(0 ,1))  * 7 ) % 10;
		  arrCkValue[6] = ( parseFloat(strCk3.substring(1 ,2))  * 1 ) % 10;
		  arrCkValue[7] = ( parseFloat(strCk3.substring(2 ,3))  * 3 ) % 10;
		  intCkTemp     = parseFloat(strCk3.substring(3 ,4))  * 5  + "0";
		  arrCkValue[8] = parseFloat(intCkTemp.substring(0,1)) + parseFloat(intCkTemp.substring(1,2));
		  arrCkValue[9] = parseFloat(strCk3.substring(4,5));
		  intCkLastid = ( 10 - ( ( arrCkValue[0]+arrCkValue[1]+arrCkValue[2]+arrCkValue[3]+arrCkValue[4]+arrCkValue[5]+arrCkValue[6]+arrCkValue[7]+arrCkValue[8] ) % 10 ) ) % 10;
		if (arrCkValue[9] != intCkLastid) {	//유효하지 않음
			  strCk1="";
			  strCk2="";
			  strCk3="";
			  obj1.focus();
			  return false;
		}
		else {	// 유효한 사업자번호
		 	return true;
		 }
	}
/*
 * corpCheck	: 법인 번호 체크
 *
 */
	function corpCheck(obj1, obj2){
		var cn1 = obj1;
		var cn2 = obj2;
		var con1 , con2, con3, con4, con5, con6, con7, con8, con9, con10, con11, con12, con13;
		var sum, rem, end ;

		con1 = cn1.substring(0,1) * 1;
		 con2 = cn1.substring(1,2) * 2;
		 con3 = cn1.substring(2,3) * 1;
		 con4 = cn1.substring(3,4) * 2;
		 con5 = cn1.substring(4,5) * 1;
		 con6 = cn1.substring(5,6) * 2;
		 con7 = cn2.substring(0,1) * 1;
		 con8 = cn2.substring(1,2) * 2;
		 con9 = cn2.substring(2,3) * 1;
		 con10 = cn2.substring(3,4) * 2;
		 con11 = cn2.substring(4,5) * 1;
		 con12 = cn2.substring(5,6) * 2;
		 con13 = cn2.substring(6,7);

		 sum = con1 + con2 + con3 + con4 + con5 + con6 + con7 + con8 + con9  + con10 + con11 + con12;

		rem = sum % 10;

		if (end != 0){
			end = 10 - rem;
		}

		if ( end == con13) {
			return true;
		}else{
			return false;
		}

	}
/*
 * validEmail	: 이메일 유효성 검사
 *
 */
function validEmail(strMail) {

	var dotPos = strMail.split("@")
	if ( dotPos[1] != null && ( dotPos[1].toUpperCase() == 'DAUM.NET' || dotPos[1].toUpperCase() == 'HANMAIL.NET'))	{
		alert("한메일은 사용하실 수 없습니다. ");
		return false;
	}
	if ( dotPos[1].toUpperCase() == 'HOTMAIL.COM'){
		alert("HotMail은 사용하실 수 없습니다. ");
		return false;
	}


	var check1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var check2 = /^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4})$/;
	if( strMail.length !="") {
		if ( !check1.test(strMail) && check2.test(strMail) ) {
			return true;
		}else {
			//alert("이메일 형식이 잘못되었습니다.");
			alert("메일 전송가능한 주소로 정확하게 기입해 주십시오.");

			return false;
		}
	}


}

/**
* 입력값이 알파벳인지 체크
* 아래 isAlphabet() 부터 isNumComma()까지의 메소드가
* 자주 쓰이는 경우에는 var chars 변수를
* global 변수로 선언하고 사용하도록 한다.
* ex) var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
*     var lowercase = "abcdefghijklmnopqrstuvwxyz";
*     var number    = "0123456789";
*     function isAlphaNum(input) {
*         var chars = uppercase + lowercase + number;
*         return containsCharsOnly(input,chars);
*     }
*/
function isAlphabet(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}

/**
* 입력값이 알파벳 대문자인지 체크
*/
function isUpperCase(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    return containsCharsOnly(input,chars);
}

/**
* 입력값이 알파벳 소문자인지 체크
*/
function isLowerCase(input) {
    var chars = "abcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}

/**
* 입력값에 숫자만 있는지 체크
*/
function isNumber(input) {
    var chars = "0123456789";
    return containsCharsOnly(input,chars);
}

/**
* 입력값이 알파벳,숫자로 되어있는지 체크 - 비밀번호
*/
function isAlphaNum(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    return containsCharsOnly(input,chars);
}

/**
* 입력값이 숫자,대시(-)로 되어있는지 체크
*/
function isNumDash(input) {
    var chars = "-0123456789";
    return containsCharsOnly(input,chars);
}
/**
* 입력값이 숫자,언더바(_),대시(-)로 되어있는지 체크 - 이메일
*/
function isNumDashUnder(input) {
    var chars = "_0123456789";
    return containsCharsOnly(input,chars);
}
/**
* 입력값이 숫자,콤마(,)로 되어있는지 체크
*/
function isNumComma(input) {
    var chars = ",0123456789";
    return containsCharsOnly(input,chars);
}

/**
* 입력값의 바이트 길이를 리턴
* ex) if (getByteLength(form.title) > 100) {
*         alert("제목은 한글 50자(영문 100자) 이상 입력할 수 없습니다.");
*     }
*
*/
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;
}
/*
 * <input type="text" onkeyup="fnCheckByte(this,12);">
 * function fnCheckByte(obj,length){
		var msg =  "한글은 최대 "+length/2 +"글자, 영문/숫자는 최대 "+ length + "글자까지 사용 가능합니다. \n초과된 내용은 자동으로 삭제 됩니다. "
		fnChkByte(obj,length,msg);
	}
 *
 */
function fnChkByte(aro_name,ari_max,msg){

		var ls_str = aro_name.value; // 이벤트가 일어난 컨트롤의 value 값
		var li_str_len = ls_str.length; // 전체길이

		// 변수초기화
		var li_max = ari_max; // 제한할 글자수 크기
		var i = 0; // for문에 사용
		var li_byte = 0; // 한글일경우는 2 그밗에는 1을 더함
		var li_len = 0; // substring하기 위해서 사용
		var ls_one_char = ""; // 한글자씩 검사한다
		var ls_str2 = ""; // 글자수를 초과하면 제한할수 글자전까지만 보여준다.

		for(i=0; i< li_str_len; i++){
			// 한글자추출
			ls_one_char = ls_str.charAt(i);

			// 한글이면 2를 더한다.
			if (escape(ls_one_char).length > 4)	{
				li_byte += 2;
			}
			// 그밗의 경우는 1을 더한다.
			else{
				li_byte++;
			}

			// 전체 크기가 li_max를 넘지않으면
			if(li_byte <= li_max){
				li_len = i + 1;
			}
		}

		// 전체길이를 초과하면
		if(li_byte > li_max){
			alert( msg);
			ls_str2 = ls_str.substr(0, li_len);
			aro_name.value = ls_str2;
		}

		aro_name.focus();
	}

/*
 *
 fnCheckLength = function(obj,length){
	var msg =  "최대 "+ length + "글자까지 사용 가능합니다. \n초과된 내용은 자동으로 삭제 됩니다. ";
	fnChkLength(obj,length,msg);
}
*/
function fnChkLength (aro_name,ari_max,msg){

	var ls_str = aro_name.value; // 이벤트가 일어난 컨트롤의 value 값
	var li_str_len = ls_str.length; // 전체길이
	// 변수초기화
	var li_max = ari_max; // 제한할 글자수 크기
	var i = 0; // for문에 사용
	var li_byte = 0;
	var li_len = 0; // substring하기 위해서 사용
	var ls_one_char = ""; // 한글자씩 검사한다
	var ls_str2 = ""; // 글자수를 초과하면 제한할수 글자전까지만 보여준다.

	for(i=0; i< li_str_len; i++){
		// 한글자
		li_byte++;

		// 전체 크기가 li_max를 넘지않으면
		if(li_byte <= li_max){
			li_len = i + 1;
		}
	}

	// 전체길이를 초과하면
	if(li_byte > li_max){
		alert( msg);
		ls_str2 = ls_str.substr(0, li_len);
		aro_name.value = ls_str2;
	}
	aro_name.focus();
}

/**
* 선택된 라디오버튼이 있는지 체크
*/
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;
}

/**
* 선택된 체크박스가 있는지 체크
*/
function hasCheckedBox(input) {
    return hasCheckedRadio(input);
}

/**
* 라디오 버튼 값 읽어오기
*/
function radioValue(obj) {
    var ret = ""
    for (i=0; i< obj.length; i++)
    {
        if (obj[i].checked == true)
        {
            ret = obj[i].value;
            return ret;
        }
    }
}

/**
* 입력값에서 콤마를 없앤다.
*/
function fnNumCommaD(input){
	    var num=new String(input.value);
	    num=num.replace(/,/gi,"");
	    input.value=num;
	    return num;
}

/**
 *	100,000 식의 쉼표 단위 붙이기
 *
 */
function makeComma(num)
{
	if (num < 0) { num *= -1; var minus = true}
	else var minus = false

	var dotPos = (num+"").split(".")
	var dotU = dotPos[0]
	var dotD = dotPos[1]
	var commaFlag = dotU.length%3

	if(commaFlag) {
		var out = dotU.substring(0, commaFlag)
		if (dotU.length > 3) out += ","
	}
	else var out = ""

	for (var i=commaFlag; i < dotU.length; i+=3) {
		out += dotU.substring(i, i+3)
		if( i < dotU.length-3) out += ","
	}

	if(minus) out = "-" + out
	if(dotD) return out + "." + dotD
	else return out
}
/*
 * 윈도우의 중앙에 Popup창을 연다
 * Parameter :
 */
function openWindow(url, width, height, scroll)
{
	var winx = (screen.width - width ) / 2;
	var winy = (screen.height- height) / 2;
	var settings  = "height=    " +height+", ";
		settings += "width=     " +width +", ";
		settings += "top=       " +winy  +", ";
		settings += "left=      " +winx  +", ";
		settings += "scrollbars=" +scroll+", ";
		settings += "resizable =no";

	win = window.open(url, "", settings);

	return win;
}

/*
 * 윈도우의 중앙에 Modal Popup창을 연다
 * Parameter :
 */
function openModal(url, arguments, width, height, scroll)
{
	var winx = (screen.width - width ) / 2;
	var winy = (screen.height- height) / 2;
	var settings  = "dialogHeight:    " +height+"px; ";
		settings += "dialogWidth:     " +width +"px; ";
		settings += "dialogTop:       " +winy  +"px; ";
		settings += "dialogLeft:      " +winx  +"px; ";
		settings += "scroll    :" +scroll+"; ";
		settings += "resizable :no; ";
		settings += "help      :no; ";
		settings += "status    :no; ";
		//settings += "unadorned:yes";

	returnValue = showModalDialog(url, arguments, settings);

	return returnValue;
}
/**
 * 입력값의 크기를 검사한다.
 *
 * @param obj	객체 ID
 * @param min	최소 자리수
 * @param max	최대 자리수
 * @param msg	메세지
 * @return
 */
function isValidSize(obj, min, max, msg)
{
	if(!isObject(obj))
		return false;

	if(isNull(obj, msg))
		return false;

	var str = trim(obj.value);

	if(!(strlen(str) >= min && strlen(str) <= max))
	{
		if(msg)
		{
			if(min == max)
				window.alert(msg + "은(는) " + min +"자로 입력하세요.");
			else
				window.alert(msg + "은(는) 최소 " + min +"자, 최대 " + max + "자로 입력하세요.");

			obj.value = str;
			obj.focus();
		}

		return false;
	}

	if(msg)
	{
		obj.value = str;
	}

	return true;
}



/**
 * 두 객체의 값이 동일한지 검사한다.
 *
 * @param obj1	객체1 ID
 * @param obj2	객체2 ID
 * @param msg	객체 이름
 * @return
 */
function isSame(obj1, obj2, msg)
{
	if(!isObject(obj1))
		return false;
	if(!isObject(obj2))
		return false;

	if(isNull(obj1, msg))
		return false;
	if(isNull(obj2, msg))
		return false;

	var str1 = trimString(obj1.value);
	var str2 = trimString(obj2.value);

	if(str1 != str2)
	{
		if(msg)
		{
			window.alert(msg + "이(가) 일치하지 않습니다. 확인 후 다시 입력해 주세요.");
			obj1.value = "";
			obj2.value = "";
			obj1.focus();
		}

		return false;
	}

	if(msg)
	{
		obj1.value = str1;
		obj2.value = str2;
	}

	return true;
}
/**
 * 객체의 값이 전화번호에 적합한지 검사한다.
 *
 * @param obj1	객체1 ID
 * @param obj2	객체2 ID
 * @param obj3	객체3 ID
 * @param msg	객체 이름
 * @return
 */
function isPhone(obj1, obj2, obj3)
{
	if(!isObject(obj1))
		return false;
	if(!isObject(obj2))
		return false;
	if(!isObject(obj3))
		return false;

	var str1 = trim(obj1.value);
	var str2 = trim(obj2.value);
	var str3 = trim(obj3.value);
	var msg = trim(obj1.alt);

	if(!isNumber(obj1, msg + "의 지역번호") || !isValidSize(obj1, 2, 3, msg + "의 지역번호"))
	{
		return false;
	}

	var ddd = ["02", "051", "053", "032", "062", "042", "052", "031", "033", "041", "043", "054", "055", "061", "063", "064"];

	var flag = false;
  	for(var i=0;i<ddd.length;i++)
	{
		if(ddd[i] == str1)
		{
			flag = true;
		}

	}

	if(!flag)
	{
		if(msg)
		{
			window.alert(msg + "의 지역번호가 유효하지 않습니다. 확인 후 다시 입력하세요.");
			obj1.focus();
		}

		return false;
	}

	if(!isNumber(obj2, msg + "의 국번호") || !isValidSize(obj2, 3, 4, msg + "의 국번호"))
	{
		return false;
	}

	if(!isNumber(obj3, msg + "의 뒷번호") || !isValidSize(obj3, 4, 4, msg + "의 뒷번호"))
	{
		return false;
	}

	return true;
}

/**
 * 정렬 함수
 * form:사용 form element, field:정렬할 db column, callback:조회를 수행할 함수
 */
function jsSort(form, field, callback) {
	if(form.s_field.value == field) {
		if(form.s_order.value == "DESC") {
			form.s_order.value = "ASC";
		} else {
			form.s_order.value = "DESC";
		}
	} else {
		form.s_field.value = field;
		form.s_order.value = "ASC";
	}
	eval(callback + "()");
}

/**
 * paging에서 사용하는 함수(공통)
 */
function jsGotoPage(callback, totalPage) {
	var obj = document.getElementById("g_gotopage");

	if(obj.value == "") {
		alert("페이지번호을(를) 입력하세요.");
		obj.focus();
		return;
	}
	if(isNumber(obj.value) == false) {
		alert("숫자만 입력하세요.");
		obj.focus();
		return;
	}

	var page = parseInt(obj.value);
	if(page < 1 || page > totalPage) {
		alert("유효한 페이지번호을(를) 입력하세요.");
		obj.focus();
		return;
	}

	eval(callback+"('"+page+"')");
}

/**
 * 엔터키 누름 여부를 체크하여 폼 전송
 */
function js_enter() {
	if(event.keyCode==13) {
		js_submit();
	}
}

/**
 * 파일 다운로드. path : 파일경로, name : 파일이름
 */
function jsDownload(path, name) {
	path = encodeURIComponent(path);
	name = encodeURIComponent(name);
	window.location = "/download.do?path="+path+"&name="+name;
}

/**
 * 페이징 Html 관리.
 * page:현재페이지,listSize:화면당건수,totCount:전체수,tagName:사용태그명,callback:콜백함수
 */
function jsPageNavigation(page, listSize, totCount, tagName, callback) {
	var pages = parseInt(totCount / listSize);
	if((totCount % listSize) != 0) {
		pages++;
	}

	var html = ""
		+ "<div class='page'>"
		+ "<div class='goto'>"
		+ "<img src='/common/images/admin/txt_goto.gif' alt='goto' />"
		+ " <input type='text' name='g_gotopage' class='txt' style='width:30px;' onkeydown=\"if(event.keyCode == 13) jsGotoPage('"+callback+"','"+pages+"');\">"
		+ " <a href=\"javascript:jsGotoPage('"+callback+"','"+pages+"')\"><img src='/common/images/admin/btn_go2.gif' alt='go' /></a>"
		+ "</div>"
		+ "<div class='number'>"
		+ "page"
		;

	if(page > 1) {
		html += " <a href=\"javascript:"+callback+"('"+(1)+"')\"><img src='/common/images/admin/page_frist.gif' alt='처음페이지' /></a>";
		html += " <a href=\"javascript:"+callback+"('"+(page-1)+"')\"><img src='/common/images/admin/page_prev.gif' alt='이전페이지' /></a>";
	}

	html += " <a href=\"javascript:"+callback+"('"+(page)+"')\" class='on'>"+page+"</a> / "+pages;

	if(page < pages) {
		html += " <a href=\"javascript:"+callback+"('"+(parseInt(page)+1)+"')\"><img src='/common/images/admin/page_next.gif' alt='다음페이지' /></a>";
		html += " <a href=\"javascript:"+callback+"('"+(pages)+"')\"><img src='/common/images/admin/page_end.gif' alt='마지막페이지' /></a>";
	}

	document.getElementById(tagName).innerHTML = html;
}




/*
 *
 * Login시 dimmed 처리
 *
 */

 /* 이벤트 핸들러부분 */
var ajax = {};
ajax.Event = {};
ajax.Event.addListener = function(element, name, observer, useCapture) {
    useCapture = useCapture || false;

	if (element.addEventListener) {
		element.addEventListener(name, observer, useCapture);
	} else if (element.attachEvent) {
		element.attachEvent('on' + name, observer);
	}
}

/* 투명도 계산해주는부분 */
ajax.GUI = {};
ajax.GUI.setOpacity = function(el, opacity) {
	if (el.filters) {
		el.style.filter = 'alpha(opacity=' + opacity * 100 + ')';
	} else {
		el.style.opacity = opacity;
	}
}

/* Dim 버튼눌렀을때 */
function dimload(width,height,layer_id) {
	var dim = document.getElementById("dim");
/* 브라우저 size구하기 */
	var x,y;

	/*
	if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		if(document.body.scrollHeight>66) {
			y = document.body.scrollHeight + 30;
		}else{
			y = document.documentElement.clientHeight;
		}

	}
	*/

	if (self.innerHeight) { // IE 외 모든 브라우저
	    x = self.innerWidth;
	    y = self.innerHeight;

	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict 모드
	    x = document.documentElement.clientWidth;
	    y = document.documentElement.clientHeight;

	}
	else if (document.body) { // 다른 IE 브라우저
	    x = document.body.clientWidth;
	    y = document.body.clientHeight;

	}

/* 새 레이어 위치 처리부분 */
	var layer_x = (x - width)/ 2
	var layer_y = (y - height)/ 2

/* 배경레이어 visible로 */
	dim.style.width = x+"px";
	dim.style.height = y+"px";
	dim.style.visibility = "visible";


/* 새 레이어 처리부분 */
	var layer = document.getElementById("layer");
	var tpl = "<iframe  id=\"ifrm_login\" src=\""+layer_id+"\" width=\""+width+"\" height=\""+height+"\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"></iframe>";
	layer.innerHTML = tpl;
	layer.style.width = width + "px";
	layer.style.height = height + "px";
	layer.style.left = layer_x + "px";
	layer.style.top = layer_y + "px";
	layer.style.visibility = "visible";

}

/* Dim 해제 버튼눌렀을때 */
function dimunload() {
	var dim = parent.document.getElementById("dim");
		dim.style.visibility = "hidden";
	var layer = parent.document.getElementById("layer");
		layer.style.visibility = "hidden";
}

/* 파일 업로드 확장자 제한(이미지 파일) */
function limitImageAttach(file) {

	var extArray = new Array(".gif", ".jpg", ".png");
	var result = false;

	if(!file) return;

	while (file.indexOf("\\") != -1) {
		file = file.slice(file.indexOf("\\") + 1);
	}

	ext = file.slice(file.indexOf(".")).toLowerCase();

	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) {
			result = true;
			break;
		}
	}

	return result;
}

/* limitImageAttach 메소드 콜백 함수 예시

	checkFileAttach(limitImageAttach(frm.file.value));

   	function checkFileAttach(result) {
		if(result) {
			frm.file_ck.value = "Y";
		} else {
			frm.file_ck.value = "N";
			alert("죄송합니다.\n\n업로드가 지원되는 파일형식은 jpg, gif, png입니다.\n\n파일형식을 확인해보시기 바랍니다.");
			frm.btn_file.focus();
		}
   	}
 */

/* 레이어를 중앙에 나타내기 */
var iframeShim = null;
function showDivCenter(div , drag) {
	var isDrag=true;

	var ly1=Ext.get(div);
	ly1.show();
	ly1.center();

	if(!drag){
		var sd=ly1.initDD();
	}

	/*
	if(iframeShim==null){
		var ss=ly1.createShim();
		iframeShim=Ext.get(ss);
		iframeShim.setStyle('z-index',2);
	}

	sd.onDrag=function(){
		iframeShim.setXY(ly1.getXY());
	}

	iframeShim.setRegion(ly1.getRegion());
	iframeShim.show();
	*/
}
/*로긴 */
function loginPop(num) {
 	var fn=function(){
		showDivCenter('loginPop',true);
	}

	Epigram.update('loginPop','/jsp/member/LoginP.jsp?errnum'+num,null,fn);
}
function hideLoginPop(){
	Ext.get('loginPop').hide();
	hideIframe();
}

function hideIframe(){
	if(Ext.isIE && !Ext.isIE7){
		try{
			iframeShim.hide();
		}catch(e){}
	}
}



/* 검색범위 선택시 액션 정의(팀웍 게시판에서 사용) */
function js_search_type(val) {

	if(frm.keyword.value != "") {
		js_search();
	} else {
		frm.keyword.focus();
	}
}

/* DIV 토글링 */
function div_switch(num_show, num_hidden){
	numshow(num_show);
	numhidden(num_hidden);
}

/* 미리보기 호출 */
function launchViewer(cKind,stylelogId,storyId,storyNo,pageSeq,source,gubun){
	// ActiveX 깔려 있는지 체크
	try{
		var xObj = new ActiveXObject("IGCREPOTLOADER.IGCrepotLoaderCtrl.1");
		if(xObj)
			Installed = true;//로컬뷰어 정상 작동할 때 (Installed = true;)로 수정 : 2007-11-07 / 15 : 22
		else
			Installed = false;
	}catch(ex){
		Installed = false;
	}
	if(Installed == true){
		// 로컬 뷰어 띄우자
		var param="loginId=&cKind="+cKind+"&stylelogId="+stylelogId+"&storyId="+storyId+"&vMode=local&storyNo="+storyNo+"&pageSeq="+pageSeq+"&source="+source+"&eKind=N&gubun="+gubun;
		var localLauncher = window.open("/common/flash/application/viewer/ex/viewerLauncher.html?"+param, "localLauncher", "status=no, scrollbars=no, width=470, height=310, resizable=no");

	}else{
		// 웹 뷰어 띄우자
		var url="/LaunchViewer.do"+
		"?cKind="+cKind+
		"&stylelogId="+stylelogId+
		"&storyId="+storyId+
		"&storyNo="+storyNo+
		"&pageSeq="+pageSeq+
		"&source="+source+
		"&gubun="+gubun;
		window.open(url, "", "status=no, scrollbars=no, width=1014, height=679, resizable=no");
	}
}

/* 미리보기 호출 */
function launchViewer2(cKind,stylelogId,storyId,storyNo,pageSeq,source,gubun){
	// ActiveX 깔려 있는지 체크
	try{
		var xObj = new ActiveXObject("IGCREPOTLOADER.IGCrepotLoaderCtrl.1");
		if(xObj)
			Installed = true;//로컬뷰어 정상 작동할 때 (Installed = true;)로 수정 : 2007-11-07 / 15 : 22
		else
			Installed = false;
	}catch(ex){
		Installed = false;
	}
	if(Installed == true){
		// 로컬 뷰어 띄우자
		var param="loginId=&cKind="+cKind+"&stylelogId="+stylelogId+"&storyId="+storyId+"&vMode=local&storyNo="+storyNo+"&pageSeq="+pageSeq+"&source="+source+"&eKind=N&gubun="+gubun;
		var localLauncher = window.open("http://devel.crepot.com/common/flash/application/viewer/ex/viewerLauncher.html?"+param, "localLauncher", "status=no, scrollbars=no, width=470, height=310, resizable=no");

	}else{
		// 웹 뷰어 띄우자
		var url="http://devel.crepot.com/LaunchViewer.do"+
		"?cKind="+cKind+
		"&stylelogId="+stylelogId+
		"&storyId="+storyId+
		"&storyNo="+storyNo+
		"&pageSeq="+pageSeq+
		"&source="+source+
		"&gubun="+gubun;
		window.open(url, "", "status=no, scrollbars=no, width=1014, height=679, resizable=no");
	}
}

/* 슬라이드쇼 호출 */
function launchSlideShow(slideShowList,source) {
	var url="/LaunchSlideShow.do"+
			"?slideShowList="+slideShowList+
			"&source="+source;
	window.open(url, "slideshow", "status=no, scrollbars=no, width=1014, height=679, resizable=no");
}

/* 버디아이콘 호출 */
function launchBuddyIcon() {
	var url="/LaunchBuddyIcon.do";

	window.open(url);
}

/* 편집기 호출 */
function launchEditor(teamworkId,cKind,stylelogId,storyId,gubun,folderSeq,selectId,eKind) {
	var url="/LaunchEditor.do"+
			"?teamworkId="+teamworkId+
			"&cKind="+cKind+
			"&stylelogId="+stylelogId+
			"&storyId="+storyId+
			"&gubun="+gubun+
			"&folderSeq="+folderSeq+
			"&selectId="+selectId+
			"&eKind="+eKind;

	window.open(url, "editor", "status=no, scrollbars=no, width=1014, height=679, resizable=yes");
}

/* 편집기 호출 */
function launchCoverEditor(teamworkId,cKind,stylelogId,storyId,gubun,folderSeq,selectId,eKind) {
	var url="/LaunchEditor.do"+
			"?teamworkId="+teamworkId+
			"&cKind="+cKind+
			"&stylelogId="+stylelogId+
			"&storyId="+storyId+
			"&gubun="+gubun+
			"&folderSeq="+folderSeq+
			"&selectId="+selectId+
			"&eKind="+eKind;

	window.open(url, "cover_editor", "status=no, scrollbars=no, width=1014, height=679, resizable=yes");
}

/* 스타일록 발행 */
function stylelogPublish(tp, id) {
	var frm=document.frm;
	if(isCheck('체크박스에 선택된 모든 스토리가 스타일록으로 발행됩니다.<br>발행할 스토리를 선택하여 주십시오.') == false) {
		return;
	}

	frm.action = "/mydesk/StoryPublish01C.do?tp="+tp+"&id="+id;
	frm.target = "ifrm";
	frm.submit();
}

/* 모두 체크 */
function checkAll(obj) {
	var frm=document.frm;
	if(frm.check == null) {
		return;
	}

	if(frm.check.length == undefined) {
		frm.check.checked = obj.checked;
	} else {
		for(i=0; i < frm.check.length; i++) {
			frm.check[i].checked = obj.checked;
		}
	}
}

/* 체크 확인 */
function isCheck(msg) {

	var frm = document.frm;
	var cnt = 0;

	if(frm.check.length != undefined) {
		for(var i = 0; i < frm.check.length; i++) {
			if(frm.check[i].checked == true) {
				cnt++;
			}
		}
	} else {
		if(frm.check.checked == true) {
			cnt++;
		}
	}

	if(cnt == 0) {
		//alert(msg);
		Ext.get("div_check_text").update(msg);
		showDivCenter('delTabCheck');
		return false;
	} else {
		return true;
	}
}

/* 슬라이드쇼 */
function slideShow() {
	if(isCheck('멀티뷰어로 조회할 데이터를 선택하여 주십시오.<br><br><br>') == false) return;

	var frm = document.frm;
	var list = "";

	if(frm.check.length == undefined) {
		list = frm.st_type.value + "_" + frm.check.value;
	} else {
		for(i=0; i < frm.check.length; i++) {
			if(frm.check[i].checked == true) {
				if(list != "") {
					list += ",";
				}
				list += frm.st_type[i].value + "_" + frm.check[i].value;
			}
		}
	}

	launchSlideShow(list,"");
}

/* 스타일록/스토리 간략보기 정보 조회 AJAX 모듈 호출 함수 */
function fnSummary(st_type, st_id) {

   var getPost = "POST";
    var urlFileAppl = "/gallery/GallerySummaryLX.do";
    var trueFalse = true;
    var sendData = "st_type="+st_type+"&st_id="+st_id;

    var vv = function(o) {
    	showDivCenter('Summary0');
    }
	Epigram.update('Summary0', urlFileAppl, sendData, vv);

//    openSendStatus(getPost, urlFileAppl, trueFalse, sendData, "cbSummary");

}

/* 스타일록/스토리 간략보기 정보 조회 AJAX 모듈 콜백 함수 */
/*
function cbSummary(xmlHttp) {
	document.getElementById("Summary0").innerHTML = xmlHttp.responseText;
	showDivCenter('Summary0');
}*/

function changeClass(obj){
	var ob=Ext.get(obj).findParent('div',4);
	ob.className='galleryImg2';
}

/* 이미지 자동 리사이징 함수 */
function js_imageResize(obj, MaxWidth) {
	var width;
	var heigth;

   	if(obj.width > MaxWidth) {
      	obj.width = MaxWidth;
   	}
}

/* Base64 인코딩/디코딩 함수 */
var enc64List, dec64List;
function initBase64() {
    enc64List = new Array();
    dec64List = new Array();
    var i;
    for (i = 0; i < 26; i++) {
        enc64List[enc64List.length] = String.fromCharCode(65 + i);
    }
    for (i = 0; i < 26; i++) {
        enc64List[enc64List.length] = String.fromCharCode(97 + i);
    }
    for (i = 0; i < 10; i++) {
        enc64List[enc64List.length] = String.fromCharCode(48 + i);
    }
    enc64List[enc64List.length] = "+";
    enc64List[enc64List.length] = "/";
    for (i = 0; i < 128; i++) {
        dec64List[dec64List.length] = -1;
    }
    for (i = 0; i < 64; i++) {
        dec64List[enc64List[i].charCodeAt(0)] = i;
    }
}

function encode(str) {
    var c, d, e, end = 0;
    var u, v, w, x;
    var ptr = -1;
    var input = str.split("");
    var output = "";
    while(end == 0) {
        c = (typeof input[++ptr] != "undefined") ? input[ptr].charCodeAt(0) :
            ((end = 1) ? 0 : 0);
        d = (typeof input[++ptr] != "undefined") ? input[ptr].charCodeAt(0) :
            ((end += 1) ? 0 : 0);
        e = (typeof input[++ptr] != "undefined") ? input[ptr].charCodeAt(0) :
            ((end += 1) ? 0 : 0);
        u = enc64List[c >> 2];
        v = enc64List[(0x00000003 & c) << 4 | d >> 4];
        w = enc64List[(0x0000000F & d) << 2 | e >> 6];
        x = enc64List[e & 0x0000003F];

        if (end >= 1) {x = "=";}
        if (end == 2) {w = "=";}

        if (end < 3) {output += u + v + w + x;}
    }
    var formattedOutput = "";
    var lineLength = 76;
    while (output.length > lineLength) {
      formattedOutput += output.substring(0, lineLength) + "\n";
      output = output.substring(lineLength);
    }
    formattedOutput += output;
    return formattedOutput;
}

function decode(str) {
    var c=0, d=0, e=0, f=0, i=0, n=0;
    var input = str.split("");
    var output = "";
    var ptr = 0;
    do {
        f = input[ptr++].charCodeAt(0);
        i = dec64List[f];
        if ( f >= 0 && f < 128 && i != -1 ) {
            if ( n % 4 == 0 ) {
                c = i << 2;
            } else if ( n % 4 == 1 ) {
                c = c | ( i >> 4 );
                d = ( i & 0x0000000F ) << 4;
            } else if ( n % 4 == 2 ) {
                d = d | ( i >> 2 );
                e = ( i & 0x00000003 ) << 6;
            } else {
                e = e | i;
            }
            n++;
            if ( n % 4 == 0 ) {
                output += String.fromCharCode(c) +
                          String.fromCharCode(d) +
                          String.fromCharCode(e);
            }
        }
    }
    while (typeof input[ptr] != "undefined");
    output += (n % 4 == 3) ? String.fromCharCode(c) + String.fromCharCode(d) :
              ((n % 4 == 2) ? String.fromCharCode(c) : "");
    return output;
}

initBase64();

/* 태그 클라우드 플래시 콜백함수 */
fnRecTag = function(g) {
//	document.getElementById("tag_cloud").style.height = e;
	var s=Ext.get('tag_cloud');
	s.setHeight(g);
	var obj=s.child('object',true);	
	Ext.get(obj).setHeight(g);	 
	var emb=s.child('embed',true);
	Ext.get(emb).setHeight(g); 
}
/* by lsy
	@param html element to toggle
*/
function toggleFx(obj){
	var s=Ext.get(obj);
	if(s.getStyle('position')=='static'){
		s.slideOut('t',{afterStyle:{position:'absolute'},block:true});
	}else{
		s.setStyle('position','static');
		s.slideIn('t',{block:true});
	}
}
/*	by lsy
	@param html element to toggle without FX
*/
function toggleDiv(obj){
	var s=Ext.get(obj);
	if(s.getStyle('position')=='static'){
		s.setStyle('position','absolute');
		s.toggle();
	}else{
		s.setStyle('position','static');
		s.toggle();
	}
}
/*
	영어 + 숫자만 입력
*/
function isEngNum (text) {    
    var regexp = /[^\u0030-\u0039\u0041-\u005a\u0061-\u007a\uac00-\ud7af]/;
    var result = !regexp.test(text); 
    return result;
}