Make sure that you read this page if you want to use the selected values in a grid:
Until some time ago I was using one of the functions that CRM uses, but since that is unsupported and the method as described in the article as stated above is supported, I am using the new approach.
In short it comes down to this:
// window.dialogArguments contains an array of the IDs for the
// selected records.
var sSelectedRows = window.dialogArguments;
// If sSelectedRows is empty, do not execute the update.
if (sSelectedRows == "" sSelectedRows.length == 0)
alert("You must select records in order to use this feature.");