/* 
   Opener Class - common class for opening action forms and folders from both the lists and MRU's
   Uses: JSUtils.js
*/

var WaitForSessionIDPeriod = 100;

// -- Opener factory class function --
function esOpenerFactory_Create(aType)
{ 
  var lType = aType.toLowerCase();
  var lBaseOpener = new esOpener(lType);
  var lChildOpener = null;
  if ( (lType == "todo") || (lType == "watch") || (lType == "folder") )
   lChildOpener = esFolderOpener(lBaseOpener);
  if ( (lType == "blank") || (lType == "admin") )
   lChildOpener = esActionFormOpener(lBaseOpener);
  if (lType == "folder_action") 
   lChildOpener = esFolderActionFormOpener(lBaseOpener);   
  if ( lType == "mru" )
   lChildOpener = esMRUActionFormOpener(lBaseOpener);
  if ( lType == "open authentication" )
   lChildOpener = esAuthenticationFormOpener(lBaseOpener);
  if ( lType == "about" )
   lChildOpener = esAboutBoxOpener(lBaseOpener);
  if ( lType == "metastorm web site" )
   lChildOpener = esMetastormWebSiteOpener(lBaseOpener);
  if ( lType == "folderonfolder" )
   lChildOpener = esFolderOnFolderOpener(lBaseOpener);   
  return lChildOpener;  
}

function esOpener(aType)
{
  // -- Properties --
  this.type = aType;
  this.firstWidth = 300; // initial size of opener window 
  this.firstHeight = 100;
  this.flags = ",status=no,toolbar=no,menubar=no,location=no,resizable=yes";
  this.windowsList = new Array();

  // -- Protected Methods
  this.canOpenNewWindow = esOpener_canOpenNewWindow;
  this.getInitialFormSize = esOpener_getInitialFormSize;
  this.createWindowName = esOpener_createWindowName;
  this.openWindow = null; // Opens a window with content
  
  // -- Public Methods --
  this.Free = esOpener_Free;
  
  // -- Public Abstract Methods --
  this.openItem = null; // Uses info from selected item of UI to open a window with content   
  return this;
} 

/*
  Opener Context Constants
*/
var esOpener_FilterContext = "Filter Tree";

function esOpener_Free()
{
  for ( var i = 0; i < this.windowsList.length; ++i )
  {
    this.windowsList[i] = null;
  }
}
  
// -- Determines if a window with an action form is already open -- 
function esOpener_canOpenNewWindow(aWindowName)
{
  var lCurWindow;  
  for(var i=0; i<this.windowsList.length; i++)
  {
     lCurWindow = this.windowsList[i];
     // Fix for PF23100
     try
     {
       if(lCurWindow && !lCurWindow.closed && lCurWindow.name == aWindowName)
       {
         lCurWindow.focus();             
         return false;
       }
     }
     catch ( e )
     {
     }
 }       
 return true;
}

// -- Sets the initial size of the action form opener window --
function esOpener_getInitialFormSize()
{
  var lAvailWidth = window.screen.availWidth;
  var lAvailHeight = window.screen.availHeight;
  var lLeft = (lAvailWidth - this.firstWidth)/2; 
  var lTop = (lAvailHeight - this.firstHeight)/2;
  return 'width=' + this.firstWidth + ',height=' + this.firstHeight + ',top=' + lTop + ',left=' + lLeft;	
}   

// -- Creates an IE safe window name --
function esOpener_createWindowName(aName)
{
  return ToAlphaNumericStr(aName);
}

/* ------------------------------------------------------------------------------------------------------- 
   Action Form Opener Class - class for opening action forms from the blank/Admin forms lists 
*/

//Helper function that returns the column index given the column name 
function GetCellIndexFromName(AColumnName)
{
    var LIndex = 1;
    for(i=0; i<alertsGrid.rows(0).cells.length; i++)
    {      
      if(alertsGrid.rows(0).cells(i).abbr == AColumnName)
      {
        LIndex = i;
        break;
      }      
    }
    return LIndex; 
}

function esActionFormOpener(aParent)
{                                 
  // -- Protected Methods --
  aParent.openWindow = esActionFormOpener_openWindow;
  aParent.Parent_Free = aParent.Free;
  
  // -- Public Methods --
  aParent.openItem = esActionFormOpener_openItem;
  aParent.openNewForm = esActionFormOpener_openNewForm;
  aParent.Free = esActionFormOpener_Free;

  return aParent;
} 

function esActionFormOpener_Free()
{
  this.Parent_Free();
}

// -- Opens an Action Form with all the various settings required to do so --
function esActionFormOpener_openWindow(aWindowName,aService,aFolderID,aMap,aAction,aUserPage)
{   
  var LDate = new Date();
  var LWindowName = this.createWindowName(LDate.toGMTString()); 
  var lQueryFields = 'eForm.aspx?Action=' + URLEncode(aAction);
  if(aMap.length > 0)
    lQueryFields += '&Map=' + URLEncode(aMap);
  if(aFolderID.length > 0)
    lQueryFields += '&FolderID=' + URLEncode(aFolderID);
  if(aService.length > 0)
    lQueryFields += '&Service=' + URLEncode(aService);

  // We need to pass the session id in the query field to overcome
  // the problem of external client dropping session cookies.
  if (getCookie(aService + 'Client') == 'external')
  {
    var lSessionID = getCookie(aService + 'SessionID')
    lQueryFields += '&SN=' + lSessionID;
  }

  // put a timestamp on the action form request
  lQueryFields = setClientTimestamp(lQueryFields);

  // save the UserOptions for HTML form time zone support
  if ((getCookie(USER_OPTIONS_COOKIE_NAME) == '') && (getCookie(USER_SESSION_OPTIONS_COOKIE_NAME) == ''))
  {
    var lUserOptions = new eUserOptions();
    lUserOptions.SaveData();
  }

  // Window open is slow if a name is passed to the newly created window.
  var newWindow = window.open(lQueryFields, "", this.getInitialFormSize() + this.flags);
  newWindow.name = LWindowName;

  // -- Update MRU menu --
  var lMRU = null;
  if (this.type == "blank")
    if (parent.eBlankFormsMRU != null) // check if we are in the e-work client, if in a portal this var will not be present     
      lMRU = parent.eBlankFormsMRU;       
  if (this.type == "admin")
    if (parent.eAdminFormsMRU != null) // check if we are in the e-work client, if in a portal this var will not be present     
      lMRU = parent.eAdminFormsMRU;     

  if (lMRU != null) // If lMRU is null then we are in a portal so we can ignore
  {
    var lService = getCookie('eService');
    lMRU.addMenuItem(lService,aMap,aAction);
  }
}

// -- Opens window content based on the selected row --
function esActionFormOpener_openItem(ASelectedRow)
{
  var LMap        = ASelectedRow.cells(GetCellIndexFromName("eMapName")).innerText;
  var LAction     = ASelectedRow.cells(GetCellIndexFromName("eActionName")).innerText;
  var LUserPage   = ASelectedRow.cells(GetCellIndexFromName("eUserPage")).innerText; 
  var LWindowName = LMap; 

  // get the service name from our global variable to allow multiple services to run simultaneously
  this.openWindow(LWindowName,eServiceName,"",LMap,LAction,LUserPage); 
}

// -- Opens window content based on passed in Map and Action (used by button operations) --
function esActionFormOpener_openNewForm(aMap, aAction)
{
  var lWindowName = aMap; 
  // get the service name from our global variable to allow multiple services to run simultaneously
  this.openWindow(lWindowName,eServiceName,"",aMap,aAction,""); 
}

/* ------------------------------------------------------------------------------------------------------- 
   FolderOnFolder Opener Class - class for opening folders from the alerts lists
*/

function esFolderOnFolderOpener(aParent)
{
  // -- Protected Methods --
  aParent.openWindow = esFolderOnFolderOpener_openWindow;
  aParent.Parent_Free = aParent.Free;
  
  // -- Public Methods --
  aParent.openItem = esFolderOnFolderOpener_openItem;
  aParent.Free = esFolderOnFolderOpener_Free;
  
  return aParent;  
} 

function esFolderOnFolderOpener_Free()
{
  this.Parent_Free = aParent.Free;
}

// -- Opens a Folder with all the various settings required to do so --
function esFolderOnFolderOpener_openWindow(aFolderID)
{
  var LWindowName = this.createWindowName(aFolderID); 
  if( this.canOpenNewWindow(LWindowName) )
	{
    // get the service name from our global variable to allow multiple services to run simultaneously
    var lService      = URLEncode(eServiceName);
    var lQueryFields  = '&Service=' + lService;
  
    // We need to pass the session id in the query field to overcome
    // the problem of external client dropping session cookies.
    if (getCookie(eServiceName + 'Client') == 'external')
    {
      var lSessionID = getCookie(eServiceName + 'SessionID');
      lQueryFields += '&SN=' + lSessionID;
    }

    // Open and store reference to new window
    var lUrl = 'eFolder.aspx?FolderID=' + aFolderID + lQueryFields;
    // put a timestamp on the folder request
    lUrl = setClientTimestamp(lUrl);
    // save the UserOptions for HTML form time zone support
    if ((getCookie(USER_OPTIONS_COOKIE_NAME) == '') && (getCookie(USER_SESSION_OPTIONS_COOKIE_NAME) == ''))
    {
      var lUserOptions = new eUserOptions();
      lUserOptions.SaveData();
    }

    // Open and store reference to new window
    // Window open is slow if a name is passed to the newly created window.
    this.windowsList[this.windowsList.length] = window.open(lUrl, "", this.getInitialFormSize() + this.flags);
    // Remember array has just dynamically grown so new window is at this.windowsList.length - 1
    this.windowsList[this.windowsList.length - 1].name = LWindowName;    
  }
}


// -- Opens window content based on the selected row --
function esFolderOnFolderOpener_openItem(AFolderOnFolderGrid)
{
  var LCurrentField = null;
  var LFolderID     = "";
  
  //Get Folder ID
  LCurrentField = null;   
  try
  {
    LCurrentField = AFolderOnFolderGrid.PagedDataset("eFolderID");
  }
  catch(error)
  {
  } 
  if(LCurrentField)
  {   
    LFolderID = LCurrentField.Value; 
    // Note: It is not necessary to pass in the service as this will be read from a cookie at the server
    if (LFolderID != "")
      this.openWindow(LFolderID);
  }    
}

/* ------------------------------------------------------------------------------------------------------- 
   Folder Opener Class - class for opening folders from the alerts lists
*/

function esFolderOpener(aParent)
{
  // -- Protected Methods --
  aParent.openWindow = esFolderOpener_openWindow;
  aParent.Parent_Free = aParent.Free;
  
  // -- Public Methods --
  aParent.openItem = esFolderOpener_openItem;
  aParent.openFolder = esFolderOpener_openFolder;  
  aParent.Free = esFolderOpener_Free;
  
  return aParent;  
} 

function esFolderOpener_Free()
{
  this.Parent_Free();
}

// -- Opens a Folder with all the various settings required to do so --
function esFolderOpener_openWindow(aFolderID)
{
  var LWindowName = this.createWindowName(aFolderID); 
  
  if( this.canOpenNewWindow(LWindowName) )	
  {
    // get the service name from our global variable to allow multiple services to run simultaneously
    var lService      = URLEncode(eServiceName);
    var lQueryFields  = '&Service=' + lService;
  
    // We need to pass the session id in the query field to overcome
    // the problem of external client dropping session cookies.
    if (getCookie(eServiceName + 'Client') == 'external')
    {
      var lSessionID = getCookie(eServiceName + 'SessionID');
      lQueryFields += '&SN=' + lSessionID;
    }

    var lUrl = 'eFolder.aspx?FolderID=' + aFolderID + lQueryFields;

    // put a timestamp on the folder request
    lUrl = setClientTimestamp(lUrl);

    // save the UserOptions for HTML form time zone support
    if ((getCookie(USER_OPTIONS_COOKIE_NAME) == '') && (getCookie(USER_SESSION_OPTIONS_COOKIE_NAME) == ''))
    {
      var lUserOptions = new eUserOptions();
      lUserOptions.SaveData();
    }

    // Open and store reference to new window
    // Window open is slow if a name is passed to the newly created window.
    this.windowsList[this.windowsList.length] = window.open(lUrl, "", this.getInitialFormSize() + this.flags);
    // Remember array has just dynamically grown so new window is at this.windowsList.length - 1
    this.windowsList[this.windowsList.length - 1].name = LWindowName;
  }
}


// -- Opens window content based on the selected row --
function esFolderOpener_openItem(ASelectedRow)
{
  var lFolderID = ASelectedRow.cells(GetCellIndexFromName("eFolderID")).children(0).innerText;  
  // Note: It is not necessary to pass in the service as this will be read from a cookie at the server
  this.openWindow(lFolderID);    
}

// -- Opens window content based on the the given Folder ID (used by Button operations) --
function esFolderOpener_openFolder(aFolderID)
{
  // Note: It is not necessary to pass in the service as this will be read from a cookie at the server
  this.openWindow(aFolderID);    
}

/* ------------------------------------------------------------------------------------------------------- 
   Action Form MRU Opener Class - class for opening action forms from the MRU's
*/

function esMRUActionFormOpener(aParent)
{
  // -- Protected Methods --
  aParent.openWindow = esMRUActionFormOpener_openWindow;
  aParent.Parent_Free = aParent.Free;
  
  // -- Public Methods --
  aParent.openItem  = esMRUActionFormOpener_openItem;
  aParent.Free      = esMRUActionFormOpener_Free;
   
  return aParent;
} 

function esMRUActionFormOpener_Free()
{
  this.Parent_Free();
}

// -- Opens window with action form content --
function esMRUActionFormOpener_openWindow(aWindowName,aService,aMap,aAction)
{
  var lEncodedMap = URLEncode(aMap);
  var lEncodedAction = URLEncode(aAction);
  var lEncodedService = URLEncode(aService);
  var LWindowName = this.createWindowName(aWindowName); 
	
  if( this.canOpenNewWindow(LWindowName) )
  {
    var lUrl = 'eForm.aspx?Map=' + lEncodedMap + '&Action=' + lEncodedAction + '&Service=' + lEncodedService;
    // put a timestamp on the action form request
    lUrl = setClientTimestamp(lUrl);

    // save the UserOptions for HTML form time zone support
    if ((getCookie(USER_OPTIONS_COOKIE_NAME) == '') && (getCookie(USER_SESSION_OPTIONS_COOKIE_NAME) == ''))
    {
      var lUserOptions = new eUserOptions();
      lUserOptions.SaveData();
    }

    // Open and store reference to new window
    // Note: Service is explicitly passed which overrides the current service in the cookie
    // Window open is slow if a name is passed to the newly created window.
    this.windowsList[this.windowsList.length] = window.open(lUrl, "", this.getInitialFormSize() + this.flags);
    // Remember array has just dynamically grown so new window is at this.windowsList.length - 1
    this.windowsList[this.windowsList.length - 1].name = LWindowName;    
  }  
}

// -- Called from MRU menu items to open action forms --
function esMRUActionFormOpener_openItem(aMRUMenuItem)
{
  var lWindowName = this.createWindowName(aMRUMenuItem.map)
  // This is the only opener class that passes in the service as it may not be the current service
  this.openWindow(lWindowName,aMRUMenuItem.service,aMRUMenuItem.map,aMRUMenuItem.action);
}


/* ------------------------------------------------------------------------------------------------------- 
   Open Authentication Action Form Opener Class - class for opening Open Authentication Action Forms  
*/

function esAuthenticationFormOpener(aParent)
{
  // -- Private Attributes --
  aParent.sessionCookieName = "";
  aParent.authCookieName = "";
  aParent.context = "";
  aParent.currentService = "";
  aParent.activeAuthenticator = false;

  // get the time at the start of the open authentication request
  var now = new Date();
  aParent.authStartTime = now.getTime();
  
  // -- Protected Methods --
  aParent.canOpenNewWindow = esAuthenticationFormOpener_canOpenNewWindow;  
  aParent.openWindow = esAuthenticationFormOpener_openWindow;
  aParent.sessionID = esAuthenticationFormOpener_sessionID;
  aParent.waitForSessionID = esAuthenticationFormOpener_waitForSessionID;
  aParent.navigateContext = esAuthenticationFormOpener_navigateContext;
  aParent.accessDenied = esAuthenticationFormOpener_accessDenied;
  aParent.setAuthenticationTime = esAuthenticationFormOpener_setAuthenticationTime;
  aParent.Parent_Free = aParent.Free;
  
  // -- Public Methods --
  aParent.openItem = esAuthenticationFormOpener_openItem;
  aParent.Free = esAuthenticationFormOpener_Free;
  
  // -- Initialisation Section --
  var lService = getCookie('eService');
  aParent.currentService = lService;
  aParent.publicWebAccess = getCookie('ePublicWebAccess');
  aParent.clientType = getCookie(lService + 'Client');
  aParent.authenticationProcess = getCookie('eAuthenticationProcess');
  aParent.sessionCookieName = aParent.currentService + 'SessionID';
  aParent.authCookieName = aParent.currentService + 'Auth';

  return aParent;
} 

function esAuthenticationFormOpener_Free()
{
  this.Parent_Free();
}

// -- Called to open authentication action forms --
function esAuthenticationFormOpener_openItem(aContext)
{
  var lSpecificService = ""; // When authentication is from the MRU a specific service is passed in for authentication
  if (arguments.length > 1)
    lSpecificService = arguments[1];
  if (lSpecificService != "")
  {
    this.currentService = lSpecificService;
    this.sessionCookieName = this.currentService + 'SessionID';
    this.authCookieName = this.currentService + 'Auth';
  }
      
  var lWindowName = this.createWindowName(""); // Title is set in server ActionHandler
  this.context = aContext;
  this.openWindow(lWindowName);
}

/*
  Checks if a new window can be opened 
*/
function esAuthenticationFormOpener_canOpenNewWindow()
{
  if (getCookie(this.authCookieName) == "1")
    return false;
  else
    return true;
}

// -- Opens window with action form content --
function esAuthenticationFormOpener_openWindow(aWindowName)
{
  if( this.canOpenNewWindow(aWindowName) )
  {
    if (this.sessionID() != "")
    {
      deleteCookie(this.sessionCookieName); 
      if (getCookie('ePublicWebAccess') != "")
        deleteCookie('ePublicWebAccess'); 
      if (getCookie('eAuthenticationProcess') != "")
        deleteCookie('eAuthenticationProcess'); 
    }
    setCookie(this.authCookieName,'1',-1);
    this.activeAuthenticator = true;
    var lURL = 'eForm.aspx?Service=' + this.currentService + '&Type=OpenAuthentication';

    // Open and store reference to new window (authentication forms are not stored on the MRU)
    // Window open is slow if a name is passed to the newly created window.
    this.windowsList[0] = window.open(lURL, "", this.getInitialFormSize() + this.flags);
    this.windowsList[0].name = aWindowName;
  }
  
  window.setTimeout("eOpener.waitForSessionID()", WaitForSessionIDPeriod);
}

/*
  Reads the Session ID data
*/
function esAuthenticationFormOpener_sessionID()
{
  return getCookie(this.sessionCookieName);
}

/*
  Detects the prescence of a Session ID 
*/
function esAuthenticationFormOpener_waitForSessionID()
{
  var lWindowClosed = false;
  if(this.activeAuthenticator)
  {
    // Detect if the window has been closed
    try
    {
      if (this.windowsList[0].closed)
      {
        lWindowClosed = true;
      }
    }
    catch(e)
    {
       lWindowClosed = true;
    }
  }
  
  // Check if we still have an authentication process to synchronise with
  var lSynchroniserRemoved = false;
  if (getCookie(this.authCookieName) != "1")
    lSynchroniserRemoved = true;
  
  
  // Check if the session ID has been set
  if ((eSessionID != "") || (this.sessionID() != ""))
  {
    if ((eSessionID != "") && (this.sessionID() == "") )
    {
      setCookie('eService', this.currentService, 365);
      setCookie(this.currentService + 'SessionID', eSessionID, -1);
    }
    if (this.publicWebAccess && (getCookie('ePublicWebAccess') == ""))
    {
      setCookie('ePublicWebAccess', "true", -1);
      setCookie('eAuthenticationProcess', this.authenticationProcess, -1);
    } 
    if (this.clientType != "")
      setCookie(this.currentService + 'Client', this.clientType, -1);  
    // Redirect client based on opener context
    deleteCookie(this.authCookieName);
    if (lSynchroniserRemoved)
    {
      window.setTimeout("eOpener.navigateContext()", 250);
    }
    else
    {
      lNewContext = this.setAuthenticationTime(this.context);
      window.navigate(lNewContext);
    }
  }
  else
  {
    if( (lWindowClosed == false) && (lSynchroniserRemoved == false) )
    {
      window.setTimeout("eOpener.waitForSessionID()", WaitForSessionIDPeriod);
    }
    else
    {
      // Authorisation process has ended so ensure we have cleaned up 
      deleteCookie(this.authCookieName);
      // Display standard access denied page. 
      window.setTimeout("eOpener.accessDenied()", WaitForSessionIDPeriod);
    }
  }  
}

function esAuthenticationFormOpener_navigateContext()
{
  lNewContext = this.setAuthenticationTime(this.context);
  window.navigate(lNewContext);
}

function esAuthenticationFormOpener_accessDenied()
{
    if (typeof(parent.eFormArea) != "undefined") 
    {
      // we are in a blank form
      parent.navigate('eMessage.aspx');
    }
    else if (typeof(parent.eMainPage) != "undefined") 
    {
      // we are in the main window
      window.navigate('eSplash.aspx?AccessDenied=1');
    }
    else if (typeof(parent.eOpenAuthentication) != "undefined") 
    {
      // we are in the open authentication window
      window.navigate('eMessage.aspx');
    }
}

function esAuthenticationFormOpener_setAuthenticationTime(aContext)
{
  var lNewContext = aContext;

  var now = new Date();
  var lAuthEndTime = now.getTime();
  var lAuthTime = lAuthEndTime - this.authStartTime;
  lNewContext += ((aContext.indexOf("?") == -1) ? "?" : "&");
  lNewContext += ("AuthenticationTime=" + lAuthTime);

  return lNewContext;
}


/* -------------------------------------------------------------------------------------------------------
 * About box opener class.*/

function esAboutBoxOpener(aParent)
{
  aParent.Parent_Free = aParent.Free;
  aParent.getInitialFormSize = esAboutBoxOpener_getInitialFormSize;
  aParent.openItem = esAboutBoxOpener_openItem;
  aParent.openWindow = esAboutBoxOpener_openWindow;
  aParent.Free = esAboutBoxOpener_Free;
  
  return aParent;
}

function esAboutBoxOpener_Free()
{
  this.Parent_Free();
}

/* Sets the initial size of the action form opener window */
function esAboutBoxOpener_getInitialFormSize()
{
  return 'dialogWidth: ' + this.firstWidth + 'px;dialogHeight:' + this.firstHeight + "px;";	
}

/* Open and store reference to new window. */
function esAboutBoxOpener_openWindow(aWindowName,aContext)
{
  if( this.canOpenNewWindow(aWindowName) )
  {
    // Size to fit contained image accordingto borwser
    
    var IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;	
	if(IE6==true)
	{
		this.firstHeight = 213;
		this.firstWidth = 454;
    }
    else
    {
		this.firstWidth = 450;
		this.firstHeight = 190;
    }
    // Non-resizeable.
    this.flags = "help: no;scroll: no;status: no";
                                                                                         
    this.windowsList[this.windowsList.length] = 
    window.showModalDialog('eAboutBox.aspx',aWindowName,this.getInitialFormSize()+this.flags);
  }
}

/* Open About Box item. */
function esAboutBoxOpener_openItem(aContext)
{
  var lWindowName = this.createWindowName("About Box");
  this.openWindow(lWindowName,aContext);
}

/* ------------------------------------------------------------------------------------------------------- 
   Metastorm Web Site Opener Class - class for opening the Metastorm Web Site in a new window
*/

function esMetastormWebSiteOpener(aParent)
{
  aParent.flags = "status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes";  //if browser tool bars are to show

  // -- Protected Methods --
  aParent.openWindow = esMetastormWebSiteOpener_openWindow;
  aParent.getInitialFormSize = esMetastormWebSiteOpener_getInitialFormSize;
  aParent.Parent_Free = aParent.Free;
  
  // -- Public Methods --
  aParent.openItem = esMetastormWebSiteOpener_openItem;
  aParent.Free = esMetastormWebSiteOpener_Free;
  
  return aParent;  
} 

function esMetastormWebSiteOpener_Free()
{
  this.Parent_Free();
}

// -- Opens the Metastorm Web Site with all the various settings required to do so --
function esMetastormWebSiteOpener_openWindow(aWindowName)
{
  if( this.canOpenNewWindow(aWindowName) )
  {
    // Open and store reference to new window
    this.windowsList[this.windowsList.length] 
    = window.open('http://www.metastorm.com', "", this.getInitialFormSize() + this.flags);
    // Remember array has just dynamically grown so new window is at this.windowsList.length - 1
    this.windowsList[this.windowsList.length - 1].name = aWindowName;    
  }
}

// -- Opens window --
function esMetastormWebSiteOpener_openItem()
{                              
  var lWindowName = 'MetastormWebSite'; 
  this.openWindow(lWindowName);    
}

// -- Sets the initial size of the Metastorm Web Site opener window --
function esMetastormWebSiteOpener_getInitialFormSize()
{
  var lAvailWidth = window.screen.availWidth/1.5;
  var lAvailHeight = window.screen.availHeight/2;
  var lLeft = (lAvailWidth)/4; 
  var lTop = (lAvailHeight)/4;
  return 'width=' + lAvailWidth + ',height=' + lAvailHeight + ',top=' + lTop + ',left=' + lLeft;	
}   

/* ----------------------------------------------------------------------------- 
   Folder Action Form Opener Class - class for opening action forms from folders 
*/

function esFolderActionFormOpener(aParent)
{                                 
  // Properties
  aParent.openedAction = null;
  // -- Protected Methods --
  aParent.openWindow = esFolderActionFormOpener_openWindow;
  aParent.Parent_Free = aParent.Free;
  
  // -- Public Methods --
  aParent.openItem = esFolderActionFormOpener_openItem;
  aParent.Free = esFolderActionFormOpener_Free;
  
  return aParent;
} 

function esFolderActionFormOpener_Free()
{
  this.Parent_Free();
}

function esFolderActionFormOpener_openWindow(aWindowName, aService, aFolderID, aFolder, aAction, aUserPage)
{
  var LWindowName = this.createWindowName(aWindowName); 
  var lQueryFields = 'eForm.aspx?Action=' + URLEncode(aAction);
  if(aFolder.length > 0)
    lQueryFields += '&Folder=' + URLEncode(aFolder);
  if(aFolderID.length > 0)
    lQueryFields += '&FolderID=' + URLEncode(aFolderID);
  if(aService.length > 0)
    lQueryFields += '&Service=' + URLEncode(aService);

  // We need to pass the session id in the query field to overcome
  // the problem of external client dropping session cookies.
  if (getCookie(aService + 'Client') == 'external')
  {
    var lSessionID = getCookie(aService + 'SessionID')
    lQueryFields += '&SN=' + lSessionID;
  }   

  try
  {
    var lLaunchURL = eFormContents.eConfirmCancelForm.LaunchURL.value;
    if (lLaunchURL != "")
      lQueryFields += '&FolderLaunchURL=' + lLaunchURL;
    var lCancelURL = eFormContents.eConfirmCancelForm.CancelURL.value;
    if (lCancelURL != "")
      lQueryFields += '&FolderCancelURL=' + lCancelURL;
  }
  catch(e)
  {
  }
    
  var lActionWindowClosed = false;
  // Detect if we have an opened folder action window
  try
  {
    if (this.openedAction.closed)
      lActionWindowClosed = true;
  }
  catch(e)
  {
    lActionWindowClosed = true;       
  }
  if(lActionWindowClosed)
  {
    // put a timestamp on the action form request
    lQueryFields = setClientTimestamp(lQueryFields);

    // save the UserOptions for HTML form time zone support
    if ((getCookie(USER_OPTIONS_COOKIE_NAME) == '') && (getCookie(USER_SESSION_OPTIONS_COOKIE_NAME) == ''))
    {
      var lUserOptions = new eUserOptions();
      lUserOptions.SaveData();
    }

    // Window open is slow if a name is passed to the newly created window.
    this.openedAction = window.open(lQueryFields, "", this.getInitialFormSize() + this.flags);
    this.openedAction.name = LWindowName;
  }
  else
    this.openedAction.focus();
}

// -- Opens window content based on the selected row --
function esFolderActionFormOpener_openItem(aService, aFolderID, aFolder, aAction, aActionType)
{
  var lWindowName = aAction + '[' + aFolder + '@' + aService + ']';
  //var lUserPage = ((aActionType.toLowerCase() == 'confirm')||(aActionType.toLowerCase() == 'non-confirm') ? "?" : "");
  //this.openWindow(lWindowName, aService, aFolderID, aFolder, aAction, lUserPage); 
  this.openWindow(lWindowName, aService, aFolderID, aFolder, aAction); 
}
   

/* ------------------------------------------------------------------------------------------------------- 
   Global Opener singleton - instantiated when the list grid is initialised
*/
var eOpener = null;
