// REQUIRES UtilityMethods.js to be loaded by the page.

function CheckForLoggedInUser()
{
  // Check a cookie to see if the current user is logged in.
  // If so, then don't do anything.
  // If not, or if the cookie doesn't exist, redirect the user to the login page.

  var isUserLoggedInCookie = GetCookie("IsUserLoggedIn");

  if ((isUserLoggedInCookie == null) || (typeof(isUserLoggedInCookie) != "string") || (isUserLoggedInCookie != "true"))
  {
    // The cookie doesn't exist, or the value of "IsUserLoggedIn" is not the correct type or value.
    // Redirect the user to the login page.

    // This redirect is complicated by the fact that the login page should
    // be retrieved using the SSL (i.e. HTTPS) protocol if possible.
    // There's no direct way for the javascript to know if the server supports SSL,
    // so the server will set a cookie value this code can examine to determine
    // which protocol to use.
    var isSSLSupportedCookie = GetCookie("IsSSLSupported");
    if ((isSSLSupportedCookie == null) || (typeof(isSSLSupportedCookie) != "string") || (isSSLSupportedCookie != "true"))
      window.location.protocol = "http:";
    else
      window.location.protocol = "https:";

    window.location.href = "star_index.aspx?controls=login";
  }
  else
  {
    // Don't do anything.  The user is logged in, so no redirect is needed.
  }
}

