/*
  This work is licensed under Creative Commons GNU GPL License
  http://creativecommons.org/licenses/GPL/2.0/
  Copyright (C) 2006 Russel Lindsay
  last updated 2006-09-28
  www.weetbixthecat.com
*/
 

Array.prototype.propertySort = function(index)
{
  var objectToString = Object.prototype.toString,
      arrayToString = Array.prototype.toString;
 
  if(typeof index != "function")
  {
    var property = index;
    index = function(){return this[property]};
  }
  Object.prototype.toString = index;
  Array.prototype.toString = index;

  this.sort();

  Object.prototype.toString = objectToString;
  Array.prototype.toString = arrayToString;
}


/**
  Sorts an array of integers
  This is very fast over large arrays - around 10 times faster than the common
  myArray.sort(function(a, b){return a - b});
  doesn't do negative numbers
*/
// if you wish to sort numbers greater than 10 digits extend this array in like
Array.prototype.integerSort = function(field)
{
  var i = this.length,
      mask = Array.integerSortMask,
      length = mask.length;

  while(i--)
  {
    obj = this[i][field];
    obj = "" + obj;
    this[i][field] = (obj.length < length ? mask[length - obj.length] : "") + obj;
  }

  this.propertySort(field);

  i = this.length;
  while(i--)
    this[i][field] = parseInt(this[i][field], 10);

}
Array.integerSortMask = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000"];


// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
Array.prototype.insert = function( i, v ) {
 if( i>=0 ) {
  var a = this.slice(), b = a.splice( i, this.length-i );
  a[i] = v;
  return a.concat( b );
 }
};


function isString() {
if (typeof arguments[0] == 'string') return true;
/* if (typeof arguments[0] == 'object') {  
	var criterion = arguments[0].constructor.toString().match(/string/i); 
 	return (criterion != null);  
	}
    */
return false;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}