/**
 *  desktop sheet object
 *
 *  @author   Tobias Hettinger
 *  @version  $Id: sheet.js,v 1.10 2009/05/15 11:54:35 tobias Exp $
 */
 
 
/**
 *  constructor
 *
 *  @param string name      name of the sheet which is used to access it
 *  @param string caption   caption of the sheet
 *  @param object frameDiv  div of the frame to which the sheet should be appended
 *  @param object sheetDiv  id of the div that should be used to create the div or null if a new div has to be created
 */
var WATDesktopSheet = function(name, caption, frameDiv, sheetDivId)
{
  //  set the member variables
  this.name = name;
  this.caption = caption;
  this.divId = sheetDivId ? sheetDivId : 'ds' + name;
  this.contentInitialized = false;
  
  //  content properties
  //  source script that is used for the ajax request
  this.requestSource = null;
  //  parameters for the ajax request (without a starting '?' or '&') but with a session id if it is required
  this.requestParameters = null;
  //  function to call in order to load the content
  this.requestFunction = null;
  //  seconds, the content is valid or -1 if the content does never time out
  this.contentTimeout = -1;
  //  true, if the content should be automatically refreshed or false if no auto-refresh is required
  this.contentAutoRefresh = false;
  
  
  this.data = new Array();
  this.flags = 0;
  
  
  this.grid = null;
  
  //  hash value that can be used to detect if a content update is required
  this.contentHash = null;
  
  if (!sheetDivId)
  {
    //  create the sheet div element
    this.divElement = document.createElement('div');
    this.divElement.id = this.divId;
    this.divElement.style.display = 'none';
    frameDiv.appendChild(this.divElement);
  }
  else
  {
    //  get the specified div
    this.divElement = document.getElementById(sheetDivId);
    if (this.divElement)
    {
      this.divElement = this.divElement.parentNode.removeChild(this.divElement);
      this.divElement.position = 'absolute';
      this.divElement.style.display = 'none';
      frameDiv.appendChild(this.divElement);
    }
  }
}

/**
 *  function to set the content of the sheet
 *
 *  @param string content      content of the sheet or null if no content is available
 *  @param string contentHash  hash value that can be used to detect if a content update is required
 */
WATDesktopSheet.prototype.SetContent = function(content, contentHash)
{
  //  set the content
  if (content != null && content != '')
    watDivContent(this.divId, content);
  else watDivContent(this.divId, '');

  //  set the content hash or null if no has has been passed
  this.contentHash = contentHash ? contentHash : null;
}

WATDesktopSheet.prototype.SetGrid = function(grid)
{
  this.grid = grid;
}


//=====================================================================================================================
//properties
//=====================================================================================================================

/**
*  function to save user data
*
*  @param string key    key of the data to save
*  @param mixed  value  value to save in the gadget
*/
WATDesktopSheet.prototype.SetData = function(key, value)
{
//  save the data
this.data[key] = value;
}

/**
*  function to get the user data with the passed key
*
*  @param string key      key of the requested data
*  @param mixed  onError  value that is returned if the value has not been found
*
*  @return mixed  the function returns the data with the passed key or the value that has been passed
               by the onError parameter
*/
WATDesktopSheet.prototype.GetData = function(key, onError)
{
if (this.data[key]) return this.data[key];
else return onError;
}


