//var selectedIds = new Array();
//var assetTypeNames = new Array();

$(function () {
    $('.rowid').click(function () { selectRow(this.value, this.checked); });
});

//function rowChecked(id, check) {
//    if ($('#id' + id).length > 0) {
//        assetTypeNames['id' + id.toString()] = $('#id' + id).attr('fullname');
//    }
//}

function selectRow(val, check) {
    var cb = $('#id' + val);
    if (check) {
        selectedIds.push(val);
        if ($('#mode').val() == 'CREATORS' || $('#mode').val() == 'COMPANYUSER' || $('#mode').val() == 'SUBSCRIBE' || $('#mode').val() == 'SERVICEUSER' || $('#mode').val() == 'EXTERNALCONTRACTORS' || (getURLParameter('selectmode') != null && getURLParameter('selectmode') != '' && getURLParameter('selectmode') == "SINGLE") || (getURLParameter('tb_mode') != null && getURLParameter('tb_mode') != '' && getURLParameter('tb_mode') == "SERVICEGROUPS")) {
            $('input:checked').parents('tr').removeClass('selected');
            $("input:checked").attr('checked', false);
            $(cb).checked = true;
            selectedIds.reverse();
        }

        if (cb) {
            $(cb).prop('checked', true);
            $(cb).parents('tr').addClass('selected');
        }
    }
    else {
        selectedIds = $.grep(selectedIds, function (i) { return i != val; });
        if (cb) {
            $(cb).prop('checked', false);
            $(cb).parents('tr').removeClass('selected');
        }
    }
    try { if (rowChecked) rowChecked(val, check); } catch (e) { }
}

function addSelectedAssetTypes() {
    if (selectedIds.length == 0) { alert(AssetResources.NoAssetSelected); return false; }
    selectedIds = $.unique(selectedIds);
    if ($('#selectmode').val().toLowerCase() == 'single' && selectedIds.length > 1) {
        id = selectedIds[0];
    }

    var result = new Array();
    result["selectedIds"] = selectedIds;
    result["selectedNames"] = selectedNames;

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

    if (self.callback == null) {
        if (getURLParameter('cbmode') != null && getURLParameter('cbmode') != '') {
            eval('opener.' + getURLParameter('cbmode') + '.assetTypesCallback(result)');
        } else {
            self.callback = opener.assetTypesCallback;
            self.callback(result);
        }
    } else {
        self.callback(result);
    }

    self.close();
    return false;
}