// both 'sindy' and 'admin' have access to Group0
var Group0 = new Group('i/aHB4/2hwexhRjRuYUY0Z');
// only 'admin' has access to Group1
var Group1 = new Group('xLyE5sy8hObguR613LketZ');



// username: sindy	password: basket/IMS groups: Group0
DeclareUser('81VsHP9VbBz/aHNZu2hzWb','PYttsD2LbbA/GKkU/xipFG',[Group0,'ArZa']);
// username: admin	password: ambriel7/IMS1 groups: Group0 + Group1
DeclareUser('hKS8jIikvIy+npVd6p6VXe','hp+/so6fv7KcztkT9M7ZE9',[Group0,'mZo7'],[Group1,'mZo7kB']);


// 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 = "You are not logged in!";
}

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();
}
