<!--

//-----------------------------------------------------------------------------
// 문자의 좌, 우 공백 제거
// @return : String
//-----------------------------------------------------------------------------
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

//-----------------------------------------------------------------------------
// 문자의 좌 공백 제거
// @return : String
//-----------------------------------------------------------------------------
String.prototype.ltrim = function() {
	return this.replace(/(^\s*)/, "");
}

//-----------------------------------------------------------------------------
// 문자의 우 공백 제거
// @return : String
//-----------------------------------------------------------------------------
String.prototype.rtrim = function() {
	return this.replace(/(\s*$)/, "");    
}

//-----------------------------------------------------------------------------
// 문자열의 byte 길이 반환
// @return : int
//-----------------------------------------------------------------------------
String.prototype.byte = function() {
	var cnt = 0;
	for (var i = 0; i < this.length; i++) {
		if (this.charCodeAt(i) > 127)
			cnt += 2;
		else
			cnt++;
	}
	return cnt;
}

//-----------------------------------------------------------------------------
// 정수형으로 변환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.int = function() {
	if(!isNaN(this)) {
		return parseInt(this);
	}else {
		return null;    
	}
}

//-----------------------------------------------------------------------------
// 숫자만 가져 오기
// @return : String
//-----------------------------------------------------------------------------
String.prototype.num = function() {
	return (this.trim().replace(/[^0-9]/g, ""));
}

//-----------------------------------------------------------------------------
// 숫자에 3자리마다 , 를 찍어서 반환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.money = function() {
	var num = this.trim();
	while((/(-?[0-9]+)([0-9]{3})/).test(num)) {
		num = num.replace((/(-?[0-9]+)([0-9]{3})/), "$1,$2");
	}
	return num;
}

//-----------------------------------------------------------------------------
// 숫자의 자리수(cnt)에 맞도록 반환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.digits = function(cnt) {
	var digit = "";
	if (this.length < cnt) {
		for(var i = 0; i < cnt - this.length; i++) {
			digit += "0";
		}
	}
	return digit + this;
}

//-----------------------------------------------------------------------------
// " -> &#34; ' -> &#39;로 바꾸어서 반환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.quota = function() {
	return this.replace(/"/g, "&#34;").replace(/'/g, "&#39;");
}

//-----------------------------------------------------------------------------
// 파일 확장자만 가져오기
// @return : String
//-----------------------------------------------------------------------------

String.prototype.ext = function() {
	return (this.indexOf(".") < 0) ? "" : this.substring(this.lastIndexOf(".") + 1, this.length);    
}

//-----------------------------------------------------------------------------
// URL에서 파라메터 제거한 순수한 url 얻기
// @return : String
//-----------------------------------------------------------------------------    

String.prototype.uri = function() {
	var arr = this.split("?");
	arr = arr[0].split("#");
	return arr[0];    
}


/*---------------------------------------------------------------------------------*\
*  각종 체크 함수들
\*---------------------------------------------------------------------------------*/

//-----------------------------------------------------------------------------
// 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.
// @return : String
//-----------------------------------------------------------------------------

String.prototype.meta = function() {
	var str = this;
	var result = ""
	for(var i = 0; i < str.length; i++) {
		if((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/).test(str.charAt(i))) {
			result += str.charAt(i).replace((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/), "\\$1");
		}else {
			result += str.charAt(i);
		}
	}
	return result;
}

//-----------------------------------------------------------------------------
// 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.
// @return : String
//-----------------------------------------------------------------------------
String.prototype.remove = function(pattern) {
	return (pattern == null) ? this : eval("this.replace(/[" + pattern.meta() + "]/g, \"\")");
}

//-----------------------------------------------------------------------------
// 최소 최대 길이인지 검증
// str.isLength(min [,max])
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isLength = function() {
	var min = arguments[0];
	var max = arguments[1] ? arguments[1] : null;
	var success = true;
	if(this.length < min) {
		success = false;
	}
	if(max && this.length > max) {
		success = false;
	}
	return success;
}

//-----------------------------------------------------------------------------
// 최소 최대 바이트인지 검증
// str.isByteLength(min [,max])
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isByteLength = function() {
	var min = arguments[0];
	var max = arguments[1] ? arguments[1] : null;
	var success = true;
	if(this.byte() < min) {
		success = false;
	}
	if(max && this.byte() > max) {
		success = false;
	}
	return success;
}

//-----------------------------------------------------------------------------
// 공백이나 널인지 확인
// @return : boolean
//-----------------------------------------------------------------------------

String.prototype.isBlank = function() {
	var str = this.trim();
	for(var i = 0; i < str.length; i++) {
		if ((str.charAt(i) != "\t") && (str.charAt(i) != "\n") && (str.charAt(i)!="\r")) {
			return false;
		}
	}
	return true;
}

//-----------------------------------------------------------------------------
// 숫자로 구성되어 있는지 학인
// arguments[0] : 허용할 문자셋
// @return : boolean
//-----------------------------------------------------------------------------

String.prototype.isNum = function() {	
	return (/^[0-9]+$/).test(this.remove(arguments[0])) ? true : false;
}

//-----------------------------------------------------------------------------
// 영어만 허용 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------

String.prototype.isEng = function() {
	return (/^[a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;
}

//-----------------------------------------------------------------------------
// 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isEngNum = function() {
	return (/^[0-9a-zA-Z,"."]+$/).test(this.remove(arguments[0])) ? true : false;
}

//-----------------------------------------------------------------------------
// 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isNumEng = function() {
	return this.isEngNum(arguments[0]);
}

//-----------------------------------------------------------------------------
// 아이디 체크 영어와 숫자만 체크 첫글자는 영어로 시작 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isUserid = function() {
	return (/^[a-zA-z]{1}[0-9a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;
}

//-----------------------------------------------------------------------------
// 한글 체크 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------

String.prototype.isKor = function() {
	return (/^[가-힣]+$/).test(this.remove(arguments[0])) ? true : false;
}

//-----------------------------------------------------------------------------
// 이메일의 유효성을 체크
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isEmail = function() {
	return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim());
}



	//------------------- 편집기 ------------------------------------------------------


	function func_selection_bbc_code(){
		var board_form = document.board_form;

		board_form.tex_content.focus();

		txt = document.getElementById('txt_bbc_code').value;
		cRange = document.selection.createRange();
		cRange.text = txt;
	}

	function func_selection_txtarea_topic(obj,prefix,postfix){

				if (document.getSelection)    ts = document.getSelection();
				else if (document.selection)  ts = document.selection.createRange().text;
				else if (window.getSelection) ts = window.getSelection();
				
				if (obj.selectionStart == obj.selectionEnd){
					if(/*@cc_on!@*/false){
						topic_write.focus();
						document.selection.createRange().duplicate().text = prefix + document.selection.createRange().duplicate().text + postfix;
						document.selection.createRange().select();
					}else{
						var s1 = obj.value.substring(0, obj.selectionStart);
						var s2 = obj.value.substring(obj.selectionStart);
						obj.value = s1 + prefix + postfix + s2;
					}
				}else{
					var s1 = obj.value.substring(0, obj.selectionStart);
					var s2 = obj.value.substring(obj.selectionStart, obj.selectionEnd);
					var s3 = obj.value.substring(obj.selectionEnd);
					obj.value = s1 + prefix + s2 + postfix + s3;
				}
	}

		function func_selection_bbc_code(option){
			var txtarea_topic = document.topic_write.tex_content;
			
			txtarea_topic.focus();				

			if(option == 'b'){			
				func_selection_txtarea_topic(txtarea_topic,'[b]','[/b]');
			}if(option == 'u'){			
				func_selection_txtarea_topic(txtarea_topic,'[u]','[/u]');
			}else if(option == 'l'){
				func_selection_txtarea_topic(txtarea_topic,'[l]','[/l]');
			}else if(option == 'i'){				
				func_selection_txtarea_topic(txtarea_topic,'[i]','[/i]');
			}else if(option == 'color'){
				func_selection_txtarea_topic(txtarea_topic,'[color=#FF0000]','[/color]');
			}else if(option == 'url'){
				func_selection_txtarea_topic(txtarea_topic,'[url]','[/url]');
			}else if(option == 'url2'){
				func_selection_txtarea_topic(txtarea_topic,'[url=http://www.youfree.or.kr/]','[/url]');	
			}else if(option == 'email'){
				func_selection_txtarea_topic(txtarea_topic,'[email]youfree@modutech.co.k','[/email]');
			}else if(option == 'email2'){
				func_selection_txtarea_topic(txtarea_topic,'[email=youfree@modutech.co.kr]','[/email]');
			}else if(option == 'quote'){
				func_selection_txtarea_topic(txtarea_topic,'[quote=상대방 이름]','[/quote]');
			}else if(option == 'img'){
				func_selection_txtarea_topic(txtarea_topic,'[img=','경로]');
	
			}
		}

		function func_selection_SyntexHighlite(option,language){
			var txtarea_topic = document.topic_write.tex_content;
			txtarea_topic.focus();				
			func_selection_txtarea_topic(txtarea_topic,'[code='+language+']','[/code]');
			
		}








//-->