/*#########################################################################
# Args : 
	chk_char => 문자열 인자
	limit_length => 최대길이
	
# Return :  true / false

# comment : 문자열을 받아서 최대길이값을 체크함
###########################################################################*/

function Check_CharLength( chk_char, limit_length, kind ) {
	var byteLength = 0;
	for (var inx = 0; inx < chk_char.length; inx++) {
		var oneChar = escape(chk_char.charAt(inx));
		if ( oneChar.length == 1 ) {
			byteLength ++;
		} else if (oneChar.indexOf("%u") != -1) {
			byteLength += 2;
		} else if (oneChar.indexOf("%") != -1) {
			byteLength += oneChar.length/3;
		}
	}
	
	if(kind=="length"){	
		return byteLength;
	} else {
		if( byteLength > limit_length ) return false; 
		else return true;	
	}

}

/*#########################################################################
# Args : 
	str => 문자열 
	
# Return :  string ( 공백을 제거한 문자열을 리턴) 

# comment : 문자열을 받아서 공백을 제거 
###########################################################################*/

function trim(str){
	try{
			if(str == '') return '';
    var len = str.length;
    for(i = (len - 1); (str.charAt(i) == ' ')||(str.charAt(i) == '\n'); i--);
    str = str.substring(0, i + 1);

    var len2 = str.length;
    for(j = 0; str.charAt(j) == ' '; j++);
    str = str.substring(j, len2);
	} catch (e) {
		str = '';
	}
    return str;
}

/*#########################################################################
# Return   : 
# Comment  : 한글을 2byte로 인식하여 length 체크
###########################################################################*/
function trim_up(input) {
    if (input == null) { 
        return true;
    }
		var new_input = input.replace(/(^\s*)|(\s*$)/gi, "");
		
    return new_input;
}
/*#########################################################################
# Args : 
	str => 문자열 
	
# Return :  true/false 

# Comment  : 입력받은 문자열에 특수문자가 입력되었는지 Check
###########################################################################*/
function char_check(str)
{
	var code;

	for( var i = 0; i < str.length; i++ ) {
		code = str.charCodeAt(i);
		if( (code >= 33 && code <= 47) || (code >= 58 && code <=64) || (code >= 91 && code <=96) || (code >=123 && code <= 126) ){
			return false;		
		}	
	}
	return true;	
	
}

/*#########################################################################
# Args : 
	str => 문자열 
	str_code => han(한글입력불가:영문,숫자가능), su(숫자만가능)
	
# Return :  true/false

# Comment  : 입력받은 문자열이 code 조건에 맞는지 Check
###########################################################################*/
function hs_check(str,str_code)
{
	if(str_code == "han")  	var check_patten = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";  
	else					var check_patten = "0123456789";

	if( str_code == "han" ) {
	 	for( i=0 ; i < str.length ; i++ ) { 
	     	ch = check_patten.indexOf(str.charAt(i)); 
	      	if( ch == -1 ) return true; 
			else continue;
	  	} 
		return false; 
	} else if( str_code == "char" ) {
		if( str_code == "char" && !char_check(str) ) {
			return true;
		}
	 	for( i=0 ; i < str.length ; i++ ) { 
	     	ch = check_patten.indexOf(str.charAt(i)); 
	      	if( ch == -1 ) continue; 
			else return true;
	  	} 
		return false;
	} else {
	 	for( i=0 ; i < str.length ; i++ ) { 
	     	ch = check_patten.indexOf(str.charAt(i)); 
	      	if( ch == -1 ) return false; 
			else continue;
	  	} 
		return true; 
	}
} 

/*#########################################################################
# Return   : true/false 
# Comment  : 댓글 쓰기 권한 여부 판단 함수 
###########################################################################*/
function chkDenyMember() 
{
	var frm = document.formComment3 ;
	alert('댓글을 쓸 수 없습니다.');
	frm.comment.value='';
	return false;
}

/*#########################################################################
# Return   : 
# Comment  : 즐겨찾기에 추가하기
###########################################################################*/
function bookmark(){
	window.external.AddFavorite('http://www.happycampus.com', '해피캠퍼스')
}

/*#########################################################################
# Return   : 
# Comment  : 한글을 2byte로 인식하여 length 체크
###########################################################################*/
function getByteLength( data ) {
    var len = 0;
    var str = data.substring(0);

    if ( str == null ) return 0;

    for(var i=0; i < str.length; i++) {
        var ch = escape(str.charAt(i));

        if( ch.length == 1 ) len++;
        else if( ch.indexOf("%u") != -1 )  len += 2;//Db가 한글을 3byte로 인식하여 2->3
        else if( ch.indexOf("%") != -1 ) len += ch.length/3;
    }

    return len;
}


