﻿Array.prototype.getIndexByVal = function(val)
{
	var iter = 0;
	for (iter = 0; iter < this.length; iter++)
		if (this[iter] == val) return iter;
	return -1;
}

Array.prototype.isInArray = function(val)
{
	return  this.getIndexByVal(val) >= 0;
}
			
Array.prototype.addVal = function(val)
{
	var addIndex = this.getIndexByVal(val);
	if (addIndex == -1)
		this[this.length] = val;
}
			
Array.prototype.delVal = function(val)
{
	var delIndex = this.getIndexByVal(val);
	if (delIndex >= 0)
		this.splice(delIndex, 1);
}

Array.fromString = function(string, delimiter)
{
	if (string.length > 0) 
		return string.split(";");
	return new Array();
}

Array.prototype.clear = function()
{
	this.splice(0, this.length);
}

Array.prototype.forEach = function(handler, scope) 
{
    scope = scope || this;
    for( var i = 0; i < this.length; i++)
        handler.call(scope, i, this[i]);
};
Array.prototype.each = Array.prototype.forEach;
