It may have something to do with the linebreaks in the source, since it appears to be reading the onclick as its own object and not as a part of the opening div's code.
You could also change that code to be simpler, like <a href="YOURURL"><div id="header"><div id="headerimg"></div></div></a>
You could even place the headerimg as a background to the header div itself, so you don't have to have two divs for one thing.