/*************************************************************************
©2004,2005 by Scalix Corporation and are the property of Scalix Corporation.
This file is available to you only under license from Scalix Corporation,
the terms of which include limited rights to install and use the software
but specifically do not permit copying and distribution of this file, and
do not permit the removal, alteration, or effacing of this notice or any
copyright or other proprietary notices contained in the software or files.
Do not use the software without a valid license from Scalix Corporation.
**************************************************************************/

// Title GUI



TitleGUI.prototype = new BaseGUI;
TitleGUI.prototype.constructor = TitleGUI;
TitleGUI.superclass = BaseGUI.prototype;

function TitleGUI() {
}

TitleGUI.create = function(parentGUI, parentElement) {
  var thisObj = new TitleGUI();
  thisObj.initialize(parentGUI, parentElement);
  return thisObj;
};

TitleGUI.prototype.setup = function(tabIndex) {
  tabIndex = TitleGUI.superclass.setup.call(this, tabIndex);

  this.rootElement.className = "Title";

  this.logo = this.createElement("DIV", this.rootElement);
  this.logo.className = "ExactPosition";
  var img = this.createElement("IMG", this.logo);
  img.src = ImageArray.logo.src;
  this.text = this.createElement("DIV", this.rootElement);
  this.text.className = "TitleTextArea";
  var te = this.createElement("SPAN", this.text);
  te.className = "TitleText";
  te.innerHTML = UIstrings.AdminTitleString;
  te = this.createElement("SPAN", this.text);
  te.className = "VersionText";
  te.innerHTML = UIstrings.AdminVersionString;

  return tabIndex;
}

TitleGUI.prototype.doLayout = function() {
  TitleGUI.superclass.doLayout.call(this);

  this.rootElement.style.width = 2000;

  var h = this.logo.offsetHeight;
  if (this.text.offsetHeight > h) {
    h = this.text.offsetHeight;
  }

  h += 10;

  this.logo.style.left = 10;
  this.logo.style.top = (h - this.logo.offsetHeight) / 2;

  this.text.style.left = this.logo.offsetLeft + ImageArray.logo.width + 20;
  this.text.style.width = this.width - this.text.offsetLeft;
  this.text.style.top = (h - this.text.offsetHeight) / 2;

  this.rootElement.style.width = this.width;
  this.rootElement.style.height = h
};


// Main Admin Login Pane

// Main Admin GUI

IndexGUI.prototype = new BaseWindowGUI;
IndexGUI.prototype.constructor = IndexGUI;
IndexGUI.superclass = BaseWindowGUI.prototype;

function IndexGUI() {
}

IndexGUI.create = function(window) {
  var thisObj = new IndexGUI();
  thisObj.initialize(window);
  return thisObj;
};

IndexGUI.prototype.setFocus = function() {
  return false;
}

IndexGUI.prototype.setup = function(tabIndex) {
  tabIndex = IndexGUI.superclass.setup.call(this, tabIndex);

  this.title = TitleGUI.create(this, null);
  tabIndex = this.title.setup(tabIndex);

  this.outerBorder = this.createElement("DIV");
  this.outerBorder.className = "ExactPosition";
  this.outerBorder.style.border = "2px solid #808080";
  this.innerBorder = this.createElement("DIV", this.outerBorder);
  this.innerBorder.className = "ExactPosition";
  this.innerBorder.style.border = "2px solid #a0a0a0";
  this.headerString = this.createElement("SPAN", this.innerBorder);  
  this.headerString.className = "ExactPosition";
  this.headerString.style.textAlign = "center";
  this.headerString.innerHTML = "<b>" + UIstrings.StartingAdminApplication + "</b>";
  this.textString = this.createElement("SPAN", this.innerBorder);
  this.textString.className = "ExactPosition";
  this.textString.style.padding = UIvalues.AdminPaneIndent;
  this.textString.innerHTML = UIstrings.StartingAdminApplicationMessage;

  return tabIndex;
}

IndexGUI.prototype.doLayout = function() {
  IndexGUI.superclass.doLayout.call(this);

  this.title.layout();

  var t = this.title.top + this.title.height;
  var w = this.width;

  this.outerBorder.style.width = this.width;
  this.outerBorder.style.height = this.height;
  this.innerBorder.style.width = this.width;
  this.innerBorder.style.height = this.height;
 
  var tw = this.headerString.offsetWidth;  
  var th = this.headerString.offsetHeight;
  
  var pos = this.headerString.offsetTop + this.headerString.offsetHeight + UIvalues.AdminPaneHeaderAbove;
  
  tw = this.textString.offsetWidth;
  th += this.textString.offsetHeight + UIvalues.AdminPaneHeaderAbove;

  this.textString.style.top = UIvalues.AdminPaneHeaderAbove + pos;

  this.innerBorder.style.width = ((tw + 2 * UIvalues.AdminPaneIndent) / 1.5) + UIvalues.AdminPaneIndent;
  this.innerBorder.style.height = (th + 4 * UIvalues.AdminPaneHeaderAbove) + UIvalues.AdminPaneHeaderAbove;
  this.innerBorder.style.left = 2;
  this.innerBorder.style.top = 2;

  this.outerBorder.style.width = this.innerBorder.offsetWidth + 4 + ((gInnerBorder) ? 4 : 0);
  this.outerBorder.style.height = this.innerBorder.offsetHeight + 4 + ((gInnerBorder) ? 4 : 0);
  this.outerBorder.style.left = (this.width - this.outerBorder.offsetWidth) / 2;
  this.outerBorder.style.top = (this.height - t - this.outerBorder.offsetHeight) / 2 + t;

  this.headerString.style.width = this.innerBorder.style.width;
  this.headerString.style.top = UIvalues.AdminPaneHeaderAbove;
  this.headerString.style.left = UIvalues.AdminPaneIndent;  
};

function IndexGUI_copyLocalValues(targetWindow) {
  targetWindow.UIstrings = UIstrings;
  targetWindow.ImageArray = ImageArray;
  targetWindow.UIvalues = UIvalues;
  targetWindow.adminInfo = adminInfo;
}

//Entry Point

function doGUI() {
  gDoc = document;
  gDocBody = document.body;

  indexPage = IndexGUI.create(window);

  getGlobalValues(null, IndexGUI_copyLocalValues);
  launchAdminApp();
  indexPage.init();
}

function launchAdminApp() {
  var width = Math.min(900, screen.availWidth);
  var height = Math.min(650, screen.availHeight);
  var name = "SAC";
  
  window.open('Admin.jsp', name, 'width=' + width + ', height=' + height + ', resizable=yes,help=no, status=no,scrollbars');
}

// BUGS:
// - Need Trademark for Scalix Logo
// - Need new bit maps for users/groups/etc.

// GLOBALS

