Probably because the document hasn't finished loading when you try to change the color the first time. Maybe you need to check to see it it has loaded before attempting the color change? If it hasn't, do a timeout and check again in 50 milliseconds or so?
If you are calling this form an <a> link, then you need to do either
<a href="something.jpg" onclick="return popitpic(this.href);">
in which case, yes, popitpic needs to return false.
Or you can do
<a href="something.jpg" onclick="popitpic(this.href); return false;">
in which case, the return from popitpic is ignored.