/* Implementing a simple bubble sort */
if (!Array.prototype.sort)
{
	Array.prototype.sort=function()
	  {
		  var tmp;
		  for(var i=0;i<this.length;i++)
		  {
			  for(var j=0;j<this.length;j++)
			  {
				  if(this[i]<this[j])
				  {
					  tmp = this[i];
					  this[i] = this[j];
					  this[j] = tmp;
				  }
			  }
		  }
	  };
}


/* Implementing ushift, which inserts an element into the beginning of the array */
if (!Array.prototype.unshift)
{
	Array.prototype.unshift=function(item)
	  {
		  this[this.length] = null;/* create a new last element */
		  for(var i=1;i<this.length;i++)
		  {
			  this[i] = this[i-1]; /* shift elements upwards */
		  }
		  this[0] = item;
	  };
}


/* Implementing shift, which removes and returns the first element of an array */
if (!Array.prototype.shift)
{
	Array.prototype.shift=function()
	  {
		  for(var i=1;i<this.length;i++)
		  {
			  this[i-1] = this[i] /* shift element downwards */
		  }
		  this.length =  this.length-1;
	  };
}


/* Implementing clear, which empties an array */
if (!Array.prototype.clear) {
 Array.prototype.clear=function()
  {
      this.length = 0;
  };
}


/* Implementing contains, which checks where the specified elements exists in the array or not */
if (!Array.prototype.contains) {
 Array.prototype.contains = function (element) 
  {
          for (var i = 0; i < this.length; i++) 
       {
              if (this[i] == element) 
          {
                      return true;
              }
          }
          return false;
  };
}
if (!Array.prototype.hasElement) {
 Array.prototype.hasElement = function(s){ 
		return new RegExp('(^|\,)'+s+'(\,|$)','gi').test(this);
 }
}

/* Remove the elements with specified value */
if (!Array.prototype.remove) {
 Array.prototype.remove = function (elementValue) 
  {
	  	var a=[],i;
          for (i = 0; i < this.length; i++) 
       {
              if (this[i] != elementValue) 
          {
                      a[a.length] = this[i];
              } 
          }
		  return a;
  };
}
  
 /* Shuffles the Array elements randomly */
if (!Array.prototype.shuffle) {
 Array.prototype.shuffle=function()
 {
     var i=this.length,j,t;
     while(i--)
     {
         j=Math.floor((i+1)*Math.random());
         t=arr[i];
         arr[i]=arr[j];
         arr[j]=t;
     }
 };
} 
 /* Removes redundant elements from the array */
if (!Array.prototype.unique) {
 Array.prototype.unique=function()
 {
     var a=[],i;
     this.sort();
     for(i=0;i<this.length;i++)
     {
         if(this[i]!==this[i+1])
         {
             a[a.length]=this[i];
         }
     }
     return a;
 };
}
 
 
 
 /* Returns the index of the element matched from the behind */
if (!Array.prototype.lastIndexOf) {
 Array.prototype.lastIndexOf=function(n)
 {
     var i=this.length;
     while(i--)
     {
         if(this[i]===n)
         {
             return i;
         }
     }
     return -1;
 };
}
 
 
// ------------------
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if (!Array.prototype.every)
{
  Array.prototype.every = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          !fun.call(thisp, this[i], i, this))
        return false;
    }

    return true;
  };
}
 
