/****
*  Session management routines
*  Requires: spaix.js
*
*  Copyright (c) 2005 VSX Vogel Software GmbH.
*  All rights reserved.
*/

var g_Session = null;


function Session()     // CTOR
{ 
  // Login-bezogene Daten
  this.bLoginFlag = false;		  // set while logging in
  this.sSessionID = "";         // unique ID for this session    
  this.sUserName  = "";         // display-name, NOT the login 
  this.urlLogout  = "";         // use this to log out

  // Settings
  this.sLgg       = "ENGLISH";
  this.sFreq      = "";
  this.sDim1      = "";					// head
  this.sDim2      = "";					// flow
  this.sDim3      = "";					// pwr
  this.sDim6      = "";					// temp
  this.sDim7      = "";					// density
  this.sDim8      = "";					// kinvisc
  this.sDim9      = "";					// press

  // Methoden
  this.LoadCookie      = Session_LoadCookie;
  this.SaveCookie			 = Session_SaveCookie;
  this.ValidateSession = Session_ValidateSession; 
  this.ClearLoginData  = Session_ClearLoginData;

  
  // restore settings, always last step
  this.LoadCookie();
}


//--- Session ----------------------------------


function Session_LoadCookie()
{
	this.sLgg  = GetCookieValueEx("LGG","");
	this.sUser = GetCookieValueEx("USER","");
	this.sFreq = GetCookieValueEx("FREQ","");
	this.sDim1 = GetCookieValueEx("DIM1","");
	this.sDim2 = GetCookieValueEx("DIM2","");
	this.sDim3 = GetCookieValueEx("DIM3","");
	this.sDim6 = GetCookieValueEx("DIM6","");
	this.sDim7 = GetCookieValueEx("DIM7","");
	this.sDim8 = GetCookieValueEx("DIM8","");
	this.sDim9 = GetCookieValueEx("DIM9","");
}


function Session_SaveCookie()
{
  setCookieValue("LGG",  this.sLgg);
  setCookieValue("USER", this.sUser);
	setCookieValue("FREQ", this.sFreq);
	setCookieValue("DIM1", this.sDim1); 
	setCookieValue("DIM2", this.sDim2); 
	setCookieValue("DIM3", this.sDim3); 
	setCookieValue("DIM6", this.sDim6); 
	setCookieValue("DIM7", this.sDim7); 
	setCookieValue("DIM8", this.sDim8); 
	setCookieValue("DIM9", this.sDim9); 
}



function Session_ValidateSession( aSessionID)
// Checks aSessionID against the current values
// Returns aSessionID if valid, an empty string otherwise
{
  // test for login process and clear the flag
  var bIsLogin = this.bLoginFlag;
  this.bLoginFlag = false;

  // the easy case: identical 
  if( this.sSessionID == aSessionID)
    return aSessionID;

  // we're currently logging in, so take the new value
  if( bIsLogin)
  {
    this.sSessionID = aSessionID;  
    return aSessionID;
  }
  
  // wrong in all other cases
  this.ClearLoginData();
  return "";
}


function Session_ClearLoginData()
// clean up all login data
{
  this.bLoginFlag = false;		  // set while logging in
  this.sSessionID = "";         // unique ID for this session    
  this.sUserName  = "";         // display-name, NOT the login 
  this.urlLogout  = "";         // use this to log out
}



// EOF

