﻿String.prototype.LTrim = function() {
    var s = this;
    while ((s.substring(0, 1) == ' ') || (s.substring(0, 1) == '\n') || (s.substring(0, 1) == '\r')) {
        s = s.substring(1, s.length);
    }
    return s;
}

/**
* RTrim - function which trims the given string from right
* @addon
* @return string trimed from right
* @type String
*/
String.prototype.RTrim = function() {
    var s = this;
    while ((s.substring(s.length - 1, s.length) == ' ') || (s.substring(s.length - 1, s.length) == '\n') || (s.substring(s.length - 1, s.length) == '\r')) {
        s = s.substring(0, s.length - 1);
    }
    return s;
}

/**
* Trim - function which trims string from left {@link #LTrim} and right {@link #RTrim}
* @addon
* @return string trimed from right and left
* @type String
*/
String.prototype.Trim = function() {
    var s = this.LTrim();
    s = s.RTrim();
    return s;

}

/**
* RemoveItemByIndex - removes items at given index
* @param i index of item
* @addon 
*/
Array.prototype.RemoveItemByIndex = function(i) {
    this.splice(i, 1);
}

Array.prototype.Insert = function(item, index) {
    this.splice(index, 0, item);
}


/**
* RemoveItemByValue - removes items of given value from array (all or one depends on all argument)
* @param value search items of given value
* @param {Boolean} all should all items of that value have to be removed
* @addon 
*/
Array.prototype.RemoveItemByValue = function(value, all) {
    for (var i = 0; i < this.length; ) {
        if (this[i] == value) {
            this.RemoveItemByIndex(i);
            if (all != true) {
                return
            }
        }
        else {
            i++;
        }
    }
}

/**
* IndexOf - returns the index of some value
* @param value search items of given value
* @return index of searched value
* @addon 
*/
Array.prototype.IndexOf = function(value) {
    if (this.indexOf) {
        return this.indexOf(value)
    }
    for (var i = 0; i < this.length; i++) {
        if (this[i] == value) {
            return i
        }
    }
    return -1;
}

