
	/*ex
		http://www.javaworld.com.tw/jute/post/view?bid=34&id=44141&sty=3&age=0&tpg=1&ppg=1#44141
		str = "       this is a sample     ";
		alert(str.trim());
	*/
	String.prototype.trim = function () {
		return this.replace(/^\s+|\s+$/g, "")
	}

	String.prototype.ltrim = function () {
		return this.replace(/^\s+/g, "")
	}

	String.prototype.rtrim = function () {
		return this.replace(/\s+$/g, "")
	}

	function str_length_bytes(str)
	{
		var count=0;
		for (i=0; i<str.length; i++) {
			if(escape(str.charAt(i)).length >= 4) {
				count += 2;
			} else {
				count ++;
			}
		}
		return count;
	}

	function str_cut_bytes(str, len)
	{
		var count=0;
		for (i=0; i<str.length; i++) {
			if(escape(str.charAt(i)).length >= 4) {
				count += 2;
			} else {
				count ++;
			}
			if (count == len) {
				i++;
				break;
			} else if (count > len) {
				break;
			}	
		}

		return str.substr(0, i);
	}
