﻿
Array.prototype.LoadArgs = function(args, start, end) {
    if (typeof(args.length) == 'undefined') { return; }
    if (isNaN(start)) { start = 0; }
    if (isNaN(end)) { end = args.length; }
    for (var i=start; i<end; i++)
    {
        this[this.length] = args[i];
    }
}

Array.prototype.Add = function(obj){
    this[this.length] = obj;
}

Array.prototype.AddRange = function(items){
    this.push.apply(this, items);
}

Array.prototype.Clear = function(){
    this.length = 0;
}

Array.prototype.Clone = function(){
    if (this.length == 1)
    {
        return [this[0]];
    }
    else 
    {
        return Array.apply(null, this);
    }
}

Array.prototype.ForEach = function(func, context) {
    var args = [];
    args[0] = null;
    args[1] = null;
    args.LoadArgs(arguments, 2);
    for (var i=0; i < this.length; i++) {
        var el = this[i];
        args[0] = el;
        args[1] = i       
        if (typeof(el) !== 'undefined') func.apply(context, args);
    }
}

Array.prototype.Contains = function(obj) {
    return (this.IndexOf(obj) >= 0);
}


Array.prototype.IndexOf = function(obj){
    for(var i=0; i<this.length; i++)
    {
        if(obj == this[i]) return i;
    }
    return -1;
}

Array.prototype.Insert = function(index, item) {    
    this.splice(index, 0, item);
}

Array.prototype.Remove = function(obj){
    var index = this.IndexOf(obj);
    this.RemoveAt(index);
}

Array.prototype.RemoveAt = function(index){
    if (index >= 0)
    {
        if (index < this.length)
        {
            this.splice(index, 1);
        } 
    }
}



Function.prototype.Inherits = function(baseClass){
    var c = function() {};
    c.prototype = baseClass.prototype;
    this.prototype = new c();
    this.prototype.NewBase = baseClass
    this.prototype.MyBase = baseClass.prototype;
}

String.prototype.Trim = function(){    
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

String.prototype.TrimStart = function(){    
    return this.replace(/^\s+/, '');
}

String.prototype.TrimEnd = function(){    
    return this.replace(/\s+$/, '');
}
