Just start by researching "doctype". Learn what a doctype is, and which one you should use.
After you've got that figured out, adjust your code accordingly. You may find you don't need to test for different browsers at all.
If you do, find a better, more thorough "browser sniffer" script.