var module = {
  id: "fetcher",
  showIf: true,
  hideIf: true,

  // aLevelName: "Light", "Pro", "Enterprise"...
  loadUI: function(aWindow, isFirstLoad, aLevelName) {
    var document = aWindow.document;
    try {
      ow.app.kernel.prefs.setBool("images.ondemandonly", true);

      document.getElementById("infoBar").setAttribute("noSideBox", "true");

      //document.getElementById("pageView").removeAttribute("height");
      //document.getElementById("pageView").setAttribute("flex", "1");
      //document.getElementById("viewsDeck").setAttribute("height", 200);
	  
      /* no menu tree */
      document.getElementById("ow-menu-tree-container").setAttribute("collapsed", "true");
      document.getElementById("sidebarSplitter").setAttribute("state", "collapsed");
      document.getElementById("sidebarSplitter").setAttribute("substate", "before");
      document.getElementById("sidebarSplitter").setAttribute("disabled", "true");
      document.getElementById("sidebarSplitter").setAttribute("style", "width:0px; visibility:hidden");

      document.getElementById("catch-splitter").setAttribute("state", "collapsed");
      document.getElementById("catch-splitter").setAttribute("disabled", "true");

      document.getElementById("linksWidget").setViewMode("data");

      //outwitHub.forceView = "selectors";
      outwitHub.forceView = "scraped";

      /*
      coreKit.timerService.setTimer(3000, null, function() {
        var emailsWidget = document.getElementById("emailsWidget");
        if (isFirstLoad) {
          emailsWidget.bottomPanel.optionsPanel.setOptionValue("contactInfo", true);
        }
        emailsWidget.bottomPanel.optionsPanel.setOptionValue("strictness", 0);
        emailsWidget.bottomPanel.optionsPanel.optionNodes["strictness"].setAttribute("defaultValue", 0);

        outwitHub.extractControls.extractors["emails"].smartGrab = false;

        emailsWidget.bottomPanel.limitPanel.setAttribute("hidden", "true");
        emailsWidget.bottomPanel.catchButton.setAttribute("hidden", "true");
        emailsWidget.bottomPanel.pageLoadPanel.defaultAutoEmpty = false;


        emailsWidget.bottomPanel.pageLoadPanel.removeAttribute("disableAutoGrab");
        emailsWidget.bottomPanel.pageLoadPanel.removeAttribute("hideAutoGrab");
        emailsWidget.bottomPanel.pageLoadPanel.defaultAutoGrab = true;

        emailsWidget.datasheetBrowser.editButton.setAttribute("hidden", "true");
        emailsWidget.datasheetBrowser.customLayoutCheckbox.setAttribute("hidden", "true");

        // Ask user before quiting if view is not empty
        document.getElementById("emailsWidget").JSDatasheet.addEventListener(["rowCountChanged", "dataChanged"], function(event) {
          contactsUnsaved = true;
        });
      });
      */

      /*
      var contactsUnsavedObserver = {
        observe: function(aMessage) {
          if (aMessage.getEvent() == "endProcess") {
            contactsUnsaved = false;
          }
        }
      };
      coreKit.observerService.subscribe(contactsUnsavedObserver, "export");
      */


      //ow.app.onUnload(function(event) {
        /*
        try {
          if (document.getElementById("emailsWidget").JSDatasheet.getLength() && contactsUnsaved) {
            outwitKit.panelDialogService.showDialog(
              "sourcer_quit_save_contacts",
              function(id, result) {
                ow.log.debug("RESULT " + id + " " + result);
                switch (result) {
                  case "save":
                    var view = outwitHub.UIControls.getWidgetForView("emails");

                    var exportObserver = {
                      observe: function(aMessage) {
                        ow.log.debug("OBSERVE " + aMessage + " " + aMessage.getEvent());
                        switch (aMessage.getEvent()) {
                          case "endProcess":
                            coreKit.observerService.unsubscribe(exportObserver, "export");
                            coreKit.observerService.unsubscribe(contactsUnsavedObserver, "export");
                            event.callback(true);
                            break;
                          case "canceled":
                            coreKit.observerService.unsubscribe(exportObserver, "export");
                            event.callback(false);
                            break;
                        }
                      }
                    };
                    coreKit.observerService.subscribe(exportObserver, "export");

                    coreKit.observerService.observe(
                      new coreKit.message("export", coreKit.message.TYPE_UIEVENT, "export", 0,
                        { location: "ask", JSDatasheet: view.JSDatasheet, onlySelection: false,
                          withoutHiddenColumns: true, type: "html",
                          withIdColumn: ow.app.kernel.prefs.getBool("export.idColumn"),
                          name: view.XULDatasheet.getAttribute("name") }));
                    ow.log.debug("saved");
                    break;
                  case "dontSave":
                    coreKit.observerService.unsubscribe(contactsUnsavedObserver, "export");
                    event.callback(true);
                    break;
                  default:
                  case "cancel":
                    event.callback(false);
                    break;
                }
              },
              true,
              "center",
              {
                "class": "dialog-panel-simple",
                titleBar: { label: coreKit.localeService.getString("dialog.saveContactsBeforeQuit.title", "chrome://outwit-modules/locale/localize.properties") },
                template: {
                  type: "html",
                  data: outwitKit.panelDialogService.getSimpleDialogTemplate("question", coreKit.localeService.getString("dialog.saveContactsBeforeQuit.message", "chrome://outwit-modules/locale/localize.properties"))
                },
                buttons: {
                  "dontRemind": { type: "dontRemind", label: coreKit.localeService.getString("dialog.saveContactsBeforeQuit.dontRemind", "chrome://outwit-modules/locale/localize.properties") },
                  "cancel": { type: "cancel", labelId: "cancel" },
                  "dontSave": { type: "ok", labelId: "dontSave" },
                  "save": { type: "ok", labelId: "save" }
                }
                , dontRemind: { type: "simple", "default": "dontSave" }
              }
            );
          }
          else {
            coreKit.observerService.unsubscribe(contactsUnsavedObserver, "export");
            event.callback(true);
          }
        }
        catch(e) {
          ow.log.error("sourcer module app.onUnload", e);
          coreKit.observerService.unsubscribe(contactsUnsavedObserver, "export");
          event.callback(true);
        }
        */
      //});
    }
    catch(e) {
      ow.log.error("Error loading OutWit Select module", e);
    }
  },

  load: function() {

  },

  unload: function(aWindow) {
  }
};
