// Adding Javascript1.6 support for IE
// There function are already exist in FF2&3

// New Array functions
// - indexOf, lastIndexOf
// - every, some, filter
// - map, forEach



if (!Array.prototype.every){

	Array.prototype.every = function(fn /*, thisp*/){

		var len = this.length;
		if (typeof fn != "function") throw new TypeError();
		var thisp = arguments[1];
		
		for (var i = 0; i < len; i++){
			if (i in this && !fn.call(thisp, this[i], i, this))
			return false;
		}
		return true;
	}
} 


//================================================================



if (!Array.prototype.lastIndexOf){

	Array.prototype.lastIndexOf = function(elt /*, from*/){
	
		var len = this.length;
		
		var from = Number(arguments[1]);
		
		if (isNaN(from)){
			from = len - 1;
		}else{
		
			from = (from < 0)? Math.ceil(from):Math.floor(from);
			
			if (from < 0){
				from += len;
			}else{
				if (from >= len){
					from = len - 1;
				}
			}
		}
		
		
		for (; from > -1; from--){
			if (from in this && this[from] === elt){
				return from;
			}
		}
		
		return -1;
	}
} 


//==================================================



if (!Array.prototype.indexOf){

	Array.prototype.indexOf = function(elt /*, from*/)	{
	
		var len = this.length;
		var from = Number(arguments[1]) || 0;
	
		from = (from < 0)? Math.ceil(from): Math.floor(from);
		
		if (from < 0){from += len;}
		
		for (; from < len; from++){
			if (from in this && this[from] === elt){return from;}
		}
		
		return -1;
	}
} 

//==============================================


if (!Array.prototype.some){

	Array.prototype.some = function(fn /*, thisp*/){
	
		var len = this.length;
		
		if (typeof fn != "function"){throw new TypeError();}
		
		var thisp = arguments[1];
		
		for (var i = 0; i < len; i++){
			if (i in this && fn.call(thisp, this[i], i, this)){return true;}
		}
		
		return false;
	}
} 

//================================================


if (!Array.prototype.map){

	Array.prototype.map = function(fn /*, thisp*/)
	
	{
	
		var len = this.length;
		
		if (typeof fn != "function"){throw new TypeError();}
		
		var res = new Array(len);
		var thisp = arguments[1];
		
		for (var i = 0; i < len; i++){
			if (i in this){res[i] = fn.call(thisp, this[i], i, this);}
		}
		
		return res;
	}
} 

//===========================================================


if (!Array.prototype.filter){

	Array.prototype.filter = function(fn /*, thisp*/){
	
		var len = this.length;
		
		if (typeof fn != "function"){throw new TypeError();}
		
		var res = new Array();
		var thisp = arguments[1];
		
		for (var i = 0; i < len; i++){
		
			if (i in this)	{
				var val = this[i]; // in case fn mutates this
				if (fn.call(thisp, val, i, this)){res.push(val);}
			}
		
		}
		
		return res;
	}
} 

//====================================================


 

if (!Array.prototype.forEach){

	Array.prototype.forEach = function(fn /*, thisp*/){
	
		var len = this.length;
		
		if (typeof fn != "function"){throw new TypeError();}
		
		var thisp = arguments[1];
		
		for (var i = 0; i < len; i++){
			if (i in this){fn.call(thisp, this[i], i, this);}
		}
	}
} 


