/* Implement array.push for browsers which don't support it natively.*/
if(Array.prototype.push == null){
	Array.prototype.push = function(){
		for(var i = 0; i < arguments.length; i++){
			this[this.length] = arguments[i];
		}
		return this.length;
	};
}

/* Implement array.pop for browsers which don't support it natively.*/
if(Array.prototype.pop == null){
	Array.prototype.pop = function(){
		var retval = null;
		if (this.length > 0) {
			retval = this[this.length-1];
			this.length--;
		}
		return retval;
	};
}

/* Implement array.shift for browsers which don't support it natively.*/
if(Array.prototype.shift == null){
	Array.prototype.shift = function(){
		var retval = this[0];
		for (var i = 1; i < this.length; ++i) {
			this[i-1] = this[i];
		}
		this.length--;
		return retval;
	};
}

/* Implement array.unshift for browsers which don't support it natively.*/
if(Array.prototype.unshift == null){
	Array.prototype.unshift = function(){
		var n = arguments.length;
		for (var i = this.length-1; i >= 0; --i) {
			this[i+n] = this[i];
		}
		for (i = 0; i < n; ++i) {
			this[i] = arguments[i];
		}
		return this.length;
	};
}

/* Implement array.splice for browsers which don't support it natively.*/
if(Array.prototype.splice == null){
	Array.prototype.splice = function(){
		var n = arguments.length;
		if (n < 2) {
			return [];
		}
		var k = arguments[0];
		var r = arguments[1];
		if (k < 0) {
			k += this.length;
			if (k < 0) {
				k = 0;
			}
		}
		if (k > this.length) {
			k = this.length;
		}
		if (r < 0) {
			r = 0;
		}
		if (k+r > this.length) {
			r = this.length - k;
		}
		var a = n - 2;
		var i;
		
		var retarr = new Array();
		for (i = 0; i < r; ++i) {
			retarr[i] = this[i+k];
		}
		
		if (a > r) {
			rs = a-r;
			for (i = this.length-1; i >= k+r; --i) {
				this[i+rs] = this[i];
			}
		}
		else if (a < r) {
			ls = r-a;
			for (i = k+a; i < this.length-ls; ++i) {
				this[i] = this[i+ls];
			}
			this.length -= ls;
		}
		for (i = 0; i < a; ++i) {
			this[i+k] = arguments[i+2];
		}
		return retarr;
	};
}
