Hey javascript experts, haven't been able to figure this one out:

I have a site where I need the javascript code to insert onto my homepage for the following:

When a user wants to exit the entire site from clicking the browser, (the 'X' CLOSE window)
how do I set a confirmation box to pop up to confirm navigation away from the page, and maybe offer 2 options "Close the window" or "Stay on this Page". If a user opts to stay on the page, I'd then want to link to an invisible page on the same site.
I've seen this on several sites and it's not specific to any browser apparently it's in the code for the sites.

Thanks mucho guys!