/*
 * Created on 16-jan-2006
 * 
 * (c) 2005-2006 Seagull Holding N.V. All rights reserved.
 */

var JRE_MINIMUM_VERSION = "1.4.2";

function Applet()
{
  Applet('GuiClient');
}

function Applet(aName)
{
  this.id_ = aName;

  /*
   * Associative array of applet parameters.
   */
  this.parameters_ = new Array();

  /*
   * Add some standard parameters.
   */
  this.addParameter('code', 'com.seagullsw.client.gui.GuiClient.class');
  this.addParameter('codebase',  '.');
  this.addParameter('type', 'application/x-java-applet;jpi-version=' + JRE_MINIMUM_VERSION);
  this.addParameter('mayscript', 'mayscript');
  this.addParameter('archive', '');

  /*
   * Add standard archives.
   */
  this.addArchive('java/guiclient.jar');
  this.addArchive('java/resources.jar');
    
  /*
   * Default size
   */
  this.setSize(600, 400);
}

Applet.prototype.write = function()
{
  document.writeln('<!--[if !IE]>-->');
  document.writeln('<object id="' + this.id_ + '" classid="java:' + this.parameters_['code'] + '" ');
  document.writeln('height="' + this.height_ + '" width="' + this.width_ + '" >');

  for(name in this.parameters_)
    document.writeln('<param name="' + name + '" value="' + this.parameters_[name] + '" />');
    
  document.writeln('<!--<![endif]-->');
  document.writeln('<object id="' + this.id_ + '" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ');
    
  var underScoreVersion = JRE_MINIMUM_VERSION.replace(/(\d+)\.(\d+)\.(\d+)/, '$1_$2_$3');
  var commaVersion = JRE_MINIMUM_VERSION.replace(/\./g, ',');
   
  document.writeln('codebase="http://java.sun.com/update/' + JRE_MINIMUM_VERSION + '/jinstall-' + underScoreVersion + '-windows-i586.cab#Version=' + commaVersion + ',0" ');
  document.writeln('width="' + this.width_ + '" height="'+ this.height_ + '" align="baseline" >');

  for(name in this.parameters_)
    document.writeln('<param name="' + name + '" value="' + this.parameters_[name] + '" />');

  document.write('<div class="warning">The LegaSuite GUI Java Client requires JRE version ' + JRE_MINIMUM_VERSION + ' or higher to run correctly.</div>');
  document.write('</object>');
  document.writeln('<!--[if !IE]>-->');
  document.write('</object>');
  document.writeln('<div class="note">NOTE: The LegaSuite GUI Java Client requires JRE version ' + JRE_MINIMUM_VERSION + ' or higher to run correctly. <a href="http://java.sun.com/products/plugin/downloads/index.html">Get the latest Java Plug-in here.</a></div>');
  document.writeln('<!--<![endif]-->');
}

Applet.prototype.addParameter = function(aName, aValue)
{
  this.parameters_[aName.toLowerCase()] = aValue;
}

Applet.prototype.addArchive = function(aArchive)
{
  if(this.parameters_['archive'] != '' && aArchive != '')
    this.parameters_['archive'] += ',';
    
  this.parameters_['archive'] += aArchive;
}

Applet.prototype.setSize = function(aWidth, aHeight)
{
  this.width_ = aWidth;
  this.height_ = aHeight;
}

Applet.prototype.getBooleanParameter = function(aName) 
{
  var lowerCaseName = aName.toLowerCase();
  
  return (this.parameters_[lowerCaseName] != null 
    && (this.parameters_[lowerCaseName].toLowerCase() == 'yes' 
    || this.parameters_[lowerCaseName].toLowerCase() == 'true'
    || this.parameters_[lowerCaseName] == 1));
}

Applet.prototype.getVariable = function(aSessionId, aVariableName)
{
  return this.getElement().getVariable(aSessionId, aVariableName);
}

Applet.prototype.setVariable = function(aSessionId, aVariableName, aVariableValue)
{
  return this.getElement().setVariable(aSessionId, aVariableName, aVariableValue);
}

Applet.prototype.println = function(aString)
{
  return this.getElement().systemErrPrintln(aString);
}

Applet.prototype.getRunningSessionId = function(n)
{
  return this.getElement().getRunningSessionId(n);
}

Applet.prototype.callScript = function(aSessionId, aScriptName, aTimeOutSeconds)
{
  this.getElement().callScript(aSessionId, aScriptName, aTimeOutSeconds);
}

Applet.prototype.getElement = function()
{
  return document.getElementById(this.id_);
}
