It's not clear to me why this script knows about the card_ids array and the deck_id.  I define those variables on the page, but I would have thought that this function would be out of their scope.