// Remove all white spaces from the beginning of the string
String.prototype.ltrim = function()
{
   return this.replace(/^[ \n\r\t]*/g, "");
}

// Remove all white spaces from the end of the string
String.prototype.rtrim = function()
{
   return this.replace(/[ \n\r\t]*$/g, "");
}

// Remove all white spaces from the beginning and the end of the string
String.prototype.trim = function()
{
   return this.ltrim().rtrim();
}

// Converts strings from something like this: hello world
// into something like this: Hello World
String.prototype.proper = function()
{
   var result = this.toLowerCase();
   var words = result.split(" ");
   for(var i = 0; i < words.length; i++)
   {
      var chars = words[i].split("");
      if(chars.length >= 1)
         chars[0] = chars[0].toUpperCase();
      words[i] = chars.join("");
   }
   result = words.join(" ");
   return result;
}

// A useful constant representing the empty string
String.empty = "";

// Returns true if the string given as argument is
// either null or empty
String.isNullOrEmpty = function(str)
{
   return (str == null || str == String.empty);
}

// Converts the string that used in URL
String.prototype.escape = function()
{
   return escape(this.replace(/\+/g, "&#43"));
}

//format
String.format = function()
{
  if( arguments.length == 0 )
        return null;
  var str = arguments[0];
  for(i = 1; i < arguments.length; i++)
  {
    str = str.replace('{' + (i - 1) + '}', arguments[i]);
  }
  return str;
}
