
Array.prototype.pushUniqueVal = function(value) {
	for (var i in this) {
		if (this[i] == value) {
			return {success:false,pos:i};
		}
	}
	var pos=this.length;
	this[pos] = value;
	return {success:true, pos:pos};
};

Array.prototype.mergeUnique=function(new_arr) {
	for (var i in new_arr) {
		this.pushUniqueVal(new_arr[i]);
	}
};

Array.prototype.swapItems=function(one,two) {
	var temp=this[one];
	this[one]=this[two];
	this[two]=temp;
};

Array.prototype.moveItem=function(from,to) {
	this.splice(to,0,this[from]);
	this.splice(from,1);
};

Array.prototype.getInd = function(value) {
	for (var i in this) {
		if (this[i] == value) {
			return i;
		}
	}
};

Array.prototype.toString= function() {
	if (this.length==0) {
		var cnt=0;
		var typ="Indexed Array"
	} else {
		var typ="Ordered Array"
	}
	var listed = "";
	var addItm=function(i, itm) {
		//for XML nodes, dont print the whole thing, just the top node
		if (itm.hasChildNodes()) {
			listed = listed + i + ":" + itm.cloneNode() + ",";
		} else {
			listed = listed + i + ":" + itm + ",";
		}
	}
	if (typ=="Indexed Array") {
		for (var i in this) {
			cnt++;
			addItm(i, this[i])
		}
		var tot=cnt;
	} else {
		for (var i = 0;i<this.length;i++) {
			addItm(i, this[i])
		}
		var tot=this.length;
	}
	listed = listed.substr(0,-1);
	return typ+" ("+tot+"): "+listed+")";
};

Array.prototype.remove = function(value) {
	var ind=this.getInd(value);
	//trace("REMOVE FROM: "+ind);
	if (isNaN(ind)) {
		this.removeByIndex(ind);
	} else {
		this.splice(ind,1);
	}
};

Array.prototype.removeByIndex = function(ind) {
	delete this[ind];
};

//returns total of filled slots for an array
Array.prototype.realLength = function() {
	var real = 0;
	for (var i in this) {
		if (this[i] != undefined) {
			real++;
		}
	}
	//trace("realLength: "+real);
	return real;
};

Array.prototype.contains = function(obj) {
	for (var i in this) {
		if (this[i]==obj) return true;
	}
	return false;
};

Array.prototype.copy = function() {
	var new_arr = new Array();
	if (this.length == 0) {
		for (var i in this) {
			new_arr[i] = this [i]
		}
	}
	for (var i=0; i<this.length; i++) {
		new_arr[i] = this[i]
	}
	return new_arr;
};

Array.prototype.clear = function() {
	for (var i in this) {
		this.splice(i,1);
	}
};

Array.prototype.sum = function() {
	var sum = 0;
	for (var i in this) {
		sum+=this[i];
	}
	return sum;
};

Array.prototype.max = function() {
	return Math.max.apply({},this)
};

Array.prototype.min = function() {
	return Math.min.apply({},this)
};

if (!Array.prototype.forEach) { // internal from Firefox 1.5
	Array.prototype.forEach = function(callback, thisObject) {
		for(var i=0,len=this.length;i<len;i++)
			callback.call(thisObject,this[i],i,this)
		}
};

if (!Array.prototype.map) { // internal from Firefox 1.5
	Array.prototype.map = function(callback, thisObject) {
		for(var i=0, res=[], len=this.length; i<len; i++)
			res[i] = callback.call(thisObject,this[i],i,this);
		return res;
	}
};

if (!Array.prototype.filter) { // internal from Firefox 1.5
	Array.prototype.filter = function(callback, thisObject) {
		for(var i=0, res=[], len=this.length; i<len; i++)
			callback.call(thisObject,this[i],i,this) && res.push(this[i]);
		return res;
	}
};

if (!Array.prototype.every) { // internal from Firefox 1.5
	Array.prototype.every = function(callback, thisObject) {
		for(var i=0,len=this.length;i<len;i++)
			if(!callback.call(thisObject,this[i],i,this)) return false;
		return true;
	}
};

if (!Array.prototype.some) { // internal from Firefox 1.5
	Array.prototype.some = function(callback, thisObject) {
		for(var i=0,len=this.length;i<len;i++)
			if(callback.call(thisObject,this[i],i,this)) return true;
		return false;
	}
};

if (!Array.prototype.indexOf) { // internal from Firefox 1.5
	Array.prototype.indexOf = function(searchElement, fromIndex) {
		var i = (fromIndex < 0) ? this.length+fromIndex : fromIndex || 0;
		for(;i<this.length;i++)
			if(searchElement === this[i]) return i;
		return -1;
	}
};

if (!Array.prototype.lastIndexOf) { // internal from Firefox 1.5
	Array.prototype.lastIndexOf = function(searchElement, fromIndex) {
		var max = this.length-1;
		var i = (fromIndex < 0)   ? Math.max(max+1 + fromIndex,0) :
				(fromIndex > max) ? max :
				max-(fromIndex||0) || max;
		for(;i>=0;i--)
			if(searchElement === this[i]) return i;
		return -1;
	}
};
