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) {                                                          
                       e.stopPropagation();

                       e.preventDefault();

                                           }
                              }
    setTimeout("enableBeforeUnloadHandler()", "100");
                    }
  }
  window.onbeforeunload=confirmExit;
  function enableBeforeUnloadHandler()
  {
  window.onebforeunload=confirmExit;
  }

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