Topic: Using the JavaScript onUnload event

Hey guys, got a general JavaScript question. I am trying to get the onUnload event working in a page.

I have been tasked with modifying a PHP script I wrote 2 years ago, that handles contact off our school's website from prospects (potential students).

Well they don't want to use databases at all (at least yet), so they want it so even if someone never submits the 2nd page of this form, an e-mail is sent to or call center.

To make a long story short, I am using onUnload to call a JavaScript function I created that I am calling a PHP function using document.write, and then it also calls an alert(). The problem is, when I am testing this, and close this 2nd page, nothing happens, so obviously the onUnload event is not being triggered.

My main question is, can onLoad and onUnload be used at the same time on a page? I tried googling it, but all the results I got had nothing to do in context of what I was seeking.

For clarity, here is the snippet in <head>:

<script type="text/javascript">
    function sendEmail() {
    document.write("<?php sendIncomplete(); ?>");
    alert("Thank you for visiting our site. A representative will contact you ASAP.");

And then here is the snippet from <body>:
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/menu/degree_programs_down.gif','images/box_1_down800-267-4869.gif','images/box_2_down.gif','images/box_3_down.gif','images/box_4_down.gif')" onUnload="sendEmail();">

The code I am working with on the main part of the pages is so badly formatted it's not even funny. Before I came back to the company, they contracted this job to some company that used FrontPage to build the new version of the site. (shoot me now I know! tongue) But my boss said I can't change the html any, so I'm at a loss there, but none the less, the js should still function.

If anyone could give me some insight on this, that'd be awesome.

Thanks in advance for the help.