String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"").replace(/(^銆€*)|(銆€*$)/g, "");
};
String.prototype.stripTags = function() 
{
	return this.replace(/<\/?[^>]+>/gi, '');
};
String.prototype.escapeHTML = function() 
{
	return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/ /g,'&nbsp;').replace(/\"/g,'&quot;');
};
String.prototype.unescapeHTML = function(str) 
{
	return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&nbsp;/g,' ').replace(/&quot;/g,'"');
};
String.prototype.startsWith = function(key)
{
	return this.indexOf(key) === 0;
};
String.prototype.endsWith = function(key)
{
	var d = str.length - key.length;
	return d >= 0 && str.lastIndexOf(key) === d;	
};
String.prototype.cutString = function(length)
{
	if(this.bytesLength() > length)
	{
		var tmpstr = "";
		for(var i = 0; i < this.length; i++)
		{
			var tmplen = tmpstr.bytesLength();
			if(tmplen == length)
			{
				break;
			}
			else
			{
				if(tmplen + this.substr(i,1).bytesLength() > length)
					tmpstr += " ";
				else
					tmpstr +=  this.substr(i,1);
			}
		}
		return tmpstr + "...";
	}
	else
	{
		return this;
	}
};
String.prototype.bytesLength = function()
{
	var sum=0;
	for(var i=0; i < this.length;i++)
	{
		if ( 
				this.charCodeAt(i)>=0 && 
				this.charCodeAt(i)<=255
			)
			sum++;
		else
			sum += 2;
	}
	return sum;
}
