Sorry, NS4 and IE4 went the way of all flesh a long time ago.
document.all was a feature if IE4 and it is no longer supported by IE9. document.layers went out with NS4.
Without a doctype IE defaults to quirks mode. (No standard).
You will need to find more up-to-date code if you want the code to validate in modern browsers.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.