
// HTML Æ¯¼ö¹®ÀÚ¸¦ º¯È¯
String.prototype.htmlChars = function () {
	var str = ((this.replace('"', '&amp;')).replace('"', '&quot;')).replace('\'', '&#39;');
	return (str.replace('<', '&lt;')).replace('>', '&gt;');
}

// ÁÂ¿ì °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/ig, ""); }

// ¿ÞÂÊ °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.ltrim = function () { return this.replace(/^s*/g, ""); }

// ¿À¸¥ÂÊ °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.rtrim = function () { return this.replace(/s*$/g, ""); }

String.prototype.replaceAll = function(str1, str2){
	var temp_str = this.trim();
	temp_str = temp_str.replace(eval("/" + str1 + "/ig"), str2);
	return temp_str;
}

// ÅÂ±×¸¸ Á¦°Å
String.prototype.stripTags = function () {
	var str = this;
	/*
	var pos1 = str.indexOf('<');

    if (pos1 == -1) return str;
    else {
        var pos2 = str.indexOf('>', pos1);
        if (pos2 == -1) return str;
        return (str.substr(0, pos1) + str.substr(pos2+1)).stripTags();
    }
	*/
	var oRegExp = new RegExp(/<.+?>/);
	while(oRegExp.test(str)) {
		str = str.replace(oRegExp, ''); 
	}
	return str; 
}

// ´ë¼Ò¹®ÀÚ ±¸º°ÇÏÁö ¾Ê°í ´Ü¾î À§Ä¡ Ã£±â
String.prototype.ipos = function (needle, offset) {
	var offset = (typeof offset == "number")?offset:0;
	return str.toLowerCase().indexOf(needle.toLowerCase(), offset);
}

// ´ë¼Ò¹®ÀÚ ±¸º°ÇÏÁö ¾Ê°í µÚ¿¡¼­ºÎÅÍ ´Ü¾îÀ§Ä¡ Ã£±â
String.prototype.ripos = function (needle, offset) {
    var offset = (typeof offset == "number")?offset:0;
	return str.toLowerCase().lastIndexOf(needle.toLowerCase(), offset);
}

// ¹®ÀÚ¿­À» ¹è¿­·Î
String.prototype.toArray = function () {
	var len = this.length;
	var arr = new Array;
	for (var i=0; i<len; i++) arr[i] = this.charAt(i);
	return arr;
}

// useful for form validation where a field must not be empty
// but presing the space bar means that string != "" string.length >0 etc won't work.
// see also String.prototype.trim in this library
String.prototype.isEmpty = function() {
	var str = this;
	/*
	var a;
	var l = this.length;
	for (a=0; a<l; a++) {
		if (this.substr(a, 1) != ("" || " ")) return false;
	}
	*/
	if (str.replace(/ /g, "") == "") {	
		return true;
	}
	return false;
}

String.prototype.compareNoCase = function(str) {
	return this.toLowerCase() == str.toLowerCase();
}

String.prototype.findNoCase = function(str) {
	var s = this;
	var sLen = s.length;
	var strLen = str.length;
	var tracking = false;
	for (var i = 0; i<sLen; i++) {
		if (s.charCodeAt(i) == str.charCodeAt(0) || s.charCodeAt(i) == (str.charCodeAt(0)-32) || s.charCodeAt(i) == (str.charCodeAt(0)+32)) {
			tracking = true;
			break;
		}
	}
	if (tracking) {
		for (var j = 0; j<strLen; j++, i++) {
			if (s.charCodeAt(i) != str.charCodeAt(j) && s.charCodeAt(i) != (str.charCodeAt(j)-32) && s.charCodeAt(i) != (str.charCodeAt(j)+32)) {
				return false;
			}
		}
	} else {
		return false;
	}
	return true;
}

String.prototype.isEmail = function() {
	return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim());
}

//-----------------------------------------------------------------------------
// ¹®ÀÚ¿­ÀÇ 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;
}

//-----------------------------------------------------------------------------
// ÀüÈ­¹øÈ£ Ã¼Å© - arguments[0] : ÀüÈ­¹øÈ£ ±¸ºÐÀÚ
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isPhone = function() {
	var arg = arguments[0] ? arguments[0] : "";
	return eval("(/(02|0[3-9]{1}[0-9]{1})" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");
}

//-----------------------------------------------------------------------------
// ÇÚµåÆù¹øÈ£ Ã¼Å© - arguments[0] : ÇÚµåÆù ±¸ºÐÀÚ
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isMobile = function() {
	var arg = arguments[0] ? arguments[0] : "";
	return eval("(/01[016789]" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");
}

/*
String.prototype.repeat = function (n){
	if(!n) return '';
	var str = this;
	for(var i=0; i<n; i++) t += str;
	return t;
}

String.prototype.number_format = function (){
	var str = this;
	var oRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
	while(oRegExp.test(str)) {
		str = str.replace(oRegExp, '$1,$2'); 
	}
	return str; 
} 
*/

