// Array Extensions  v1.0.6
// documentation: http://www.dithered.com/javascript/array/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
/*
Array.concat() - Join two arrays
Array.copy() - Copy an array
Array.pop() - Remove the last element of an array and return it
Array.push(element) - Add an element to the end of an array
Array.shift() - Remove the first element of an array and return it
Array.slice() - Copy several elements of an array and return them
Array.splice() - Splice out and / or replace several elements of an array and return any deleted elements
Array.unshift(element) - Add an element to the beginning of an array

Fonctions ajoutées : Claude Frascadore
Array.inArray(value) - Returns true if the passed value is found in the array.  Returns false if it is not.
Array.partOfArrayElements(value) - Returns true if the passed value is found in an mixed element (e.g. "aaaa,34,26" ) of the array.  Returns false if it is not.
Array.delElement(index) - deletes an element at index 
Array.getElementPos(value) - Returne the index of a given element

*/

var undefined;
function isUndefined(property) {
  return (typeof property == 'undefined');
}


// Array.concat() - Join two arrays
if (isUndefined(Array.prototype.concat) == true) {
  Array.prototype.concat = function (secondArray) {
     var firstArray = this.copy();
     for (var i = 0; i < secondArray.length; i++) {
        firstArray[firstArray.length] = secondArray[i];
     }
     return firstArray;
  };
}

// Array.copy() - Copy an array
if (isUndefined(Array.prototype.copy) == true) {
  Array.prototype.copy = function() {
     var copy = new Array();
     for (var i = 0; i < this.length; i++) {
        copy[i] = this[i];
     }
     return copy;
  };
}

// Array.pop() - Remove the last element of an array and return it
if (isUndefined(Array.prototype.pop) == true) {
  Array.prototype.pop = function() {
     var lastItem = undefined;
    if ( this.length > 0 ) {
        lastItem = this[this.length - 1];
        this.length--;
    }
    return lastItem;
  };
}

// Array.push() - Add an element to the end of an array
if (isUndefined(Array.prototype.push) == true) {
  Array.prototype.push = function() {
     var currentLength = this.length;
     for (var i = 0; i < arguments.length; i++) {
        this[currentLength + i] = arguments[i];
     }
     return this.length;
  };
}


// Array.shift() - Remove the first element of an array and return it
if (isUndefined(Array.prototype.shift) == true) {
  Array.prototype.shift = function() {
     var firstItem = this[0];
     for (var i = 0; i < this.length - 1; i++) {
        this[i] = this[i + 1];
     }
     this.length--;
     return firstItem;
  };
}

// Array.slice() - Copy several elements of an array and return them
if (isUndefined(Array.prototype.slice) == true) {
  Array.prototype.slice = function(start, end) {
     var temp;
     
     if (end == null || end == '') end = this.length;
     
     // negative arguments measure from the end of the array
     else if (end < 0) end = this.length + end;
     if (start < 0) start = this.length + start;
     
     // swap limits if they are backwards
     if (end < start) {
        temp  = end;
        end   = start;
        start = temp;
     }
     
     // copy elements from array to a new array and return the new array
     var newArray = new Array();
     for (var i = 0; i < end - start; i++) {
        newArray[i] = this[start + i];
     }
     return newArray;
  };
}

// Array.splice() - Splice out and / or replace several elements of an array and return any deleted elements
if (isUndefined(Array.prototype.splice) == true) {
  Array.prototype.splice = function(start, deleteCount) {
     if (deleteCount == null || deleteCount == '') deleteCount = this.length - start;
     
     // create a temporary copy of the array
     var tempArray = this.copy();
     
     // Copy new elements into array (over-writing old entries)
     for (var i = start; i < start + arguments.length - 2; i++) {
        this[i] = arguments[i - start + 2];
     }
     
     // Copy old entries after the end of the splice back into array and return
     for (var i = start + arguments.length - 2; i < this.length - deleteCount + arguments.length - 2; i++) {
        this[i] = tempArray[i + deleteCount - arguments.length + 2];
     }
     this.length = this.length - deleteCount + (arguments.length - 2);
     return tempArray.slice(start, start + deleteCount);
  };
}

// Array.unshift - Add an element to the beginning of an array
if (isUndefined(Array.prototype.unshift) == true) {
  Array.prototype.unshift = function(the_item) {
     for (loop = this.length-1 ; loop >= 0; loop--) {
        this[loop+1] = this[loop];
     }
     this[0] = the_item;
     return this.length;
  };
}

if (isUndefined(Array.prototype.inArray) == true) {
  Array.prototype.inArray = function (value)
  // Returns true if the passed value is found in the
  // array.  Returns false if it is not.
  {
	var i;
	for (i=0; i < this.length; i++) {
		// Matches identical (===), not just similar (==).
		if (this[i] === value) {
			return true;
		}
	}
	return false;
  }
};



if (isUndefined(Array.prototype.partOfArrayElements) == true) {
  Array.prototype.partOfArrayElements = function (value)
  // Returns true if the passed value is found in the
  // array.  Returns false if it is not.
  {
	var i;
	for (i=0; i < this.length; i++) {
		// Matches identical (===), not just similar (==).
		if (this[i].indexOf(value)!=-1) {
			return true;
		}
	}
	return false;
  }
};

if (isUndefined(Array.prototype.partOfArrayComposedElements) == true) {
  Array.prototype.partOfArrayComposedElements = function (value)
  // Returns true if the passed value is found in the first element of
	// an array made of comma delimited strings (eg. 1,2;2,3;1.3... )
  // Returns false if it is not.
  {
	var i;
	for (i=0; i < this.length; i++) {
		// Matches identical (===), not just similar (==).
		elements = this[i].split(',')
		if (elements[0].indexOf(value)!=-1) {
			return true;
		}
	}
	return false;
  }
};




if (isUndefined(Array.prototype.delElement) == true) {
  Array.prototype.delElement = function (delindex)
  {
  	size = this.length;
	validNo = (delindex != "NaN");
	inRange = ( (delindex >= 0) && (delindex <= this.length) );
	if (validNo && inRange) {
		for (var i=0; i<=size; i++)
			this[i] = ((i == delindex) ? "delete" : this[i]);
		for (var j=delindex; j<size-1; j++)
			if (j != size) this[j] = this[j+1];
		this.length = size-1;
	}
  }
}


if (isUndefined(Array.prototype.getElementPos) == true) {
  Array.prototype.getElementPos = function (value)
  {
	var pos = -1;
	for (var i=0; i< this.length; i++)
		if (this[i].indexOf(value)!=-1) {
		// if (this[i]==value) {
			return pos = i;
			break;
		}
	return pos;
  }
}

if (isUndefined(Array.prototype.getComposedElementPos) == true) {
  Array.prototype.getComposedElementPos = function (value)
  // Returns the position if the passed value if found in the first element 
	// of an array made of comma delimited strings (eg. 1,2;2,3;1.3... )
  {
	var pos = -1;
	for (var i=0; i< this.length; i++) {
		elements = this[i].split(',')
		if (elements[0].indexOf(value)!=-1) {
			return pos = i;
			break;
		}
	}
	return pos;
  }
}
