function trim(str){ return str.replace(/(^\s*)|(\s*$)/g,''); } // ¾ÕµÚ °ø¹é Á¦°Å

String.prototype.replaceAll = replaceAll;
function replaceAll(s1, s2){ // »ç¿ë¹æ¹ý 'abcd'.replaceAll('bc','bb')
	var str = this;
	str = str.replace(new RegExp(s1,"g"), s2);
	return str;
}

function countBytes(o){ // Byte ¼ö¸¦ °è¼öÇÑ´Ù
	o.value = trim(o.value); // ¾ÕµÚ °ø¹é Á¦°Å
	return countBytesNoTrim(o);
}

function countBytesNoTrim(o){ // Byte ¼ö¸¦ °è¼öÇÑ´Ù
	var str = o.value;
	if(str=='') return 0;

	var bytes = 0;
	for(var i=0,s=str.length; i<s; i++){
		var chr = str.charCodeAt(i);
		if(chr>31 && chr<127) bytes++; // 32~47 Æ¯¼ö±âÈ£, 48~57 ¼ýÀÚ, 58~64 Æ¯¼ö±âÈ£, 65~90 ¿µ¹® ´ë¹®ÀÚ, 91~96 Æ¯¼ö¹®ÀÚ, 97~122 ¿µ¹® ¼Ò¹®ÀÚ, 123~126 Æ¯¼ö¹®ÀÚ
		else if(escape(chr).length>1) bytes += 2; // \n ÀÇ °æ¿ì \r\n À¸·Î DB ¿¡ µé¾î°©´Ï´Ù. µû¶ó¼­ 4Bytes
		else bytes++;
	}

	return bytes;
}

function delDoubleReturn(str){ return str.replaceAll('\n\n','\n'); }
