It's a scope issue (and I don't mean the mouthwash).
You are attempting to access a page element that hasn't been created yet. Try moving this:
to the end of the page (just before or just after the </body> tag).
if (isValidIE || isValidNetscape)...
is executing right after the <body> tag, but before any other page elements have been created.
A better solution would be to wrap that bit of code in a function, and to call it from the onload event of the <body> tag.
// Context menu stuff
if (isValidIE || isValidNetscape)
var menuobj = document.getElementById( "myId" )
if ( null == menuobj )
window.alert("menu obj is null");
If you did that, then the external .js file could be loaded in the <head> section (or anywhere else).