'use strict';

(function () {

  var response = document.getElementById('reponse');

  function install(manifest_url) {

    var installReq = navigator.mozApps.install(manifest_url);

    installReq.onsuccess = function () {
      response.innerHTML = 'Instalado com sucesso!';
    };

    installReq.onerror = function () {
      response.innerHTML = 'Deu erro!';
    };
  }

  if ('mozApps' in navigator) {

      var manifest_url = location.href + 'manifest.webapp';

      var checkInstalledReq = navigator.mozApps.checkInstalled(manifest_url);

      checkInstalledReq.onsuccess = function () {

        if (!checkInstalledReq.result) {
          install(manifest_url);
        }
      };
  }
}());
