// String extensions
Object.extend(String.prototype, {
		
	/**
	 * Trims whitespace off beginning and end 
	 * 
	 * @return String
	 */
	trim: function() 
  	{
		var s = this.toString();
		s = s.replace(/^\s+/,'');
		s = s.replace(/\s+$/,'');
		return s;
  	},
  	
  	/**
  	 * Wordwrapper
  	 * 
  	 * @param int m Maximum amount of characters per line
  	 * @param String b String that will be added whenever it's needed to break the line
  	 * @param int c Cuttype: 0 (words longer than maxLength will not be broken) / 1 (words will be broken when needed) or 2 (any word that trespass the limit will be broken)
  	 * @return String
  	 */
  	wordWrap: function (m, b, c) 
	{
  		//+ Jonas Raoni Soares Silva
  		//@ http://jsfromhell.com/string/wordwrap [v1.0]
  		
	    var i, j, l, s, r = this.split(" ");
	    if (m > 0) 
	    {
	    	for(i = -1, l = r.length; ++i < l;) 
	    	{
		        for (s = r[i], r[i] = ""; s.length > m;
		            j = c ? m : (j = s.substr(0, m).match (/\S*$/)).input.length - j[0].length || 
		            j.input.length + (j = s.substr(m).match (/^\S*/)).input.length + j[0].length,
		            r[i] += s.substr (0, j) + ((s = s.substr(j)).length ? b : "")
		        ) 
		        {
		        	// do nothing
		        }
		        r[i] += s;
		    }
	    }
	    return r.join ("\n");
	},
	
	/**
	 * Pad a string
	 * 
	 * @param String l Length to pad to
	 * @param String s String to pad with
	 * @param bool t True for end, false for beginning
	 * @return String
	 */
	pad: function(l, s, t) 
	{
		s = s || " ";
		
		if (l <= this.length)
		{
			return this;
		}
		
		var result = "";
		
		s = s.times(Math.ceil(l / s.length) + 1);
		
		if (t)
		{
			// pad at the end
			result = this + s;
			result = result.substr(0, l);
		}
		else
		{
			// pad at the beginning
			result = s + this;
			result = result.substr(result.length - l, l);
		}
		
		return result;
	},
	
	/**
	 * replaceAll function (as replace() only replaces one!)
	 * 
	 * @return String
	 */
	replaceAll: function(needle, replacement) {
		var str = this;
		if (!str || (str === undefined) || (str === ''))
		{
			return '';
		}
		return str.replace(new RegExp(needle, 'g'), replacement);
	},

	/**
	 * Make the first letter of this string uppercase
	 * 
	 * @return String
	 */
	ucFirst: function() 
	{
		//@ http://snipplr.com/view/3354/ucfirst/
    	return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
	},
	
	_eoo: true
  	
});

function addslashes(str) 
{
	return str.replace(/\'/g,'\\\'').replace(/\"/g,'\\"').replace(/\\/g,'\\\\');
}

function stripslashes(str) 
{
	return str.replace(/\\'/g,'\'').replace(/\\"/g,'"').replace(/\\\\/g,'\\');
}

String.prototype.md5 = function() {
	return Framework.md5.hex(this);
};