Your javascript looks fine. The ultimatebb.cgi hack doesn't effect the cookie at all so the problem lies somewhere else. If you put that javascript code on any page of your site it will read the cookie and let you know if you are logged in or not even if you don't do any hacks to UBB whatsoever. As log as you don't logout first, when you go to a non-UBB page on your site the cookie is still there and shows you as logged in which is why you don't need to log in again if you return to the forums.
The only things that I can think of that could be wrong is that your UBB and pages either aren't on the same domain (cookies can only be read by the domain that wrote them) or you have a typo in your cookie number.