Simple, you're doing it backwards. Pick a doctype, and write your code to fit that. Or in your case, alter your code to fit it. Use the W3C Validator to assist you.
I personally like XHTML Transitional, requires you to write code very cleanly but it does wonders for cross-browser consistency.