Window.onbeforeunload event is firing twice making the confirmation message to pop up twice

     function confirmExit(e) {

      var f = FormChanges();

    //checking if page has been modified or not
    if (f.length > 0){
                        if (submitForm == false)
                             if(!e) e = window.event;
                             e.cancelBubble = true;
                             e.returnValue = "You have made updates to this page which have not been saved.";
                        //e.stopPropagation for Firefox.
                        if (e.stopPropagation) {                                                          


    setTimeout("enableBeforeUnloadHandler()", "100");
  function enableBeforeUnloadHandler()

The pop up message is displaying twice in both Firefox and IE and it's not waiting for the User Input in Firefox.How do I fix this?

The popup displays Twice like this