$.fn.addItems = function (data, conditionFunction) {
    return this.emptySelect().each(function () {
        if (this.tagName == 'SELECT') {
            var list = this;
            $.each(data, function (index, itemData) {
                if (conditionFunction == null || conditionFunction(itemData)) {
                    var option = new Option(itemData.Text, itemData.Value);
                    option.selected = itemData.Selected;
                    option.title = itemData.Text;

                    if ($.browser.msie) {
                        list.add(option);
                    }
                    else {
                        list.add(option, null);
                    }
                }
            });
        }
    });
};

$.fn.emptySelect = function() {
    return this.each(function() {
        if (this.tagName == 'SELECT')
            this.options.length = 0;
    });
};

Array.prototype.remove = function(matchFunction) {
    for (var i = 0; i < this.length; i++) {
        if (matchFunction(this[i])) {
            this.splice(i, 1);
        }
    }
}

Array.prototype.indexOfMatched = function(matchFunction) {
    for (var i = 0; i < this.length; i++) {
        if (matchFunction(this[i])) {
            return i;
        }
    }
}

Array.prototype.existsMatch = function(matchFunction) {
    for (var i = 0; i < this.length; i++) {
        if (matchFunction(this[i])) {
            return true;
        }
    }

    return false;
}
