﻿//-----------------------------------------------------------------------------
// XPanel
//
// Copyright 2005-2010 - Xcential Group LLC.
//
//-----------------------------------------------------------------------------

XPanel.prototype = new XControl;
XPanel.prototype.constructor = XPanel;

//=============================================================================
// Constructor

function XPanel(
   id,
   create
)
{
   id = (id == null) ? null : id;
   create = (create == null) ? true : false;

   if (create)
      return new XPanel(id, false);

   //--------------------------------------------------------------------------
   // Private Interface

   //--------------------------------------------------------------------------
   // Privileged Interface

   this.valueOf = function()
   {

      return oSpec;
   }

   //--------------------------------------------------------------------------

   this.setObjectValue = function(
      id
   )
   {
      id = (id == null) ? null : id;

      oSpec = XPanel.getSpecFrom(id);

      return oSpec;
   }

   //--------------------------------------------------------------------------
   // Initialization

   var oSpec = this.setObjectValue(id);

   XControl.controls[oSpec.id] = this;

}

XPanel.prototype.objectClass = "XPanel";

//=============================================================================
// Static Interface

XPanel.MAX_SPEC = new Array();
XPanel.MAX_SPEC.left = 0;
XPanel.MAX_SPEC.top = 0;
XPanel.MAX_SPEC.right = 0;
XPanel.MAX_SPEC.bottom = 0;
XPanel.MAX_SPEC.width = "100%";
XPanel.MAX_SPEC.height = "100%";

XPanel.ACTION_GO_BACK     = "go_back";
XPanel.ACTION_GO_FORWARD  = "go_forward";
XPanel.ACTION_GO_HOME     = "go_home";
XPanel.ACTION_EXPAND      = "expand";
XPanel.ACTION_COLLAPSE    = "collapse";
XPanel.ACTION_HIGHLIGHT   = "highlight";
XPanel.ACTION_MINIMIZE    = "minimize";
XPanel.ACTION_DEMINIMIZE  = "deminimize";
XPanel.ACTION_MAXIMIZE    = "maximize";
XPanel.ACTION_DEMAXIMIZE  = "demaximize";
XPanel.ACTION_CLOSE       = "close";

XPanel.LAYOUT_STANDARD    = "standard";
XPanel.LAYOUT_DYNAMIC     = "dynamic";

XPanel.SIZE_STANDARD      = "standard";
XPanel.SIZE_COMPACT       = "compact";

//-----------------------------------------------------------------------------

XPanel.getSpecFrom = function(
   id
)
{
   id = (id == null) ? XUtils.generateId("urn:xcential-com:panel:", XUtils.SCHEME_RANDOM) : id;

   var spec = new Array();
   spec.id = id;
   spec.className = "XPanel";
   spec.mouseLeave = false;
   spec.htmlNode = null;
   spec.left = 10;
   spec.top = 10;
   spec.right = null;
   spec.bottom = null;
   spec.width = null;
   spec.height = null;
   spec.shadowSize = 0;
   spec.headerHeight = 21;
   spec.toolbarHeight = 0;
   spec.xNode = null;
   spec.title = null;
   spec.titleIcon = null;
   spec.info = null;
   spec.visible = true;
   spec.src = null;
   spec.format = null;
   spec.cacheContent = false;
   spec.hideBorder = false;
   spec.showHeader = false;
   spec.showHeaderToolbar = true;
   spec.showHistory = false;
   spec.backHistory = new Array();
   spec.forwardHistory = new Array();
   spec.showPrint = false;
   spec.showMailto = false;
   spec.showPermalink = false;
   spec.showDelicious = false;
   spec.showBlogThis = false;
   spec.showHighlighter = false;
   spec.highlightWords = new Array();
   spec.maximized = false;
   spec.minimized = false;
   spec.expanded = false;
   spec.allowMinimize = false;
   spec.allowMaximize = false;
   spec.allowClose = false;
   spec.closeByHide = false;
   spec.layout = XPanel.LAYOUT_STANDARD;
   spec.size = XPanel.SIZE_STANDARD;
   spec.scrollContent = false;

   return spec;
}

//=============================================================================
// Event Handlers

XPanel.prototype.onShowContent = null;
XPanel.prototype.onHideContent = null;
XPanel.prototype.onMinimize = null;
XPanel.prototype.onMaximize = null;
XPanel.prototype.onExpand = null;
XPanel.prototype.onCollapse = null;
XPanel.prototype.onBeforeClose = null;
XPanel.prototype.onAfterClose = null;
XPanel.prototype.onGoBack = null;
XPanel.prototype.onForward = null;
XPanel.prototype.onAfterSetSrc = null;
XPanel.prototype.onLoad = null;
XPanel.prototype.onTransform = null;
XPanel.prototype.onGoto = null;
XPanel.prototype.onShowPrintText = null;
XPanel.prototype.onGrabPermalink = null;
XPanel.prototype.onSaveToDelicious = null;

XPanel.prototype.homeURL = null;

XPanel.prototype.getTitleHTML = null;
XPanel.prototype.getToolbarHTML = null;
XPanel.prototype.getContentHTML = null;

XPanel.prototype.composeTitle = null;

//-----------------------------------------------------------------------------

XPanel.prototype.doHighlight = function(
   event,
   id
)
{
   event = (event == null) ? window.event : event;

   var spec = this.valueOf();

   var item = $(spec.id + "." + id);
   if (item == null)
      item = $(id);

   if (item != null)
   {
      switch (item.tagName.toLowerCase())
      {
         case "img":
            var img = item;
            var imgSrc = img.src;
            var extension = "";
            if (XMatch(imgSrc, /^(.*)(\.[^\.]+)$/))
            {
               imgSrc = XMatch.matches[1];
               extension = XMatch.matches[2];
            }
            img.src = imgSrc.replace(/\.Highlight$/, "") + ".Highlight" + extension;
            break;
         case "div":
            var div = item;
            div.className = div.className.replace(/\-Highlight$/i, "") + "-Highlight";
            break;
         case "span":
            var span = item;
            span.className = span.className.replace(/\-Highlight$/i, "") + "-Highlight";
            break;
      }
   }

   if (event)
      event.cancelBubble = true;

}

//-----------------------------------------------------------------------------

XPanel.prototype.doUnhighlight = function(
   event,
   id
)
{
   event = (event == null) ? window.event : event;

   var spec = this.valueOf();

   var item = $(spec.id + "." + id);
   if (item == null)
      item = $(id);

   if (item != null)
   {
      switch (item.tagName.toLowerCase())
      {
         case "img":
            var img = item;
            var imgSrc = img.src;
            var extension = "";
            if (XMatch(imgSrc, /^(.*)(\.[^\.]+)$/))
            {
               imgSrc = XMatch.matches[1];
               extension = XMatch.matches[2];
            }
            img.src = imgSrc.replace(/\.Highlight$/, "") + extension;
            break;
         case "div":
            var div = item;
            div.className = div.className.replace(/\-Highlight$/i, "");
            break;
         case "span":
            var span = item;
            span.className = span.className.replace(/\-Highlight$/i, "");
            break;
      }
   }

   if (event)
      event.cancelBubble = true;

}

//-----------------------------------------------------------------------------

XPanel.prototype.doGrabPermalink = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      var spec = this.valueOf();

      if (this.onGrabPermalink)
         this.onGrabPermalink(event, this);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.doSaveTo = function(
   event,
   destination
)
{
   event = (event == null) ? window.event : event;

   try
   {
      var spec = this.valueOf();

      if (this.onSaveTo)
         this.onSaveTo(destination, this, this.getSelectedText());
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.doGoBack = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      goBack();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.doGoForward = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.goForward();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doGoHome = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.goHome();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doExpand = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.expand();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doCollapse = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.collapse();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doToggleExpand = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      if (this.isExpanded())
         this.collapse();
      else
         this.expand();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doMinimize = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.minimize();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doDeminimize = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.deminimize();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doMaximize = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.maximize();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doDemaximize = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      this.demaximize();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.doSelectHighlightWords = function()
{

   try
   {
      this.selectHighlightWords();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.doHighlightWords = function(
   wordsText
)
{
   wordsText = (wordsText == null) ? null : wordsText;

   try
   {
      this.highlightWords(wordsText);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.doLinkTo = function(
   event,
   ref
)
{
   event = (event == null) ? window.event : event;
   ref = (ref == null) ? null : ref.toString();

   try
   {
      XUI.doLinkTo(event, ref);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.doTitleIconClick = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {

      var format = this.getFormat();
      if (format)
      {
         switch (format)
         {
            case RSS.FORMAT:
            case RSS1.FORMAT:
            case RSS2.FORMAT:
            case Atom.FORMAT:
               var url = this.getSrc();
               //url = url.replace(/\.atom/gi,".rss2");
               url = url.replace(/format=atom/gi,"format=rss2");
               //url = url.replace(/\/atom\//gi,"/rss/");
               if (XApp.isBrowser("Firefox"))
               {
                  XUI.openWindow(url, "_blank");
               }
               else
               {
                  url = "feed:" + url.replace(/^http:/, "");
                  XUI.openWindow(url, "_top");
               }
               break;
         }
      }

   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

   if (event)
      event.cancelBubble = true;

}

//-----------------------------------------------------------------------------

XPanel.prototype.doShowContent = function(
   event,
   id
)
{
   event = (event == null) ? window.event : event;

   try
   {
      XUI(id + ".expandIcon").hide();
      XUI(id + ".collapseIcon").show(XUI.INLINE_BLOCK_DISPLAY);
      XUI(id + ".summary").hide();
      XUI(id + ".content").show();

      if (this.onShowContent)
         this.onShowContent(this, id);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

   if (event)
      event.cancelBubble = true;

}

//-----------------------------------------------------------------------------

XPanel.prototype.doHideContent = function(
   event,
   id
)
{
   event = (event == null) ? window.event : event;

   try
   {
      XUI(id + ".expandIcon").show(XUI.INLINE_BLOCK_DISPLAY);
      XUI(id + ".collapseIcon").hide();
      XUI(id + ".summary").show();
      XUI(id + ".content").hide();

      if (this.onHideContent)
         this.onHideContent(this, id);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

   if (event)
      event.cancelBubble = true;

}

//-----------------------------------------------------------------------------

XPanel.prototype.doToggleContent = function(
   event,
   id
)
{
   event = (event == null) ? window.event : event;

   try
   {
      if (XUI(id + ".expandIcon").isVisible())
         this.doShowContent(event, id);
      else
         this.doHideContent(event, id);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.doSetSrc = function(
   event,
   src,
   format,
   initParams,
   noCache
)
{
   event = (event == null) ? window.event : event;
   src = (src == null) ? null : src.toString();
   format = (format == null) ? null : format.toLowerCase();
   initParams = (initParams == null) ? null : initParams;
   noCache = (noCache == null) ? false : noCache;

   try
   {
      this.setSrc(src, format, initParams, noCache);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

   if (event)
      event.cancelBubble = true;

}

//-----------------------------------------------------------------------------

XPanel.prototype.doClose = function(
   event
)
{
   event = (event == null) ? window.event : event;

   try
   {
      var spec = this.valueOf();

      if (this.onBeforeClose)
         this.onBeforeClose(this);

      if (spec.allowClose)
      {
         this.hide();
         if (!spec.closeByHide && spec.htmlNode)
         {
            spec.htmlNode.parentNode.removeChild(spec.htmlNode);
            spec.htmlNode = null;
         }
      }

      if (this.onAfterClose)
         this.onAfterClose(this);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
      XMsg.alert(error);
   }

   return null;
}

//-----------------------------------------------------------------------------

XPanel.prototype.doKeyDown = function(
   event,
   action
)
{
   event = (event == null) ? window.event : event;

   var keyCode = event.keyCode;
   switch (action)
   {
      case XPanel.ACTION_GO_BACK:
         if (keyCode == XUI.KEY_ENTER)
            this.doGoBack(event);
         break;
      case XPanel.ACTION_GO_FORWARD:
         if (keyCode == XUI.KEY_ENTER)
            this.doGoForward(event);
         break;
      case XPanel.ACTION_GO_HOME:
         if (keyCode == XUI.KEY_ENTER)
            this.doGoHome(event);
         break;
      case XPanel.ACTION_HIGHLIGHT:
         if (keyCode == XUI.KEY_ENTER)
            this.doHighlightWords();
         break;
      case XPanel.ACTION_EXPAND:
         if (keyCode == XUI.KEY_ENTER)
            this.doExpand(event);
         break;
      case XPanel.ACTION_COLLAPSE:
         if (keyCode == XUI.KEY_ENTER)
            this.doCollapse(event);
         break;
      case XPanel.ACTION_MINIMIZE:
         if (keyCode == XUI.KEY_ENTER)
            this.doMinimize(event);
         break;
      case XPanel.ACTION_DEMINIMIZE:
         if (keyCode == XUI.KEY_ENTER)
            this.doDeminimize(event);
         break;
      case XPanel.ACTION_MAXIMIZE:
         if (keyCode == XUI.KEY_ENTER)
            this.doMaximize(event);
         break;
      case XPanel.ACTION_DEMAXIMIZE:
         if (keyCode == XUI.KEY_ENTER)
            this.doDemaximize(event);
         break;
      case XPanel.ACTION_CLOSE:
         if (keyCode == XUI.KEY_ENTER)
            this.doClose(event);
         break;
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.goTo = function(
   id
)
{
   id = (id == null) ? null : id;

   try
   {
      if (id == null)
         return;

      var spec = this.valueOf();

      var iframe = $(spec.id + ".iframe");
      if (iframe)
      {
         iframe.title = id;
         if (iframe.contentWindow.goTo)
            iframe.contentWindow.goTo(id);
      }

      if (this.onGoto)
         this.onGoto(this);
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
   }

   return id;
}

//=============================================================================
// Public Interface

XPanel.prototype.setClass = function(
   className
)
{
   className = (className == null) ? "XPanel" : className;

   var spec = this.valueOf();
   spec.className = className;

   return className;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getTitle = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   return (castAs == null) ? spec.title : castAs(spec.title);
}

//-----------------------------------------------------------------------------

XPanel.prototype.setTitle = function(
   title
)
{
   title = (title == null) ? "" : title.toString();

   var spec = this.valueOf();

   // Clear out the info always when changing the title
   if (spec.title != title)
   {
      this.setInfo();
      this.setTitleIcon();
   }

   spec.title = title;
   if (spec.htmlNode)
   {
      var titleNode = spec.htmlNode.ownerDocument.getElementById(spec.id + ".title");
      if (titleNode)
         titleNode.innerHTML = (XString(spec.title).isSomething()) ? spec.title : "";
   }


   return spec.title;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getTitleIcon = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   return (castAs == null) ? spec.titleIcon : castAs(spec.titleIcon);
}

//-----------------------------------------------------------------------------

XPanel.prototype.setTitleIcon = function(
   titleIcon
)
{
   titleIcon = (titleIcon == null) ? null : titleIcon.toString();

   var spec = this.valueOf();

   spec.titleIcon = titleIcon;

   var titleIconElement = $(spec.id + ".titleIcon");
   if (titleIconElement)
   {
      if (XString(titleIcon).isSomething())
      {
         titleIconElement.src = titleIcon;
         titleIconElement.title = "";
         XUI(titleIconElement).setRuntimeStyle("display", "inline");
      }
      else
      {
         titleIconElement.src = null;
         titleIconElement.title = "";
         XUI(titleIconElement).setRuntimeStyle("display", "none");
      }
   }

   return spec.titleIcon;
}

//-----------------------------------------------------------------------------

XPanel.prototype.hideTitle = function()
{

   var spec = this.valueOf();

   if (spec.htmlNode)
   {
      var titleNode = spec.htmlNode.ownerDocument.getElementById(spec.id + ".title");
      if (titleNode)
         XUI(titleNode).setRuntimeStyle("display", "none");
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.showTitle = function()
{

   var spec = this.valueOf();

   if (spec.htmlNode)
   {
      var titleNode = spec.htmlNode.ownerDocument.getElementById(spec.id + ".title");
      if (titleNode)
         XUI(titleNode).setRuntimeStyle("display", XUI.INLINE_BLOCK);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.getInfo = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   return (castAs == null) ? spec.info : castAs(spec.info);
}

//-----------------------------------------------------------------------------

XPanel.prototype.setInfo = function(
   info
)
{
   info = (info == null) ? "" : info.toString();

   var spec = this.valueOf();

   spec.info = info;
   if (spec.htmlNode)
   {
      var infoNode = spec.htmlNode.ownerDocument.getElementById(spec.id + ".info");
      if (infoNode)
         infoNode.innerHTML = (XString(spec.info).isSomething()) ? spec.info : "";
   }

   return spec.info;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getHeaderHeight = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var headerHeight = (spec.showHeader) ? spec.headerHeight : 0;

   return (headerHeight == null) ? null : (castAs == null) ? headerHeight : castAs(headerHeight);
}

//-----------------------------------------------------------------------------

XPanel.prototype.setHeaderHeight = function(
   headerHeight
)
{
   headerHeight = (headerHeight == null) ? null : headerHeight;

   var spec = this.valueOf()

   spec.headerHeight = headerHeight;

   if (spec.htmlNode && !spec.minimized && !spec.minimized)
   {
      var header = spec.htmlNode.ownerDocument.getElementById(spec.id + "Header");
      if (header)
         header.height = XUtils.dimText(spec.headerHeight);
      var title = spec.htmlNode.ownerDocument.getElementById(spec.id + ".title");
      if (title)
         title.lineHeight = XUtils.dimText(spec.headerHeight);
      var content = spec.htmlNode.ownerDocument.getElementById(spec.id + ".content");
      if (content)
         content.top = XUtils.dimText(spec.headerHeight);
   }

   return spec.htmlNode;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getHideBorder = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var hideBorder = spec.hideBorder;

   return (castAs == null) ? hideBorder : castAs(hideBorder);
}

//-----------------------------------------------------------------------------

XPanel.prototype.hideBorder = function(
   hideBorder
)
{
   hideBorder = (hideBorder == null) ? true : hideBorder;

   var spec = this.valueOf();

   spec.hideBorder = hideBorder;

   return hideBorder;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getShowHeader = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var showHeader = spec.showHeader;

   return (castAs == null) ? showHeader : castAs(showHeader);
}

//-----------------------------------------------------------------------------

XPanel.prototype.showHeader = function(
   showHeader
)
{
   showHeader = (showHeader == null) ? true : showHeader;

   var spec = this.valueOf();

   spec.showHeader = showHeader;

   return showHeader;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getShowHistory = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var showHistory = spec.showHistory;

   return (castAs == null) ? showHistory : castAs(showHistory);
}

//-----------------------------------------------------------------------------

XPanel.prototype.showHistory = function(
   showHistory
)
{
   showHistory = (showHistory == null) ? true : showHistory;

   var spec = this.valueOf();

   spec.showHistory = showHistory;
   if (showHistory && this.getHeaderHeight() < 30)
      this.setHeaderHeight(30);

   return showHistory;
}

//-----------------------------------------------------------------------------

XPanel.prototype.updateHistory = function()
{

   var spec = this.valueOf();

   var historyNode = $(spec.id + ".history");
   if (historyNode)
   {
      if (spec.showHistory)
      {
         historyNode.visible = false
         XUI(spec.id + ".goBackImage").setRuntimeStyle("display", (spec.backHistory.length > 0) ? "inline" : "none");
         XUI(spec.id + ".goBackDisabledImage").setRuntimeStyle("display", (spec.backHistory.length > 0) ? "none" : "inline");
         XUI(spec.id + ".goForwardImage").setRuntimeStyle("display", (spec.forwardHistory.length > 0) ? "inline" : "none");
         XUI(spec.id + ".goForwardDisabledImage").setRuntimeStyle("display", (spec.forwardHistory.length > 0) ? "none" : "inline");
      }
      else
      {
         historyNode.visible = false;
      }
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.goBack = function()
{

   var spec = this.valueOf();

   if (spec.backHistory.length > 0)
   {
      if (spec.src && !(/\/Blank.html/i).test(spec.src))
         spec.forwardHistory.push(spec.src);
      spec.src = null;
      var src = spec.backHistory.pop();
      this.setSrc(src);

      if (this.onGoBack)
         this.onGoBack(this);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.goForward = function()
{

   var spec = this.valueOf();

   if (spec.forwardHistory.length > 0)
   {
      var src = spec.forwardHistory.pop();
      this.setSrc(src);

      if (this.onGoForward)
         this.onGoForward(this);
   }
}

//-----------------------------------------------------------------------------

XPanel.prototype.goHome = function()
{

   var spec = this.valueOf();

   if (XString(this.homeURL).isNothing())
      return;

   this.setSrc(this.homeURL);

}

//-----------------------------------------------------------------------------

XPanel.prototype.showHeaderToolbar = function(
   showHeaderToolbar
)
{
   showHeaderToolbar = (showHeaderToolbar == null) ? true : showHeaderToolbar;

   var spec = this.valueOf();

   spec.showHeaderToolbar = showHeaderToolbar;
   if (spec.htmlNode)
      XUI(spec.id + ".headerToolbar").setRuntimeStyle("display", (showHeaderToolbar) ? "inline" : "none");

   return showHeaderToolbar;
}

//-----------------------------------------------------------------------------

XPanel.prototype.showPrint = function(
   showPrint
)
{
   showPrint = (showPrint == null) ? true : showPrint;

   var spec = this.valueOf();

   spec.showPrint = showPrint;

   return showPrint;
}

//-----------------------------------------------------------------------------

XPanel.prototype.showPrintText = function()
{

   var spec = this.valueOf();

   if (this.onShowPrintText)
   {
      this.onShowPrintText(this);
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.getPrintText = function()
{

   var spec = this.valueOf();

   var frameElement = $(spec.id + ".iframe");
   if (frameElement)
      return frameElement.contentWindow.document.body.innerHTML;

   var contentElement = $(spec.id + ".content");
   if (contentElement)
      return contentElement.innerHTML;

   return "";
}


//-----------------------------------------------------------------------------

XPanel.prototype.showMailto = function(
   showMailto
)
{
   showMailto = (showMailto == null) ? true : showMailto;

   var spec = this.valueOf();

   spec.showMailto = showMailto;

   return showMailto;
}

//-----------------------------------------------------------------------------

XPanel.prototype.mailto = function()
{

   var spec = this.valueOf();

   if (this.onMailto)
      this.onMailto(this, this.getSelectedText());

}

//-----------------------------------------------------------------------------

XPanel.prototype.showPermalink = function(
   showPermalink
)
{
   showPermalink = (showPermalink == null) ? true : showPermalink;

   var spec = this.valueOf();

   spec.showPermalink = showPermalink;

   return showPermalink;
}

//-----------------------------------------------------------------------------

XPanel.prototype.showDelicious = function(
   showDelicious
)
{
   showDelicious = (showDelicious == null) ? true : showDelicious;

   var spec = this.valueOf();

   spec.showDelicious = showDelicious;

   return showDelicious;
}

//-----------------------------------------------------------------------------

XPanel.prototype.showBlogThis = function(
   showBlogThis
)
{
   showBlogThis = (showBlogThis == null) ? true : showBlogThis;

   var spec = this.valueOf();

   spec.showBlogThis = showBlogThis;

   return showBlogThis;
}

//-----------------------------------------------------------------------------

XPanel.prototype.showHighlighter = function(
   showHighlighter
)
{
   showHighlighter = (showHighlighter == null) ? true : showHighlighter;

   var spec = this.valueOf();

   spec.showHighlighter = showHighlighter;

   return showHighlighter;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getHighlightWords = function()
{

   var spec = this.valueOf();

   return spec.highlightWords;
}

//-----------------------------------------------------------------------------

XPanel.prototype.selectHighlightWords = function()
{

   var spec = this.valueOf();

   var input = $(spec.id + ".highlightInput");
   if (input)
   {
      input.select();
      XUI(input).clearTitle();
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.clearHighlighting = function()
{

   var spec = this.valueOf();

   try
   {
      var iframe = $(spec.id + ".iframe");
      if (iframe)
         iframe.contentWindow.clearHighlighting();
   }
   catch (error)
   {
      XApp.logEvent(XApp.EVENT_ERROR, error);
   }

   var input = $(spec.id + ".highlightInput");
   if (input)
   {
      spec.highlightWords = new Array();
      XUI(input).setTitle("highlighter");
      input.focus();
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.highlightWords = function(
   wordsText
)
{
   wordsText = (wordsText == null) ? null : wordsText;

   var spec = this.valueOf();

   var input = $(spec.id + ".highlightInput");
   if (wordsText || input)
   {
      var previousWordsText = spec.highlightWords.sort().join(" ").toLowerCase();
      var nextWordsText = (wordsText != null) ? wordsText : XUI(input).getValue();

      // Convert text for highlighting a quoted string
      while (XMatch(nextWordsText, /\"([^\"]*)\"/))
         nextWordsText = XMatch.leftContext + XMatch.matches[1].replace(/\s+/g, "+") + XMatch.rightContext;

      // Remove unwanted characters
      nextWordsText = nextWordsText.replace(/[\'\"\,\;\!\?\(\)\{\}\[\]]/g, " ");

      // Cleanup spaces
      nextWordsText = XString(nextWordsText).normalize();

      // And turn into an array
      var nextWords = (nextWordsText.length == 0) ? new Array() : nextWordsText.split(" ");
      nextWordsText = nextWords.sort().join(" ").toLowerCase();

      if (previousWordsText != nextWordsText)
      {
         spec.highlightWords = nextWords;
         try
         {
            var iframe = $(spec.id + ".iframe");
            if (iframe)
               iframe.contentWindow.highlightWords();
         }
         catch (error)
         {
            XApp.logEvent(XApp.EVENT_ERROR, error);
         }
      }
      if (nextWords.length == 0)
         XUI(input).setTitle("highlighter");
      else
      {
         while (XMatch(nextWordsText, /[^\s]*\+[^\s]*/))
            nextWordsText = XMatch.leftContext + "\"" + XMatch.lastMatch.replace(/\+/g, " ") + "\"" + XMatch.rightContext;
         XUI(input).setValue(nextWordsText);
      }
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.allowExpand = function(
   allowExpand
)
{
   allowExpand = (allowExpand == null) ? true : allowExpand;

   var spec = this.valueOf();

   spec.allowExpand = allowExpand;

   return allowExpand;
}

//-----------------------------------------------------------------------------

XPanel.prototype.isExpanded = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var expanded = spec.expanded;

   return (castAs == null) ? expanded : castAs(expanded);
}

//-----------------------------------------------------------------------------

XPanel.prototype.setExpanded = function(
   expanded
)
{
   expanded = (expanded == null) ? true : expanded;

   var spec = this.valueOf();

   if (spec.allowExpand)
   {
      spec.expanded = expanded;
      if (spec.htmlNode)
      {
         XUI(spec.id + ".expandButton").setRuntimeStyle("display", (expanded) ? "none" : XUI.INLINE_BLOCK_DISPLAY);
         XUI(spec.id + ".collapseButton").setRuntimeStyle("display", (expanded) ? XUI.INLINE_BLOCK_DISPLAY : "none");

         if ($(spec.id + ".iframe"))
         {
            try
            {
               var frameBody = $(spec.id + ".iframe").contentWindow.document.body;
               if (frameBody)
                  XUI(frameBody).fireEvent("onresizeend");
            }
            catch (error) { /* Fails if referencing external doc */ }
         }
      }
   }

   return expanded;
}

//-----------------------------------------------------------------------------

XPanel.prototype.expand = function()
{

   var spec = this.valueOf();

   if (!spec.expanded && spec.allowExpand)
   {
      spec.expanded = true;
      if (spec.htmlNode)
      {
         XUI(spec.id + ".expandButton").setRuntimeStyle("display", "none");
         XUI(spec.id + ".collapseButton").setRuntimeStyle("display", XUI.INLINE_BLOCK_DISPLAY);

         if ($(spec.id + ".iframe"))
         {
            try
            {
               var frameBody = $(spec.id + ".iframe").contentWindow.document.body;
               if (frameBody)
                  XUI(frameBody).fireEvent("onresizeend");
            }
            catch (error) { /* Fails if referencing external doc */ }
         }
      }

      if (this.onExpand)
         this.onExpand(this);
   }


   return spec.htmlNode;
}

//-----------------------------------------------------------------------------

XPanel.prototype.collapse = function()
{

   var spec = this.valueOf();

   if (spec.expanded)
   {
      spec.expanded = false;
      if (spec.htmlNode)
      {
         XUI(spec.id + ".expandButton").setRuntimeStyle("display", XUI.INLINE_BLOCK_DISPLAY);
         XUI(spec.id + ".collapseButton").setRuntimeStyle("display", "none");

         if ($(spec.id + ".iframe"))
         {
            try
            {
               var frameBody = $(spec.id + ".iframe").contentWindow.document.body;
               if (frameBody)
                  XUI(frameBody).fireEvent("onresizeend");
            }
            catch (error) { /* Fails if referencing external doc */ }
         }
      }

      if (this.onCollapse)
         this.onCollapse(this);
   }

   return spec.htmlNode;
}

//-----------------------------------------------------------------------------

XPanel.prototype.allowMinimize = function(
   allowMinimize
)
{
   allowMinimize = (allowMinimize == null) ? true : allowMinimize;

   var spec = this.valueOf();

   spec.allowMinimize = allowMinimize;

   return allowMinimize;
}

//-----------------------------------------------------------------------------

XPanel.prototype.isMinimized = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var minimized = spec.minimized;

   return (castAs == null) ? minimized : castAs(minimized);
}

//-----------------------------------------------------------------------------

XPanel.prototype.minimize = function(
   toTop
)
{
   toTop = (toTop == null) ? true : toTop;

   var spec = this.valueOf();

   if (!spec.minimized && spec.allowMinimize)
   {
      spec.minimized = true;
      if (spec.htmlNode)
      {
         var nodeXUI = XUI(spec.htmlNode);
         var minimizedHeight = XUI(spec.id + ".header").getCurrentStyle("height", XUtils.dimText(this.getHeaderHeight()));
         var content = spec.htmlNode.ownerDocument.getElementById(spec.id + ".content");
         if (content)
            XUI(content).setRuntimeStyle("display", "none");
         if (toTop)
         {
            nodeXUI.setRuntimeStyle("height", XUtils.dimText(minimizedHeight));
            nodeXUI.setRuntimeStyle("bottom", null);
         }
         else
         {
            nodeXUI.setRuntimeStyle("height", XUtils.dimText(minimizedHeight));
            nodeXUI.setRuntimeStyle("top", null);
         }
         XUI(spec.id + ".minimizeButton").setRuntimeStyle("display", "none");
         XUI(spec.id + ".deminimizeButton").setRuntimeStyle("display", XUI.INLINE_BLOCK_DISPLAY);

         this.configurePositioning();

         if ($(spec.id + ".iframe"))
         {
            try
            {
               var frameBody = $(spec.id + ".iframe").contentWindow.document.body;
               if (frameBody)
                  XUI(frameBody).fireEvent("onresizeend");
            }
            catch (error) { /* Fails if referencing external doc */ }
         }
      }

      if (this.onMinimize)
         this.onMinimize(this);
   }

   return spec.htmlNode;
}

//-----------------------------------------------------------------------------

XPanel.prototype.deminimize = function()
{

   var spec = this.valueOf();

   if (spec.minimized)
   {
      spec.minimized = false;
      if (spec.htmlNode)
      {
         this.applyPositioning();
         XUI(spec.id + ".content").setRuntimeStyle("display", "block");
         XUI(spec.id + ".minimizeButton").setRuntimeStyle("display", XUI.INLINE_BLOCK_DISPLAY);
         XUI(spec.id + ".deminimizeButton").setRuntimeStyle("display", "none");

         this.configurePositioning();

         if ($(spec.id + ".iframe"))
         {
            try
            {
               var frameBody = $(spec.id + ".iframe").contentWindow.document.body;
               if (frameBody)
                  XUI(frameBody).fireEvent("onresizeend");
            }
            catch (error) { /* Fails if referencing external doc */ }
         }
      }
   }

   return spec.htmlNode;
}

//-----------------------------------------------------------------------------

XPanel.prototype.allowMaximize = function(
   allowMaximize
)
{
   allowMaximize = (allowMaximize == null) ? true : allowMaximize;

   var spec = this.valueOf();

   spec.allowMaximize = allowMaximize;

   return allowMaximize;
}

//-----------------------------------------------------------------------------

XPanel.prototype.isMaximized = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var maximized = spec.maximized;

   return (castAs == null) ? maximized : castAs(maximized);
}

//-----------------------------------------------------------------------------

XPanel.prototype.maximize = function()
{

   var spec = this.valueOf();

   if (!spec.maximized && spec.allowMaximize)
   {
      spec.maximized = true;
      if (spec.htmlNode)
      {
         for (index in XControl.controls)
         {
            if (index == spec.id)
               continue;
            var control = XControl.controls[index];
            if (!control.isVisible())
               continue;
            var htmlNode = control.getHtmlNode();
            if (htmlNode && htmlNode.parentNode == spec.htmlNode.parentNode)
            {
               control.maximizeHidden = true;
               control.hide();
            }
         }
         this.applyPositioning(XPanel.MAX_SPEC);
         XUI(spec.id + ".maximizeButton").setRuntimeStyle("display", "none");
         XUI(spec.id + ".demaximizeButton").setRuntimeStyle("display", XUI.INLINE_BLOCK_DISPLAY);
         XUI(spec.id + ".expandButton").setRuntimeStyle("display", "none");
         XUI(spec.id + ".collapseButton").setRuntimeStyle("display", "none");

         this.configurePositioning();

         if ($(spec.id + ".iframe"))
         {
            try
            {
               var frameBody = $(spec.id + ".iframe").contentWindow.document.body;
               if (frameBody)
                  XUI(frameBody).fireEvent("onresizeend");
            }
            catch (error) { /* Fails if referencing external doc */ }
         }
      }

      if (this.onMaximize)
         this.onMaximize(this);
   }


   return spec.htmlNode;
}

//-----------------------------------------------------------------------------

XPanel.prototype.demaximize = function()
{

   var spec = this.valueOf();

   if (spec.maximized)
   {
      spec.maximized = false;
      if (spec.htmlNode)
      {
         for (index in XControl.controls)
         {
            if (index == spec.id)
               continue;
            var control = XControl.controls[index];
            if (!control.maximizeHidden)
               continue;
            var htmlNode = control.getHtmlNode();
            if (htmlNode && htmlNode.parentNode == spec.htmlNode.parentNode)
            {
               control.maximizeHidden = false;
               control.show();
            }
         }
         this.applyPositioning();
         XUI(spec.id + ".maximizeButton").setRuntimeStyle("display", XUI.INLINE_BLOCK_DISPLAY);
         XUI(spec.id + ".demaximizeButton").setRuntimeStyle("display", "none");
         XUI(spec.id + ".expandButton").setRuntimeStyle("display", (spec.expanded) ? "none" : XUI.INLINE_BLOCK_DISPLAY);
         XUI(spec.id + ".collapseButton").setRuntimeStyle("display", (spec.expanded) ? XUI.INLINE_BLOCK_DISPLAY : "none");

         this.configurePositioning();

         if ($(spec.id + ".iframe"))
         {
            try
            {
               if (frameBody)
                  XUI(frameBody).fireEvent("onresizeend");
            }
            catch (error) { /* Fails if referencing external doc */ }
         }

      }
   }

   return spec.htmlNode;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getFormat = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var format = spec.format

   return (castAs == null) ? format : (format == null) ? null : castAs(format);
}

//-----------------------------------------------------------------------------

XPanel.prototype.setFormat = function(
   format
)
{
   format = (format == null) ? null : format;

   var spec = this.valueOf();

   // The specified titleIcon is always an override
   if (spec.titleIcon == null)
   {
      var titleIcon = $(spec.id + ".titleIcon");
      if (titleIcon)
      {
         if (format)
         {
            switch (format)
            {
               case RSS.FORMAT:
               case RSS1.FORMAT:
               case RSS2.FORMAT:
               case Atom.FORMAT:
                  titleIcon.src = "/app/pkgs/xfw/images/WebFeed.gif";
                  titleIcon.title = "Subscribe to web feed";
                  XUI(titleIcon).setRuntimeStyle("display", "inline");
                  break;
               case "asx":
               case "wmf":
                  titleIcon.src = "/app/pkgs/xfw/images/VideoFeed.gif";
                  titleIcon.title = "Video Feed";
                  XUI(titleIcon).setRuntimeStyle("display", "inline");
                  break;
               default:
                  titleIcon.src = "/app/pkgs/xfw/images/Blank.gif";
                  titleIcon.title = "";
                  XUI(titleIcon).setRuntimeStyle("display", "none");
                  break;
            }
            spec.format = format;
         }
         else
         {
            titleIcon.src = "/app/pkgs/xfw/images/Blank.gif";
            titleIcon.title = "";
            XUI(titleIcon).setRuntimeStyle("display", "none");
         }
      }
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.getSrc = function(
   castAs
)
{
   castAs = (castAs == null) ? null : castAs;

   var spec = this.valueOf();

   var iframe = $(spec.id + ".iframe");

   var src = null;
   if (spec.src && (!iframe || (iframe && iframe.title != "ERROR")))
      src = spec.src;

   return (castAs == null) ? src : castAs(src);
}

//-----------------------------------------------------------------------------

XPanel.prototype.setSrc = function(
   src,
   format,
   initParams,
   noCache
)
{
   src = (src == null) ? null : src.toString();
   format = (format == null) ? null : format.toLowerCase();
   initParams = (initParams == null) ? null : initParams;
   noCache = (noCache == null) ? false : noCache;

   var spec = this.valueOf();

   var content = $(spec.id + ".content");
   var message = $(spec.id + ".message");
   var iframe = $(spec.id + ".iframe");

   if (src == null && content)
   {
      content.innerHTML = "";
      return null;
   }

   if (spec.src && src.toLowerCase() == spec.src.toLowerCase() && (iframe && iframe.title != "ERROR"))
      return src;

   var xRef = XRef(src);
   if (xRef.isLocalRef())
      xRef.setArg("controlId", spec.id);

   // Now clear the title - may be reset once something is loaded
   this.setTitle();

   if (content)
   {
      try
      {
         format = (format == null) ? xRef.getFormat() : format;
         this.setFormat(format);
         switch (format)
         {
            case RSS.FORMAT:
            case RSS1.FORMAT:
            case RSS2.FORMAT:
            case Atom.FORMAT:
               try
               {
                  var srcURN = src.replace(/^http:\/\//, "");
                  srcURN = srcURN.replace(/^\//,"");
                  srcURN = srcURN.replace(/[^A-Z0-9]/ig, "-");
                  // Note: Avoid a double HTTP call if the reference is local
                  if ((new RegExp("^" + XApp.getDomainURL().toLowerCase())).test(src.toLowerCase()) ||
                      (new RegExp("^" + XApp.URL_APP.toLowerCase())).test(src.toLowerCase()))
                  {
                     src = src.replace(/([\?\&])format=[^\&]*\&?/, "$1"); // Override a format spec in the url
                     src = XRef(src).addArgs("format=" + format);
                     var feedXDoc = XDoc(src, null, (noCache) ? XDoc.CACHE_NONE : null);
                  }
                  else
                  {
                     var srcURN = "urn:feeds:" + srcURN + ":doc:" + format + "?srcURL=" + encodeURIComponent(src);
                     var feedXDoc = XDoc(srcURN, null, (noCache) ? XDoc.CACHE_NONE : null);
                  }
               }
               catch (error)
               {
                  throw XMsg("Cannot load feed document at '" + src + "'.", error);
               }
               feedXDoc.setModel(format);
               //var domainURL = (XMatch(src, /^(http:\/\/[^\/]*)/i)) ? XMatch.matches[1] : "";
               var domainURL = XApp.getDomainURL();  //Use the LegisWeb domain instead of the feed domain
               var showHeading = "yes";
               var showCategories = "no";
               var showEntryLinks = "no";
               var showPermalinks = "no";
               var numberItems = "no";
               var layout = spec.layout;
               var size = spec.size;
               if (format == "atom" && feedXDoc.X$("//opensearch:totalResults"))
               {
                  showHeading = "yes";
                  numberItems = "yes";
               }
               var params = [
                  ["domainURL", domainURL],
                  ["browserName", XApp.browserName],
                  ["browserVersion", XApp.browserVersion],
                  ["applicationNameHTML", XApp.APPLICATION_NAME_HTML],
                  ["controlId", spec.id],
                  ["showHeading", showHeading],
                  ["showCategories", showCategories],
                  ["showEntryLinks", showEntryLinks],
                  ["showPermalinks", showPermalinks],
                  ["numberItems", numberItems],
                  ["addHooks", "yes"],
                  ["layout", layout],
                  ["size", size]
               ];
               if (initParams)
                  params = params.concat(initParams);
               content.innerHTML = feedXDoc.transformTo("html", params, this.onTransform);

               // Make some changes to the content to improve appearance
               var images = content.getElementsByTagName("img");
               for (var i=0; i<images.length; i++)
                  XUI(images[i]).setRuntimeStyle("padding", "3px");
               XUI(content).setRuntimeStyle("overflowY", "auto");

               // Note: The format isn't always reliable - so we try both ways
               var titleXNode = feedXDoc.X$(["/atom:feed/atom:title","/rss/channel/title"]);
               this.setTitle((titleXNode != null) ? titleXNode.toText() : "Web Feed");
               feedXDoc = null;
               if (this.onLoad)
                  this.onLoad(this);
               break;
            case "html_fragment":
               try
               {
                  var fragmentXDoc = XTextDoc(xRef.getURL());
                  fragmentXDoc.read(null, null, noCache);
               }
               catch (error)
               {
                  throw XMsg("Cannot load fragment document at '" + src + "'.", error);
               }
               content.innerHTML = fragmentXDoc.toText();
               XUI(content).setRuntimeStyle("overflowY", "auto");
               fragmentXDoc = null;
               if (this.onLoad)
                  this.onLoad(this);
               break;
            default:
               if (message && iframe)
               {
                  XUI(message).setRuntimeStyle("display", "block");
                  XUI(iframe).setRuntimeStyle("display", "none");
               }
               else
               {
                  content.innerHTML =
                     "<div " +
                        "class=\"" + spec.className + "Message\" " +
                        "id=\"" + spec.id + ".message\" " +
                        "tabindex=\"-1\" " +
                        "style=\"" +
                        "\" " +
                     ">" +
                        "<span " +
                           "id=\"" + spec.id + ".loadingMessage\" " +
                           "class=\"" + spec.className + "LoadingMessage Busy\" " +
                           "tabindex=\"-1\" " +
                        ">" +
                           "Loading..." +
                        "</span>" +
                     "</div>" +
                     "<iframe " +
                        "id=\"" + spec.id + ".iframe\" " +
                        "class=\"" + spec.className + "Iframe\" " +
                        "style=\"" +
                        "\" " +
                        "frameborder=\"no\" " +
                        "hidefocus=\"false\" " +
                        "scrolling=\"" + ((spec.scrollContent) ? "yes" : "no") + "\" " +
                        "onload=\"XControl.controls['" + spec.id + "'].hideBusy()\" " +
                     ">" +
                     "</iframe>";
                  XUI(content).setRuntimeStyle("overflowY", "hidden");
                  message = $(spec.id + ".message");
                  iframe = $(spec.id + ".iframe");
               }
               if (iframe)
               {
                  iframe.title = "";
                  iframe.src = xRef.getURL();
                  iframe.title = ""; // Must be cleared now (it carries the gotoId down)
                  XUI(spec.id + ".iframe").setRuntimeStyle("display", "block");
                  if (xRef.getFormat() == "pdf")
                     XControl.controls[spec.id].hideBusy(); // This may be an iframe bug, but the onload event doesn't fire with acrobat so we do this instead
               }
               if (this.composeTitle == true)
                  this.setTitle(src.replace(/[\?\#].*/, ""));
               else if (this.composeTitle && typeof(this.composeTitle) == "function")
                  this.setTitle(this.composeTitle(src));
               break;
         }
      }
      catch (error)
      {
         content.innerHTML = "";
         this.setTitle("");
         throw error;
      }
   }

   if (spec.src && !(/\/Blank.html/i).test(spec.src))
      spec.backHistory.push(spec.src);
   spec.src = src;
   this.updateHistory();

   if (this.homeURL == null || spec.src == this.homeURL)
      XUI(spec.id + ".home").setRuntimeStyle("display", "none");
   else
      XUI(spec.id + ".home").setRuntimeStyle("display", XUI.INLINE_BLOCK);

   if (this.onAfterSetSrc)
      this.onAfterSetSrc(this);

   return src;
}

//-----------------------------------------------------------------------------

XPanel.prototype.cacheContent = function(
   cacheContent
)
{
   cacheContent = (cacheContent == null) ? true : cacheContent;

   var spec = this.valueOf();

   spec.cacheContent = cacheContent;

   return cacheContent;
}

//-----------------------------------------------------------------------------

XPanel.prototype.hideBusy = function()
{

   var spec = this.valueOf();

   XUI(spec.id + ".message").setRuntimeStyle("display", "none");

   if (this.onLoad)
      this.onLoad(this);

}

//-----------------------------------------------------------------------------

XPanel.prototype.getContentWindow = function()
{

   var spec = this.valueOf();

   var iframe = $(spec.id + ".iframe");

   return (iframe != null) ? iframe.contentWindow : null;
}

//-----------------------------------------------------------------------------

XPanel.prototype.allowClose = function(
   allowClose
)
{
   allowClose = (allowClose == null) ? true : allowClose;

   var spec = this.valueOf();

   spec.allowClose = allowClose;

   return allowClose;
}

//-----------------------------------------------------------------------------

XPanel.prototype.closeByHide = function(
   closeByHide
)
{
   closeByHide = (closeByHide == null) ? true : closeByHide;

   var spec = this.valueOf();

   spec.closeByHide = closeByHide;

   return closeByHide;
}

//-----------------------------------------------------------------------------

XPanel.prototype.setLayout = function(
   layout
)
{
   layout = (layout == null) ? XPanel.LAYOUT_STANDARD : layout;

   var spec = this.valueOf();

   spec.layout = layout;

   return layout;
}

//-----------------------------------------------------------------------------

XPanel.prototype.setSize = function(
   size
)
{
   size = (size == null) ? XPanel.SIZE_STANDARD : size;

   var spec = this.valueOf();

   spec.size = size;

   return size;
}

//-----------------------------------------------------------------------------

XPanel.prototype.scrollContent = function(
   scrollContent
)
{
   scrollContent = (scrollContent == null) ? true : scrollContent;

   var spec = this.valueOf();

   spec.scrollContent = scrollContent;

   if (spec.htmlNode)
   {
      var iframe = $(spec.id + ".iframe");
      if (iframe)
      {
         iframe.scrolling = (scrollContent) ? "yes" : "no";
         iframe.contentWindow.document.body.scroll = iframe.scrolling;
      }
   }

   return scrollContent;
}

//-----------------------------------------------------------------------------

XPanel.prototype.getSelectedText = function()
{

   var spec = this.valueOf();

   var selectedText = "";

   if (spec.htmlNode)
   {
      var iframe = $(spec.id + ".iframe");
      if (iframe)
      {
         if(iframe.contentWindow.document.selection)
            selectedText = iframe.contentWindow.document.selection.createRange().text;
         else if (iframe.contentWindow.getSelection)
            selectedText = iframe.contentWindow.getSelection();
         else if (iframe.contentWindow.document.getSelection)
            selectedText = iframe.contentWindow.document.getSelection();
      }
   }

   return selectedText;
}

//-----------------------------------------------------------------------------

XPanel.prototype.focus = function()
{

   var spec = XControl.getSpecFrom(this.valueOf());

   var content = $(spec.id + ".content");
   if (content)
      content.focus();
   else if (spec.htmlNode)
      spec.htmlNode.focus();

}

//-----------------------------------------------------------------------------

XPanel.prototype.configurePositioning = function()
{

   var spec = this.valueOf();

   // Note: The content must be hidden if the height is such that it won't
   //       be fully rendered. If it isn't hidden in this case (on IE6 at
   //       least, things go very awry.

   if (spec.htmlNode)
   {
      var content = $(spec.id + ".content");
      if (content)
      {
         var contentVisible = true;
         if (spec.height && typeof(spec.height) == "number")
         {
            if (spec.maximized)
               contentVisible = true;
            else if (spec.minimized)
               contentVisible = false;
            else if ((spec.height - this.getHeaderHeight() - spec.toolbarHeight) < 5)
               contentVisible = false;
         }

         XUI(content).setRuntimeStyle("display", (contentVisible) ? "block" : "none");
      }
   }

}

//-----------------------------------------------------------------------------

XPanel.prototype.toHTML = function()
{

   var spec = this.valueOf();

   var offsetWidth = null;
   if (XApp.isBrowser("MSIE", null, 7.0) && spec.left && spec.left != "auto" && spec.right && spec.right != "auto")
      offsetWidth = spec.left + spec.right;
   var offsetHeight = null;
   if (XApp.isBrowser("MSIE", null, 7.0) && spec.top && spec.top != "auto" && spec.bottom && spec.bottom != "auto")
      offsetHeight = spec.top + spec.bottom;

   var controlHTML = "";

   controlHTML += "<div " +
      "id=\"" + spec.id + "\" " +
      "class=\"" + spec.className + ((spec.hideBorder) ? "" : " Border1") + "\" " +
      "style=\"" +
         "display: " + ((spec.visible) ? "block" : "none") + "; " +
         ((spec.left) ? "left: " + XUtils.dimText(spec.left) + "; " : "") +
         ((spec.top) ? "top: " + XUtils.dimText(spec.top) + "; " : "") +
         ((spec.right) ? "right: " + XUtils.dimText(spec.right) + "; " : "") +
         ((spec.bottom) ? "bottom: " + XUtils.dimText(spec.bottom) + "; " : "") +
         ((offsetWidth != null) ? "_width: expression($('" + spec.id + "').parentNode.style.pixelWidth - " + offsetWidth + "); " : "") +
         ((spec.width) ? "width: " + XUtils.dimText(spec.width) + "; " : "") +
         ((offsetHeight != null) ? "_height: expression($('" + spec.id + "').parentNode.style.pixelHeight - "+ offsetHeight  + "); " : "") +
         ((spec.height) ? "height: " + XUtils.dimText(spec.height) + "; " : "") +
      "\" " +
   ">";
      if (spec.showHeader)
      {
         controlHTML += "<div " +
            "id=\"" + spec.id + ".header\" " +
            "class=\"" + spec.className + "Header" + ((this.getHeaderHeight() > 21) ? " HeaderTall TextHeaderTall" : " Header TextHeader") + "\" " +
            "style=\"" +
               "padding-top: " + Math.floor((this.getHeaderHeight() - 21)/2) + "px; " +
               "height: " + XUtils.dimText(this.getHeaderHeight()) + "; " +
            "\">";
            controlHTML += "<span " +
               "id=\"" + spec.id + ".header.left\" " +
               "class=\"" + spec.className + "HeaderLeft\" " +
            ">";
               if (spec.showHistory)
               {
                  controlHTML += "<span " +
                     "id=\"" + spec.id + ".history\" " +
                     "class=\"" + spec.className + "History InlineBlock\" " +
                     "style=\"" +
                     "\" " +
                  ">";
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".goBackImage\" " +
                        "class=\"" + spec.className + "HistoryButton\" " +
                        ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 1) + "\" " : "") +
                        "src=\"" + "/app/pkgs/xfw/images/GoBackButton.gif" + "\" " +
                        "style=\"" +
                           "display: " + ((spec.backHistory.length > 0) ? "inline" : "none") + "; " +
                        "\" " +
                        "title=\"Go back\" " +
                        "onclick=\"XControl.controls['" + spec.id + "'].doGoBack(event)\" " +
                        "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_GO_BACK)\" " +
                     "/>";
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".goBackDisabledImage\" " +
                        "class=\"" + spec.className + "HistoryButton-Disabled\" " +
                        ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 2) + "\" " : "") +
                        "src=\"" + "/app/pkgs/xfw/images/GoBackButton.Disabled.gif" + "\" " +
                        "style=\"" +
                           "display: " + ((spec.backHistory.length > 0) ? "none" : "inline") + "; " +
                        "\" " +
                        "title=\"Go back\" " +
                     "/>";
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".goForwardImage\" " +
                        "class=\"" + spec.className + "HistoryButton\" " +
                        ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 3) + "\" " : "") +
                        "src=\"" + "/app/pkgs/xfw/images/GoForwardButton.gif" + "\" " +
                        "style=\"" +
                           "display: " + ((spec.forwardHistory.length > 0) ? "inline" : "none") + "; " +
                        "\" " +
                        "title=\"Go forward\" " +
                        "onclick=\"XControl.controls['" + spec.id + "'].doGoForward(event)\" " +
                        "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_GO_FORWARD)\" " +
                     "/>";
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".goForwardDisabledImage\" " +
                        "class=\"" + spec.className + "HistoryButton-Disabled\" " +
                        ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 4) + "\" " : "") +
                        "src=\"" + "/app/pkgs/xfw/images/GoForwardButton.Disabled.gif" + "\" " +
                        "style=\"" +
                           "display: " + ((spec.forwardHistory.length > 0) ? "none" : "inline") + "; " +
                        "\" " +
                        "title=\"Go forward\" " +
                     "/>";
                  controlHTML += "</span>";
               }
               if (XString(this.homeURL).isSomething())
               {
                  controlHTML += "<span " +
                     "id=\"" + spec.id + ".home\" " +
                     "class=\"" + spec.className + "Home InlineBlock\" " +
                     "style=\"" +
                     "\" " +
                     "onmouseover=\"XUI.doHighlight(event,'" + spec.id + ".goHomeImage')\" " +
                     "onmouseout=\"XUI.doUnhighlight(event,'" + spec.id + ".goHomeImage')\" " +
                     "onclick=\"XControl.controls['" + spec.id + "'].doGoHome(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_GO_HOME)\" " +
                  ">";
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".goHomeImage\" " +
                        "class=\"" + spec.className + "GoHomeButton\" " +
                        ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 5) + "\" " : "") +
                        "src=\"" + "/app/pkgs/xfw/images/HomeButton.gif" + "\" " +
                        "style=\"" +
                        "\" " +
                        "title=\"Go home\" " +
                     "/>";
                     controlHTML += "<span " +
                        "class=\"" + spec.className + "GoHomeText Accent\" " +
                     ">Home</span>";
                  controlHTML += "</span>";
               }
               if (spec.allowExpand)
               {
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".expandButton\" " +
                     "class=\"" + spec.className + "HeaderButton\" " +
                     ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 8) + "\" " : "") +
                     "src=\"" + "/app/pkgs/xfw/images/ExpandButton.gif" + "\" " +
                     "style=\"" +
                        "display: " + ((spec.expanded) ? "none" : XUI.INLINE_BLOCK_DISPLAY ) + "; " +
                     "\" " +
                     "title=\"Expand\" " +
                     ((XApp.isBrowser("MSIE")) ? "onmouseenter=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'expandButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseover=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'expandButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseout=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'expandButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseleave=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'expandButton')\" " : "") +
                     "onclick=\"XControl.controls['" + spec.id + "'].doExpand(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_EXPAND)\" " +
                  "/>";
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".collapseButton\" " +
                     "class=\"" + spec.className + "HeaderButton\" " +
                     ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 9) + "\" " : "") +
                     "src=\"" + "/app/pkgs/xfw/images/CollapseButton.gif" + "\" " +
                     "style=\"" +
                        "display: " + ((spec.expanded) ? XUI.INLINE_BLOCK_DISPLAY : "none" ) + "; " +
                     "\" " +
                     "title=\"Collapse\" " +
                     ((XApp.isBrowser("MSIE")) ? "onmouseenter=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'collapseButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseover=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'collapseButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseout=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'collapseButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseleave=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'collapseButton')\" " : "") +
                     "onclick=\"XControl.controls['" + spec.id + "'].doCollapse(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_COLLAPSE)\" " +
                  "/>";
               }
               if (this.getTitleHTML)
                  controlHTML += this.getTitleHTML(this);
               else
               {
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".titleIcon\" " +
                     "class=\"" + spec.className + "TitleIcon LinkImage\" " +
                     "style=\"" +
                        "display: none; " +
                     "\" " +
                     "src=\"" + "/app/pkgs/xfw/images/Blank.gif\" " +
                     "title=\"\" " +
                     "onclick=\"XControl.controls['" + spec.id + "'].doTitleIconClick(event)\" " +
                  "/>";
                  controlHTML += "<span " +
                     "id=\"" + spec.id + ".title\" " +
                     "class=\"" + spec.className + ((spec.allowExpand) ? "Title-Expand" : "Title") + " InlineBlock\" " +
                     "style=\"" +
                        "top: " + ((this.getHeaderHeight() > 21) ? "0" : "2") + "px; " +
                     "\" " +
                     ((spec.allowExpand) ? "title=\"Expand/Collapse\" " : "") +
                     ((spec.allowExpand) ? "onclick=\"XControl.controls['" + spec.id + "'].doToggleExpand()\" " : "") +
                  ">";
                     controlHTML += (spec.title != null) ? spec.title : "";
                  controlHTML += "</span>";
               }
            controlHTML += "</span>";
            controlHTML += "<span " +
               "id=\"" + spec.id + ".header.right\" " +
               "class=\"" + spec.className + "HeaderRight\" " +
               "style=\"" +
                  "height: " + XUtils.dimText(this.getHeaderHeight()) + "; " +
               "\" " +
            ">";
               controlHTML += "<span " +
                  "id=\"" + spec.id + ".info\" " +
                  "class=\"" + spec.className + "Info\" " +
                  "style=\"" +
                     "top: " + ((this.getHeaderHeight() > 21) ? "0" : "2") + "px; " +
                  "\" " +
               ">";
                  controlHTML += (spec.info != null) ? spec.info : "";
               controlHTML += "</span>";
               controlHTML += "<span " +
                  "id=\"" + spec.id + ".headerToolbar\" " +
                  "class=\"" + spec.className + "HeaderToolbar\" " +
                  "style=\"" +
                     "display: " +  ((spec.showHeaderToolbar) ? "inline" : "none") + "; " +
                  "\" " +
               ">";
                  if (spec.showPrint)
                  {
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".printer\" " +
                        "class=\"" + spec.className + "HeaderButton\" " +
                        "style=\"" +
                        "\" " +
                        "src=\"" + "/app/pkgs/xfw/images/Printer.gif" + "\" " +
                        "title=\"Show printer friendly text\" " +
                        "onClick=\"XControl.controls['" + spec.id + "'].showPrintText()\" " +
                     "/>";
                  }
                  if (spec.showMailto)
                  {
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".mailer\" " +
                        "class=\"" + spec.className + "HeaderButton\" " +
                        "style=\"" +
                        "\" " +
                        "src=\"" + "/app/pkgs/xfw/images/Mailto.gif" + "\" " +
                        "title=\"Send link to someone\" " +
                        "onClick=\"XControl.controls['" + spec.id + "'].mailto()\" " +
                     "/>";
                  }
                  if (spec.showPermalink)
                  {
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".permalink\" " +
                        "class=\"" + spec.className + "HeaderButton\" " +
                        "style=\"" +
                        "\" " +
                        "src=\"" + "/app/pkgs/xfw/images/Permalink.gif" + "\" " +
                        "title=\"Get a permalink\" " +
                        "onClick=\"XControl.controls['" + spec.id + "'].doGrabPermalink(event)\" " +
                     "/>";

                  }
                  if (spec.showDelicious)
                  {
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".delicious\" " +
                        "class=\"" + spec.className + "HeaderButton\" " +
                        "style=\"" +
                        "\" " +
                        "src=\"" + "/app/pkgs/xfw/images/Delicious.gif" + "\" " +
                        "title=\"Save to Del.icio.us\" " +
                        "onClick=\"XControl.controls['" + spec.id + "'].doSaveTo(event,'delicious')\" " +
                     "/>";

                  }
                  if (spec.showBlogThis)
                  {
                     controlHTML += "<img " +
                        "id=\"" + spec.id + ".blogger\" " +
                        "class=\"" + spec.className + "HeaderButton\" " +
                        "style=\"" +
                        "\" " +
                        "src=\"" + "/app/pkgs/xfw/images/Blogger.gif" + "\" " +
                        "title=\"BlogThis!\" " +
                        "onClick=\"XControl.controls['" + spec.id + "'].doSaveTo(event,'blogger')\" " +
                     "/>";

                  }
                  if (spec.showHighlighter)
                  {
                     controlHTML += "<span " +
                        "id=\"" + spec.id + ".highlighter\" " +
                        "class=\"" + spec.className + "Highlighter TextInput\" " +
                        "style=\"" +
                        "\" " +
                        "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_HIGHLIGHT)\" " +
                     ">";
                        controlHTML += "<span " +
                           "class=\"" + spec.className + "HighlightInner\" " +
                           "style=\"" +
                           "\" " +
                        ">";
                           controlHTML += "<input " +
                              "type=\"text\" " +
                              "id=\"" + spec.id + ".highlightInput\" " +
                              "class=\"" + spec.className + "HighlightInput Input\" " +
                              ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 6) + "\" " : "") +
                              "size=\"12\" " +
                              "value=\"highlighter\" " +
                              "onfocus=\"XControl.controls['" + spec.id + "'].doSelectHighlightWords()\" " +
                              "onblur=\"XControl.controls['" + spec.id + "'].doHighlightWords()\" " +
                           "/>";
                           controlHTML += "<img " +
                              "id=\"" + spec.id + ".highlightButton\" " +
                              "class=\"" + spec.className + "HighlightButton\" " +
                              ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 7) + "\" " : "") +
                              "src=\"" + "/app/pkgs/xfw/images/HighlightButton.gif" + "\" " +
                              "style=\"" +
                                 ((XApp.isBrowser("Firefox", null, 2.9)) ? "top: 7px; " : "top: 2px;") +
                                 ((XApp.isBrowser("Firefox", null, 2.9)) ? "right: 28px; " : "right: 4px;") +
                              "\" " +
                              "title=\"Highlight (Ctrl-Y)\" " +
                              "onclick=\"XControl.controls['" + spec.id + "'].doHighlightWords()\" " +
                              "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_HIGHLIGHT)\" " +
                           "/>";
                        controlHTML += "</span>";
                     controlHTML += "</span>";
                  }
               controlHTML += "</span>";
               if (spec.allowMinimize)
               {
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".minimizeButton\" " +
                     "class=\"" + spec.className + "Button\" " +
                     ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 10) + "\" " : "") +
                     "src=\"" + "/app/pkgs/xfw/images/MinimizeButton.gif" + "\" " +
                     "style=\"" +
                        "display: " + XUI.INLINE_BLOCK_DISPLAY + "; " +
                     "\" " +
                     "title=\"Minimize\" " +
                     ((XApp.isBrowser("MSIE")) ? "onmouseenter=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'minimizeButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseover=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'minimizeButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseout=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'minimizeButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseleave=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'minimizeButton')\" " : "") +
                     "onclick=\"XControl.controls['" + spec.id + "'].doMinimize(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_MINIMIZE)\" " +
                  "/>";
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".deminimizeButton\" " +
                     "class=\"" + spec.className + "HeaderButton\" " +
                     ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 11) + "\" " : "") +
                     "src=\"" + "/app/pkgs/xfw/images/DeminimizeButton.gif" + "\" " +
                     "style=\"" +
                        "display: none; " +
                     "\" " +
                     "title=\"Deminimize\" " +
                     ((XApp.isBrowser("MSIE")) ? "onmouseenter=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'deminimizeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseover=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'deminimizeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseout=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'deminimizeButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseleave=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'deminimizeButton')\" " : "") +
                     "onclick=\"XControl.controls['" + spec.id + "'].doDeminimize(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_DEMINIMIZE)\" " +
                  "/>";
               }
               if (spec.allowMaximize)
               {
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".maximizeButton\" " +
                     "class=\"" + spec.className + "HeaderButton\" " +
                     ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 12) + "\" " : "") +
                     "src=\"" + "/app/pkgs/xfw/images/MaximizeButton.gif" + "\" " +
                     "style=\"" +
                        "display: " + XUI.INLINE_BLOCK_DISPLAY + "; " +
                     "\" " +
                     "title=\"Maximize\" " +
                     ((XApp.isBrowser("MSIE")) ? "onmouseenter=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'maximizeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseover=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'maximizeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseout=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'maximizeButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseleave=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'maximizeButton')\" " : "") +
                     "onclick=\"XControl.controls['" + spec.id + "'].doMaximize(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_MAXIMIZE)\" " +
                  "/>";
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".demaximizeButton\" " +
                     "class=\"" + spec.className + "HeaderButton\" " +
                     ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 13) + "\" " : "") +
                     "src=\"" + "/app/pkgs/xfw/images/DemaximizeButton.gif" + "\" " +
                     "style=\"" +
                        "display: none; " +
                     "\" " +
                     "title=\"Demaximize\" " +
                     ((XApp.isBrowser("MSIE")) ? "onmouseenter=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'demaximizeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseover=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'demaximizeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseout=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'demaximizeButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseleave=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'demaximizeButton')\" " : "") +
                     "onclick=\"XControl.controls['" + spec.id + "'].doDemaximize(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_DEMAXIMIZE)\" " +
                  "/>";
               }
               if (spec.allowClose)
               {
                  controlHTML += "<img " +
                     "id=\"" + spec.id + ".closeButton\" " +
                     "class=\"" + spec.className + "HeaderButton\" " +
                     ((spec.tabIndex != null) ? "tabindex=\"" + (spec.tabIndex + 14) + "\" " : "") +
                     "src=\"" + "/app/pkgs/xfw/images/CloseButton.gif" + "\" " +
                     "style=\"" +
                        "display: " + XUI.INLINE_BLOCK_DISPLAY + "; " +
                     "\" " +
                     "title=\"Close\" " +
                     ((XApp.isBrowser("MSIE")) ? "onmouseenter=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'closeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseover=\"XControl.controls['" + spec.id + "'].doHighlight(event, 'closeButton')\" " : "") +
                     ((!XApp.isBrowser("MSIE")) ? "onmouseout=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'closeButton')\" " : "") +
                     ((XApp.isBrowser("MSIE")) ? "onmouseleave=\"XControl.controls['" + spec.id + "'].doUnhighlight(event, 'closeButton')\" " : "") +
                     "onclick=\"XControl.controls['" + spec.id + "'].doClose(event)\" " +
                     "onkeydown=\"XControl.controls['" + spec.id + "'].doKeyDown(event, XPanel.ACTION_CLOSE)\" " +
                  "/>";
               }
            controlHTML += "</span>";
         controlHTML += "</div>";
      }
      if (this.getToolbarHTML)
         controlHTML += this.getToolbarHTML(this);
      if (this.getContentHTML)
         controlHTML += this.getContentHTML(this);
      else
      {
         var contentVisible = true;
         if ((this.height - this.getHeaderHeight() - spec.toolbarHeight) < 5)
            contentVisible = false;

         controlHTML += "<div " +
            "id=\"" + spec.id + ".content\" " +
            "class=\"" + spec.className + "Content\" " +
            "style=\"" +
               "display: " + ((contentVisible) ? "block" : "none") + "; " +
               "top: " + XUtils.dimText(this.getHeaderHeight() + spec.toolbarHeight + 1) + "; " +
               "_height: expression(XControl.getPixelHeight('" + spec.id + "') - " + (this.getHeaderHeight() + spec.toolbarHeight + 1) + "); " +
            "\">";
         controlHTML += "</div>";
      }
   controlHTML += "</div>";

   return controlHTML;
}

//=============================================================================

