I am a javascript noob, so this question might seem very basic and I might need a lot of directions :)
This is the effect I want to create:

The user is currently viewing a PDF in the browser. The doc is embedded with the tag in the HTML. My PDF has forms in it, so there is some processing (validations etc) that I do inside the PDF as the user is interacting with it. Sometimes, after immediately entering a value the user closes the PDF - and my last bit of processing is incomplete.

In such a case, I would like to (1) stop the PDF from closing till my processing is done (the HTML is aware of the processing status of the PDF, so the HTML knows when a close can be allowed) (2) While I have stopped the PDF from closing, after the user has tried to close the window, I want to display some sort of a message to him indicating that the PDf is not done with the processing yet (3) When the message from (2) is being displayed to the user, interaction with the PDF should be disabled - and ideally this fact should be expressed visually. For ex, the PDF can appear grayed out in the background of the message (4)After I am done with the processing I want to close the browser window

For (1),(4) I am using onbeforeunload, and it serves my purposes well. But on the usability front -(2), (3) - I have no clue as to how I must proceed. It could be sort of what [Google Image search does when you click on a thumbnail on the main page](http://www.google.co.in/imgres?imgurl=http://images.free-extras.com/pics/g/garfield-1069.gif&imgrefurl=http://www.free-extras.com/cartoons.html&usg=__VpWTwwzrmSK163w4QeMTuYeqydk=&h=300&w=400&sz=48&hl=en&start=1&zoom=1&tbnid=ZDqJfdmBZVdQkM%3a&tbnh=93&tbnw=124&prev=/images%3Fq%3Dgarfield%26um%3D1%26hl%3Den%26biw%3D1440%26bih%3D781%26tbs%3Disch:1&um=1&itbs=1). - there is an image in the foreground(I could replace this with a message of my own), the background is grayed. However it doesnt prevent interactions with the background - clicking on it takes me to the original webpage. Also, I dont know whether the JS will work when a PDF is already open.

Thanks!