Bug 1541789 - Port bug 1529231: Replace ondialogaccept and ondialogcancel attributes with addEventListener. rs=bustage-fix,jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 04 Apr 2019 18:58:52 +1300
changeset 34130 ea892780482c5941b4df1b179cd6b92c681d8757
parent 34129 270dd6e228211877eb570b1245f5a2d5fe516fc8
child 34131 13ef0f807c907927b2bc68f6add6a1648edbd1ee
push id2407
push userclokep@gmail.com
push dateMon, 20 May 2019 17:11:26 +0000
treeherdercomm-beta@193428fd6fd4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix, jorgk
bugs1541789, 1529231
Bug 1541789 - Port bug 1529231: Replace ondialogaccept and ondialogcancel attributes with addEventListener. rs=bustage-fix,jorgk
calendar/base/content/dialogs/calendar-conflicts-dialog.xul
calendar/base/content/dialogs/calendar-event-dialog-attendees.js
calendar/base/content/dialogs/calendar-event-dialog-attendees.xul
calendar/base/content/dialogs/calendar-event-dialog-recurrence.js
calendar/base/content/dialogs/calendar-event-dialog-recurrence.xul
calendar/base/content/dialogs/calendar-event-dialog-reminder.js
calendar/base/content/dialogs/calendar-event-dialog-reminder.xul
calendar/base/content/dialogs/calendar-event-dialog-timezone.js
calendar/base/content/dialogs/calendar-event-dialog-timezone.xul
calendar/base/content/dialogs/calendar-event-dialog.xul
calendar/base/content/dialogs/calendar-invitations-dialog.js
calendar/base/content/dialogs/calendar-invitations-dialog.xul
calendar/base/content/dialogs/calendar-occurrence-prompt.xul
calendar/base/content/dialogs/calendar-print-dialog.js
calendar/base/content/dialogs/calendar-print-dialog.xul
calendar/base/content/dialogs/calendar-properties-dialog.js
calendar/base/content/dialogs/calendar-properties-dialog.xul
calendar/base/content/dialogs/calendar-providerUninstall-dialog.js
calendar/base/content/dialogs/calendar-providerUninstall-dialog.xul
calendar/base/content/dialogs/calendar-subscriptions-dialog.js
calendar/base/content/dialogs/calendar-subscriptions-dialog.xul
calendar/base/content/dialogs/calendar-summary-dialog.js
calendar/base/content/dialogs/calendar-summary-dialog.xul
calendar/base/content/dialogs/chooseCalendarDialog.js
calendar/base/content/dialogs/chooseCalendarDialog.xul
calendar/base/content/preferences/editCategory.js
calendar/base/content/preferences/editCategory.xul
calendar/lightning/content/lightning-item-panel.js
calendar/providers/gdata/content/gdata-migration-wizard.xul
calendar/providers/gdata/content/gdata-migration.js
calendar/resources/content/publishDialog.js
calendar/resources/content/publishDialog.xul
editor/ui/dialogs/content/EdAdvancedEdit.js
editor/ui/dialogs/content/EdAdvancedEdit.xul
editor/ui/dialogs/content/EdButtonProps.js
editor/ui/dialogs/content/EdButtonProps.xul
editor/ui/dialogs/content/EdColorPicker.js
editor/ui/dialogs/content/EdColorPicker.xul
editor/ui/dialogs/content/EdColorProps.js
editor/ui/dialogs/content/EdColorProps.xul
editor/ui/dialogs/content/EdConvertToTable.js
editor/ui/dialogs/content/EdConvertToTable.xul
editor/ui/dialogs/content/EdDialogTemplate.js
editor/ui/dialogs/content/EdDialogTemplate.xul
editor/ui/dialogs/content/EdDictionary.js
editor/ui/dialogs/content/EdDictionary.xul
editor/ui/dialogs/content/EdFieldSetProps.js
editor/ui/dialogs/content/EdFieldSetProps.xul
editor/ui/dialogs/content/EdFormProps.js
editor/ui/dialogs/content/EdFormProps.xul
editor/ui/dialogs/content/EdHLineProps.js
editor/ui/dialogs/content/EdHLineProps.xul
editor/ui/dialogs/content/EdImageProps.js
editor/ui/dialogs/content/EdImageProps.xul
editor/ui/dialogs/content/EdInputImage.js
editor/ui/dialogs/content/EdInputImage.xul
editor/ui/dialogs/content/EdInputProps.js
editor/ui/dialogs/content/EdInputProps.xul
editor/ui/dialogs/content/EdInsSrc.js
editor/ui/dialogs/content/EdInsSrc.xul
editor/ui/dialogs/content/EdInsertMath.js
editor/ui/dialogs/content/EdInsertMath.xul
editor/ui/dialogs/content/EdInsertTOC.js
editor/ui/dialogs/content/EdInsertTOC.xul
editor/ui/dialogs/content/EdInsertTable.js
editor/ui/dialogs/content/EdInsertTable.xul
editor/ui/dialogs/content/EdLabelProps.js
editor/ui/dialogs/content/EdLabelProps.xul
editor/ui/dialogs/content/EdLinkChecker.js
editor/ui/dialogs/content/EdLinkChecker.xul
editor/ui/dialogs/content/EdLinkProps.js
editor/ui/dialogs/content/EdLinkProps.xul
editor/ui/dialogs/content/EdListProps.js
editor/ui/dialogs/content/EdListProps.xul
editor/ui/dialogs/content/EdNamedAnchorProps.js
editor/ui/dialogs/content/EdNamedAnchorProps.xul
editor/ui/dialogs/content/EdPageProps.js
editor/ui/dialogs/content/EdPageProps.xul
editor/ui/dialogs/content/EdReplace.js
editor/ui/dialogs/content/EdReplace.xul
editor/ui/dialogs/content/EdSelectProps.js
editor/ui/dialogs/content/EdSelectProps.xul
editor/ui/dialogs/content/EdSnapToGrid.js
editor/ui/dialogs/content/EdSnapToGrid.xul
editor/ui/dialogs/content/EdSpellCheck.js
editor/ui/dialogs/content/EdSpellCheck.xul
editor/ui/dialogs/content/EdTableProps.js
editor/ui/dialogs/content/EdTableProps.xul
editor/ui/dialogs/content/EdTextAreaProps.js
editor/ui/dialogs/content/EdTextAreaProps.xul
editor/ui/dialogs/content/EditConflict.js
editor/ui/dialogs/content/EditConflict.xul
editor/ui/dialogs/content/EditorPublish.js
editor/ui/dialogs/content/EditorPublish.xul
editor/ui/dialogs/content/EditorPublishProgress.js
editor/ui/dialogs/content/EditorPublishProgress.xul
editor/ui/dialogs/content/EditorPublishSettings.js
editor/ui/dialogs/content/EditorPublishSettings.xul
editor/ui/dialogs/content/EditorSaveAsCharset.js
editor/ui/dialogs/content/EditorSaveAsCharset.xul
mail/base/content/newTagDialog.js
mail/base/content/newTagDialog.xul
mail/base/content/safeMode.js
mail/base/content/safeMode.xul
mail/base/content/sanitize.xul
mail/base/content/sanitizeDialog.js
mail/base/content/systemIntegrationDialog.js
mail/base/content/systemIntegrationDialog.xul
mail/components/addrbook/content/abEditCardDialog.xul
mail/components/addrbook/content/abEditListDialog.xul
mail/components/addrbook/content/abMailListDialog.xul
mail/components/addrbook/content/abNewCardDialog.xul
mail/components/im/content/addbuddy.js
mail/components/im/content/addbuddy.xul
mail/components/im/content/joinchat.js
mail/components/im/content/joinchat.xul
mail/components/preferences/applicationManager.js
mail/components/preferences/applicationManager.xul
mail/components/preferences/attachmentReminder.js
mail/components/preferences/attachmentReminder.xul
mail/components/preferences/fonts.js
mail/components/preferences/fonts.xul
mail/extensions/mailviews/content/mailViewSetup.js
mail/extensions/mailviews/content/mailViewSetup.xul
mailnews/addrbook/content/abAddressBookNameDialog.js
mailnews/addrbook/content/abAddressBookNameDialog.xul
mailnews/addrbook/prefs/content/pref-directory-add.js
mailnews/addrbook/prefs/content/pref-directory-add.xul
mailnews/base/content/folderProps.js
mailnews/base/content/folderProps.xul
mailnews/base/content/junkLog.xul
mailnews/base/content/markByDate.js
mailnews/base/content/markByDate.xul
mailnews/base/content/msgSelectOfflineFolders.js
mailnews/base/content/msgSelectOfflineFolders.xul
mailnews/base/content/msgSynchronize.js
mailnews/base/content/msgSynchronize.xul
mailnews/base/content/newFolderDialog.js
mailnews/base/content/newFolderDialog.xul
mailnews/base/content/renameFolderDialog.js
mailnews/base/content/renameFolderDialog.xul
mailnews/base/content/shutdownWindow.js
mailnews/base/content/shutdownWindow.xul
mailnews/base/content/subscribe.js
mailnews/base/content/subscribe.xul
mailnews/base/content/virtualFolderListEdit.js
mailnews/base/content/virtualFolderListEdit.xul
mailnews/base/content/virtualFolderProperties.js
mailnews/base/content/virtualFolderProperties.xul
mailnews/base/prefs/content/AccountManager.js
mailnews/base/prefs/content/AccountManager.xul
mailnews/base/prefs/content/SmtpServerEdit.js
mailnews/base/prefs/content/SmtpServerEdit.xul
mailnews/base/prefs/content/am-archiveoptions.js
mailnews/base/prefs/content/am-archiveoptions.xul
mailnews/base/prefs/content/am-identities-list.js
mailnews/base/prefs/content/am-identities-list.xul
mailnews/base/prefs/content/am-identity-edit.js
mailnews/base/prefs/content/am-identity-edit.xul
mailnews/base/prefs/content/am-server-advanced.js
mailnews/base/prefs/content/am-server-advanced.xul
mailnews/base/prefs/content/removeAccount.js
mailnews/base/prefs/content/removeAccount.xul
mailnews/base/search/content/CustomHeaders.js
mailnews/base/search/content/CustomHeaders.xul
mailnews/base/search/content/FilterEditor.js
mailnews/base/search/content/FilterEditor.xul
mailnews/base/search/content/viewLog.xul
mailnews/compose/content/askSendFormat.js
mailnews/compose/content/askSendFormat.xul
mailnews/compose/content/sendProgress.js
mailnews/compose/content/sendProgress.xul
mailnews/extensions/smime/content/am-smime.js
mailnews/extensions/smime/content/am-smime.xul
mailnews/extensions/smime/content/certFetchingStatus.js
mailnews/extensions/smime/content/certFetchingStatus.xul
mailnews/extensions/smime/content/certpicker.js
mailnews/extensions/smime/content/certpicker.xul
mailnews/import/content/fieldMapImport.js
mailnews/import/content/fieldMapImport.xul
mailnews/news/content/downloadheaders.js
mailnews/news/content/downloadheaders.xul
--- a/calendar/base/content/dialogs/calendar-conflicts-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-conflicts-dialog.xul
@@ -4,18 +4,16 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet type="text/css" href="chrome://global/skin/global.css"?>
 <?xml-stylesheet type="text/css" href="chrome://calendar/skin/calendar-views.css"?>
 
 <dialog id="calendar-conflicts-dialog"
         windowtype="Calendar:Conflicts"
         onload="onLoad()"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();"
         persist="screenX screenY"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
   <script type="application/javascript" src="chrome://calendar/content/mouseoverPreviews.js"/>
   <script type="application/javascript"><![CDATA[
     const { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
     function onLoad() {
         let docEl = document.documentElement;
         let item = window.arguments[0].item;
@@ -40,23 +38,23 @@
             docEl.getButton("accept").setAttribute("label", cal.l10n.getCalString("proceedDelete"));
         }
 
         docEl.getButton("cancel").setAttribute("label", cal.l10n.getCalString("updateFromServer"));
 
         window.sizeToContent();
     }
 
-    function onAccept() {
+    document.addEventListener("dialogaccept", () => {
         window.arguments[0].overwrite = true;
-    }
+    });
 
-    function onCancel() {
+    document.addEventListener("dialogcancel", () => {
         window.arguments[0].overwrite = false;
-    }
+    });
   ]]></script>
 
   <vbox id="conflicts-vbox" flex="1">
     <vbox id="item-box" flex="1"/>
     <description id="conflicts-description"
                  style="max-width: 40em; margin-top: 1ex"/>
   </vbox>
 </dialog>
--- a/calendar/base/content/dialogs/calendar-event-dialog-attendees.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-attendees.js
@@ -21,16 +21,19 @@ var gEndHour = 24;
 var gIsReadOnly = false;
 var gIsInvitation = false;
 var gIgnoreUpdate = false;
 var gDisplayTimezone = true;
 var gUndoStack = [];
 var gForce24Hours = false;
 var gZoomFactor = 100;
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * Sets up the attendee dialog
  */
 function onLoad() {
     // set calendar-event-freebusy-timebar date and time properties
     setFreebusyTimebarTime();
 
     // set up some calendar-event-freebusy-timebar properties
--- a/calendar/base/content/dialogs/calendar-event-dialog-attendees.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog-attendees.xul
@@ -14,18 +14,16 @@
   <!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/calendar.dtd" > %dtd1;
   <!ENTITY % dtd2 SYSTEM "chrome://calendar/locale/calendar-event-dialog.dtd" > %dtd2;
 ]>
 
 <dialog id="calendar-event-dialog-attendees-v2"
         title="&invite.title.label;"
         windowtype="Calendar:EventDialog:Attendees"
         onload="onLoad()"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();"
         defaultButton="none"
         height="500"
         persist="screenX screenY height width"
         orient="vertical"
         style="padding-top: 8px; padding-bottom: 10px; padding-inline-start: 8px; padding-inline-end: 10px;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
--- a/calendar/base/content/dialogs/calendar-event-dialog-recurrence.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-recurrence.js
@@ -1,25 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoad, onAccept, onCancel */
+/* exported onLoad */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { splitRecurrenceRules } = ChromeUtils.import("resource://calendar/modules/calRecurrenceUtils.jsm");
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var gIsReadOnly = false;
 var gStartTime = null;
 var gEndTime = null;
 var gUntilDate = null;
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * Object wrapping the methods and properties of recurrence-preview binding.
  */
 const RecurrencePreview = {
     /**
      * Initializes some properties and adds event listener to the #recurrence-preview node.
      */
     init() {
--- a/calendar/base/content/dialogs/calendar-event-dialog-recurrence.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog-recurrence.xul
@@ -17,18 +17,16 @@
   <!ENTITY % dialogDTD SYSTEM "chrome://calendar/locale/calendar-event-dialog.dtd">
   %dialogDTD;
 ]>
 
 <dialog id="calendar-event-dialog-recurrence"
         title="&recurrence.title.label;"
         windowtype="Calendar:EventDialog:Recurrence"
         onload="onLoad()"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();"
         persist="screenX screenY width height"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
   <script type="application/javascript" src="chrome://calendar/content/calendar-event-dialog-recurrence.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-dialog-utils.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-statusbar.js"/>
--- a/calendar/base/content/dialogs/calendar-event-dialog-reminder.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-reminder.js
@@ -1,26 +1,27 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoad, onReminderSelected, updateReminder, onNewReminder,
- *          onRemoveReminder, onAccept, onCancel
- */
+/* exported onLoad, onReminderSelected, updateReminder, onNewReminder, onRemoveReminder */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { PluralForm } = ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
 var allowedActionsMap = {};
 var suppressListUpdate = false;
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * Sets up the reminder dialog.
  */
 function onLoad() {
     let calendar = window.arguments[0].calendar;
 
     // Make sure the origin menulist uses the right labels, depending on if the
     // dialog is showing an event or task.
--- a/calendar/base/content/dialogs/calendar-event-dialog-reminder.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog-reminder.xul
@@ -13,18 +13,16 @@
 <?xml-stylesheet type="text/css" href="chrome://calendar/content/calendar-bindings.css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://calendar/locale/dialogs/calendar-event-dialog-reminder.dtd" >
 
 <dialog id="calendar-event-dialog-reminder"
         title="&reminderdialog.title;"
         windowtype="Calendar:EventDialog:Reminder"
         onload="onLoad()"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();"
         persist="screenX screenY width height"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
   <script type="application/javascript" src="chrome://calendar/content/calendar-event-dialog-reminder.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
   <script type="application/javascript" src="chrome://messenger/content/customElements.js"/>
   <script type="application/javascript" src="chrome://calendar/content/datetimepickers/datetimepickers.js"/>
--- a/calendar/base/content/dialogs/calendar-event-dialog-timezone.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-timezone.js
@@ -1,18 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoad, onAccept, onCancel */
+/* exported onLoad */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * Sets up the timezone dialog from the window arguments, also setting up all
  * dialog controls from the window's dates.
  */
 function onLoad() {
     let args = window.arguments[0];
     window.time = args.time;
     window.onAcceptCallback = args.onOk;
--- a/calendar/base/content/dialogs/calendar-event-dialog-timezone.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog-timezone.xul
@@ -16,18 +16,16 @@
   <!ENTITY % dtd3 SYSTEM "chrome://calendar/locale/calendar-event-dialog.dtd" > %dtd3;
   <!ENTITY % dtd4 SYSTEM "chrome://calendar/locale/preferences/timezones.dtd" > %dtd4;
 ]>
 
 <dialog id="calendar-event-dialog-timezone"
         title="&timezone.title.label;"
         windowtype="Calendar:EventDialog:Timezone"
         onload="onLoad()"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();"
         persist="screenX screenY width height"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
   <script type="application/javascript" src="chrome://calendar/content/calendar-event-dialog-timezone.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-dialog-utils.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
   <script type="application/javascript" src="chrome://messenger/content/customElements.js"/>
--- a/calendar/base/content/dialogs/calendar-event-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog.xul
@@ -28,18 +28,16 @@
 <?xul-overlay href="chrome://lightning/content/lightning-item-toolbar.xul"?>
 
 <!-- Dialog id is changed during execution to allow different Window-icons
      on this dialog. document.loadOverlay() will not work on this one. -->
 <dialog title="&event.title.label;"
         windowtype="Calendar:EventDialog"
         onload="onLoadLightningItemPanel();"
         onunload="onUnloadLightningItemPanel();"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();"
         persist="screenX screenY width height"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
   <script type="application/javascript"
           src="chrome://lightning/content/lightning-item-panel.js"/>
   <script type="application/javascript"
           src="chrome://calendar/content/calendar-dialog-utils.js"/>
--- a/calendar/base/content/dialogs/calendar-invitations-dialog.js
+++ b/calendar/base/content/dialogs/calendar-invitations-dialog.js
@@ -1,18 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoad, onUnload, onAccept, onCancel */
+/* exported onLoad, onUnload */
 
 /* globals invitationsText */// From calendar-invitations-dialog.xul.
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * Sets up the invitations dialog from the window arguments, retrieves the
  * invitations from the invitations manager.
  */
 function onLoad() {
     let operationListener = {
         QueryInterface: ChromeUtils.generateQI([Ci.calIOperationListener]),
         onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {
--- a/calendar/base/content/dialogs/calendar-invitations-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-invitations-dialog.xul
@@ -11,18 +11,16 @@
     <!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/calendar-invitations-dialog.dtd" >  %dtd1;
 ]>
 
 <dialog
   id="calendar-invitations-dialog"
   title="&calendar.invitations.dialog.invitations.text;"
   windowtype="Calendar:InvitationsDialog"
   buttons="accept,cancel"
-  ondialogaccept="return onAccept();"
-  ondialogcancel="return onCancel();"
   onload="return onLoad();"
   onunload="return onUnload();"
   persist="screenX screenY width height"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
   <script type="application/javascript" src="chrome://calendar/content/calendar-invitations-dialog.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
--- a/calendar/base/content/dialogs/calendar-occurrence-prompt.xul
+++ b/calendar/base/content/dialogs/calendar-occurrence-prompt.xul
@@ -6,26 +6,27 @@
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://calendar-common/skin/calendar-occurrence-prompt.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://calendar/locale/calendar-occurrence-prompt.dtd">
 
 <dialog id="calendar-occurrence-prompt"
         buttons="accept,cancel"
         windowtype="Calendar:OccurrencePrompt"
-        ondialogcancel="return exitOccurrenceDialog(0)"
-        ondialogaccept="exitOccurrenceDialog(1)"
         onload="onLoad()"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns:xhtml2="http://www.w3.org/TR/xhtml2"
         xmlns:wairole="http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#"
         xhtml2:role="wairole:alertdialog">
   <script type="application/javascript"><![CDATA[
       const { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
+      document.addEventListener("dialogaccept", () => exitOccurrenceDialog(1));
+      document.addEventListener("dialogcancel", () => exitOccurrenceDialog(0));
+
       function exitOccurrenceDialog(aReturnValue) {
           window.arguments[0].value = aReturnValue;
           window.close();
           return true;
       }
 
       function getDString(aKey) {
           return cal.l10n.getString("calendar-occurrence-prompt", aKey);
--- a/calendar/base/content/dialogs/calendar-print-dialog.js
+++ b/calendar/base/content/dialogs/calendar-print-dialog.js
@@ -7,16 +7,18 @@
 /* import-globals-from ../../../../../toolkit/components/printing/content/printUtils.js */
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
 var printContent = "";
 
+document.addEventListener("dialogaccept", printAndClose);
+
 /**
  * Gets the calendar view from the opening window
  */
 function getCalendarView() {
     let theView = window.opener.currentView();
     if (!theView.startDay) {
         theView = null;
     }
--- a/calendar/base/content/dialogs/calendar-print-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-print-dialog.xul
@@ -18,18 +18,16 @@
 <dialog id="calendar-new-printwindow"
         title="&calendar.print.window.title;"
         windowtype="Calendar:PrintDialog"
         onload="loadCalendarPrintDialog();"
         buttons="accept,cancel"
         buttonlabelaccept="&calendar.print.button.label;"
         buttonaccesskeyaccept="&calendar.print.button.accesskey;"
         defaultButton="accept"
-        ondialogaccept="return printAndClose();"
-        ondialogcancel="return true;"
         persist="screenX screenY width height"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <script type="application/javascript" src="chrome://calendar/content/calendar-print-dialog.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
   <script type="application/javascript" src="chrome://global/content/printUtils.js"/>
   <script type="application/javascript" src="chrome://calendar/content/datetimepickers/datetimepickers.js"/>
 
--- a/calendar/base/content/dialogs/calendar-properties-dialog.js
+++ b/calendar/base/content/dialogs/calendar-properties-dialog.js
@@ -4,16 +4,19 @@
 
 /* exported onLoad, onAcceptDialog, unsubscribeCalendar */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { PluralForm } = ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
 
+document.addEventListener("dialogextra1", unsubscribeCalendar);
+document.addEventListener("dialogaccept", onAcceptDialog);
+
 /**
  * The calendar to modify, is retrieved from window.arguments[0].calendar
  */
 var gCalendar;
 
 /**
  * This function gets called when the calendar properties dialog gets opened. To
  * open the window, use an object as argument. The object needs a 'calendar'
--- a/calendar/base/content/dialogs/calendar-properties-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-properties-dialog.xul
@@ -14,19 +14,16 @@
 
 <dialog
     id="calendar-properties-dialog-2"
     windowtype="Calendar:PropertiesDialog"
     title="&calendar.server.dialog.title.edit;"
     buttons="accept,cancel,extra1"
     buttonlabelextra1="&calendarproperties.unsubscribe.label;"
     buttonaccesskeyextra1="&calendarproperties.unsubscribe.accesskey;"
-    ondialogextra1="unsubscribeCalendar()"
-    ondialogaccept="return onAcceptDialog();"
-    ondialogcancel="return true;"
     onload="onLoad()"
     persist="screenX screenY"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     xmlns:html="http://www.w3.org/1999/xhtml"
     width="500">
 
   <script type="application/javascript" src="chrome://calendar/content/calendar-properties-dialog.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
--- a/calendar/base/content/dialogs/calendar-providerUninstall-dialog.js
+++ b/calendar/base/content/dialogs/calendar-providerUninstall-dialog.js
@@ -1,16 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoad, onAccept, onCancel */
+/* exported onLoad */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function onLoad() {
     let extension = window.arguments[0].extension;
     document.getElementById("provider-name-label").value = extension.name;
 
     let calendars = cal.getCalendarManager().getCalendars({})
                        .filter(x => x.providerID == extension.id);
 
     document.getElementById("calendar-list-tree").calendars = calendars;
--- a/calendar/base/content/dialogs/calendar-providerUninstall-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-providerUninstall-dialog.xul
@@ -13,19 +13,17 @@
 <dialog id="calendar-provider-uninstall-dialog"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         title="&providerUninstall.title;"
         windowtype="Calendar:ProviderUninstall"
         height="320"
         width="480"
         onload="onLoad()"
         buttonlabelaccept="&providerUninstall.accept.label;"
-        buttonaccesskeyaccept="&providerUninstall.accept.accesskey;"
-        ondialogaccept="return onAccept()"
-        ondialogcancel="return onCancel()">
+        buttonaccesskeyaccept="&providerUninstall.accept.accesskey;">
 
   <script type="application/javascript" src="chrome://calendar/content/calendar-providerUninstall-dialog.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
 
   <description id="pre-name-description">&providerUninstall.preName.label;</description>
   <label id="provider-name-label"/>
   <description id="post-name-description">&providerUninstall.postName.label;</description>
   <description id="reinstall-note-description">&providerUninstall.reinstallNote.label;</description>
--- a/calendar/base/content/dialogs/calendar-subscriptions-dialog.js
+++ b/calendar/base/content/dialogs/calendar-subscriptions-dialog.js
@@ -1,18 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoad, onUnload, onKeyPress, onTextBoxKeyPress, onAccept,
- *          onCancel, onSubscribe, onUnsubscribe
- */
+/* exported onLoad, onUnload, onKeyPress, onTextBoxKeyPress, onSubscribe, onUnsubscribe */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * Cancels any pending search operations.
  */
 var gCurrentSearchOperation = null;
 function cancelPendingSearchOperation() {
     if (gCurrentSearchOperation && gCurrentSearchOperation.isPending) {
         gCurrentSearchOperation.cancel(Ci.calIErrors.OPERATION_CANCELLED);
     }
--- a/calendar/base/content/dialogs/calendar-subscriptions-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-subscriptions-dialog.xul
@@ -13,18 +13,16 @@
     <!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/calendar-subscriptions-dialog.dtd" >  %dtd1;
 ]>
 
 <dialog
   id="calendar-subscriptions-dialog"
   title="&calendar.subscriptions.dialog.title;"
   windowtype="Calendar:SubscriptionsDialog"
   buttons="accept,cancel"
-  ondialogaccept="return onAccept();"
-  ondialogcancel="return onCancel();"
   onload="return onLoad();"
   onunload="return onUnload();"
   onkeypress="onKeyPress(event);"
   persist="screenX screenY width height"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
   <script type="application/javascript" src="chrome://calendar/content/calendar-subscriptions-dialog.js"/>
--- a/calendar/base/content/dialogs/calendar-summary-dialog.js
+++ b/calendar/base/content/dialogs/calendar-summary-dialog.js
@@ -1,22 +1,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoad, onUnload, onAccept, onCancel, updatePartStat, browseDocument,
+/* exported onLoad, onUnload, updatePartStat, browseDocument,
  *          sendMailToOrganizer, openAttachment, reply
  */
 
 /* import-globals-from ../../src/calApplicationUtils.js */
 /* import-globals-from calendar-dialog-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { recurrenceRule2String } = ChromeUtils.import("resource://calendar/modules/calRecurrenceUtils.jsm");
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * Sets up the summary dialog, setting all needed fields on the dialog from the
  * item received in the window arguments.
  */
 function onLoad() {
     let args = window.arguments[0];
     let item = args.calendarEvent;
     item = item.clone(); // use an own copy of the passed item
--- a/calendar/base/content/dialogs/calendar-summary-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-summary-dialog.xul
@@ -26,18 +26,16 @@
 ]>
 
 <!-- Dialog id is changed during execution to allow different Window-icons
      on this dialog. document.loadOverlay() will not work on this one. -->
 <dialog id="calendar-summary-dialog"
         windowtype="Calendar:EventSummaryDialog"
         onload="onLoad()"
         onunload="onUnload()"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();"
         onresize="rearrangeAttendees();"
         persist="screenX screenY width height"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml">
 
   <!-- Javascript includes -->
   <script type="application/javascript"
           src="chrome://calendar/content/calendar-summary-dialog.js"/>
--- a/calendar/base/content/dialogs/chooseCalendarDialog.js
+++ b/calendar/base/content/dialogs/chooseCalendarDialog.js
@@ -3,16 +3,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* exported loadCalendars, doOK, doExtra1 */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
+document.addEventListener("dialogaccept", doOK);
+document.addEventListener("dialogextra1", doExtra1);
+
 function loadCalendars() {
     const calendarManager = Cc["@mozilla.org/calendar/manager;1"]
                               .getService(Ci.calICalendarManager);
     let listbox = document.getElementById("calendar-list");
     let composite = cal.view.getCompositeCalendar(window.opener);
     let selectedIndex = 0;
     let calendars;
 
--- a/calendar/base/content/dialogs/chooseCalendarDialog.xul
+++ b/calendar/base/content/dialogs/chooseCalendarDialog.xul
@@ -12,18 +12,16 @@
 ]>
 
 <dialog id="chooseCalendar"
         title="&calendar.select.dialog.title;"
         windowtype="Calendar:CalendarPicker"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         buttons="accept,cancel"
         onload="setTimeout('loadCalendars()',0);"
-        ondialogaccept="return doOK();"
-        ondialogextra1="return doExtra1();"
         persist="screenX screenY height width">
 
     <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
     <script type="application/javascript" src="chrome://calendar/content/chooseCalendarDialog.js"/>
 
     <vbox id="dialog-box" flex="1">
         <label id="prompt" control="calendar-list"/>
         <richlistbox id="calendar-list" flex="1" seltype="single"/>
--- a/calendar/base/content/preferences/editCategory.js
+++ b/calendar/base/content/preferences/editCategory.js
@@ -1,16 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* exported editCategoryLoad, doOK, categoryNameChanged, clickColor, delay */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
+document.addEventListener("dialogaccept", doOK);
+
 // Global variable, set to true if the user has picked a custom color.
 var customColorSelected = false;
 
 /**
  * Load Handler, called when the edit category dialog is loaded
  */
 function editCategoryLoad() {
     let winArg = window.arguments[0];
--- a/calendar/base/content/preferences/editCategory.xul
+++ b/calendar/base/content/preferences/editCategory.xul
@@ -11,18 +11,17 @@
   <!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/preferences/categories.dtd" > %dtd1;
   <!ENTITY % dtd2 SYSTEM "chrome://calendar/locale/global.dtd" > %dtd2;
 ]>
 
 <dialog id="editCategory"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         buttons="accept,cancel"
-        onload="editCategoryLoad();"
-        ondialogaccept="return doOK();">
+        onload="editCategoryLoad();">
   <script type="application/javascript" src="chrome://calendar/content/preferences/editCategory.js"/>
 
   <vbox id="dialog-box">
     <label value="&pref.categories.name.label;"
            control="categoryName"/>
     <textbox id="categoryName"
              flex="1"
              onchange="categoryNameChanged()"
--- a/calendar/lightning/content/lightning-item-panel.js
+++ b/calendar/lightning/content/lightning-item-panel.js
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported onLoadLightningItemPanel, onAccept, onCancel, onCommandSave,
+/* exported onLoadLightningItemPanel, onCommandSave,
  *          onCommandDeleteItem, editAttendees, editPrivacy, editPriority,
  *          editStatus, editShowTimeAs, updateShowTimeAs, editToDoStatus,
  *          postponeTask, toggleTimezoneLinks, toggleLink, attachURL,
  *          onCommandViewToolbar, onCommandCustomize, attachFileByAccountKey,
  *          onUnloadLightningItemPanel, openNewEvent, openNewTask,
  *          openNewMessage, openNewCardDialog
  */
 
@@ -57,16 +57,19 @@ if (!gTabmail) {
     /**
      * Update menu items that depend on clipboard contents.
      */
     window.goUpdatePasteMenuItems = () => {
         goUpdateCommand("cmd_paste");
     };
 }
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 // Stores the ids of the iframes of currently open event/task tabs, used
 // when window is closed to prompt for saving changes.
 var gItemTabIds = [];
 var gItemTabIdsCopy;
 
 // gConfig is used when switching tabs to restore the state of
 // toolbar, statusbar, and menubar for the current tab.
 var gConfig = {
--- a/calendar/providers/gdata/content/gdata-migration-wizard.xul
+++ b/calendar/providers/gdata/content/gdata-migration-wizard.xul
@@ -8,18 +8,16 @@
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
 
 <dialog id="gdata-migration-wizard"
         title="&gdata.migration.title;"
         windowtype="Calendar:GData:MigrationDialog"
         buttons="accept,cancel"
         acceptLabel="&gdata.migration.upgrade.label;"
         acceptKey="&gdata.migration.upgrade.accesskey;"
-        ondialogaccept="migrateSelectedCalendars(); return true;"
-        ondialogcancel="window.close()"
         width="300"
         height="300"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
   <script type="application/javascript" src="chrome://gdata-provider/content/gdata-migration.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-views.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calendar-ui-utils.js"/>
 
   <description>&gdata.migration.description;</description>
--- a/calendar/providers/gdata/content/gdata-migration.js
+++ b/calendar/providers/gdata/content/gdata-migration.js
@@ -2,17 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../../base/content/calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-/* exported migrateSelectedCalendars */
+document.addEventListener("dialogaccept", migrateSelectedCalendars);
 
 /**
  * Migrate the calendar selected in the wizard from ics to gdata.
  */
 function migrateSelectedCalendars() {
     let listbox = document.getElementById("calendars-listbox");
     let calmgr = cal.getCalendarManager();
 
--- a/calendar/resources/content/publishDialog.js
+++ b/calendar/resources/content/publishDialog.js
@@ -1,19 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported loadCalendarPublishDialog, onOKCommand, closeDialog */
+/* exported loadCalendarPublishDialog, closeDialog */
 
 /* globals publishButtonLabel, closeButtonLabel */// From publishDialog.xul
 
 var gOnOkFunction;   // function to be called when user clicks OK
 var gPublishObject;
 
+document.addEventListener("dialogaccept", onOKCommand);
+
 /**
 *   Called when the dialog is loaded.
 */
 function loadCalendarPublishDialog() {
     // Get arguments, see description at top of file
 
     let args = window.arguments[0];
 
@@ -33,38 +35,34 @@ function loadCalendarPublishDialog() {
 
     let firstFocus = document.getElementById("publish-remotePath-textbox");
     firstFocus.focus();
 }
 
 /**
 *   Called when the OK button is clicked.
 */
-function onOKCommand() {
+function onOKCommand(event) {
     gPublishObject.remotePath = document.getElementById("publish-remotePath-textbox").value;
 
     // call caller's on OK function
     gOnOkFunction(gPublishObject, progressDialog);
     document.getElementById("calendar-publishwindow").getButton("accept").setAttribute("label", closeButtonLabel);
-    document.getElementById("calendar-publishwindow").setAttribute("ondialogaccept", "closeDialog()");
-    return false;
+    document.removeEventListener("dialogaccept", onOKCommand);
+    event.preventDefault();
 }
 
 function checkURLField() {
     if (document.getElementById("publish-remotePath-textbox").value.length == 0) {
         document.getElementById("calendar-publishwindow").getButton("accept").setAttribute("disabled", "true");
     } else {
         document.getElementById("calendar-publishwindow").getButton("accept").removeAttribute("disabled");
     }
 }
 
-function closeDialog() {
-    self.close();
-}
-
 var progressDialog = {
     onStartUpload: function() {
         document.getElementById("publish-progressmeter").removeAttribute("value");
     },
 
     onStopUpload: function() {
         document.getElementById("publish-progressmeter").setAttribute("value", "0");
     }
--- a/calendar/resources/content/publishDialog.xul
+++ b/calendar/resources/content/publishDialog.xul
@@ -13,18 +13,16 @@
   <!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/global.dtd" > %dtd1;
   <!ENTITY % dtd2 SYSTEM "chrome://calendar/locale/calendar.dtd" > %dtd2;
 ]>
 
 <dialog id="calendar-publishwindow"
         title="&calendar.publish.dialog.title;"
         windowtype="Calendar:PublishDialog"
         buttons="accept,cancel"
-        ondialogaccept="return onOKCommand();"
-        ondialogcancel="return true;"
         onload="loadCalendarPublishDialog()"
         persist="screenX screenY"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns:nc="http://home.netscape.com/NC-rdf#">
 
   <!-- Javascript includes -->
   <script type="application/javascript" src="chrome://calendar/content/publishDialog.js"/>
--- a/editor/ui/dialogs/content/EdAdvancedEdit.js
+++ b/editor/ui/dialogs/content/EdAdvancedEdit.js
@@ -15,16 +15,19 @@ var JSERAttrs   = [];   // removed js ev
 /* Set false to allow changing selection in tree
    without doing "onselect" handler actions
 */
 var gDoOnSelectTree = true;
 var gUpdateTreeValue = true;
 
 /************** INITIALISATION && SETUP **************/
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 /**
  * function   : void Startup();
  * parameters : none
  * returns    : none
  * desc.      : startup and initialisation, prepares dialog.
  **/
 function Startup()
 {
--- a/editor/ui/dialogs/content/EdAdvancedEdit.xul
+++ b/editor/ui/dialogs/content/EdAdvancedEdit.xul
@@ -11,19 +11,17 @@
 <?xml-stylesheet href="chrome://messenger/skin/menulist.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EdAdvancedEdit.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     id="advancedEditDlg"
     style="width: 40em;"
     title="&WindowTitle.label;"
-    onload="Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <!-- element page functions -->
   <script type="application/javascript" src="chrome://editor/content/EdAEHTMLAttributes.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdAECSSAttributes.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdAEJSEAttributes.js"/>
--- a/editor/ui/dialogs/content/EdButtonProps.js
+++ b/editor/ui/dialogs/content/EdButtonProps.js
@@ -2,16 +2,19 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var insertNew;
 var buttonElement;
 
 // dialog initialization code
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdButtonProps.xul
+++ b/editor/ui/dialogs/content/EdButtonProps.xul
@@ -11,19 +11,17 @@
 %edButtonProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdButtonProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdColorPicker.js
+++ b/editor/ui/dialogs/content/EdColorPicker.js
@@ -13,16 +13,20 @@ var ColorType = "Text";
 var TextType = false;
 var HighlightType = false;
 var TableOrCell = false;
 var LastPickedIsDefault = true;
 var NoDefault = false;
 var gColorObj;
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancelColor);
+
 function Startup()
 {
   if (!window.arguments[1])
   {
     dump("EdColorPicker: Missing color object param\n");
     return;
   }
 
--- a/editor/ui/dialogs/content/EdColorPicker.xul
+++ b/editor/ui/dialogs/content/EdColorPicker.xul
@@ -6,19 +6,17 @@
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EdColorPicker.dtd">
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     xmlns:html="http://www.w3.org/1999/xhtml"
-    onload="Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancelColor();">
+    onload="Startup()">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdColorPicker.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
   <hbox id="TableOrCellGroup" align="center" collapsed="true">
--- a/editor/ui/dialogs/content/EdColorProps.js
+++ b/editor/ui/dialogs/content/EdColorProps.js
@@ -9,16 +9,19 @@
   even if 1 or more (but not all) are actually null (= "use default")
  When in "Custom Colors" mode, all colors will be set on body tag,
   even if they are just default colors, to assure compatible colors in page.
  User cannot select "use default" for individual colors
 */
 
 //Cancel() is in EdDialogCommon.js
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 var gBodyElement;
 var prefs;
 var gBackgroundImage;
 
 // Initialize in case we can't get them from prefs???
 var defaultTextColor="#000000";
 var defaultLinkColor="#000099";
 var defaultActiveColor="#000099";
--- a/editor/ui/dialogs/content/EdColorProps.xul
+++ b/editor/ui/dialogs/content/EdColorProps.xul
@@ -12,19 +12,17 @@
 <!ENTITY % composeEditorOverlayDTD SYSTEM "chrome://messenger/locale/messengercompose/mailComposeEditorOverlay.dtd">
 %composeEditorOverlayDTD;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload="Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload="Startup()">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdColorProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
   <groupbox align="start">
--- a/editor/ui/dialogs/content/EdConvertToTable.js
+++ b/editor/ui/dialogs/content/EdConvertToTable.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 var gIndex;
 var gCommaIndex = "0";
 var gSpaceIndex = "1";
 var gOtherIndex = "2";
 
 // dialog initialization code
 function Startup()
 {
--- a/editor/ui/dialogs/content/EdConvertToTable.xul
+++ b/editor/ui/dialogs/content/EdConvertToTable.xul
@@ -7,18 +7,16 @@
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EdConvertToTable.dtd">
 
 <dialog title="&windowTitle.label;"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
    onload = "Startup()"
-   ondialogaccept="return onAccept();"
-   ondialogcancel="return onCancel();"
    style="min-width:20em">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <!--- Element-specific methods -->
   <script type="application/javascript" src="chrome://editor/content/EdConvertToTable.js"/>
 
--- a/editor/ui/dialogs/content/EdDialogTemplate.js
+++ b/editor/ui/dialogs/content/EdDialogTemplate.js
@@ -3,16 +3,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 //Cancel() is in EdDialogCommon.js
 var insertNew = true;
 var tagname = "TAG NAME"
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   if (!GetCurrentEditor())
   {
     window.close();
     return;
   }
   // gDialog is declared in EdDialogCommon.js
--- a/editor/ui/dialogs/content/EdDialogTemplate.xul
+++ b/editor/ui/dialogs/content/EdDialogTemplate.xul
@@ -7,19 +7,17 @@
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <?xul-overlay href="chrome://editor/content/EdDialogOverlay.xul"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/Ed?????????.dtd">
 <!-- dialog containing a control requiring initial setup -->
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload="Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/Ed?????.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 </dialog>
--- a/editor/ui/dialogs/content/EdDictionary.js
+++ b/editor/ui/dialogs/content/EdDictionary.js
@@ -1,16 +1,18 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var gSpellChecker;
 var gWordToAdd;
 
+document.addEventListener("dialogcancel", onClose);
+
 function Startup()
 {
   if (!GetCurrentEditor())
   {
     window.close();
     return;
   }
   // Get the SpellChecker shell
--- a/editor/ui/dialogs/content/EdDictionary.xul
+++ b/editor/ui/dialogs/content/EdDictionary.xul
@@ -4,18 +4,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorPersonalDictionary.dtd">
 <dialog buttons="cancel" title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     persist="screenX screenY"
-    onload = "Startup()"
-    ondialogcancel="return onClose();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDictionary.js"/>
 
   <grid>
     <columns><column style="width: 15em" flex="1"/><column flex="1"/></columns>
--- a/editor/ui/dialogs/content/EdFieldSetProps.js
+++ b/editor/ui/dialogs/content/EdFieldSetProps.js
@@ -4,16 +4,19 @@
 
 var insertNew;
 var fieldsetElement;
 var newLegend;
 var legendElement;
 
 // dialog initialization code
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     dump("Failed to get active editor!\n");
     window.close();
     return;
--- a/editor/ui/dialogs/content/EdFieldSetProps.xul
+++ b/editor/ui/dialogs/content/EdFieldSetProps.xul
@@ -11,19 +11,17 @@
 %edFieldSetProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdFieldSetProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdFormProps.js
+++ b/editor/ui/dialogs/content/EdFormProps.js
@@ -2,16 +2,19 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var gForm;
 var insertNew;
 var formElement;
 var formActionWarning;
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     dump("Failed to get active editor!\n");
     window.close();
     return;
--- a/editor/ui/dialogs/content/EdFormProps.xul
+++ b/editor/ui/dialogs/content/EdFormProps.xul
@@ -12,19 +12,17 @@
 %edFormProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdFormProps.js"/>
 
   <script type="application/javascript" src="chrome://messenger/content/customElements.js"/>
 
--- a/editor/ui/dialogs/content/EdHLineProps.js
+++ b/editor/ui/dialogs/content/EdHLineProps.js
@@ -6,16 +6,20 @@ var tagName = "hr";
 var gHLineElement;
 var width;
 var height;
 var align;
 var shading;
 const gMaxHRSize = 1000; // This is hard-coded in nsHTMLHRElement::StringToAttribute()
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdHLineProps.xul
+++ b/editor/ui/dialogs/content/EdHLineProps.xul
@@ -11,19 +11,17 @@
 <!ENTITY % edHLineProperties SYSTEM "chrome://editor/locale/EditorHLineProperties.dtd">
 %edHLineProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload="Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <!--- Element-specific methods -->
   <script type="application/javascript" src="chrome://editor/content/EdHLineProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
--- a/editor/ui/dialogs/content/EdImageProps.js
+++ b/editor/ui/dialogs/content/EdImageProps.js
@@ -4,16 +4,19 @@
 
 var gAnchorElement = null;
 var gLinkElement = null;
 var gOriginalHref = "";
 var gHNodeArray = {};
 
 // dialog initialization code
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdImageProps.xul
+++ b/editor/ui/dialogs/content/EdImageProps.xul
@@ -14,19 +14,17 @@
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <!-- dialog containing a control requiring initial setup -->
 <dialog id="imageDlg" title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     onload="Startup()"
-    buttons="accept,cancel"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    buttons="accept,cancel">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdImageProps.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdImageDialog.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdImageLinkLoader.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
--- a/editor/ui/dialogs/content/EdInputImage.js
+++ b/editor/ui/dialogs/content/EdInputImage.js
@@ -1,14 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // dialog initialization code
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdInputImage.xul
+++ b/editor/ui/dialogs/content/EdInputImage.xul
@@ -14,19 +14,17 @@
 <!ENTITY % composeEditorOverlayDTD SYSTEM "chrome://messenger/locale/messengercompose/mailComposeEditorOverlay.dtd">
 %composeEditorOverlayDTD;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitleImage.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-        onload="Startup();"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        onload="Startup();">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdInputImage.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdImageDialog.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdInputProps.js
+++ b/editor/ui/dialogs/content/EdInputProps.js
@@ -2,16 +2,19 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var insertNew;
 var inputElement;
 
 // dialog initialization code
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     dump("Failed to get active editor!\n");
     window.close();
     return;
--- a/editor/ui/dialogs/content/EdInputProps.xul
+++ b/editor/ui/dialogs/content/EdInputProps.xul
@@ -11,19 +11,17 @@
 %edInputProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdInputProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdInsSrc.js
+++ b/editor/ui/dialogs/content/EdInsSrc.js
@@ -4,16 +4,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Insert Source HTML dialog */
 
 var gFullDataStrings = new Map();
 var gShortDataStrings = new Map();
 var gListenerAttached = false;
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   let editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdInsSrc.xul
+++ b/editor/ui/dialogs/content/EdInsSrc.xul
@@ -9,19 +9,17 @@
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorInsertSource.dtd">
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     xmlns:html="http://www.w3.org/1999/xhtml"
     onload = "Startup()"
     buttonlabelaccept="&insertButton.label;"
-    buttonaccesskeyaccept="&insertButton.accesskey;"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    buttonaccesskeyaccept="&insertButton.accesskey;">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdInsSrc.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdInsertMath.js
+++ b/editor/ui/dialogs/content/EdInsertMath.js
@@ -2,16 +2,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Insert MathML dialog */
 
 var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor) {
     window.close();
     return;
   }
 
--- a/editor/ui/dialogs/content/EdInsertMath.xul
+++ b/editor/ui/dialogs/content/EdInsertMath.xul
@@ -9,19 +9,17 @@
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorInsertMath.dtd">
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
         buttonlabelaccept="&insertButton.label;"
-        buttonaccesskeyaccept="&insertButton.accesskey;"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttonaccesskeyaccept="&insertButton.accesskey;">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript"
           src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript"
           src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript"
           src="chrome://editor/content/EdInsertMath.js"/>
--- a/editor/ui/dialogs/content/EdInsertTOC.js
+++ b/editor/ui/dialogs/content/EdInsertTOC.js
@@ -18,16 +18,18 @@ var orderedList = true;
 // constants
 const kMozToc                  = "mozToc";
 const kMozTocLength            = 6;
 const kMozTocIdPrefix          = "mozTocId";
 const kMozTocIdPrefixLength    = 8;
 const kMozTocClassPrefix       = "mozToc";
 const kMozTocClassPrefixLength = 6;
 
+document.addEventListener("dialogaccept", () => BuildTOC(true));
+
 // Startup() is called when EdInsertTOC.xul is opened
 function Startup()
 {
   // early way out if if we have no editor
   if (!GetCurrentEditor()) {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdInsertTOC.xul
+++ b/editor/ui/dialogs/content/EdInsertTOC.xul
@@ -8,17 +8,16 @@
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorInsertTOC.dtd">
 
 <dialog title="&Window.title;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     xmlns:html="http://www.w3.org/1999/xhtml"
     onload="Startup();"
-    ondialogaccept="return BuildTOC(true);"
     oncancel="window.close(); return true;">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
 
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdInsertTOC.js"/>
 
--- a/editor/ui/dialogs/content/EdInsertTable.js
+++ b/editor/ui/dialogs/content/EdInsertTable.js
@@ -5,16 +5,20 @@
 //Cancel() is in EdDialogCommon.js
 
 var gTableElement = null;
 var gRows;
 var gColumns;
 var gActiveEditor;
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   gActiveEditor = GetCurrentTableEditor();
   if (!gActiveEditor)
   {
     dump("Failed to get active editor!\n");
     window.close();
     return;
--- a/editor/ui/dialogs/content/EdInsertTable.xul
+++ b/editor/ui/dialogs/content/EdInsertTable.xul
@@ -11,19 +11,17 @@
 <!ENTITY % edInsertTable SYSTEM "chrome://editor/locale/EditorInsertTable.dtd">
 %edInsertTable;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload = "Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload = "Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdInsertTable.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
   <groupbox><label class="header">&size.label;</label>
--- a/editor/ui/dialogs/content/EdLabelProps.js
+++ b/editor/ui/dialogs/content/EdLabelProps.js
@@ -1,16 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var labelElement;
 
 // dialog initialization code
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     dump("Failed to get active editor!\n");
     window.close();
     return;
--- a/editor/ui/dialogs/content/EdLabelProps.xul
+++ b/editor/ui/dialogs/content/EdLabelProps.xul
@@ -11,19 +11,17 @@
 %edLabelProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdLabelProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdLinkChecker.js
+++ b/editor/ui/dialogs/content/EdLinkChecker.js
@@ -5,16 +5,19 @@
 // Variables used across all the links being checked:
 var gNumLinksToCheck = 0;     // The number of nsILinkCheckers
 var gLinksBeingChecked = [];  // Array of nsIURICheckers
 var gURIRefObjects = [];      // Array of nsIURIRefObjects
 var gNumLinksCalledBack = 0;
 var gStartedAllChecks = false;
 var gLinkCheckTimerID = 0;
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancelLinkChecker);
+
 // Implement nsIRequestObserver:
 var gRequestObserver =
 {
   // urichecker requires that we have an OnStartRequest even tho it's a nop.
   onStartRequest: function(request) { },
 
   // onStopRequest is where we really handle the status.
   onStopRequest: function(request, status)
--- a/editor/ui/dialogs/content/EdLinkChecker.xul
+++ b/editor/ui/dialogs/content/EdLinkChecker.xul
@@ -6,19 +6,17 @@
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EdLinkChecker.dtd">
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     onload="Startup()"
-    buttonlabelcancel="&closeButton.label;"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancelLinkChecker();">
+    buttonlabelcancel="&closeButton.label;">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdLinkChecker.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
   <listbox rows="8" id="LinksList" class="MinWidth20" flex="1"/>
--- a/editor/ui/dialogs/content/EdLinkProps.js
+++ b/editor/ui/dialogs/content/EdLinkProps.js
@@ -18,16 +18,20 @@ var gCanChangeHeadingSelected = true;
 var gCanChangeAnchorSelected = true;
 var gHaveDocumentUrl = false;
 
 // NOTE: Use "href" instead of "a" to distinguish from Named Anchor
 // The returned node is has an "a" tagName
 var tagName = "href";
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   gActiveEditor = GetCurrentEditor();
   if (!gActiveEditor)
   {
     dump("Failed to get active editor!\n");
     window.close();
     return;
--- a/editor/ui/dialogs/content/EdLinkProps.xul
+++ b/editor/ui/dialogs/content/EdLinkProps.xul
@@ -13,19 +13,17 @@
 <!ENTITY % composeEditorOverlayDTD SYSTEM "chrome://messenger/locale/messengercompose/mailComposeEditorOverlay.dtd">
 %composeEditorOverlayDTD;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog id="linkDlg" title="&windowTitle.label;"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-   onload = "Startup()"
-   ondialogaccept="return onAccept();"
-   ondialogcancel="return onCancel();">
+   onload = "Startup()">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdLinkProps.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdImageLinkLoader.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdListProps.js
+++ b/editor/ui/dialogs/content/EdListProps.js
@@ -24,16 +24,20 @@ const gUpperLetters = "A";
 const gLowerLetters = "a";
 const gDecimalCSS = "decimal";
 const gUpperRomanCSS = "upper-roman";
 const gLowerRomanCSS = "lower-roman";
 const gUpperAlphaCSS = "upper-alpha";
 const gLowerAlphaCSS = "lower-alpha";
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdListProps.xul
+++ b/editor/ui/dialogs/content/EdListProps.xul
@@ -10,19 +10,17 @@
 <!ENTITY % edListProperties SYSTEM "chrome://editor/locale/EditorListProperties.dtd">
 %edListProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload = "Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdListProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdNamedAnchorProps.js
+++ b/editor/ui/dialogs/content/EdNamedAnchorProps.js
@@ -3,16 +3,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var gInsertNew = true;
 var gAnchorElement = null;
 var gOriginalName = "";
 const kTagName = "anchor";
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdNamedAnchorProps.xul
+++ b/editor/ui/dialogs/content/EdNamedAnchorProps.xul
@@ -11,19 +11,17 @@
 <!ENTITY % edNamedAnchorProperties SYSTEM "chrome://editor/locale/EdNamedAnchorProperties.dtd">
 %edNamedAnchorProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload = "Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdNamedAnchorProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdPageProps.js
+++ b/editor/ui/dialogs/content/EdPageProps.js
@@ -10,16 +10,20 @@ var gDescriptionElement;
 var gInsertNewAuthor = false;
 var gInsertNewDescription = false;
 var gTitleWasEdited = false;
 var gAuthorWasEdited = false;
 var gDescWasEdited = false;
 
 //Cancel() is in EdDialogCommon.js
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdPageProps.xul
+++ b/editor/ui/dialogs/content/EdPageProps.xul
@@ -5,19 +5,17 @@
 
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorPageProperties.dtd">
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-        onload="Startup();"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        onload="Startup();">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdPageProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
   <grid>
     <columns><column flex="1"/><column flex="2"/></columns>
--- a/editor/ui/dialogs/content/EdReplace.js
+++ b/editor/ui/dialogs/content/EdReplace.js
@@ -4,16 +4,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var gReplaceDialog;      // Quick access to document/form elements.
 var gFindInst;           // nsIWebBrowserFind that we're going to use
 var gFindService;        // Global service which remembers find params
 var gEditor;             // the editor we're using
 
+document.addEventListener("dialogaccept", (event) => {
+  onFindNext();
+  event.preventDefault();
+});
+
 function initDialogObject()
 {
   // Create gReplaceDialog object and initialize.
   gReplaceDialog = {};
   gReplaceDialog.findInput       = document.getElementById("dialog.findInput");
   gReplaceDialog.replaceInput    = document.getElementById("dialog.replaceInput");
   gReplaceDialog.caseSensitive   = document.getElementById("dialog.caseSensitive");
   gReplaceDialog.wrap            = document.getElementById("dialog.wrap");
--- a/editor/ui/dialogs/content/EdReplace.xul
+++ b/editor/ui/dialogs/content/EdReplace.xul
@@ -8,18 +8,17 @@
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorReplace.dtd">
 
 <dialog id="replaceDlg" title="&replaceDialog.title;"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
    persist="screenX screenY"
    buttons="cancel"
-   onload = "onLoad()"
-   ondialogaccept="onFindNext(); return false">
+   onload="onLoad()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdReplace.js"/>
   <stringbundle id="findBundle" src="chrome://global/locale/finddialog.properties"/>
 
   <hbox>
--- a/editor/ui/dialogs/content/EdSelectProps.js
+++ b/editor/ui/dialogs/content/EdSelectProps.js
@@ -10,16 +10,19 @@ var insertNew;
 var itemArray;
 var theTree;
 var treeSelection;
 var selectElement;
 var currentItem = null;
 var selectedOption = null;
 var selectedOptionCount = 0;
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 // Utility functions
 
 function getParentIndex(index)
 {
   switch (itemArray[index].level)
   {
   case 0: return -1;
   case 1: return 0;
--- a/editor/ui/dialogs/content/EdSelectProps.xul
+++ b/editor/ui/dialogs/content/EdSelectProps.xul
@@ -11,19 +11,17 @@
 %edSelectProperties;
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdSelectProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdSnapToGrid.js
+++ b/editor/ui/dialogs/content/EdSnapToGrid.js
@@ -1,15 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var gEditor;
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   gEditor = GetCurrentEditor();
   if (!gEditor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdSnapToGrid.xul
+++ b/editor/ui/dialogs/content/EdSnapToGrid.xul
@@ -5,19 +5,17 @@
 
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorSnapToGrid.dtd">
 
 <dialog title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload="Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <!--- Element-specific methods -->
   <script type="application/javascript" src="chrome://editor/content/EdSnapToGrid.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
--- a/editor/ui/dialogs/content/EdSpellCheck.js
+++ b/editor/ui/dialogs/content/EdSpellCheck.js
@@ -8,16 +8,19 @@ var {InlineSpellChecker} = ChromeUtils.i
 var gMisspelledWord;
 var gSpellChecker = null;
 var gAllowSelectWord = true;
 var gPreviousReplaceWord = "";
 var gFirstTime = true;
 var gLastSelectedLang = null;
 var gDictCount = 0;
 
+document.addEventListener("dialogaccept", doDefault);
+document.addEventListener("dialogcancel", CancelSpellCheck);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdSpellCheck.xul
+++ b/editor/ui/dialogs/content/EdSpellCheck.xul
@@ -7,19 +7,17 @@
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorSpellCheck.dtd">
 
 <!-- dialog containing a control requiring initial setup -->
 <dialog id="spellCheckDlg" buttons="cancel" title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     persist="screenX screenY"
-    onload = "Startup()"
-    ondialogaccept="return doDefault();"
-    ondialogcancel="return CancelSpellCheck();">
+    onload="Startup()">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://communicator/content/utilityOverlay.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdSpellCheck.js"/>
   <script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
 
   <stringbundle id="languageBundle" src="chrome://global/locale/languageNames.properties"/>
--- a/editor/ui/dialogs/content/EdTableProps.js
+++ b/editor/ui/dialogs/content/EdTableProps.js
@@ -59,16 +59,21 @@ var gSelectedCellCount = 0;
 var gApplyUsed = false;
 var gSelection;
 var gCellDataChanged = false;
 var gCanDelete = false;
 var gUseCSS = true;
 var gActiveEditor;
 
 // dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogextra1", Apply);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   gActiveEditor = GetCurrentTableEditor();
   if (!gActiveEditor)
   {
     window.close();
     return;
   }
--- a/editor/ui/dialogs/content/EdTableProps.xul
+++ b/editor/ui/dialogs/content/EdTableProps.xul
@@ -16,20 +16,17 @@
 
 <dialog title="&tableWindow.title;"
     id="tableDlg"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     onload="Startup()"
     buttons="accept,extra1,cancel"
     buttonlabelclose="&closeButton.label;"
     buttonlabelextra1="&applyButton.label;"
-    buttonaccesskeyextra1="&applyButton.accesskey;"
-    ondialogaccept="return onAccept();"
-    ondialogextra1="return Apply();"
-    ondialogcancel="return onCancel();">
+    buttonaccesskeyextra1="&applyButton.accesskey;">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdTableProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EdTextAreaProps.js
+++ b/editor/ui/dialogs/content/EdTextAreaProps.js
@@ -2,16 +2,19 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var insertNew;
 var textareaElement;
 
 // dialog initialization code
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     dump("Failed to get active editor!\n");
     window.close();
     return;
--- a/editor/ui/dialogs/content/EdTextAreaProps.xul
+++ b/editor/ui/dialogs/content/EdTextAreaProps.xul
@@ -12,19 +12,17 @@
 <!ENTITY % edDialogOverlay SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
 %edDialogOverlay;
 ]>
 
 <dialog title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdTextAreaProps.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EditConflict.js
+++ b/editor/ui/dialogs/content/EditConflict.js
@@ -1,13 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // dialog initialization code
+
+document.addEventListener("dialogcancel", onClose);
+
 function Startup()
 {
   if (!GetCurrentEditor())
   {
     window.close();
     return;
   }
 
--- a/editor/ui/dialogs/content/EditConflict.xul
+++ b/editor/ui/dialogs/content/EditConflict.xul
@@ -6,18 +6,17 @@
 
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditConflict.dtd">
 
 <dialog buttons="cancel" title="&windowTitle.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-    onload = "Startup()"
-    ondialogcancel="return onClose();">
+    onload="Startup()">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EditConflict.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EditorPublish.js
+++ b/editor/ui/dialogs/content/EditorPublish.js
@@ -9,16 +9,20 @@ var gDefaultSiteName;
 var gPreviousDefaultDir;
 var gPreviousTitle;
 var gSettingsChanged = false;
 var gInitialSiteName;
 var gInitialSiteIndex = -1;
 var gPasswordManagerOn = true;
 
 // Dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   window.opener.ok = false;
 
   // Element to edit is passed in
   gInitialSiteName = window.arguments[1];
   gReturnData = window.arguments[2];
   if (!gReturnData || !GetCurrentEditor())
--- a/editor/ui/dialogs/content/EditorPublish.xul
+++ b/editor/ui/dialogs/content/EditorPublish.xul
@@ -12,19 +12,17 @@
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorPublish.dtd">
 
 <dialog title="&windowTitle.label;"
         id="publishDlg"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup()"
         buttons="accept,cancel"
-        buttonlabelaccept="&publishButton.label;"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttonlabelaccept="&publishButton.label;">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EditorPublish.js"/>
   <script type="application/javascript" src="chrome://editor/content/publishprefs.js"/>
   <script type="application/javascript" src="chrome://messenger/content/customElements.js"/>
 
--- a/editor/ui/dialogs/content/EditorPublishProgress.js
+++ b/editor/ui/dialogs/content/EditorPublishProgress.js
@@ -51,16 +51,18 @@ const kAccessDenied = 2152857621;
 //const kInProgress = 2152398863; // netCore.h
 //const kNoContent = 2152398865; // netCore.h
 //const kUnknownProtocol = 2152398866 // netCore.h
 //const kFtpLogin = 2152398869; // ftpCore.h
 //const kFtpCWD = 2152398870; // ftpCore.h
 //const kFtpPasv = 2152398871; // ftpCore.h
 //const kFtpPwd = 2152398872; // ftpCore.h
 
+document.addEventListener("dialogaccept", onEnterKey);
+document.addEventListener("dialogcancel", onClose);
 
 function Startup()
 {
   gPublishData = window.arguments[0];
   if (!gPublishData)
   {
     dump("No publish data!\n");
     window.close();
--- a/editor/ui/dialogs/content/EditorPublishProgress.xul
+++ b/editor/ui/dialogs/content/EditorPublishProgress.xul
@@ -8,19 +8,17 @@
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorPublishProgress.dtd">
 
 <dialog title=""
     id="publishProgressDlg"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     buttons="cancel"
     buttonlabelclose="&closeButton.label;"
-    onload="Startup()"
-    ondialogaccept="return onEnterKey();"
-    ondialogcancel="return onClose();">
+    onload="Startup()">
 
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/publishprefs.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EditorPublishProgress.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/editor/ui/dialogs/content/EditorPublishSettings.js
+++ b/editor/ui/dialogs/content/EditorPublishSettings.js
@@ -10,16 +10,20 @@ var gPreviousDefaultSite;
 var gPreviousTitle;
 var gSettingsChanged = false;
 var gSiteDataChanged = false;
 var gAddNewSite = false;
 var gCurrentSiteIndex = -1;
 var gPasswordManagerOn = true;
 
 // Dialog initialization code
+
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 function Startup()
 {
   if (!GetCurrentEditor())
   {
     window.close();
     return;
   }
 
--- a/editor/ui/dialogs/content/EditorPublishSettings.xul
+++ b/editor/ui/dialogs/content/EditorPublishSettings.xul
@@ -10,19 +10,17 @@
 <?xul-overlay href="chrome://editor/content/EditorPublishOverlay.xul"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorPublish.dtd">
 
 <dialog title="&windowTitleSettings.label;"
         id="publishSettingsDlg"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup()"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <!-- Methods common to all editor dialogs -->
   <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
   <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
   <script type="application/javascript" src="chrome://editor/content/EditorPublishSettings.js"/>
   <script type="application/javascript" src="chrome://editor/content/publishprefs.js"/>
 
   <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
--- a/editor/ui/dialogs/content/EditorSaveAsCharset.js
+++ b/editor/ui/dialogs/content/EditorSaveAsCharset.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 var {CharsetMenu} = ChromeUtils.import("resource://gre/modules/CharsetMenu.jsm");
 
 var gCharset="";
 var gTitleWasEdited = false;
 var gCharsetWasChanged = false;
 var gInsertNewContentType = false;
 var gContenttypeElement;
 var gInitDone = false;
--- a/editor/ui/dialogs/content/EditorSaveAsCharset.xul
+++ b/editor/ui/dialogs/content/EditorSaveAsCharset.xul
@@ -6,18 +6,16 @@
 <?xml-stylesheet href="chrome://editor/skin/editor.css" type="text/css"?>
 <?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://editor/locale/EditorSaveAsCharset.dtd">
 
 <dialog title="&windowTitle2.label;"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
     onload = "Startup()"
-    ondialogaccept="return onAccept();"
-    ondialogcancel="return onCancel();"
     style="width: 32em;">
 
     <script type="application/javascript" src="chrome://editor/content/editorUtilities.js"/>
     <script type="application/javascript" src="chrome://editor/content/EdDialogCommon.js"/>
     <script type="application/javascript" src="chrome://editor/content/EditorSaveAsCharset.js"/>
 
     <spacer id="location" offsetY="50" persist="offsetX offsetY"/>
 
--- a/mail/base/content/newTagDialog.js
+++ b/mail/base/content/newTagDialog.js
@@ -2,16 +2,18 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
+document.addEventListener("dialogaccept", onOKNewTag);
+
 var dialog;
 
 /**
  * Pass in keyToEdit as a window argument to turn this dialog into an edit
  * tag dialog.
  */
 function onLoad() {
   let windowArgs = window.arguments[0];
--- a/mail/base/content/newTagDialog.xul
+++ b/mail/base/content/newTagDialog.xul
@@ -6,18 +6,17 @@
 
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/newTagDialog.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         title="&newTagDialog1.title;"
-        onload="onLoad();"
-        ondialogaccept="return onOKNewTag();">
+        onload="onLoad();">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
   </stringbundleset>
 
   <script type="application/javascript" src="chrome://messenger/content/newTagDialog.js"/>
   <label value="&name.label;" accesskey="&name.accesskey;" control="name"/>
   <hbox>
--- a/mail/base/content/safeMode.js
+++ b/mail/base/content/safeMode.js
@@ -1,16 +1,20 @@
 /* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var {AddonManager} = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
+document.addEventListener("dialogaccept", onOK);
+document.addEventListener("dialogcancel", onCancel);
+document.addEventListener("dialogextra1", () => window.close());
+
 function restartApp() {
   Services.startup.quit(Services.startup.eForceQuit | Services.startup.eRestart);
 }
 
 function deleteLocalstore() {
   // Delete the xulstore file.
   let xulstoreFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
   xulstoreFile.append("xulstore.json");
--- a/mail/base/content/safeMode.xul
+++ b/mail/base/content/safeMode.xul
@@ -25,19 +25,16 @@
             buttonaccesskeycancel="&quitApplicationCmd.accesskey;"
 #else
             buttonlabelcancel="&quitApplicationCmdUnix.label;"
             buttonaccesskeycancel="&quitApplicationCmdUnix.accesskey;"
 #endif
             buttonlabelextra1="&continueButton.label;"
             buttonaccesskeyextra1="&continueButton.accesskey;"
             width="&window.width;"
-            ondialogaccept="return onOK()"
-            ondialogcancel="onCancel()"
-            ondialogextra1="window.close()"
             onload="onLoad();"
             buttondisabledaccept="true">
 
   <script type="application/javascript" src="chrome://messenger/content/safeMode.js"/>
 
   <stringbundle id="preferencesBundle" src="chrome://messenger/locale/preferences/preferences.properties"/>
 
   <description>&safeModeDescription.label;</description>
--- a/mail/base/content/sanitize.xul
+++ b/mail/base/content/sanitize.xul
@@ -16,18 +16,17 @@
 ]>
 
 <dialog id="SanitizeDialog" type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         dlgbuttons="accept,cancel"
         title="&sanitizeDialog2.title;"
         noneverythingtitle="&sanitizeDialog2.title;"
         style="width: &dialog.width;"
-        onload="gSanitizePromptDialog.init();"
-        ondialogaccept="gSanitizePromptDialog.sanitize();">
+        onload="gSanitizePromptDialog.init();">
 
   <vbox id="SanitizeDialogPane">
     <stringbundle id="bundleBrowser"
             src="chrome://messenger/locale/messenger.properties"/>
 
     <script type="application/javascript"
             src="chrome://messenger/content/sanitize.js"/>
     <script type="application/javascript"
--- a/mail/base/content/sanitizeDialog.js
+++ b/mail/base/content/sanitizeDialog.js
@@ -226,8 +226,10 @@ var gSanitizePromptDialog = {
     var itemList = document.getElementById("itemList");
 
     if (itemList.collapsed)
       this.showItemList();
     else
       this.hideItemList();
   },
 };
+
+document.addEventListener("dialogaccept", gSanitizePromptDialog.sanitize);
--- a/mail/base/content/systemIntegrationDialog.js
+++ b/mail/base/content/systemIntegrationDialog.js
@@ -139,8 +139,11 @@ var gSystemIntegrationDialog = {
     // Set the search integration pref if it is changed.
     // The integration will handle the rest.
     if (searchIntegPossible)
       SearchIntegration.prefEnabled = this._searchCheckbox.checked;
 
     return true;
   },
 };
+
+document.addEventListener("dialogaccept", () => gSystemIntegrationDialog.onDialogClose(true));
+document.addEventListener("dialogcancel", () => gSystemIntegrationDialog.onDialogClose(false));
--- a/mail/base/content/systemIntegrationDialog.xul
+++ b/mail/base/content/systemIntegrationDialog.xul
@@ -32,18 +32,16 @@
 <dialog xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         id="systemIntegrationDialog"
         buttons="accept,cancel"
         buttonlabelaccept="&acceptIntegration.label;"
         buttonlabelcancel="&cancelIntegration.label;"
         buttonlabelcancel2="&cancelIntegration2.label;"
         onload="gSystemIntegrationDialog.onLoad();"
-        ondialogaccept="return gSystemIntegrationDialog.onDialogClose(true);"
-        ondialogcancel="return gSystemIntegrationDialog.onDialogClose(false);"
         title="&systemIntegration.title;">
 
   <script type="application/javascript"
           src="chrome://messenger/content/systemIntegrationDialog.js"/>
 
   <label control="defaultClientList">&defaultClient.intro;</label>
   <vbox id="defaultClientList">
     <checkbox id="checkMail"
--- a/mail/components/addrbook/content/abEditCardDialog.xul
+++ b/mail/components/addrbook/content/abEditCardDialog.xul
@@ -9,22 +9,24 @@
 <?xml-stylesheet href="chrome://messenger/content/bindings.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/addressbook/abCard.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:html="http://www.w3.org/1999/xhtml"
   id="abcardWindow"
   icon="abcardWindow"
-  onload="OnLoadEditCard()"
-  ondialogaccept="return EditCardOKButton();"
-  ondialogcancel="return EditCardCancelButton();">
+  onload="OnLoadEditCard()">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_addressBook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
   </stringbundleset>
 
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abCommon.js"/>
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abCard.js"/>
+  <script type="application/javascript"><![CDATA[
+    document.addEventListener("dialogaccept", EditCardOKButton);
+    document.addEventListener("dialogcancel", EditCardCancelButton);
+  ]]></script>
 
 #include abCard.inc.xul
 
 </dialog>
--- a/mail/components/addrbook/content/abEditListDialog.xul
+++ b/mail/components/addrbook/content/abEditListDialog.xul
@@ -6,28 +6,30 @@
 
 <?xml-stylesheet href="chrome://messenger/skin/addressbook/cardDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/addressbook/abMailListDialog.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         id="ablistWindow"
         onload="OnLoadEditList();"
-        ondialogaccept="return EditListOKButton();"
         ondragover="DragOverAddressListTree(event);"
         ondrop="DropOnAddressListTree(event);">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_addressBook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
   </stringbundleset>
 
   <!-- move needed functions into a single js file -->
   <script type="application/javascript" src="chrome://messenger/content/messengercompose/addressingWidgetOverlay.js"/>
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abCommon.js"/>
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abMailListDialog.js"/>
+  <script type="application/javascript"><![CDATA[
+    document.addEventListener("dialogaccept", EditListOKButton);
+  ]]></script>
 
   <vbox id="editlist">
     <hbox id="ListNameContainer" align="center">
       <spacer flex="1"/>
       <label control="ListName" value="&ListName.label;" accesskey="&ListName.accesskey;" class="CardEditLabel"/>
       <hbox class="CardEditWidth">
         <textbox id="ListName" flex="1"/>
       </hbox>
--- a/mail/components/addrbook/content/abMailListDialog.xul
+++ b/mail/components/addrbook/content/abMailListDialog.xul
@@ -6,29 +6,31 @@
 
 <?xml-stylesheet href="chrome://messenger/skin/addressbook/cardDialog.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/addressbook/abMailListDialog.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         id="ablistWindow"
         title="&mailListWindowAdd.title;"
-        ondialogaccept="return MailListOKButton();"
         onload="OnLoadNewMailList();"
         ondragover="DragOverAddressListTree(event);"
         ondrop="DropOnAddressListTree(event);">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_addressBook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
   </stringbundleset>
 
   <!-- move needed functions into a single js file -->
   <script type="application/javascript" src="chrome://messenger/content/messengercompose/addressingWidgetOverlay.js"/>
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abCommon.js"/>
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abMailListDialog.js"/>
+  <script type="application/javascript"><![CDATA[
+    document.addEventListener("dialogaccept", MailListOKButton);
+  ]]></script>
 
   <hbox align="center">
     <label control="abPopup" value="&addToAddressBook.label;" accesskey="&addToAddressBook.accesskey;"/>
     <menulist id="abPopup">
       <menupopup id="abPopup-menupopup" class="addrbooksPopup" writable="true"
                  supportsmaillists="true"/>
     </menulist>
   </hbox>
--- a/mail/components/addrbook/content/abNewCardDialog.xul
+++ b/mail/components/addrbook/content/abNewCardDialog.xul
@@ -14,26 +14,28 @@
   %abCardDTD;
 ]>
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     xmlns:html="http://www.w3.org/1999/xhtml"
     id="abcardWindow"
     icon="abcardWindow"
     windowtype="mailnews:newcarddialog"
-    onload="OnLoadNewCard()"
-    ondialogaccept="return NewCardOKButton();"
-    ondialogcancel="return NewCardCancelButton();">
+    onload="OnLoadNewCard()">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_addressBook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
   </stringbundleset>
 
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abCommon.js"/>
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abCard.js"/>
+  <script type="application/javascript"><![CDATA[
+    document.addEventListener("dialogaccept", NewCardOKButton);
+    document.addEventListener("dialogcancel", NewCardCancelButton);
+  ]]></script>
 
   <hbox align="center">
     <label id="abPopupLabel" control="abPopup" value="&chooseAddressBook.label;" accesskey="&chooseAddressBook.accesskey;"/>
     <menulist id="abPopup">
       <menupopup id="abPopup-menupopup" class="addrbooksPopup" writable="true"/>
     </menulist>
   </hbox>
 
--- a/mail/components/im/content/addbuddy.js
+++ b/mail/components/im/content/addbuddy.js
@@ -31,8 +31,10 @@ var addBuddy = {
   getValue(aId) { return document.getElementById(aId).value; },
 
   create() {
     let account = Services.accounts.getAccountById(this.getValue("accountlist"));
     let group = document.getElementById("chatBundle").getString("defaultGroup");
     account.addBuddy(Services.tags.createTag(group), this.getValue("name"));
   },
 };
+
+document.addEventListener("dialogaccept", addBuddy.create);
--- a/mail/components/im/content/addbuddy.xul
+++ b/mail/components/im/content/addbuddy.xul
@@ -9,17 +9,16 @@
 <!DOCTYPE window SYSTEM "chrome://messenger/locale/addbuddy.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
   id="addBuddyDialog"
   windowtype="Messenger:AddBuddy"
   title="&addBuddyWindow.title;"
   buttons="accept,cancel"
   onload="addBuddy.onload()"
-  ondialogaccept="addBuddy.create()"
   buttondisabledaccept="true">
   <script type="application/javascript" src="chrome://messenger/content/chat/addbuddy.js"/>
 
   <stringbundle id="chatBundle" src="chrome://messenger/locale/chat.properties"/>
 
   <grid>
    <columns>
     <column/>
--- a/mail/components/im/content/joinchat.js
+++ b/mail/components/im/content/joinchat.js
@@ -146,8 +146,10 @@ var joinChat = {
         autojoin.push(name);
         prefBranch.setStringPref(autoJoinPref, autojoin.join(","));
       }
     }
 
     return true;
   },
 };
+
+document.addEventListener("dialogaccept", joinChat.join);
--- a/mail/components/im/content/joinchat.xul
+++ b/mail/components/im/content/joinchat.xul
@@ -8,18 +8,17 @@
 
 <!DOCTYPE window SYSTEM "chrome://messenger/locale/joinChat.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
   id="joinChatDialog"
   windowtype="Messenger:JoinChat"
   title="&joinChatWindow.title;"
   buttons="accept,cancel"
-  onload="joinChat.onload()"
-  ondialogaccept="joinChat.join()">
+  onload="joinChat.onload()">
   <script type="application/javascript" src="chrome://messenger/content/chat/joinchat.js"/>
 
   <grid>
     <columns>
       <column/>
       <column flex="1"/>
       <column id="optionalcolumn" labeltxt="&optional.label;"/>
     </columns>
--- a/mail/components/preferences/applicationManager.js
+++ b/mail/components/preferences/applicationManager.js
@@ -96,8 +96,11 @@ var gAppManagerDialog = {
       address = app.uri;
     document.getElementById("appLocation").value = address;
     var bundle = document.getElementById("appManagerBundle");
     var appType = (app instanceof Ci.nsILocalHandlerApp) ?
                     "descriptionLocalApp" : "descriptionWebApp";
     document.getElementById("appType").value = bundle.getString(appType);
   },
 };
+
+document.addEventListener("dialogaccept", gAppManagerDialog.onOK);
+document.addEventListener("dialogcancel", gAppManagerDialog.onCancel);
--- a/mail/components/preferences/applicationManager.xul
+++ b/mail/components/preferences/applicationManager.xul
@@ -6,18 +6,16 @@
 <?xml-stylesheet href="chrome://global/skin/"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/preferences/applicationManager.dtd">
 
 <dialog id="appManager"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         buttons="accept,cancel"
         onload="gAppManagerDialog.init();"
-        ondialogaccept="gAppManagerDialog.onOK();"
-        ondialogcancel="gAppManagerDialog.onCancel();"
         title="&appManager.title;"
         style="&appManager.style;"
         persist="screenX screenY">
 
   <script type="application/javascript"
           src="chrome://messenger/content/preferences/applications.js"/>
   <script type="application/javascript"
           src="chrome://messenger/content/preferences/applicationManager.js"/>
--- a/mail/components/preferences/attachmentReminder.js
+++ b/mail/components/preferences/attachmentReminder.js
@@ -72,8 +72,10 @@ var gAttachmentReminderOptionsDialog = {
       if (i != this.keywordListBox.getRowCount() - 1)
         keywordList += ",";
     }
 
     Services.prefs.setStringPref("mail.compose.attachment_reminder_keywords",
                                  keywordList);
   },
 };
+
+document.addEventListener("dialogaccept", gAttachmentReminderOptionsDialog.saveKeywords);
--- a/mail/components/preferences/attachmentReminder.xul
+++ b/mail/components/preferences/attachmentReminder.xul
@@ -13,17 +13,16 @@
 %sendOptionsDTD;
 ]>
 
 <dialog id="attachmentReminderOptionsDialog" type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         dlgbuttons="accept,cancel"
         title="&attachmentReminderDialog.title;"
         onload="gAttachmentReminderOptionsDialog.init();"
-        ondialogaccept="gAttachmentReminderOptionsDialog.saveKeywords();"
         style="width:38em;">
 
   <prefpane id="attachmentReminderOptionsDialogPane">
     <script type="application/javascript" src="chrome://messenger/content/preferences/attachmentReminder.js"/>
     <stringbundle id="bundlePreferences" src="chrome://messenger/locale/preferences/preferences.properties"/>
 
     <groupbox>
       <label control="keywordList">&attachKeywordText.label;</label>
--- a/mail/components/preferences/fonts.js
+++ b/mail/components/preferences/fonts.js
@@ -125,8 +125,10 @@ var gFontsDialog = {
 
     if (viewCharsetStr === defaultPrefs.getComplexValue(
           "view_default_charset", Ci.nsIPrefLocalizedString).data)
       Services.prefs.clearUserPref("mailnews.view_default_charset");
 
     return true;
   },
 };
+
+document.addEventListener("dialogaccept", gFontsDialog.ondialogaccept);
--- a/mail/components/preferences/fonts.xul
+++ b/mail/components/preferences/fonts.xul
@@ -12,18 +12,17 @@
 ]>
 
 <dialog id="FontsDialog" type="child" class="prefwindow"
             xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
             xmlns:html="http://www.w3.org/1999/xhtml"
             title="&fontsAndEncodingsDialog.title;"
             buttons="accept,cancel"
             persist="lastSelected screenX screenY"
-            role="dialog"
-            ondialogaccept="gFontsDialog.ondialogaccept();">
+            role="dialog">
 
   <keyset>
     <key data-l10n-id="fonts-window-close" modifiers="accel" oncommand="Preferences.close(event)"/>
   </keyset>
 
   <vbox id="FontsDialogPane" class="prefpane largeDialogContainer">
 
     <stringbundle id="bundlePreferences" src="chrome://messenger/locale/preferences/preferences.properties"/>
--- a/mail/extensions/mailviews/content/mailViewSetup.js
+++ b/mail/extensions/mailviews/content/mailViewSetup.js
@@ -1,15 +1,17 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../../../mailnews/base/search/content/searchTerm.js */
 
+document.addEventListener("dialogaccept", onOK);
+
 var gMailView = null;
 
 var dialog;
 
 function mailViewOnLoad() {
   initializeSearchWidgets();
   initializeMailViewOverrides();
   dialog = {};
--- a/mail/extensions/mailviews/content/mailViewSetup.xul
+++ b/mail/extensions/mailviews/content/mailViewSetup.xul
@@ -13,17 +13,16 @@
   <!ENTITY % searchTermDTD SYSTEM "chrome://messenger/locale/searchTermOverlay.dtd">
   %searchTermDTD;
 ]>
 
 <dialog id="mailViewSetupDialog"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="mailViewOnLoad();"
         onunload="mailViewOnUnLoad();"
-        ondialogaccept="return onOK();"
         buttons="accept,cancel"
         buttonalign="right"
         windowtype="mailnews:mailview"
         title="&mailViewSetupTitle.label;"
         style="width: 52em; height: 22em;"
         persist="screenX screenY width height">
 
   <stringbundleset id="stringbundleset">
--- a/mailnews/addrbook/content/abAddressBookNameDialog.js
+++ b/mailnews/addrbook/content/abAddressBookNameDialog.js
@@ -12,16 +12,18 @@ var gOkButton;
 var gNameInput;
 var gDirectory = null;
 
 var kPersonalAddressbookURI = "moz-abmdbdirectory://abook.mab";
 var kCollectedAddressbookURI = "moz-abmdbdirectory://history.mab";
 var kAllDirectoryRoot = "moz-abdirectory://";
 var kPABDirectory = 2; // defined in nsDirPrefs.h
 
+document.addEventListener("dialogaccept", abNameOKButton);
+
 function abNameOnLoad() {
   // Get the document elements.
   gOkButton = document.documentElement.getButton("accept");
   gNameInput = document.getElementById("name");
 
   // look in arguments[0] for parameters to see if we have a directory or not
   if ("arguments" in window && window.arguments[0] &&
       "selectedDirectory" in window.arguments[0]) {
--- a/mailnews/addrbook/content/abAddressBookNameDialog.xul
+++ b/mailnews/addrbook/content/abAddressBookNameDialog.xul
@@ -4,18 +4,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/addressbook/abAddressBookNameDialog.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         style="width: 36em;"
-        onload="abNameOnLoad();"
-        ondialogaccept="return abNameOKButton();">
+        onload="abNameOnLoad();">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_addressBook"
                   src="chrome://messenger/locale/addressbook/addressBook.properties"/>
   </stringbundleset>
 
   <script type="application/javascript" src="chrome://messenger/content/addressbook/abAddressBookNameDialog.js"/>
 
--- a/mailnews/addrbook/prefs/content/pref-directory-add.js
+++ b/mailnews/addrbook/prefs/content/pref-directory-add.js
@@ -24,16 +24,19 @@ var gProgressText;
 var gProgressMeter;
 var gDownloadInProgress = false;
 
 var kDefaultMaxHits = 100;
 var kDefaultLDAPPort = 389;
 var kDefaultSecureLDAPPort = 636;
 var kLDAPDirectory = 0;  // defined in nsDirPrefs.h
 
+document.addEventListener("dialogaccept", onAccept);
+document.addEventListener("dialogcancel", onCancel);
+
 var ldapOfflineObserver = {
   observe(subject, topic, state) {
     // sanity checks
     if (topic != "network:offline-status-changed") return;
     setDownloadOfflineOnlineState(state == "offline");
   },
 };
 
--- a/mailnews/addrbook/prefs/content/pref-directory-add.xul
+++ b/mailnews/addrbook/prefs/content/pref-directory-add.xul
@@ -8,19 +8,17 @@
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/addressbook/pref-directory-add.dtd">
 
 <dialog id="addDirectory"
         style="width: &newDirectoryWidth;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         onload="Startup();"
         onunload="onUnload();"
-        buttons="accept,cancel"
-        ondialogaccept="return onAccept();"
-        ondialogcancel="return onCancel();">
+        buttons="accept,cancel">
 
   <script type="application/javascript" src="chrome://messenger/content/addressbook/pref-directory-add.js"/>
   <stringbundle id="bundle_addressBook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
   <stringbundle id="bundle_replication" src="chrome://messenger/locale/addressbook/replicationProgress.properties"/>
 
   <keyset id="keyset"/>
   <vbox id="editDirectory">
 
--- a/mailnews/base/content/folderProps.js
+++ b/mailnews/base/content/folderProps.js
@@ -3,16 +3,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {Gloda} = ChromeUtils.import("resource:///modules/gloda/gloda.js");
 
 var gMsgFolder;
 var gLockedPref = null;
 
+document.addEventListener("dialogaccept", folderPropsOKButton);
+
 // The folderPropsSink is the class that gets notified of an imap folder's properties
 
 var gFolderPropsSink = {
     setFolderType: function(folderTypeString)
     {
       var typeLabel = document.getElementById("folderType.text");
       if (typeLabel)
       {
--- a/mailnews/base/content/folderProps.xul
+++ b/mailnews/base/content/folderProps.xul
@@ -9,18 +9,17 @@
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/folderProps.dtd">
 
 <dialog
   id="folderPropertiesDialog"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:html="http://www.w3.org/1999/xhtml"
   title="&folderProps.windowtitle.label;"
   buttons="accept,cancel"
-  onload="folderPropsOnLoad();" style="width: 56ch;"
-  ondialogaccept="return folderPropsOKButton();">
+  onload="folderPropsOnLoad();" style="width: 56ch;">
 
   <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
   <script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
   <script type="application/javascript" src="chrome://messenger/content/retention.js"/>
   <script type="application/javascript" src="chrome://messenger/content/folderProps.js"/>
   <script type="application/javascript" src="chrome://messenger/content/menulist-charsetpicker.js"/>
 
 <tabbox id="folderPropTabBox">
--- a/mailnews/base/content/junkLog.xul
+++ b/mailnews/base/content/junkLog.xul
@@ -12,17 +12,16 @@
 <dialog id="viewLogWindow"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="onLoad();"
         title="&adaptiveJunkLog.title;"
         windowtype="mailnews:junklog"
         buttons="accept"
         buttonlabelaccept="&closeLog.label;"
         buttonaccesskeyaccept="&closeLog.accesskey;"
-        ondialogaccept="window.close();"
         persist="screenX screenY width height"
         style="width: 40em; height: 25em;">
 
   <script type="application/javascript" src="chrome://messenger/content/junkLog.js"/>
 
   <vbox flex="1">
     <hbox>
       <label value="&adaptiveJunkLogInfo.label;"/>
--- a/mailnews/base/content/markByDate.js
+++ b/mailnews/base/content/markByDate.js
@@ -1,16 +1,18 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var MILLISECONDS_PER_HOUR   = 60 * 60 * 1000;
 var MICROSECONDS_PER_DAY    = 1000 * MILLISECONDS_PER_HOUR * 24;
 
+document.addEventListener("dialogaccept", onAccept);
+
 function onLoad()
 {
   var upperDateBox = document.getElementById("upperDate");
   // focus the upper bound control - this is where we expect most users to enter
   // a date
   upperDateBox.focus();
 
   // and give it an initial date - "yesterday"
--- a/mailnews/base/content/markByDate.xul
+++ b/mailnews/base/content/markByDate.xul
@@ -7,18 +7,17 @@
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/markByDate.dtd">
 
 <dialog
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
   title="&messageMarkByDate.label;"
   buttons="accept,cancel"
-  onload="onLoad();"
-  ondialogaccept="return onAccept();">
+  onload="onLoad();">
 
   <script type="application/javascript" src="chrome://messenger/content/markByDate.js"/>
   <script type="application/javascript" src="chrome://messenger/content/dateFormat.js"/>
 
   <hbox align="center" pack="end">
     <label control="lowerDate"
            value="&markByDateLower.label;"
            accesskey="&markByDateLower.accesskey;"/>
--- a/mailnews/base/content/msgSelectOfflineFolders.js
+++ b/mailnews/base/content/msgSelectOfflineFolders.js
@@ -97,8 +97,11 @@ var gSelectOffline = {
   onCancel: function() {
     gFolderTreeView.unload();
     for (let [folder, value] of this._rollbackMap) {
       if (value != folder.getFlag(Ci.nsMsgFolderFlags.Offline))
         folder.toggleFlag(Ci.nsMsgFolderFlags.Offline);
     }
   }
 };
+
+document.addEventListener("dialogaccept", gSelectOffline.onAccept);
+document.addEventListener("dialogcancel", gSelectOffline.onCancel);
--- a/mailnews/base/content/msgSelectOfflineFolders.xul
+++ b/mailnews/base/content/msgSelectOfflineFolders.xul
@@ -8,19 +8,17 @@
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/msgSynchronize.dtd" >
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         id="select-offline"
         windowtype="mailnews:selectOffline"
         title="&MsgSelect.label;"
         width="450" height="400"
         persist="width height"
-        onload="gSelectOffline.load();"
-        ondialogaccept="return gSelectOffline.onAccept();"
-        ondialogcancel="return gSelectOffline.onCancel();">
+        onload="gSelectOffline.load();">
 
   <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
   <stringbundle id="bundle_brand" src="chrome://branding/locale/brand.properties"/>
 
   <script type="application/javascript"
           src="chrome://messenger/content/msgSelectOfflineFolders.js"/>
   <script type="application/javascript"
           src="chrome://messenger/content/folderPane.js"/>
--- a/mailnews/base/content/msgSynchronize.js
+++ b/mailnews/base/content/msgSynchronize.js
@@ -7,16 +7,18 @@ var {Services} = ChromeUtils.import("res
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 
 var gSynchronizeTree = null;
 var gParentMsgWindow;
 var gMsgWindow;
 
 var gInitialFolderStates = {};
 
+document.addEventListener("dialogaccept", syncOkButton);
+
 function OnLoad()
 {
     if (window.arguments && window.arguments[0]) {
         if (window.arguments[0].msgWindow) {
             gParentMsgWindow = window.arguments[0].msgWindow;
         }
     }
 
--- a/mailnews/base/content/msgSynchronize.xul
+++ b/mailnews/base/content/msgSynchronize.xul
@@ -9,18 +9,17 @@
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/msgSynchronize.dtd" >
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         id="msg-synchronizer"
         windowtype="mailnews:synchronizeOffline"
         title="&MsgSynchronize.label;"
         onload="OnLoad();"
-        style="width: 35em;"
-        ondialogaccept="return syncOkButton();">
+        style="width: 35em;">
 
 <script type="application/javascript" src="chrome://messenger/content/msgSynchronize.js"/>
 
     <keyset id="keyset"/>
     <label hidden="true" wsm_persist="true" id="server.type"/>
 
     <description class="desc">&MsgSyncDesc.label;</description>
     <separator class="thin"/>
--- a/mailnews/base/content/newFolderDialog.js
+++ b/mailnews/base/content/newFolderDialog.js
@@ -3,16 +3,18 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var FOLDERS = 1;
 var MESSAGES = 2;
 var dialog;
 
+document.addEventListener("dialogaccept", onOK);
+
 function onLoad()
 {
   var windowArgs = window.arguments[0];
 
   dialog = {};
 
   dialog.nameField = document.getElementById("name");
   dialog.nameField.focus();
--- a/mailnews/base/content/newFolderDialog.xul
+++ b/mailnews/base/content/newFolderDialog.xul
@@ -11,18 +11,17 @@
 <!DOCTYPE dialog [
 <!ENTITY % newFolderDTD SYSTEM "chrome://messenger/locale/newFolderDialog.dtd">%newFolderDTD;
 ]>
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         title="&newFolderDialog.title;"
         onload="onLoad();"
         buttonlabelaccept="&accept.label;"
-        buttonaccesskeyaccept="&accept.accesskey;"
-        ondialogaccept="return onOK();">
+        buttonaccesskeyaccept="&accept.accesskey;">
 
   <stringbundleset id="stringbundleset"/>
   <script type="application/javascript" src="chrome://messenger/content/newFolderDialog.js"/>
 
     <label value="&name.label;" accesskey="&name.accesskey;" control="name"/>
     <textbox id="name" oninput="doEnabling();"/>
 
     <separator/>
--- a/mailnews/base/content/renameFolderDialog.js
+++ b/mailnews/base/content/renameFolderDialog.js
@@ -1,16 +1,18 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var dialog;
 
+document.addEventListener("dialogaccept", onOK);
+
 function onLoad()
 {
   var windowArgs = window.arguments[0];
 
   dialog = {};
 
   dialog.OKButton = document.documentElement.getButton("accept");
 
--- a/mailnews/base/content/renameFolderDialog.xul
+++ b/mailnews/base/content/renameFolderDialog.xul
@@ -6,17 +6,16 @@
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/renameFolderDialog.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         title="&renameFolderDialog.title;"
         buttonlabelaccept="&accept.label;"
         buttonaccesskeyaccept="&accept.accesskey;"
-        ondialogaccept="return onOK();"
         onload="onLoad();">
 
   <stringbundleset id="stringbundleset"/>
   <script type="application/javascript" src="chrome://messenger/content/renameFolderDialog.js"/>
 
   <label value="&rename.label;" accesskey="&rename.accesskey;" control="name"/>
   <textbox id="name" oninput="doEnabling();"/>
 </dialog>
--- a/mailnews/base/content/shutdownWindow.js
+++ b/mailnews/base/content/shutdownWindow.js
@@ -6,16 +6,18 @@
 
 var curTaskIndex = 0;
 var numTasks = 0;
 var stringBundle;
 
 var msgShutdownService = Cc["@mozilla.org/messenger/msgshutdownservice;1"]
                            .getService(Ci.nsIMsgShutdownService);
 
+document.addEventListener("dialogcancel", onCancel);
+
 function onLoad()
 {
   numTasks = msgShutdownService.getNumTasks();
 
   stringBundle = document.getElementById("bundle_shutdown");
   document.title = stringBundle.getString("shutdownDialogTitle");
 
   updateTaskProgressLabel(1);
--- a/mailnews/base/content/shutdownWindow.xul
+++ b/mailnews/base/content/shutdownWindow.xul
@@ -6,18 +6,17 @@
 -->
 
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         style="padding: 20px; width: 350px"
         onload="onLoad()"
-        buttons="cancel"
-        ondialogcancel="return onCancel();">
+        buttons="cancel">
 
   <script type="application/javascript" src="chrome://messenger/content/shutdownWindow.js"/>
   <stringbundle id="bundle_shutdown" src="chrome://messenger/locale/shutdownWindow.properties"/>
 
   <vbox align="center">
     <label id="shutdownStatus_label" value="" />
     <separator class="thin" />
   </vbox>
--- a/mailnews/base/content/subscribe.js
+++ b/mailnews/base/content/subscribe.js
@@ -13,16 +13,19 @@ var gSubscribableServer = null;
 var gNameField = null;
 var gNameFieldLabel = null;
 var gStatusFeedback;
 var gSubscribeDeck = null;
 var gSearchView = null;
 var gSearchTree = null;
 var gSubscribeBundle;
 
+document.addEventListener("dialogaccept", subscribeOK);
+document.addEventListener("dialogcancel", subscribeCancel);
+
 function Stop()
 {
   if (gSubscribableServer) {
     gSubscribableServer.stopPopulating(msgWindow);
   }
 }
 
 function SetServerTypeSpecificTextValues()
--- a/mailnews/base/content/subscribe.xul
+++ b/mailnews/base/content/subscribe.xul
@@ -15,19 +15,17 @@
 <dialog id="subscribeWindow"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         title="&subscribeDialog.title;"
         style="width: 44em; height: 33em;"
         persist="width height screenX screenY"
         onload="SubscribeOnLoad()"
         onunload="SubscribeOnUnload()"
-        windowtype="mailnews:subscribe"
-        ondialogaccept="return subscribeOK();"
-        ondialogcancel="return subscribeCancel();">
+        windowtype="mailnews:subscribe">
 
   <stringbundle id="bundle_subscribe" src="chrome://messenger/locale/subscribe.properties"/>
   <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
 
   <script type="application/javascript"
           src="chrome://global/content/globalOverlay.js"/>
   <script type="application/javascript"
           src="chrome://messenger/content/mailWindow.js"/>
--- a/mailnews/base/content/virtualFolderListEdit.js
+++ b/mailnews/base/content/virtualFolderListEdit.js
@@ -98,8 +98,11 @@ var gSelectVirtual = {
     if (window.arguments[0].okCallback)
       window.arguments[0].okCallback(uris);
   },
 
   onCancel: function() {
     gFolderTreeView.unload();
   }
 };
+
+document.addEventListener("dialogaccept", gSelectVirtual.onAccept);
+document.addEventListener("dialogcancel", gSelectVirtual.onCancel);
--- a/mailnews/base/content/virtualFolderListEdit.xul
+++ b/mailnews/base/content/virtualFolderListEdit.xul
@@ -9,19 +9,17 @@
 <!DOCTYPE window SYSTEM "chrome://messenger/locale/virtualFolderListDialog.dtd">
 
 <dialog id="searchFolderWindow"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         title="&virtualFolderListTitle.title;"
         windowtype="mailnews:virtualFolderList"
         style="width: 27em; height: 25em;"
         persist="width height screenX screenY"
-        onload="gSelectVirtual.load();"
-        ondialogaccept="return gSelectVirtual.onAccept();"
-        ondialogcancel="return gSelectVirtual.onCancel();">
+        onload="gSelectVirtual.load();">
 
   <script type="application/javascript"
           src="chrome://messenger/content/virtualFolderListEdit.js"/>
   <script type="application/javascript"
           src="chrome://messenger/content/folderPane.js"/>
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
--- a/mailnews/base/content/virtualFolderProperties.js
+++ b/mailnews/base/content/virtualFolderProperties.js
@@ -16,16 +16,18 @@ var {Services} = ChromeUtils.import("res
 var {PluralForm} = ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 var {
   VirtualFolderHelper,
 } = ChromeUtils.import("resource:///modules/virtualFolderWrapper.js");
 var {fixIterator} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 
+document.addEventListener("dialogaccept", onOK);
+
 function onLoad()
 {
   var windowArgs = window.arguments[0];
   var acceptButton = document.documentElement.getButton("accept");
 
   gMessengerBundle = document.getElementById("bundle_messenger");
 
   // call this when OK is pressed
--- a/mailnews/base/content/virtualFolderProperties.xul
+++ b/mailnews/base/content/virtualFolderProperties.xul
@@ -21,18 +21,17 @@
         title="&virtualFolderProperties.title;"
         onload="onLoad();"
         buttons="accept,cancel"
         newFolderAcceptButtonLabel="&newFolderButton.label;"
         newFolderAcceptButtonAccessKey="&newFolderButton.accesskey;"
         editFolderAcceptButtonLabel="&editFolderButton.label;"
         editFolderAcceptButtonAccessKey="&editFolderButton.accesskey;"
         style="width: 50em; height: 28em;"
-        windowtype="mailnews:virtualFolderProperties"
-        ondialogaccept="return onOK();">
+        windowtype="mailnews:virtualFolderProperties">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_search"    src="chrome://messenger/locale/search.properties"/>
     <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
     <stringbundle id="bundle_folder"    src="chrome://messenger/locale/folderWidgets.properties"/>
   </stringbundleset>
 
   <script type="application/javascript" src="chrome://messenger/content/mailCommands.js"/>
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -28,16 +28,19 @@
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {BrowserUtils} = ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm");
 var {Gloda} = ChromeUtils.import("resource:///modules/gloda/gloda.js");
 var {fixIterator} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 var {allAccountsSorted} = ChromeUtils.import("resource:///modules/folderUtils.jsm");
 var {cleanUpHostName, isLegalHostNameOrIP} = ChromeUtils.import("resource:///modules/hostnameUtils.jsm");
 
+document.addEventListener("dialogcancel", onNotAccept);
+document.addEventListener("dialogaccept", () => onAccept(true));
+
 // If Local directory has changed the app needs to restart. Once this is set
 // a restart will be attempted at each attempt to close the Account manager with OK.
 var gRestartNeeded = false;
 
 // This is a hash-map for every account we've touched in the pane. Each entry
 // has additional maps of attribute-value pairs that we're going to want to save
 // when the user hits OK.
 var accountArray;
--- a/mailnews/base/prefs/content/AccountManager.xul
+++ b/mailnews/base/prefs/content/AccountManager.xul
@@ -10,19 +10,17 @@
 <dialog id="accountManager"
         windowtype="mailnews:accountmanager"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         title="&accountManagerTitle.label;"
         style="&accountManager.size;"
         persist="width height screenX screenY"
         buttons="accept,cancel"
         onload="onLoad(event);"
-        onunload="onUnload();"
-        ondialogcancel="return onNotAccept();"
-        ondialogaccept="return onAccept(true);">
+        onunload="onUnload();">
 <stringbundle id="bundle_brand" src="chrome://branding/locale/brand.properties"/>
 <stringbundle id="bundle_prefs" src="chrome://messenger/locale/prefs.properties"/>
 <script type="application/javascript" src="chrome://messenger/content/accountUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/am-prefs.js"/>
 <script type="application/javascript" src="chrome://messenger/content/AccountManager.js"/>
 <script type="application/javascript" src="chrome://messenger/content/am-help.js"/>
 <script type="application/javascript" src="chrome://messenger/content/amUtils.js"/>
 
--- a/mailnews/base/prefs/content/SmtpServerEdit.js
+++ b/mailnews/base/prefs/content/SmtpServerEdit.js
@@ -13,16 +13,18 @@ var gSmtpDescription;
 var gSmtpUsernameLabel;
 var gSmtpHostname;
 var gSmtpPort;
 var gSmtpAuthMethod;
 var gSmtpSocketType;
 var gPort;
 var gDefaultPort;
 
+document.addEventListener("dialogaccept", onAccept);
+
 function onLoad(event)
 {
   gSmtpServer = window.arguments[0].server;
   initSmtpSettings(gSmtpServer);
 }
 
 function onAccept()
 {
--- a/mailnews/base/prefs/content/SmtpServerEdit.xul
+++ b/mailnews/base/prefs/content/SmtpServerEdit.xul
@@ -10,18 +10,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/smtpEditOverlay.dtd">
 
 <dialog title="&smtpEditTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
-        onload="onLoad();"
-        ondialogaccept="return onAccept();">
+        onload="onLoad();">
   <stringbundle id="bundle_prefs"
                 src="chrome://messenger/locale/prefs.properties"/>
   <stringbundle id="bundle_brand"
                 src="chrome://branding/locale/brand.properties"/>
   <stringbundle id="bundle_messenger"
                 src="chrome://messenger/locale/messenger.properties"/>
   <script type="application/javascript"
           src="chrome://messenger/content/SmtpServerEdit.js"/>
--- a/mailnews/base/prefs/content/am-archiveoptions.js
+++ b/mailnews/base/prefs/content/am-archiveoptions.js
@@ -1,15 +1,17 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var gIdentity = null;
 
+document.addEventListener("dialogaccept", onAcceptArchiveOptions);
+
 /**
  * Load the archive options dialog, set the radio/checkbox items to the
  * appropriate values, and update the archive hierarchy example.
  */
 function onLoadArchiveOptions() {
   // extract the account
   gIdentity = window.arguments[0];
 
--- a/mailnews/base/prefs/content/am-archiveoptions.xul
+++ b/mailnews/base/prefs/content/am-archiveoptions.xul
@@ -9,18 +9,17 @@
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/am-archiveoptions.dtd" >
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         id="archive-options"
         title="&dialogTitle.label;"
         width="350" height="350"
         persist="width height"
-        onload="onLoadArchiveOptions();"
-        ondialogaccept="onAcceptArchiveOptions();">
+        onload="onLoadArchiveOptions();">
 
   <script type="application/javascript" src="chrome://messenger/content/am-archiveoptions.js"/>
 
   <vbox flex="1">
     <label>&archiveGranularityPrefix.label;</label>
     <radiogroup id="archiveGranularity">
       <radio label="&archiveFlat.label;" accesskey="&archiveFlat.accesskey;"
              class="indent"/>
--- a/mailnews/base/prefs/content/am-identities-list.js
+++ b/mailnews/base/prefs/content/am-identities-list.js
@@ -10,16 +10,19 @@ var {Services} = ChromeUtils.import("res
 var gIdentityListBox;                 // the root <listbox> node
 var gAddButton;
 var gEditButton;
 var gSetDefaultButton;
 var gDeleteButton;
 
 var gAccount = null;  // the account we are showing the identities for
 
+document.addEventListener("dialogaccept", onOk);
+document.addEventListener("dialogcancel", onOk);
+
 function onLoad()
 {
   gIdentityListBox  = document.getElementById("identitiesList");
   gAddButton        = document.getElementById("cmd_add");
   gEditButton       = document.getElementById("cmd_edit");
   gSetDefaultButton = document.getElementById("cmd_default");
   gDeleteButton     = document.getElementById("cmd_delete");
 
--- a/mailnews/base/prefs/content/am-identities-list.xul
+++ b/mailnews/base/prefs/content/am-identities-list.xul
@@ -10,18 +10,16 @@
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/am-identities-list.dtd">
 
 <dialog
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
   onload="onLoad();"
   buttons="accept"
   buttonlabelaccept="&identitiesListClose.label;"
   buttonaccesskeyaccept="&identitiesListClose.accesskey;"
-  ondialogaccept="return onOk();"
-  ondialogcancel="return onOk();"
   style="width: 40em;">
 
 <stringbundle id="bundle_prefs" src="chrome://messenger/locale/prefs.properties"/>
 <script type="application/javascript"
         src="chrome://messenger/content/am-identities-list.js"/>
 
 <commandset>
   <command id="cmd_add"     oncommand="openIdentityEditor(null);"/>
--- a/mailnews/base/prefs/content/am-identity-edit.js
+++ b/mailnews/base/prefs/content/am-identity-edit.js
@@ -4,16 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var gIdentity = null;  // the identity we are editing (may be null for a new identity)
 var gAccount = null;   // the account the identity is (or will be) associated with
 
+document.addEventListener("dialogaccept", onOk);
+
 function onLoadIdentityProperties()
 {
   // extract the account
   gIdentity = window.arguments[0].identity;
   gAccount = window.arguments[0].account;
   let prefBundle = document.getElementById("bundle_prefs");
 
   // Make the dialog the same height and 90% of the width of the main Account
--- a/mailnews/base/prefs/content/am-identity-edit.xul
+++ b/mailnews/base/prefs/content/am-identity-edit.xul
@@ -19,17 +19,16 @@
 <!ENTITY % smimeDTD SYSTEM "chrome://messenger/locale/am-smime.dtd" >
 %smimeDTD;
 ]>
 
 <dialog id="identityDialog"
         xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="onLoadIdentityProperties();"
-        ondialogaccept="return onOk();"
         style="&identityDialog.style;">
 
   <stringbundle id="bundle_prefs"
                 src="chrome://messenger/locale/prefs.properties"/>
   <stringbundle id="bundle_messenger"
                 src="chrome://messenger/locale/messenger.properties"/>
 
   <script type="application/javascript"
--- a/mailnews/base/prefs/content/am-server-advanced.js
+++ b/mailnews/base/prefs/content/am-server-advanced.js
@@ -1,16 +1,18 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
+document.addEventListener("dialogaccept", onOk);
+
 // pull stuff out of window.arguments
 var gServerSettings = window.arguments[0];
 
 var gFirstDeferredAccount;
 // initialize the controls with the "gServerSettings" argument
 
 var gControls;
 function getControls()
--- a/mailnews/base/prefs/content/am-server-advanced.xul
+++ b/mailnews/base/prefs/content/am-server-advanced.xul
@@ -9,18 +9,17 @@
 <?xml-stylesheet href="chrome://messenger/skin/folderMenus.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/am-server-advanced.dtd">
 
 <dialog
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         title="&serverAdvanced.label;"
         buttons="accept,cancel"
-        onload="onLoad();"
-        ondialogaccept="return onOk();">
+        onload="onLoad();">
 
   <script type="application/javascript"
           src="chrome://messenger/content/am-server-advanced.js"/>
   <stringbundle id="bundle_prefs"
                 src="chrome://messenger/locale/prefs.properties"/>
 
     <label id="serverPrettyName"/>
 
--- a/mailnews/base/prefs/content/removeAccount.js
+++ b/mailnews/base/prefs/content/removeAccount.js
@@ -4,16 +4,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var gServer;
 var gDialog;
 
+document.addEventListener("dialogdisclosure", showInfo);
+document.addEventListener("dialogaccept", onAccept);
+
 function onLoad(event) {
   gServer = window.arguments[0].account.incomingServer;
   gDialog = document.documentElement;
 
   let bundle = document.getElementById("bundle_removeAccount");
   let removeQuestion = bundle.getFormattedString("removeQuestion",
                                                  [gServer.prettyName]);
   document.getElementById("accountName").textContent = removeQuestion;
--- a/mailnews/base/prefs/content/removeAccount.xul
+++ b/mailnews/base/prefs/content/removeAccount.xul
@@ -17,19 +17,17 @@
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         title="&dialogTitle;"
         width="600"
         buttons="accept,disclosure,cancel"
         buttonlabelaccept="&removeButton.label;"
         buttonaccesskeyaccept="&removeButton.accesskey;"
         defaultButton="cancel"
-        onload="onLoad();"
-        ondialogdisclosure="showInfo();"
-        ondialogaccept="return onAccept();">
+        onload="onLoad();">
   <stringbundle id="bundle_removeAccount"
                 src="chrome://messenger/locale/removeAccount.properties"/>
   <script type="application/javascript"
           src="chrome://messenger/content/removeAccount.js"/>
   <deck id="infoPane">
     <vbox flex="1">
       <label id="accountName"></label>
       <separator class="thin"/>
--- a/mailnews/base/search/content/CustomHeaders.js
+++ b/mailnews/base/search/content/CustomHeaders.js
@@ -9,16 +9,20 @@ var gAddButton;
 var gRemoveButton;
 var gHeaderInputElement;
 var gArrayHdrs;
 var gHdrsList;
 var gContainer;
 var gFilterBundle=null;
 var gCustomBundle=null;
 
+document.addEventListener("dialogaccept", onOk);
+document.addEventListener("dialogextra1", onAddHeader);
+document.addEventListener("dialogextra2", onRemoveHeader);
+
 function onLoad()
 {
     let hdrs = Services.prefs.getCharPref("mailnews.customHeaders");
     gHeaderInputElement = document.getElementById("headerInput");
     gHeaderInputElement.focus();
 
     gHdrsList = document.getElementById("headerList");
     gArrayHdrs = new Array();
--- a/mailnews/base/search/content/CustomHeaders.xul
+++ b/mailnews/base/search/content/CustomHeaders.xul
@@ -7,19 +7,16 @@
 #else
 <?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
 #endif
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/CustomHeaders.dtd">
 <dialog id="customHeadersDialog"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="onLoad();"
-        ondialogaccept="return onOk();"
-        ondialogextra1="onAddHeader();"
-        ondialogextra2="onRemoveHeader();"
         style="width: 30em; height: 25em;"
         persist="width height screenX screenY"
         title="&window.title;"
         buttons="accept,cancel,extra1,extra2">
 
   <stringbundleset id="stringbundleset">
   <stringbundle id="bundle_filter" src="chrome://messenger/locale/filter.properties"/>
   <stringbundle id="bundle_custom" src="chrome://messenger/locale/custom.properties"/>
--- a/mailnews/base/search/content/FilterEditor.js
+++ b/mailnews/base/search/content/FilterEditor.js
@@ -37,16 +37,18 @@ var gActionListOrdered = null;
 
 var gFilterEditorMsgWindow = null;
 
 var nsMsgFilterAction = Ci.nsMsgFilterAction;
 var nsMsgFilterType   = Ci.nsMsgFilterType;
 var nsIMsgRuleAction  = Ci.nsIMsgRuleAction;
 var nsMsgSearchScope  = Ci.nsMsgSearchScope;
 
+document.addEventListener("dialogaccept", onAccept);
+
 function filterEditorOnLoad()
 {
   getCustomActions();
   initializeSearchWidgets();
   initializeFilterWidgets();
 
   gFilterBundle = document.getElementById("bundle_filter");
 
--- a/mailnews/base/search/content/FilterEditor.xul
+++ b/mailnews/base/search/content/FilterEditor.xul
@@ -20,18 +20,17 @@
 <dialog id="FilterEditor"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
   title="&window.title;"
   style="&filterEditorDialog.dimensions;"
   windowtype="mailnews:filtereditor"
   persist="width height screenX screenY"
   buttons="accept,cancel"
   onload="filterEditorOnLoad();"
-  onunload="filterEditorOnUnload();"
-  ondialogaccept="return onAccept();">
+  onunload="filterEditorOnUnload();">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
     <stringbundle id="bundle_filter" src="chrome://messenger/locale/filter.properties"/>
     <stringbundle id="bundle_search" src="chrome://messenger/locale/search.properties"/>
   </stringbundleset>
 
   <script type="application/javascript" src="chrome://messenger/content/searchWidgets.js"/>
--- a/mailnews/base/search/content/viewLog.xul
+++ b/mailnews/base/search/content/viewLog.xul
@@ -11,17 +11,16 @@
 <dialog id="viewLogWindow"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         onload="onLoad();"
         title="&viewLog.title;"
         windowtype="mailnews:filterlog"
         buttons="accept"
         buttonlabelaccept="&closeLog.label;"
         buttonaccesskeyaccept="&closeLog.accesskey;"
-        ondialogaccept="window.close();"
         persist="screenX screenY width height"
         style="width: 40em; height: 25em;">
 
   <script type="application/javascript" src="chrome://messenger/content/viewLog.js"/>
 
   <vbox flex="1">
     <description>&viewLogInfo.text;</description>
     <hbox>
--- a/mailnews/compose/content/askSendFormat.js
+++ b/mailnews/compose/content/askSendFormat.js
@@ -1,14 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var gParam = null;
 
+document.addEventListener("dialogaccept", Send);
+
 /**
  * This dialog should be opened with arguments like e.g.
  * {action: nsIMsgCompSendFormat.AskUser, convertible: nsIMsgCompConvertible.Yes}
  */
 function Startup()
 {
   gParam = window.arguments[0];
 
--- a/mailnews/compose/content/askSendFormat.xul
+++ b/mailnews/compose/content/askSendFormat.xul
@@ -7,17 +7,16 @@
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/messengercompose/askSendFormat.dtd">
 
 <dialog id="askSendFormat"
         title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         buttonpack="center"
         onload="Startup();"
-        ondialogaccept="Send();"
         buttonlabelaccept="&send.label;"
         buttonaccesskeyaccept="&send.accesskey;"
         style="width: 75ch;">
 
   <script type="application/javascript"
           src="chrome://messenger/content/messengercompose/askSendFormat.js"/>
 
   <stringbundle id="askSendFormatStringBundle"
--- a/mailnews/compose/content/sendProgress.js
+++ b/mailnews/compose/content/sendProgress.js
@@ -10,16 +10,18 @@ var dialog;
 
 // the msgProgress is a nsIMsgProgress object
 var msgProgress = null;
 
 // random global variables...
 var itsASaveOperation = false;
 var gSendProgressStringBundle;
 
+document.addEventListener("dialogcancel", onCancel);
+
 // all progress notifications are done through the nsIWebProgressListener implementation...
 var progressListener = {
     onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
     {
       if (aStateFlags & Ci.nsIWebProgressListener.STATE_START)
       {
         // Set no value to progress meter when undetermined.
         dialog.progress.removeAttribute("value");
--- a/mailnews/compose/content/sendProgress.xul
+++ b/mailnews/compose/content/sendProgress.xul
@@ -10,18 +10,17 @@
 
 <dialog id="sendProgress"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         title="&sendDialog.title;"
         style="width: 56ch;"
         onload="onLoad();"
         onunload="onUnload();"
-        buttons="cancel"
-        ondialogcancel="return onCancel();">
+        buttons="cancel">
 
   <script type="application/javascript"
           src="chrome://messenger/content/messengercompose/sendProgress.js"/>
   <stringbundle id="sendProgressStringBundle"
                 src="chrome://messenger/locale/messengercompose/sendProgress.properties"/>
 
     <grid flex="1">
       <columns>
--- a/mailnews/extensions/smime/content/am-smime.js
+++ b/mailnews/extensions/smime/content/am-smime.js
@@ -24,16 +24,18 @@ var gNeverEncrypt = null;
 var gBundle = null;
 var gBrandBundle;
 var gSmimePrefbranch;
 var gEncryptionChoicesLocked;
 var gSigningChoicesLocked;
 var kEncryptionCertPref = "identity.encryption_cert_name";
 var kSigningCertPref = "identity.signing_cert_name";
 
+document.addEventListener("dialogaccept", smimeOnAcceptEditor);
+
 function onInit()
 {
   smimeInitializeFields();
 }
 
 function smimeInitializeFields()
 {
   // initialize all of our elements based on the current identity values....
--- a/mailnews/extensions/smime/content/am-smime.xul
+++ b/mailnews/extensions/smime/content/am-smime.xul
@@ -4,18 +4,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://messenger/skin/accountManage.css" type="text/css"?>
 
 <!DOCTYPE page SYSTEM "chrome://messenger/locale/am-smime.dtd">
 
 <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         class="color-dialog"
-        onload="parent.onPanelLoaded('am-smime.xul');"
-        ondialogaccept="smimeOnAcceptEditor();">
+        onload="parent.onPanelLoaded('am-smime.xul');">
 
   <vbox flex="1" style="overflow: auto;">
     <script type="application/javascript" src="chrome://messenger/content/AccountManager.js"/>
     <script type="application/javascript" src="chrome://messenger/content/am-smime.js"/>
 
     <hbox class="dialogheader">
       <label class="dialogheader-title" value="&securityTitle.label;"/>
     </hbox>
--- a/mailnews/extensions/smime/content/certFetchingStatus.js
+++ b/mailnews/extensions/smime/content/certFetchingStatus.js
@@ -22,16 +22,18 @@ var CertAttribute = "usercertificate;bin
 var gEmailAddresses;
 var gDirectoryPref;
 var gLdapServerURL;
 var gLdapConnection;
 var gCertDB;
 var gLdapOperation;
 var gLogin;
 
+document.addEventListener("dialogcancel", stopFetching);
+
 function onLoad()
 {
   gDirectoryPref = window.arguments[0];
   gEmailAddresses = window.arguments[1];
 
   if (!gEmailAddresses.length)
   {
     window.close();
--- a/mailnews/extensions/smime/content/certFetchingStatus.xul
+++ b/mailnews/extensions/smime/content/certFetchingStatus.xul
@@ -8,17 +8,16 @@
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger-smime/locale/certFetchingStatus.dtd">
 
 <dialog id="certFetchingStatus" title="&title.label;"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
   style="width: 50em;"
   buttons="cancel"
   buttonlabelcancel="&stop.label;"
-  ondialogcancel="return stopFetching();"
   onload="onLoad();">
 
   <stringbundle id="bundle_ldap" src="chrome://mozldap/locale/ldap.properties"/>
 <script type="application/javascript" src="chrome://messenger-smime/content/certFetchingStatus.js"/>
 
   <description>&info.message;</description>
 
 </dialog>
--- a/mailnews/extensions/smime/content/certpicker.js
+++ b/mailnews/extensions/smime/content/certpicker.js
@@ -4,16 +4,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 const nsIDialogParamBlock = Ci.nsIDialogParamBlock;
 
 var dialogParams;
 var itemCount = 0;
 
+document.addEventListener("dialogaccept", doOK);
+document.addEventListener("dialogcancel", doCancel);
+
 function onLoad()
 {
   dialogParams = window.arguments[0].QueryInterface(nsIDialogParamBlock);
 
   var selectElement = document.getElementById("nicknames");
   itemCount = dialogParams.GetInt(0);
 
   var selIndex = dialogParams.GetInt(1);
--- a/mailnews/extensions/smime/content/certpicker.xul
+++ b/mailnews/extensions/smime/content/certpicker.xul
@@ -10,18 +10,16 @@
 %amSMIMEDTD;
 ]>
 
 <dialog id="certPicker" title="&certPicker.title;"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:html="http://www.w3.org/1999/xhtml"
   style="width: 50em;"
   buttons="accept,cancel"
-  ondialogaccept="return doOK();"
-  ondialogcancel="return doCancel();"
   onload="onLoad();">
 
 <script type="application/javascript"
         src="chrome://messenger/content/certpicker.js"/>
 
   <hbox align="center">
     <label id="pickerInfo" value="&certPicker.info;"/>
     <!-- The items in this menulist must never be sorted,
--- a/mailnews/import/content/fieldMapImport.js
+++ b/mailnews/import/content/fieldMapImport.js
@@ -9,16 +9,18 @@ var addInterface = null;
 var dialogResult = null;
 var gPreviousButton;
 var gNextButton;
 var gMoveUpButton;
 var gMoveDownButton;
 var gListbox;
 var gSkipFirstRecordButton;
 
+document.addEventListener("dialogaccept", FieldImportOKButton);
+
 function OnLoadFieldMapImport()
 {
   top.importService = Cc["@mozilla.org/import/import-service;1"]
                         .getService(Ci.nsIImportService);
 
   // We need a field map object...
   // assume we have one passed in? or just make one?
   if (window.arguments && window.arguments[0]) {
--- a/mailnews/import/content/fieldMapImport.xul
+++ b/mailnews/import/content/fieldMapImport.xul
@@ -11,17 +11,16 @@
 <?xml-stylesheet href="chrome://messenger/content/fieldMapImport.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/fieldMapImport.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         buttons="accept,cancel"
         title="&fieldMapImport.title;"
         style="&fieldMapImport.size;"
-        ondialogaccept="FieldImportOKButton();"
         onload="OnLoadFieldMapImport();">
 
   <script type="application/javascript" src="chrome://messenger/content/fieldMapImport.js"/>
   <script><![CDATA[
       function resizeColumns() {
         let list = document.getElementById("fieldList");
         let cols = list.getElementsByTagName("treecol");
         list.style.setProperty("--column1width", cols[0].boxObject.width + "px");
--- a/mailnews/news/content/downloadheaders.js
+++ b/mailnews/news/content/downloadheaders.js
@@ -6,16 +6,19 @@
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var markreadElement = null;
 var numberElement = null;
 
 var nntpServer = null;
 var args = null;
 
+document.addEventListener("dialogaccept", OkButtonCallback);
+document.addEventListener("dialogcancel", CancelButtonCallback);
+
 function OnLoad() {
   let newsBundle = document.getElementById("bundle_news");
 
   if ("arguments" in window && window.arguments[0]) {
     args = window.arguments[0]
                  .QueryInterface(Ci.nsINewsDownloadDialogArgs);
     /* by default, act like the user hit cancel */
     args.hitOK = false;
--- a/mailnews/news/content/downloadheaders.xul
+++ b/mailnews/news/content/downloadheaders.xul
@@ -5,18 +5,16 @@
 
 <?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/downloadheaders.dtd">
 
 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         style="max-width: 27em;"
         buttonpack="center"
-        ondialogaccept="return OkButtonCallback();"
-        ondialogcancel="return CancelButtonCallback();"
         onload="OnLoad();">
 
   <stringbundle id="bundle_news" src="chrome://messenger/locale/news.properties"/>
   <script type="application/javascript" src="chrome://messenger/content/downloadheaders.js"/>
 
   <label class="header" style="width: 25em; max-width: 25em;" id="newsgroupLabel" control="downloadGroup"/>
   <description style="width: 25em; max-width: 25em;" id="info" control="downloadGroup"/>
   <separator class="thin"/>