/* -------------------------------------------------------------------------------------------------------- *\
   Object
\* -------------------------------------------------------------------------------------------------------- */
Object.prototype.ForEach = function(fFunction)
{
  for (var i in this)
  {
    if (typeof(this[i]) != "function")
    {
      var bReturn = fFunction(this[i], i);
      if (String(bReturn) != "undefined")
      {
        return bReturn;
        break;
      }
    }
      
  }
}

/* -------------------------------------------------------------------------------------------------------- *\
   Array
\* -------------------------------------------------------------------------------------------------------- */
Array.prototype.Exists = function(sValue)
{
  var bReturn = this.ForEach(function(oValue, oKey)
  {
    if (oValue == sValue)
      return true;
  });

  return bReturn ? true : false;
}

Array.prototype.Rand = function()
{
  var i = this.length;

  if (i == 0)
    return false;

  while (--i)
  {
     var j = Math.floor(Math.random() * (i + 1));
     var aTemp1 = this[i];
     var aTemp2 = this[j];
     this[i] = aTemp2;
     this[j] = aTemp1;
   }

}

Array.prototype.Search = function(sValue)
{
  var bReturn = this.ForEach(function(oValue, oKey)
  {
    if (oValue == sValue)
      return oKey;
  });

  return bReturn ? bReturn : false;
}

Array.prototype.Remove = function(sValue)
{
  var aDelete = new Array();
  this.ForEach(function(oValue, oKey)
  {
    if (oValue == sValue)
      aDelete.push(oKey);
  });
  
  if (aDelete.length == 0)
    return false;

  for (var i in aDelete)
    if (typeof(aDelete[i]) != "function")
      delete this[aDelete[i]];

  return true;
}

Array.prototype.Implode = function(sCharacter)
{
  var sImplode = new String();
  this.ForEach(function (sValue)
  {
    sImplode += sValue + sCharacter;
  })

  return sImplode.substr(0, sImplode.length - sCharacter.length);
}

/* -------------------------------------------------------------------------------------------------------- *\
   String
\* -------------------------------------------------------------------------------------------------------- */
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
}