Related cases fix

http://manage.dimagi.com/default.asp?149765#838590
Actually with first commit I did that, with that, for some reason case-history tab broke due to some javascript error, I could have dug into that, but thought not worth, since this is very weird edge case. WIll do that.