Fix ability to sort by case owner

http://manage.dimagi.com/default.asp?121159

best reviewed commit by commit.
IMO it's less than ideal to pull this out into a global. I guess this was necessary because SortRow is a global, but the reasoning for that is less clear, I imagine it's used somewhere else? Do you have any thoughts on that?