Well, first I said that it's a Javascript function that's causing the problem instead of a PHP one. Subtle hint: you're not as likely to get help here, perhaps...(dunno for sure). I'm tryin', eh?
Secondly, I pointed out that the Javascript function takes you to a URL that doesn't match the URL you get if you simple navigate to the forum manually, as the poster mentions. It seems to me, from my POV, that your best option would be to correct the data that the Javascript function is using so that it calls the URL correctly.
The alternative, I suppose, is to disable whatever security or coding is giving the "You can't access this page directly" message. It's likely this wouldn't do much good, though, since, as I mentioned, it seems like the JS thing is leaving out a needed PHP variable: $viewforum
HTH,