Using jQuery Dialog to give a message before leaving page

this dialog example should replace the Prototype ModalBox (okonet.ru) which is used along our customers pages.

HTML

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/ui-lightness/jquery-ui.css">

JavaScript

window.onbeforeunload = function (e) {
			$('<div title="Warning!">A search is in progress, do you really want to stop the search and '+ 			'close the tab? If not, choose "Stay on page" on the browser alert.</div>').dialog({
				modal:true,
				close: function(){$(this).dialog('destroy').remove();},
				position: { my: "center top", at: "center", of: window }
			});
			return "Random message to trigger the browser's native alert.";
}