Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) {
    "use strict";

    if (this === void 0 || this === null)
        throw new TypeError();

    var t = Object(this);
    var len = t.length >>> 0;
    if (len === 0)
        return -1;

    var n = len;
    if (arguments.length > 1) {
        n = Number(arguments[1]);
        if (n !== n)
            n = 0;
        else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
            n = (n > 0 || -1) * Math.floor(Math.abs(n));
    }

    var k = n >= 0
          ? Math.min(n, len - 1)
          : len - Math.abs(n);

    for (; k >= 0; k--) {
        if (k in t && t[k] === searchElement)
            return k;
    }
    return -1;
};

Array.prototype.filter = function(fn, obj) {
    for (var l = this.length, i = 0, a = []; i < l; i++) {
        fn.apply(obj, [this[i], i, this]) && a.push(this[i]);
    }
    return a;
}


Array.prototype.unique = function() {
    return this.filter(function(e, i, a) {
        return a.lastIndexOf(e) == i;
    });
}

function addSelectedGroups(id) {
    if (id) { selectedIds.length = 0; selectedIds.push(id); rowChecked(id, true); }
    if (selectedIds.length == 0) { alert(ExecutorGroupResources.NoGroupsSelected); return false; }
    selectedIds = selectedIds.unique();

    var result = new Array();

    result["selectedIds"] = selectedIds;
    result["selectedNames"] = selectedNames;

    if (getURLParameter('msName') != null && getURLParameter('msName') != '') {
        result["msName"] = getURLParameter('msName');
    }

    var targetBlock = getURLParameter('targetBlock');
    if ((self.callback == null || (self.callback == undefined && navigator.appName == 'Opera')) && targetBlock != null && targetBlock != '') {
        if (targetBlock == 'ExecutorGroupItemData') {
            self.callback = opener.ExecutorGroupItemData.selectExecutorGroupsCallback;
        }
        else {
            self.callback = opener.executorGroupsCallback;
        }
    }
    else if (self.callback == null || (self.callback == undefined && navigator.appName == 'Opera')) {
        self.callback = opener.executorGroupsCallback;
    }

    //if (self.callback == null) self.callback = opener.executorGroupsCallback;
    self.callback(result);
    
    self.close();
    return false;
}