text: ﻿    
  (function () {
  
      // Enter Global Config Values & Instantiate ADAL AuthenticationContext
      window.config = {
          instance: 'https://login.microsoftonline.com/',
          tenant: 'davedlbhotmail.onmicrosoft.com',
          clientId: '805ae1dd-1b37-4a06-9c45-6c2169376137',
          postLogoutRedirectUri: window.location.origin,
          cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
      };
      var authContext = new AuthenticationContext(config);
  
      // Get UI jQuery Objects
      var $panel = $(".panel-body");
      var $userDisplay = $(".app-user");
      var $signInButton = $(".app-login");
      var $signOutButton = $(".app-logout");
      var $errorMessage = $(".app-error");
  
      // Check For & Handle Redirect From AAD After Login
      var isCallback = authContext.isCallback(window.location.hash);
      authContext.handleWindowCallback();
      $errorMessage.html(authContext.getLoginError());
  
      if (isCallback && !authContext.getLoginError()) {
          window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
      }
  
      // Check Login Status, Update UI
      var user = authContext.getCachedUser();
      if (user) {
          $userDisplay.html(user.userName);
          $userDisplay.show();
          $signInButton.hide();
          $signOutButton.show();
      } else {
          $userDisplay.empty();
          $userDisplay.hide();
          $signInButton.show();
          $signOutButton.hide();
      }
  
      // Handle Navigation Directly to View
      window.onhashchange = function () {
          loadView(stripHash(window.location.hash));
      };
      window.onload = function () {
          $(window).trigger("hashchange");
      };
  
      // Register NavBar Click Handlers
      $signOutButton.click(function () {
          authContext.logOut();
      });
      $signInButton.click(function () {
          authContext.login();
      });
  
      // Route View Requests To Appropriate Controller
      function loadCtrl(view) {
          switch (view.toLowerCase()) {
              case 'home':
                  return homeCtrl;
              case 'todolist':
                  return todoListCtrl;
              case 'userdata':
                  return userDataCtrl;
          }
      }
  
      // Show a View
      function loadView(view) {
  
          $errorMessage.empty();
          var ctrl = loadCtrl(view);
  
          if (!ctrl)
              return;
  
          // Check if View Requires Authentication
          if (ctrl.requireADLogin && !authContext.getCachedUser()) {
              authContext.config.redirectUri = window.location.href;
              authContext.login();
              return;
          }
  
          // Load View HTML
          $.ajax({
              type: "GET",
              url: "App/Views/" + view + '.html',
              dataType: "html",
          }).done(function (html) {
  
              // Show HTML Skeleton (Without Data)
              var $html = $(html);
              $html.find(".data-container").empty();
              $panel.html($html.html());
              ctrl.postProcess(html);
  
          }).fail(function () {
              $errorMessage.html('Error loading page.');
          }).always(function () {
  
          });
      };
  
      function stripHash(view) {
          return view.substr(view.indexOf('#') + 1);
      }
  
  }());
  
          
  
  
  