onbeforeunload is always going to execute whenever you're going to move from the current page. there's no way to control when onbeforeunload executes. About the only thing you can try to do is do an onclick on the buttons on the page and make the onbeforeunload function you call check to see if the unload was do to a onclick of a button and then don't execute the alert.
so why exactly do you need to notify the user when they click the close box?
I did a little more digging and you must not be setting your onclick event properly if it never gets called before the onbeforeunload. onclick should always have precedence to your onbeforeunload event. I did a quick test and confirmed that is indeed the case.So, if you can't get the onclick event to work then you're basically done and your client is just going to have to treat it as a training issue (which is what it should have been from the start).