// both 'user' and 'bob' have access to Group0
var Group0 = new Group('ZPk2cmT5NnJ+Htyq9h7cqj');
// only 'bob' has access to Group1
var Group1 = new Group('VBS2A1wUtgNIdiPC/HYjwu');

// username: user	password: pass	groups: Group0
DeclareUser('VjzxL1488S9d+oFvffqBbz','RQTT2UkE09l/JlsXHyZbFx',[Group0,'S/i1GMyvrC']);
// username: user	password: pass	groups: Group0 + Group1
DeclareUser('fvFGdn7xRnZ/KIe94yiHvc','BlGczw5RnM8+RTF1/kUxdX',[Group0,'MzHCJgXUaA'],[Group1,'MzHCJgXUbA']);

// This keeps track of the users to they dont need to log in
// every time the load a new page
var S = new Session('my_session');
S.Callback = s_cb; // function s_cb defined below
// if the user doesn't come back after 48 hours, he'll need to login again:
S.nCookieExpirationDelay = 48;
S.bLocationLogin = true;

// Resource callback. Called before and after a resource gets decrypted
function r_cb(context,lparam)
{
  if(context == this.ccAfterDecrypt)
  {
    if(!lparam)
      document.all['cnt'].innerHTML = "Error!";
    else
      document.all['cnt'].innerHTML = lparam;
  } else if(context == this.ccInvallidMaster)
  {
    document.all['cnt'].innerHTML = "You do not have the right to view this page!";
  }
  return true;
}

// Session callback. Called on login / logout
function s_cb(context,lparam)
{
  switch(context)
  {
    case this.ccLogin:
      document.all['login'].style.display = 'none';
      document.all['logout'].style.display = '';
      document.all['username'].value = '';
      document.all['password'].value = '';
      document.all['cnt'].innerHTML = "Loading...";
      document.all['curuser'].innerHTML = this.sUserName;
// Trick: use a setTimeout to decrypt the page content in order to let the browser
// update the page with the changes we made above before beginning decryption
      setTimeout("Content.DecryptResourceS(S)",0);
      break;
    case this.ccLogout:
      document.all['login'].style.display = '';
      document.all['logout'].style.display = 'none';
      default_text();
  }
  return true;
}

function default_text()
{
  document.all['cnt'].innerHTML = "You are not logged in!";
  document.all['curuser'].innerHTML = "";
}

function login() // called by 'login' button
{
  S.UserLogin(
	document.all['username'].value,
	document.all['password'].value,
	document.all['usecookies'].checked
  );
}

function logout() // called by 'logout' button
{
  S.Logout();
}
