Hi,
I'm not going to dig into your code but I believe this might be a case of having duplicate id values in your code and perhaps this is why JS won't execute correctly if and when duplicates exist. So, I suggest you check what attribute is being used to call for the "close/cancel" command. Hope...
I think you could try jQuery. My suggestion is you insert a white/non-transparent overlay div on top of your page and let your background load behind it. Once the background is done loading hide the overlay div. Check out the event-load function on jquery.com: http://docs.jquery.com/Events/load...
I was working on this for a minute, and then I finally figured it out... (heh, yes I'm sleepy that is why this took a while):
The problem is with your where clause, if you have zero records per day your SQL will not return any rows. If you have a timestamp for a day it will automatically...