What I meant is either:

    (function() {
      // define elements here.
      var messageText = null;
      ...
      function init() {
         // Init the elements here
         messageText = document.getElementById('messageText');
         ...
      }

      function uninit() {
        // do some cleaning work
      }

      window.addEventListener('load', init);
      window.addEventListener('unload', uninit);
    })();

or like this:

    function FMRadioTest() {
       if (!navigator.mozFMRadio) {
         alert("No FM radio!");
         return;
       }

       // Because FMRadioTest is invoked when document is loaded, it's kinda the init function,
       // so we can init the elements here, because the document has been loaded.
       var messageText = document.getElementById('messageText');
       ...

       function uninit() {
          // do some cleaning work
       }

      window.addEventListener('unload', uninit);
    }

    window.addEventListener('load', FMRadioTest);

and I prefer the second one.