/*
 *      Author: Erik Borra - erik@erikborra.net
 *      Copyright (C) 2007, Erik Borra
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or (at
 *      your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful, but
 *      WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *      General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software Foundation,
 *      Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

// some generic and useful functions on arrays

// check if an element is in an array
if( typeof Array.inArray=='undefined' ) {
	Array.prototype.inArray = function(val) {
	   for (var i = 0; i < this.length; i++) {
	      if(this[i] == val) return true;
	   }
	   return false;
	}
}

// removes an element from an array
if( typeof Array.remove=='undefined') {
	Array.prototype.remove=function(s){
	   for(i=0;i<this .length;i++){
	      if(s==this[i]) this.splice(i, 1);
	   }
	}
}

// removes duplicates from an array
if( typeof Array().arrayUnique=='undefined' )
	Array.prototype.arrayUnique=function() {
		var noDuplicates=[];
	
		for( var i=0, k=0; i<this.length; i++ ) {
			for( var j=0; j<noDuplicates.length && this[i]!=noDuplicates[j] ; j++ )
				;
			if(j==noDuplicates.length)
				noDuplicates[k++]=this[i];
		}

	return noDuplicates;
}

// trashes duplicates
if( typeof Array().trashDuplicates=='undefined' ) 
	Array.prototype.trashDuplicates=function() {
		for( var i=0; i<this.length; i++ )
			for( var j=0; j<this.length; j++ )
				if( i!=j && this[i]==this[j] /** && typeof(this[i])==typeof(this[j]) **/ )
					for( var k=j; k<this.length; k++ ) {
						this[k]=this[k+1];
						this.length--;
					} // no .splice() in I.E. 5.0 :(
	return this;
}