/**
* Classes included in this file:
*     JavaWindow
*     JavaWindow.TitleBar
*     JavaWindow.StatusBar
* This file requires the use of the following files:
*     base.js
*     base_classes.js
**/
// TODO: Implement drag-to-resize functionality.
function JavaWindow(elementId, instanceName, title, imageFolderPath)
{
    /// <summary modifiers="public" type="class" extends="BasicEventObjectBase">This class allows for a "popup" window that is completely javascript based, and does not physically open a new window.</summary>
    /// <remarks>
    /// By default, the image folder path is set to "/images" (path relative to the root of the website). All of the control buttons for the window
    /// are looked for in "/images/javawin_images".
    /// Links, buttons, and on-click handlers within the window content that open another <see cref="JavaWindow"/> instance must call the
    /// Utils.CancelEventBubble(event) method or the opening window's on-click handler will be executed bringing the opening window back to the front
    /// of the window order.
    /// </remarks>
    /// <example>
    /// var v_test = new JavaWindow('test_window', 'v_test', 'My Test JavaWindow');
    /// v_test.Size.Set(300, 200);
    /// v_test.Show();
    /// v_test.SetContent('This is some test content.');
    /// </example>
    /// <param name="elementId"       type="String" optional="false">The ID of the HTML element that contains the content of the <see cref="JavaWindow"/>. If the element does not exist, it will be created the first time the window is shown.</param>
    /// <param name="instanceName"    type="String" optional="false">The name of the instance variable.</param>
    /// <param name="title"           type="String" optional="true">The string displayed in the titlebar of the <see cref="JavaWindow"/>.</param>
    /// <param name="imageFolderPath" type="String" optional="true">The path to the images used by the <see cref="JavaWindow"/>.</param>
    /// <field name="Parent"      type="Object"     modifiers="public">Gets or sets the parent object of the <see cref="JavaWindow"/>.</field>
    /// <field name="ElementId"   type="String"     modifiers="public">Gets or sets the ID of the HTML element that contains the content of the <see cref="JavaWindow"/>. If the element does not exist, it will be created the first time the <see cref="JavaWindow"/> is shown.</field>
    /// <field name="Name"        type="String"     modifiers="public">Gets or sets the name of the instance variable.</field>
    /// <field name="Location"    type="Point"      modifiers="public">Gets or sets the location in the browser window to show the <see cref="JavaWindow"/> at.</fi
    /// <field name="Size"        type="Size"       modifiers="public">Gets or sets the size of the <see cref="JavaWindow"/>.</field>
    /// <field name="Bounds"      type="Rectangle"  modifiers="public">Gets a rectangle that represents the location and size of the <see cref="JavaWindow"/>.</field>
    /// <field name="Centered"    type="Boolean"    modifiers="public">Gets or sets a value indicating if the <see cref="JavaWindow"/> should be centered by default.</field>
    /// <field name="Scrollbar"   type="Boolean"    modifiers="public">Gets or sets a value indicating if the content area of the <see cref="JavaWindow"/> can have scrollbars.</field>
    /// <field name="Border"      type="Border"     modifiers="public">Gets or sets the border of the <see cref="JavaWindow"/>.</field>
    /// <field name="Background"  type="Background" modifiers="public">Gets or sets the background of the <see cref="JavaWindow"/>.</field>
    /// <field name="Padding"     type="Padding"    modifiers="public">Gets or sets the padding of the content area of the <see cref="JavaWindow"/>.</field>
    /// <field name="Font"        type="Font"       modifiers="public">Gets or sets the font information used for the <see cref="JavaWindow"/>.</field>
    /// <field name="ForeColor"   type="String"     modifiers="public">Gets or sets the text color for the <see cref="JavaWindow"/>.</field>
    /// <field name="Cursor"      type="String"     modifiers="public">Gets or sets the cursor of the <see cref="JavaWindow"/>.</field>
    /// <field name="WhiteSpace"  type="String"     modifiers="public">Gets or sets how whitespace is handled by default in the content area of the <see cref="JavaWindow"/>.</field>
    /// <field name="Moveable"    type="Boolean"    modifiers="public">Gets or sets a value indicating if the <see cref="JavaWindow"/> can be moved.</field>
    /// <field name="Visible"     type="Boolean"    modifiers="public">Gets a value indicating if the <see cref="JavaWindow"/> is currently visible.</field>
    /// <field name="IsMinimized" type="Boolean"    modifiers="public">Gets a value indicating if the <see cref="JavaWindow"/> is currently minimized.</field>
    /// <field name="IsMaximized" type="Boolean"    modifiers="public">Gets a value indicating if the <see cref="JavaWindow"/> is currently maximized.</field>
    /// <field name="TitleBar"    type="JavaWindow.TitleBar"  modifiers="public">Gets the title bar for the <see cref="JavaWindow"/>.</field>
    /// <field name="StatusBar"   type="JavaWindow.StatusBar" modifiers="public">Gets the status bar for the <see cref="JavaWindow"/>.</field>
    /// <field name="IsModal"               type="Boolean"    modifiers="public">Gets or sets a value indicating if the <see cref="JavaWindow"/> should display a modal window with a transparent mask over the background.</field>
    /// <field name="ModalBackground"       type="Background" modifiers="public">Gets of sets the background behind the modal <see cref="JavaWindow"/>.</field>
    /// <field name="ModalOpacity"          type="Opacity"    modifiers="public">Gets of sets the opacity for the background behind the modal <see cref="JavaWindow"/>.</field>
    /// <field name="_ContentFlag"          type="Boolean"    modifiers="private">Internal flag used to specify if the window content has already been loaded from it's content div.</field>
    /// <field name="_WindowDivId"          type="String"     modifiers="private">Holds the DIV ID for the main window container.</field>
    /// <field name="_ContentAreaDivId"     type="String"     modifiers="private">Holds the DIV ID for the window's content area.</field>
    /// <field name="_ModalBackgroundDivId" type="String"     modifiers="private">Holds the DIV ID for the background behind the modal window.</field>
    /// <field name="_SizeBackup"           type="Size"       modifiers="private">Holds a backup of the normal size when the window is maximized.</field>
    /// <field name="_LocationBackup"       type="Point"      modifiers="private">Holds a backup of the normal location when the window is maximized.</field>
    /// <event name="Opening"        type="EventHandler" modifiers="public">Occurs right before the <see cref="JavaWindow"/> is opened.</event>
    /// <event name="Opened"         type="EventHandler" modifiers="public">Occurs right after the <see cref="JavaWindow"/> is opened.</event>
    /// <event name="Closing"        type="EventHandler" modifiers="public">Occurs right before the <see cref="JavaWindow"/> is closed.</event>
    /// <event name="Closed"         type="EventHandler" modifiers="public">Occurs right after the <see cref="JavaWindow"/> is closed.</event>
    /// <event name="ContentChanged" type="EventHandler" modifiers="public">Occurs when the content of the <see cref="JavaWindow"/> is changed.</event>
    /// <event name="Move"           type="EventHandler" modifiers="public">Occurs when the <see cref="JavaWindow"/> is moved.</event>
    /// <event name="Resize"         type="EventHandler" modifiers="public">Occurs when the <see cref="JavaWindow"/> is resized.</event>
    /// <event name="Minimized"      type="EventHandler" modifiers="public">Occurs when the <see cref="JavaWindow"/> is minimized.</event>
    /// <event name="Restored"       type="EventHandler" modifiers="public">Occurs when the <see cref="JavaWindow"/> is restored.</event>
    /// <event name="Maximized"      type="EventHandler" modifiers="public">Occurs when the <see cref="JavaWindow"/> is maximized.</event>
    JavaWindow.baseConstructor.call(this);

    if (TypeOf(elementId) != 'String')
    {
        throw new Error('elementId is not a string!');
    }
    if (elementId == null || elementId.length <= 0)
    {
        throw new Error('elementId is null!');
    }
    if (TypeOf(instanceName) != 'String')
    {
        throw new Error('instanceName is not a string!');
    }
    if (instanceName == null || instanceName.length <= 0)
    {
        throw new Error('instanceName is null!');
    }
    if (title && TypeOf(title) != 'String')
    {
        throw new Error('title is not a string!');
    }

    // Properties
    this.Parent = null;
    this.ElementId = String(elementId);
    this.Name = String(instanceName);
    this.Location = new Point(0, 0);
    this.Size = new Size(200, 200);
    this.Bounds = new Rectangle(0, 0, 200, 200);
    this.Centered = true;
    this.Scrollbar = true;
    this.Border = new Border(1, 'solid', '#000000');
    this.Background = new Background('#FFFFFF');
    this.Padding = new Padding(3, 3, 3, 3);
    this.Font = new Font('verdana', '12px');
    this.ForeColor = '#000000';
    this.Cursor = 'default';
    this.WhiteSpace = 'normal';
    this.Moveable = true;
    this.Visible = false;
    this.IsMinimized = false;
    this.IsMaximized = false;
    this.TitleBar = new JavaWindow.TitleBar(this, imageFolderPath);
    this.StatusBar = new JavaWindow.StatusBar(this);
    this.IsModal = false;
    this.ModalBackground = new Background('#666666', null, BackgroundRepeat.None, BackgroundPosition.TopLeft, BackgroundAttachment.Fixed);
    this.ModalOpacity = new Opacity('0.7');

    this.TitleBar.Text = String(title);

    // Main window events.
    this.Opening = null;
    this.Opened = null;
    this.Closing = null;
    this.Closed = null;
    this.ContentChanged = null;
    this.Move = null;
    this.Resize = null;
    this.Minimized = null;
    this.Restored = null;
    this.Maximized = null;
    
    // Confirm window specific events
    this.YesOkClicked = null;
    this.NoCancelClicked = null;

    // Internal use.
    this._ContentFlag = false;
    this._WindowDivId = '';
    this._ContentAreaDivId = '';
    this._ModalBackgroundDivId = '';
    this._SizeBackup = new Size(0, 0);
    this._LocationBackup = new Point(0, 0);
    this.__Order = -1;
    this._ScrollCache = null;

    return;
}

// Inherit from the BasicEventObjectBase object.
Extend(JavaWindow, BasicEventObjectBase);

/*****************
* Event Handlers *
*****************/

JavaWindow.prototype.OnOpening = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Opening"/> event.</summary>
    if (this.Opening)
    {
        this.Opening(this);
    }
    return;
}

JavaWindow.prototype.OnOpened = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Opened"/> event.</summary>
    if (this.Opened)
    {
        this.Opened(this);
    }
    return;
}

JavaWindow.prototype.OnClosing = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Closing"/> event.</summary>
    if (this.Closing)
    {
        this.Closing(this);
    }
    return;
}

JavaWindow.prototype.OnClosed = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Closed"/> event.</summary>
    if (this.Closed)
    {
        this.Closed(this);
    }
    return;
}

JavaWindow.prototype.OnContentChanged = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.ContentChanged"/> event.</summary>
    if (this.ContentChanged)
    {
        this.ContentChanged(this);
    }
    return;
}

JavaWindow.prototype.OnMove = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Move"/> event.</summary>
    if (this.Move)
    {
        this.Move(this);
    }
    return;
}

JavaWindow.prototype.OnResize = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Resize"/> event.</summary>
    if (this.Resize)
    {
        this.Resize(this);
    }
    return;
}

JavaWindow.prototype.OnMinimized = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Minimized"/> event.</summary>
    if (this.Minimized)
    {
        this.Minimized(this);
    }
    return;
}

JavaWindow.prototype.OnRestored = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Restored"/> event.</summary>
    if (this.Restored)
    {
        this.Restored(this);
    }
    return;
}

JavaWindow.prototype.OnMaximized = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.Maximized"/> event.</summary>
    if (this.Maximized)
    {
        this.Maximized(this);
    }
    return;
}

JavaWindow.prototype.OnMouseDown = function(e)
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.MouseDown"/> event.</summary>
    this.BringToFront();
    JavaWindow.superClass.OnMouseDown.call(this, e);
    return;
}

JavaWindow.prototype.OnYesOkClicked = function(text)
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.YesOkClicked"/> event.</summary>
    if (this.YesOkClicked)
    {
        this.YesOkClicked(this, text);
    }
    return;
}

JavaWindow.prototype.OnNoCancelClicked = function()
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.NoCancelClicked"/> event.</summary>
    if (this.NoCancelClicked)
    {
        this.NoCancelClicked(this);
    }
    return;
}

/*****************
* Public Methods *
*****************/

JavaWindow.prototype.GetType = function()
{
    /// <summary modifiers="public">Gets the current object type.</summary>
    /// <returns type="String">The current object type.</returns>
    return 'JavaWindow';
}

JavaWindow.prototype.GetHashCode = function()
{
    /// <summary modifiers="public">Gets a hash code that represents this object instance.</summary>
    /// <returns type="String">A hash code that represents this object instance.</returns>
    return this.Name;
}

JavaWindow.prototype.ToString = function()
{
    /// <summary modifiers="public">Gets a string that represents this object instance.</summary>
    /// <returns type="String">A string that represents this object instance.</returns>
    return 'JavaWindow: ' + this.Name;
}

JavaWindow.prototype.SendToBack = function()
{
    /// <summary modifiers="public">Sends the window to the back of all other <see cref="JavaWindow"/> instances.</summary>
    if (!this.Visible)
    {
        return;
    }
    if (this.__Order == 0)
    {
        return; // Already at the back.
    }
    // We only need to do something if there is more than one window visible.
    if (JavaWindow.__Windows.length > 1)
    {
        // Increase the order of all windows under the current one.
        for (var i = 0; i < this.__Order; i++)
        {
            JavaWindow.__Windows[i].__Order++;
        }
        JavaWindow.__Windows.RemoveAt(this.__Order);
        JavaWindow.__Windows.unshift(this);
        this.__Order = 0;
        JavaWindow.__UpdateZIndexes();
    }
    return;
}

JavaWindow.prototype.BringToFront = function()
{
    /// <summary modifiers="public">Brings the window to the front of all other <see cref="JavaWindow"/> instances.</summary>
    if (!this.Visible)
    {
        return;
    }
    if (this.__Order + 1 == JavaWindow.__Windows.length)
    {
        return; // Already at the front.
    }
    // We only need to do something if there is more than one window visible.
    if (JavaWindow.__Windows.length > 1)
    {
        // Decrease the order of all windows on top of the current one.
        for (var i = this.__Order + 1; i < JavaWindow.__Windows.length; i++)
        {
            JavaWindow.__Windows[i].__Order--;
        }
        JavaWindow.__Windows.RemoveAt(this.__Order);
        this.__Order = JavaWindow.__Windows.Add(this);
        JavaWindow.__UpdateZIndexes();
    }
    return;
}

JavaWindow.prototype.ScrollToTop = function()
{
    /// <summary modifiers="public">Scrolls the <see cref="JavaWindow"/> content area to the top of the content.</summary>
    if (!this.Visible)
    {
        return;
    }
    var v_element = $(this._ContentAreaDivId);
    if (v_element == null)
    {
        throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
    }
    v_element.scrollTop = 0;
    return;
}

JavaWindow.prototype.ScrollToBottom = function()
{
    /// <summary modifiers="public">Scrolls the <see cref="JavaWindow"/> content area to the bottom of the content.</summary>
    if (!this.Visible)
    {
        return;
    }
    var v_element = $(this._ContentAreaDivId);
    if (v_element == null)
    {
        throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
    }
    v_element.scrollTop = v_element.scrollHeight;
    return;
}

JavaWindow.prototype.GetClientSize = function()
{
    /// <summary modifiers="public">Gets the size of the client content area of the <see cref="JavaWindow"/>.</summary>
    /// <returns type="Size">The size of the client content area.</returns>
    var v_size = new Size(0, 0);
    v_size.Width = this.Size.Width - this.Padding.Left - this.Padding.Right - 2;
    v_size.Height = this.Size.Height - this.TitleBar.GetHeight() - this.StatusBar.GetHeight() - this.Padding.Bottom - this.Padding.Top - 2;
    return v_size;
}

JavaWindow.prototype.SetClientSize = function(width, height)
{
    /// <summary modifiers="public">Sets the size of the client content area of the <see cref="JavaWindow"/>.</summary>
    /// <param name="width" type="Number" optional="false">The width to resize the <see cref="JavaWindow"/> to.</param>
    /// <param name="height" type="Number" optional="false">The height to resize the <see cref="JavaWindow"/> to.</param>
    if (TypeOf(width) != 'Number')
    {
        throw new Error('width is not a number!');
    }
    if (TypeOf(height) != 'Number')
    {
        throw new Error('height is not a number!');
    }
    var v_size = new Size(0, 0);
    v_size.Width = width + this.Padding.Left + this.Padding.Right + (this.Border.Width * 2);
    v_size.Height = height + this.TitleBar.GetHeight() + this.StatusBar.GetHeight() + this.Padding.Bottom + this.Padding.Top + (this.Border.Width * 2);
    this.ResizeTo(v_size.Width, v_size.Height);
    return;
}

JavaWindow.prototype.MoveTo = function(x, y)
{
    /// <summary modifiers="public">Moves the <see cref="JavaWindow"/> to the specified coordinates.</summary>
    /// <param name="x" type="Number" optional="false">The x-coordinate to move the <see cref="JavaWindow"/> to in the browser window.</param>
    /// <param name="y" type="Number" optional="false">The y-coordinate to move the <see cref="JavaWindow"/> to in the browser window.</param>
    if (TypeOf(x) != 'Number')
    {
        throw new Error('x is not a number!');
    }
    if (TypeOf(y) != 'Number')
    {
        throw new Error('y is not a number!');
    }
    if (this.IsMaximized)
    {
        this._LocationBackup.Set(x, y);
        return;
    }
    this.SetBounds(x, y, this.Size.Width, this.Size.Height);
    return;
}

JavaWindow.prototype.ResizeTo = function(width, height)
{
    /// <summary modifiers="public">Resizes the <see cref="JavaWindow"/> to the specified size.</summary>
    /// <param name="width" type="Number" optional="false">The width of the new size of the <see cref="JavaWindow"/>.</param>
    /// <param name="height" type="Number" optional="false">The height of the new size of the <see cref="JavaWindow"/>.</param>
    if (TypeOf(width) != 'Number')
    {
        throw new Error('width is not a number!');
    }
    if (TypeOf(height) != 'Number')
    {
        throw new Error('height is not a number!');
    }
    if (this.IsMaximized)
    {
        this._SizeBackup.Set(width, height);
        return;
    }
    this.SetBounds(this.Location.X, this.Location.Y, width, height);
    return;
}

JavaWindow.prototype.CenterWindow = function()
{
    /// <summary modifiers="public">Centers the <see cref="JavaWindow"/> to the browser window.</summary>
    var v_browser_size = Utils.GetBrowserSize();
    var v_size = this.IsMaximized ? this._SizeBackup : this.Size;
    var v_x = Math.floor((v_browser_size.Width - v_size.Width) / 2);
    var v_y = Math.floor((v_browser_size.Height - v_size.Height) / 2);
    if (Utils.IsIE && !Utils.IsIE7 && !Utils.IsIE8 && !this.IsModal) // need to check for modal because it sets overflow to hidden which changes the scroll offsets
    {
        var v_scroll_offset = Utils.GetPageScrollOffest();
        v_x += v_scroll_offset.X;
        v_y += v_scroll_offset.Y;
    }
    if (Utils.IsIE6 && this.IsModal)
    {
        v_x += this._ScrollCache.X;
        v_y += this._ScrollCache.Y;
    }
    this.SetBounds(v_x < 0 ? 0 : v_x, v_y < 0 ? 0 : v_y, v_size.Width, v_size.Height);
    return;
}

JavaWindow.prototype.SetBounds = function(x, y, width, height)
{
    /// <summary modifiers="public">Sets the location and size of the <see cref="JavaWindow"/> to the specified coordinates and size.</summary>
    /// <param name="x" type="Number" optional="false">The x-coordinate of the new <see cref="JavaWindow"/> location.</param>
    /// <param name="y" type="Number" optional="false">The y-coordinate of the new <see cref="JavaWindow"/> location.</param>
    /// <param name="width" type="Number" optional="false">The width of the new size of the <see cref="JavaWindow"/>.</param>
    /// <param name="height" type="Number" optional="false">The height of the new size of the <see cref="JavaWindow"/>.</param>
    if (TypeOf(x) != 'Number')
    {
        throw new Error('x is not a number!');
    }
    if (TypeOf(y) != 'Number')
    {
        throw new Error('y is not a number!');
    }
    if (TypeOf(width) != 'Number')
    {
        throw new Error('width is not a number!');
    }
    if (TypeOf(height) != 'Number')
    {
        throw new Error('height is not a number!');
    }

    if (this.IsMaximized)
    {
        this._SizeBackup.Set(width, height);
        this._LocationBackup.Set(x, y);
        return;
    }

    var v_browser_size = Utils.GetBrowserSize();
    var move_flag = this.Location.X != x || this.Location.Y != y;
    var resize_flag = this.Size.Width != width || this.Size.Height != height;

    this.Location.Set(x, y);
    this.Size.Set(width > v_browser_size.Width ? v_browser_size.Width : width, height > v_browser_size.Height ? v_browser_size.Height : height);

    if (this.Visible)
    {
        var v_window_div = $(this._WindowDivId);
        if (v_window_div == null)
        {
            throw new Error('Element with ID of "' + this._WindowDivId + '" does not exist!');
        }
        var v_content_div = $(this._ContentAreaDivId);
        if (v_content_div == null)
        {
            throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
        }

        // Set the location of the window.
        if (move_flag)
        {
            v_window_div.style.left = this.Location.X.ToCssString();
            v_window_div.style.top = this.Location.Y.ToCssString();
            this.OnMove();
        }

        // Set the size of the window.
        if (resize_flag)
        {
            v_window_div.style.width = (this.Size.Width - (this.Border.Width * 2)).ToCssString();
            v_window_div.style.height = (this.Size.Height - (this.Border.Width * 2)).ToCssString();
            var v_csize = this.GetClientSize();
            v_content_div.style.width = v_csize.Width.ToCssString();
            v_content_div.style.height = v_csize.Height.ToCssString();
            this.OnResize();
        }
    }

    this._SetupResizeRectangles();
    return;
}

JavaWindow.prototype.ExecuteContentScripts = function()
{
    /// <summary modifiers="public">Executes any javascript inside of HTML SCRIPT blocks found in the window's content.</summary>
    if (!Ajax || !Ajax.ExecuteScript)
    {
        throw new Error('cls_ajax.js must be included on the page for this functionality.');
    }
    Ajax.ExecuteScript($(this._ContentAreaDivId));
    return;
}

JavaWindow.prototype.SetContent = function(content)
{
    /// <summary modifiers="public">Sets the content of the <see cref="JavaWindow"/> to the specified content string. The content will only be set if the window is currently visible.</summary>
    /// <param name="content" type="String" optional="false">The content string to use for the <see cref="JavaWindow"/> content.</param>
    if (TypeOf(content) != 'String')
    {
        throw new Error('content is not a string!');
    }

    if (this.Visible)
    {
        var v_contentarea = $(this._ContentAreaDivId);
        if (v_contentarea == null)
        {
            throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
        }
        if (!this._ContentFlag)
        {
            var v_content = $(this.ElementId);
            if (v_content == null)
            {
                throw new Error('Element with ID of "' + this.ElementId + '" does not exist!');
            }
            v_content.innerHTML = v_contentarea.innerHTML;
            this._ContentFlag = true;
        }
        v_contentarea.innerHTML = content;
        this.OnContentChanged();
    }
    return;
}

JavaWindow.prototype.Write = function(text)
{
    /// <summary modifiers="public">Writes the specified text to the end of the content of the <see cref="JavaWindow"/>. The text will only be written if the window is currently visible.</summary>
    /// <param name="text" type="String" optional="false">The text to write to the end of the content of the <see cref="JavaWindow"/>.</param>
    if (TypeOf(text) != 'String')
    {
        throw new Error('text is not a string!');
    }
    if (this.Visible)
    {
        var v_contentarea = $(this._ContentAreaDivId);
        if (v_contentarea == null)
        {
            throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
        }
        if (!this._ContentFlag)
        {
            var v_content = $(this.ElementId);
            if (v_content == null)
            {
                throw new Error('Element with ID of "' + this.ElementId + '" does not exist!');
            }
            v_content.innerHTML = v_contentarea.innerHTML;
            this._ContentFlag = true;
        }
        v_contentarea.innerHTML += text;
        this.OnContentChanged();
    }
    return;
}

JavaWindow.prototype.SetCursor = function(cursor)
{
    /// <summary modifiers="public">Sets the cursor of the <see cref="JavaWindow"/> to the specified cursor.</summary>
    /// <param name="cursor" type="String" optional="false">The name of the cursor to use.</param>
    if (TypeOf(cursor) != 'String')
    {
        throw new Error('cursor is not a string!');
    }
    this.Cursor = cursor;
    if (this.Visible)
    {
        var v_win = $(this._WindowDivId);
        if (v_win == null)
        {
            throw new Error('Element with ID of "' + this._WindowDivId + '" does not exist!');
        }
        v_win.style.cursor = this.Cursor;
    }
    return;
}

JavaWindow.prototype.Refresh = function()
{
    /// <summary modifiers="public">Refreshes the <see cref="JavaWindow"/>.</summary>
    if (!this.Visible)
    {
        return;
    }
    var v_window = $(this._WindowDivId);
    if (v_window == null)
    {
        throw new Error('Element with ID of "' + this._WindowDivId + '" does not exist!');
    }
    var v_content_area = $(this._ContentAreaDivId);
    if (v_content_area == null)
    {
        throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
    }
    this._SetWindowDivDomAttributes(v_window);
    this._SetContentDivDomAttributes(v_content_area);
    this.TitleBar.Refresh();
    this.StatusBar.Refresh();
    return;
}

JavaWindow.prototype.Show = function()
{
    /// <summary modifiers="public">Shows the <see cref="JavaWindow"/>.</summary>
    Utils.GetOrCreateElement(this.ElementId, 'div', true); // Make sure that the content element exists.
    if (!this.Visible)
    {
        this.OnOpening();
        this.__Order = JavaWindow.__Windows.Add(this);
        var v_window_div = this._GetContainer();
        v_window_div.appendChild(this.TitleBar.GetDivElement());
        v_window_div.appendChild(this._GetContentArea());
        v_window_div.appendChild(this.StatusBar.GetDivElement());
        if (Utils.IsIE6)
        {
            // Add an iframe to prevent select tags from displaying over the JavaWindow
            v_window_div.style.overflow = 'hidden';
            v_window_div.style.position = 'absolute';
            var v_iframe = document.createElement('iframe');
            v_iframe.src = 'about:blank';
            v_iframe.width = (this.Size.Width).ToCssString();
            v_iframe.height = (this.Size.Height).ToCssString();
            v_iframe.style.position = 'absolute';
            v_iframe.style.top = '-' + (this.Border.Width * 2);
            v_iframe.style.left = '-' + (this.Border.Width * 2);
            v_iframe.style.zIndex = '-1';
            v_window_div.appendChild(v_iframe);
        }
        document.body.appendChild(v_window_div);
        if (this.IsModal)
        {
            if (Utils.IsIE6)
            {
                this._ScrollCache = Utils.GetPageScrollOffest();
            }
            Utils.GetOrCreateElement(this.Name + '_background', 'div', true);
            var v_background_div = this._GetBackground();
            document.body.appendChild(v_background_div);
            document.getElementsByTagName('html')[0].style.overflow = "hidden";
        }
        this.Visible = true;
        this._SetupResizeRectangles();
        this.OnOpened();
    }
    else
    {
        this.BringToFront();
    }
    if (this.IsMinimized)
    {
        this.Restore(true, false);
    }
    if (this.Centered)
    {
        this.CenterWindow();
    }
    return;
}

JavaWindow.prototype.Close = function()
{
    /// <summary modifiers="public">Closes the <see cref="JavaWindow"/> and destroys all references to the HTML elements it created.</summary>
    if (this.Visible)
    {
        this.OnClosing();
        if (this._ContentFlag == false)
        {
            var v_content = $(this.ElementId);
            if (v_content == null)
            {
                throw new Error('Element with ID of "' + this.ElementId + '" does not exist!');
            }
            var v_content_area = $(this._ContentAreaDivId);
            if (v_content_area == null)
            {
                throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
            }
            v_content.innerHTML = v_content_area.innerHTML;
        }
        var v_window = $(this._WindowDivId);
        if (v_window == null)
        {
            throw new Error('Element with ID of "' + this._WindowDivId + '" does not exist!');
        }
        v_window.parentNode.removeChild(v_window);
        if (this.IsModal)
        {
            if (Utils.IsIE6)
            {
                this._ScrollCache = Utils.GetPageScrollOffest();
            }
            var v_background = $(this._ModalBackgroundDivId);
            if (v_background == null)
            {
                throw new Error('Element with ID of "' + this._ModalBackgroundDivId + '" does not exist!');
            }
            v_background.parentNode.removeChild(v_background);
            if (JavaWindow.__Windows.length <= 1)
            {
                document.getElementsByTagName('html')[0].style.overflow = "";
            }
        }
        if (this.__Order + 1 < JavaWindow.__Windows.length)
        {
            for (var i = this.__Order + 1; i < JavaWindow.__Windows.length; i++)
            {
                JavaWindow.__Windows[i].__Order--;
            }
        }
        JavaWindow.__Windows.RemoveAt(this.__Order);
        JavaWindow.__UpdateZIndexes();
        this.OnClosed();
    }
    this._ContentFlag = false;
    this.Visible = false;
    this.Restore(true, false);
    return;
}

JavaWindow.prototype.Minimize = function()
{
    /// <summary modifiers="public">Minimizes the <see cref="JavaWindow"/> by collapsing it into it's title bar.</summary>
    if (!this.IsMinimized)
    {
        if (this.Visible)
        {
            var v_win_div = $(this._WindowDivId);
            if (v_win_div == null)
            {
                throw new Error('Element with ID of "' + this._WindowDivId + '" does not exist!');
            }
            v_win_div.style.height = this.TitleBar.Height.ToCssString();
            var v_content = $(this._ContentAreaDivId);
            if (v_content == null)
            {
                throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
            }
            v_content.style.display = 'none';
            var v_status = $(this.StatusBar.Id);
            if (v_status == null)
            {
                throw new Error('Element with ID of "' + this.StatusBar.Id + '" does not exist!');
            }
            v_status.style.display = 'none';
        }
        this.TitleBar.MinimizeButton.IconNormal = this.TitleBar.ImageFolderPath + '/javawin_images/button_res_min.gif';
        this.TitleBar.MinimizeButton.AltText = '+';
        this.TitleBar.MinimizeButton.TitleText = 'Restore (Minimize)';
        this.TitleBar.MinimizeButton.Refresh();
        this.IsMinimized = true;
        this.OnMinimized();
    }
    return;
}

JavaWindow.prototype.Maximize = function()
{
    /// <summary modifiers="public">Maximizes the <see cref="JavaWindow"/> to the current visible area of the browser window.</summary>
    if (this.IsMinimized)
    {
        this.Restore(true, false);
    }
    if (!this.IsMaximized)
    {
        this._SizeBackup.Set(this.Size.Width, this.Size.Height);
        this._LocationBackup.Set(this.Location.X, this.Location.Y);
        if (this.Visible)
        {
            var v_browser_size = Utils.GetBrowserSize();
            var v_scrollbar_width = this.IsModal ? 0 : Utils.GetScrollBarWidth();
            var v_offset = Utils.IsIE6 ? Utils.GetPageScrollOffest() : new Point(0, 0);
            this.SetBounds(v_offset.X, v_offset.Y, v_browser_size.Width - v_scrollbar_width - 1, v_browser_size.Height - v_scrollbar_width - 1);
        }
        this.TitleBar.MaximizeButton.IconNormal = this.TitleBar.ImageFolderPath + '/javawin_images/button_res_max.gif';
        this.TitleBar.MaximizeButton.AltText = '-';
        this.TitleBar.MaximizeButton.TitleText = 'Restore (Maximize)';
        this.TitleBar.MaximizeButton.Refresh();
        this.IsMaximized = true;
        this.OnMaximized();
    }
    return;
}

JavaWindow.prototype.Restore = function(minimize, maximize)
{
    /// <summary modifiers="public">Restores the <see cref="JavaWindow"/> to it's normal dimensions.</summary>
    /// <param name="minimize" type="Boolean" optional="false">When true, if the window is minimized then it will be expanded back out from the title bar.</param>
    /// <param name="maximize" type="Boolean" optional="false">When true, if the window is maximized then it will be restored to it's normal size.</param>
    minimize = TypeOf(minimize) == 'Boolean' ? minimize : true;
    maximize = TypeOf(maximize) == 'Boolean' ? maximize : true;
    if (this.IsMaximized && this.IsMinimized && maximize)
    {
        minimize = true;
    }
    if (this.IsMinimized && minimize)
    {
        this.IsMinimized = false;
        this.TitleBar.MinimizeButton.IconNormal = this.TitleBar.ImageFolderPath + '/javawin_images/button_min.gif';
        this.TitleBar.MinimizeButton.AltText = '_';
        this.TitleBar.MinimizeButton.TitleText = 'Minimize';
        if (this.Visible)
        {
            var v_win_div = $(this._WindowDivId);
            if (v_win_div == null)
            {
                throw new Error('Element with ID of "' + this._WindowDivId + '" does not exist!');
            }
            v_win_div.style.height = (this.Size.Height - (this.Border.Width * 2)).ToCssString();
            var v_content = $(this._ContentAreaDivId);
            if (v_content == null)
            {
                throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
            }
            v_content.style.display = 'block';
            var v_status = $(this.StatusBar.Id);
            if (v_status == null)
            {
                throw new Error('Element with ID of "' + this.StatusBar.Id + '" does not exist!');
            }
            v_status.style.display = 'block';
            this.TitleBar.MinimizeButton.Refresh();
            this.OnRestored();
        }
    }
    if (this.IsMaximized && maximize)
    {
        this.IsMaximized = false;
        this.TitleBar.MaximizeButton.IconNormal = this.TitleBar.ImageFolderPath + '/javawin_images/button_max.gif';
        this.TitleBar.MaximizeButton.AltText = '[]';
        this.TitleBar.MaximizeButton.TitleText = 'Maximize';
        if (this.Visible)
        {
            this.SetBounds(this._LocationBackup.X, this._LocationBackup.Y, this._SizeBackup.Width, this._SizeBackup.Height);
            this.TitleBar.MaximizeButton.Refresh();
            this.OnRestored();
        }
        else
        {
            this.Location.Set(this._LocationBackup.X, this._LocationBackup.Y);
            this.Size.Set(this._SizeBackup.Width, this._SizeBackup.Height);
        }
    }
    return;
}

JavaWindow.prototype.MinToggle = function()
{
    /// <summary modifiers="public">Toggles the <see cref="JavaWindow"/> between being minimized and normal.</summary>
    if (!this.IsMinimized)
    {
        this.Minimize();
    }
    else
    {
        this.Restore(true, false);
    }
    return;
}

JavaWindow.prototype.MaxToggle = function()
{
    /// <summary modifiers="public">Toggles the <see cref="JavaWindow"/> between being maximized and normal.</summary>
    if (!this.IsMaximized)
    {
        this.Maximize();
    }
    else
    {
        this.Restore(false, true);
    }
    return;
}

JavaWindow.__AlertWindow = null;
JavaWindow.Alert = function(text, options, okCallback)
{
    /// <summary modifiers="public static">Creates and displays a <see ref="JavaWindow"/> alert window, just like the javascript alert() function.</summary>
    /// <param name="text" type="String" optional="false">The text to display in the alert window.</param>
    /// <param name="options" type="Object" optional="true">The options object for the <see ref="JavaWindow"/> alert window.</param>
    if (JavaWindow.__AlertWindow == null)
    {
        JavaWindow.__AlertWindow = new JavaWindow('jw_alert_window', 'JavaWindow.__AlertWindow', 'The page says:');
    }
    if (JavaWindow.__AlertWindow.Visible)
    {
        JavaWindow.__AlertWindow.Close();
    }
    var v_calc_height = ((1 + text.Count('\n') + text.Count('<br />')) * 15) + 45 + JavaWindow.__AlertWindow.TitleBar.Height + (JavaWindow.__AlertWindow.Border.Width * 3);
    JavaWindow.__AlertWindow.Size.Width = 400;
    JavaWindow.__AlertWindow.Size.Height = v_calc_height > 500 ? 500 : v_calc_height;
    JavaWindow.__AlertWindow.LoadOptions(options);
    JavaWindow.__AlertWindow.IsModal = true;
    JavaWindow.__AlertWindow.YesOkClicked = okCallback;
    JavaWindow.__AlertWindow.Show();
    JavaWindow.__AlertWindow.SetContent(text.replace(/\n/g, '<br />') + '<div style="text-align: center;"><br /><button type="button" onclick="JavaWindow.__AlertWindow.OnYesOkClicked(); JavaWindow.__AlertWindow.Close();">OK</button></div>');
    return JavaWindow.__AlertWindow;
}

JavaWindow.__ConfirmWindow = null;
JavaWindow.Confirm = function(text, options, buttonTypes, yesOkCallback, noCancelCallback)
{
    /// <summary modifiers="public static">Creates and displays a <see ref="JavaWindow"/> confirmation window, similar to the javascript confirm() function.</summary>
    /// <param name="text" type="String" optional="false">The text to display in the confirm window.</param>
    /// <param name="options" type="Object" optional="true">The options object for the <see ref="JavaWindow"/> confirm window.</param>
    /// <param name="buttonTypes" type="Integer">Specifies the type of buttons to show in the confirm box.  0: Yes/No  1: OK/Cancel</param>
    /// <param name="noCancelCallback" type="Function">This function is called when either a No/Cancel button is clicked.</param>
    /// <param name="yesOkCallback" type="Function">This function is called when either a Yes/OK button is clicked.</param>
    if (JavaWindow.__ConfirmWindow == null)
    {
        JavaWindow.__ConfirmWindow = new JavaWindow('jw_confirm_window', 'JavaWindow.__ConfirmWindow', 'The page asks:');
    }
    
    if (JavaWindow.__ConfirmWindow.Visible)
    {
        JavaWindow.__ConfirmWindow.Close();
    }
    
    var v_calc_height = ((1 + text.Count('\n') + text.Count('<br />')) * 15) + 45 + JavaWindow.__ConfirmWindow.TitleBar.Height + (JavaWindow.__ConfirmWindow.Border.Width * 3);
    JavaWindow.__ConfirmWindow.Size.Width = 400;
    JavaWindow.__ConfirmWindow.Size.Height = v_calc_height > 500 ? 500 : v_calc_height;
    JavaWindow.__ConfirmWindow.LoadOptions(options);
    JavaWindow.__ConfirmWindow.IsModal = true;
    JavaWindow.__ConfirmWindow.YesOkClicked = yesOkCallback;
    JavaWindow.__ConfirmWindow.NoCancelClicked = noCancelCallback;
    JavaWindow.__ConfirmWindow.Show();

    var v_button_type = Utils.GetIntValue(buttonTypes);
    var v_output = new StringBuilder();
    v_output.Append(text.replace(/\n/g, '<br />'))
        .Append('<div style="text-align: center;"><br />')
        .Append('<button type="button" onclick="JavaWindow.__ConfirmWindow.OnYesOkClicked(null); JavaWindow.__ConfirmWindow.Close();">').Append(v_button_type == 1 ? 'OK' : 'Yes').Append('</button>&nbsp;&nbsp;')
        .Append('<button type="button" onclick="JavaWindow.__ConfirmWindow.OnNoCancelClicked(); JavaWindow.__ConfirmWindow.Close();">').Append(v_button_type == 1 ? 'Cancel' : 'No').Append('</button>')
        .Append("</div>");
    JavaWindow.__ConfirmWindow.SetContent(v_output.ToString());
    return JavaWindow.__ConfirmWindow;
}

JavaWindow.__PromptWindow = null;
JavaWindow.Prompt = function(text, defaultValue, options, okCallback, cancelCallback)
{
    /// <summary modifiers="public static">Creates and displays a <see ref="JavaWindow"/> prompt window, similar to the javascript prompt() function.</summary>
    /// <param name="text" type="String" optional="false">The text to display in the prompt window.</param>
    /// <param name="defaultValue" type="String" optional="true">The default value of the text box in the prompt window.</param>
    /// <param name="options" type="Object" optional="true">The options object for the <see ref="JavaWindow"/> prompt window.</param>
    /// <param name="okCallback" type="Function">This function is called when the OK button is clicked.</param>
    /// <param name="cancelCallback" type="Function">This function is called when the Cancel button is clicked.</param>
    if (JavaWindow.__PromptWindow == null)
    {
        JavaWindow.__PromptWindow = new JavaWindow('jw_prompt_window', 'JavaWindow.__PromptWindow', 'The page asks:');
    }

    if (JavaWindow.__PromptWindow.Visible)
    {
        JavaWindow.__PromptWindow.Close();
    }

    var v_calc_height = ((1 + text.Count('\n') + text.Count('<br />')) * 15) + 70 + JavaWindow.__PromptWindow.TitleBar.Height + (JavaWindow.__PromptWindow.Border.Width * 3);
    JavaWindow.__PromptWindow.Size.Width = 400;
    JavaWindow.__PromptWindow.Size.Height = v_calc_height > 500 ? 500 : v_calc_height;
    JavaWindow.__PromptWindow.LoadOptions(options);
    JavaWindow.__PromptWindow.IsModal = true;
    JavaWindow.__PromptWindow.YesOkClicked = okCallback;
    JavaWindow.__PromptWindow.NoCancelClicked = cancelCallback;
    JavaWindow.__PromptWindow.Show();

    var v_output = new StringBuilder();
    v_output.Append(text.replace(/\n/g, '<br />'))
        .Append('<br /><input type="text" name="jw_prompt_window_text" id="jw_prompt_window_text" style="width: 98%;" value="').Append(TypeOf(defaultValue) == 'String' ? defaultValue : '').Append('" /><br />')
        .Append('<div style="text-align: center;"><br />')
        .Append('<button type="button" onclick="JavaWindow.__PromptWindow.OnYesOkClicked($(\'jw_prompt_window_text\').value); JavaWindow.__PromptWindow.Close();">OK</button>&nbsp;&nbsp;')
        .Append('<button type="button" onclick="JavaWindow.__PromptWindow.OnNoCancelClicked(); JavaWindow.__PromptWindow.Close();">Cancel</button>')
        .Append("</div>");
    JavaWindow.__PromptWindow.SetContent(v_output.ToString());
    return JavaWindow.__PromptWindow;
}

/******************
* Private Methods *
******************/

JavaWindow.prototype._GetContainer = function()
{
    /// <summary modifiers="private">Gets a handle to the container HTML element for the <see cref="JavaWindow"/>.</summary>
    // Create the window div element.
    this._WindowDivId = this.Name + '_window';
    var v_window_div = $(this._WindowDivId);
    if (v_window_div == null)
    {
        v_window_div = document.createElement('div');
        v_window_div.setAttribute('id', this._WindowDivId);
    }
    this._SetWindowDivDomAttributes(v_window_div);
    return v_window_div;
}

JavaWindow.prototype._SetWindowDivDomAttributes = function(element)
{
    /// <summary modifiers="private">Sets the HTML DOM attributes for the main window container element.</summary>
    /// <param name="element" type="HtmlDOMElement" optional="false">The element to set the HTML DOM properties for.</param>
    // Set the attributes of the window.
    if (Utils.IsIE && !Utils.IsIE7 && !Utils.IsIE8)
    {
        element.style.position = 'absolute';
    }
    else
    {
        element.style.position = 'fixed';
    }
    element.style.display = 'block';
    element.style.border = this.Border.ToCssString();
    element.style.background = this.Background.ToCssString();
    element.style.color = this.ForeColor;
    element.style.font = this.Font.ToCssString();
    element.style.cursor = this.Cursor;
    element.style.margin = '0px;';
    element.style.padding = '0px;';
    element.style.zIndex = (101 + this.__Order).toString();

    // Set the size of the window.
    element.style.width = (this.Size.Width - (this.Border.Width * 2)).ToCssString();
    element.style.height = (this.Size.Height - (this.Border.Width * 2)).ToCssString();

    // Set the location of the window.
    var v_x = this.Location.X;
    var v_y = this.Location.Y;
    var v_browser_size = Utils.GetBrowserSize();
    if (this.Centered)
    {
        v_x = Math.floor((v_browser_size.Width - this.Size.Width) / 2);
        v_y = Math.floor((v_browser_size.Height - this.Size.Height) / 2);
    }
    if (Utils.IsIE)
    {
        var v_scroll_offset = Utils.GetPageScrollOffest();
        v_x += v_scroll_offset.X;
        v_y += v_scroll_offset.Y;
    }
    this.Location.Set(v_x < 0 ? 0 : v_x, v_y < 0 ? 0 : v_y);
    element.style.left = this.Location.X.ToCssString();
    element.style.top = this.Location.Y.ToCssString();
    return;
}

JavaWindow.prototype._GetBackground = function()
{
    /// <summary modifiers="private">Gets a handle to the background HTML element for the <see cref="JavaWindow"/>.</summary>
    // Create the window div element.
    this._ModalBackgroundDivId = this.Name + '_background';
    var v_backgound_div = $(this._ModalBackgroundDivId);
    if (v_backgound_div == null)
    {
        v_backgound_div = document.createElement('div');
        v_backgound_div.setAttribute('id', this._ModalBackgroundDivId);
    }
    this._SetBackgroundDivDomAttributes(v_backgound_div);
    return v_backgound_div;
}

JavaWindow.prototype._SetBackgroundDivDomAttributes = function(element)
{
    /// <summary modifiers="private">Sets the HTML DOM attributes for the background element.</summary>
    /// <param name="element" type="HtmlDOMElement" optional="false">The element to set the HTML DOM properties for.</param>
    // Set the attributes of the background.
    if (Utils.IsIE)
    {
        element.style.filter = this.ModalOpacity.ToCssString();
    }
    else
    {
        element.style.opacity = this.ModalOpacity.ToCssString();
    }
    element.style.position = 'absolute';
    element.style.display = 'block';
    element.style.border = 'none';
    element.style.background = this.ModalBackground.ToCssString();
    element.style.margin = '0px;';
    element.style.padding = '0px;';
    element.style.zIndex = (100 + this.__Order).toString();

    // Set the size of the background.
    var v_browser_size = Utils.GetBrowserSizeWithScoll();
    element.style.width = '100%';
    element.style.minWidth = (v_browser_size.Width - 1).ToCssString();
    element.style.height = (v_browser_size.Height - 1).ToCssString();

    // Set the location of the background.
    if (Utils.IsIE)
    {
        var v_loc = Utils.GetPageScrollOffest();
        element.style.left = v_loc.X.ToCssString();
        element.style.top = v_loc.Y.ToCssString();
    }
    else
    {
        element.style.left = '0';
        element.style.top = '0';
    }
    return;
}

JavaWindow.prototype._GetContentArea = function()
{
    /// <summary modifiers="private">Gets a handle to the content area HTML element for the <see cref="JavaWindow"/>.</summary>
    this._ContentAreaDivId = this.Name + '_content';
    var v_content_div = $(this._ContentAreaDivId);
    if (v_content_div == null)
    {
        v_content_div = document.createElement('div');
        v_content_div.setAttribute('id', this._ContentAreaDivId);
        v_content_div.setAttribute('onclick', this.Name + '.OnClick(event, this);');
        v_content_div.setAttribute('ondblclick', this.Name + '.OnDoubleClick(event, this);');
        v_content_div.setAttribute('onmousedown', this.Name + '.OnMouseDown(event, this);');
        v_content_div.setAttribute('onmouseup', this.Name + '.OnMouseUp(event, this);');
        v_content_div.setAttribute('onmouseover', this.Name + '.OnMouseOver(event, this);');
        v_content_div.setAttribute('onmousemove', this.Name + '.OnMouseMove(event, this);');
        v_content_div.setAttribute('onmouseout', this.Name + '.OnMouseOut(event, this);');
        v_content_div.setAttribute('onkeypress', this.Name + '.OnKeyPress(event, this);');
        v_content_div.setAttribute('onkeydown', this.Name + '.OnKeyDown(event, this);');
        v_content_div.setAttribute('onkeyup', this.Name + '.OnKeyUp(event, this);');
    }
    this._SetContentDivDomAttributes(v_content_div);
    var v_content = $(this.ElementId);
    if (v_content == null)
    {
        throw new Error('Element with ID of "' + this.ElementId + '" does not exist!');
    }
    v_content_div.innerHTML = v_content.innerHTML;
    v_content.innerHTML = '';
    return v_content_div;
}

JavaWindow.prototype._SetContentDivDomAttributes = function(element)
{
    /// <summary modifiers="private">Sets the HTML DOM attributes for the window content area element.</summary>
    /// <param name="element" type="HtmlDOMElement" optional="false">The element to set the HTML DOM properties for.</param>
    element.style.padding = this.Padding.ToCssString();
    element.style.overflow = (this.Scrollbar == true) ? 'auto' : 'hidden';
    var v_csize = this.GetClientSize();
    element.style.width = v_csize.Width.ToCssString();
    element.style.height = v_csize.Height.ToCssString();
    element.style.whiteSpace = this.WhiteSpace;
    return;
}

JavaWindow.prototype._UpdateContentAreaSize = function()
{
    /// <summary modifiers="private">Updates the content area's size.</summary>
    if (!this.Visible)
    {
        return;
    }
    var v_content_div = $(this._ContentAreaDivId);
    if (v_content_div == null)
    {
        throw new Error('Element with ID of "' + this._ContentAreaDivId + '" does not exist!');
    }
    var v_csize = this.GetClientSize();
    v_content_div.style.width = v_csize.Width.ToCssString();
    v_content_div.style.height = v_csize.Height.ToCssString();
    this._SetupResizeRectangles();
    return;
}

JavaWindow.prototype._MoveInternal = function(x, y)
{
    /// <summary modifiers="private">Performs the minimal operations nessecary to move the <see cref="JavaWindow"/> to the specified coordinates (used while draging the window).</summary>
    /// <param name="x" type="Number" optional="false">The x-coordinate of the new <see cref="JavaWindow"/> location.</param>
    /// <param name="y" type="Number" optional="false">The y-coordinate of the new <see cref="JavaWindow"/> location.</param>
    if (this.IsMaximized)
    {
        return;
    }
    this.Location.Set(x, y);
    if (this.Visible)
    {
        var v_window_div = $(this._WindowDivId);
        v_window_div.style.left = this.Location.X.ToCssString();
        v_window_div.style.top = this.Location.Y.ToCssString();
    }
    this._SetupResizeRectangles();
    return;
}

JavaWindow.prototype._SetupResizeRectangles = function()
{
    /// <summary modifiers="private">Sets up the bounds and resize rectangles.</summary>
    this.Bounds.Set(this.Location.X, this.Location.Y, this.Size.Width, this.Size.Height);
    return;
}

JavaWindow.__Windows = new Array();
JavaWindow.__UpdateZIndexes = function()
{
    /// <summary modifiers="private static">Updates the Z-indexes of the visible window instances.</summary>
    for (var i = 0; i < JavaWindow.__Windows.length; i++)
    {
        var v_win = JavaWindow.__Windows[i];
        var v_element = $(v_win._WindowDivId);
        if (v_element == null)
        {
            throw new Error('Element with ID of "' + v_win._WindowDivId + '" does not exist!');
        }
        v_element.style.zIndex = (101 + v_win.__Order).toString();
        if (v_win.IsModal)
        {
            var v_background = $(v_win._ModalBackgroundDivId);
            if (v_background == null)
            {
                throw new Error('Element with ID of "' + v_win._ModalBackgroundDivId + '" does not exist!');
            }
            v_background.style.zIndex = (100 + v_win.__Order).toString();
        }
    }
    return;
}

/**************************************************************************/

JavaWindow.StatusBar = function(parentJavaWindow)
{
    /// <summary modifiers="public" type="class" extends="BasicEventObjectBase">Represents the status bar of a <see cref="JavaWindow"/>.</summary>
    /// <param name="parentJavaWindow" type="JavaWindow" optional="false">The <see cref="JavaWindow"/> that this <see cref="JavaWindow.StatusBar"/> belongs to.</param>
    /// <field name="Parent"     type="JavaWindow" modifiers="public">Gets the parent <see cref="JavaWindow"/> that this <see cref="JavaWindow.StatusBar"/> belongs to.</field>
    /// <field name="Id"         type="String"     modifiers="public">Gets the Id of the HTML element that contains the <see cref="JavaWindow.StatusBar"/>.</field>
    /// <field name="Visible"    type="Boolean"    modifiers="public">Gets or sets a value indicating if the <see cref="JavaWindow.StatusBar"/> is visible.</field>
    /// <field name="Text"       type="String"     modifiers="public">Gets or sets the text of the <see cref="JavaWindow.StatusBar"/>.</field>
    /// <field name="Height"     type="Number"     modifiers="public">Gets or sets the height of the <see cref="JavaWindow.StatusBar"/>.</field>
    /// <field name="Background" type="Background" modifiers="public">Gets or sets the background of the <see cref="JavaWindow.StatusBar"/>.</field>
    /// <field name="Padding"    type="Padding"    modifiers="public">Gets or sets the padding of the <see cref="JavaWindow.StatusBar"/>.</field>
    /// <field name="Font"       type="Font"       modifiers="public">Gets or sets the font of the <see cref="JavaWindow.StatusBar"/>.</field>
    /// <field name="ForeColor"  type="String"     modifiers="public">Gets or sets the text color of the <see cref="JavaWindow.StatusBar"/>.</field>
    /// <field name="Cursor"     type="String"     modifiers="public">Gets or sets the cursor for the <see cref="JavaWindow.StatusBar"/>.</field>
    JavaWindow.StatusBar.baseConstructor.call(this);
    if (parentJavaWindow == null)
    {
        throw new Error('parentJavaWindow is null!');
    }

    this.Parent = parentJavaWindow;
    this.Id = this.Parent.Name + '_statusbar';
    this.Visible = false;
    this.Text = '';
    this.Height = 20;
    this.Background = new Background('#D4D0C8');
    this.Padding = new Padding(1, 1, 1, 1);
    this.Font = new Font('verdana', '12px');
    this.ForeColor = '#000000';
    this.Cursor = 'default';
    return;
}

// Inherit from the BasicEventObjectBase object.
Extend(JavaWindow.StatusBar, BasicEventObjectBase);

JavaWindow.StatusBar.prototype.OnMouseDown = function(e)
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.MouseDown.Click"/> event.</summary>
    this.Parent.BringToFront();
    JavaWindow.StatusBar.superClass.OnMouseDown.call(this, e);
    return;
}

JavaWindow.StatusBar.prototype.GetType = function()
{
    /// <summary modifiers="public">Gets the current object type.</summary>
    /// <returns type="String">The current object type.</returns>
    return 'JavaWindow.StatusBar';
}

JavaWindow.StatusBar.prototype.GetHashCode = function()
{
    /// <summary modifiers="public">Gets a hash code that represents this object instance.</summary>
    /// <returns type="String">A hash code that represents this object instance.</returns>
    return this.Id;
}

JavaWindow.StatusBar.prototype.ToString = function()
{
    /// <summary modifiers="public">Gets a string that represents this object instance.</summary>
    /// <returns type="String">A string that represents this object instance.</returns>
    return this.Text;
}

JavaWindow.StatusBar.prototype.SetText = function(text)
{
    /// <summary modifiers="public">Sets the text of the status bar to the specified text.</summary>
    /// <param name="text" type="String" optional="false">The text to set.</param>
    if (typeof (text) != 'string')
    {
        throw new Error('text is not a string!');
    }

    this.Text = text;
    if (this.Parent != null && this.Visible && this.Parent.Visible)
    {
        var v_element = $(this.Parent.Name + '_statusbar');
        if (v_element == null)
        {
            throw new Error('Element with ID of "' + this.Parent.Name + '_statusbar" does not exist!');
        }
        v_element.innerHTML = this.Text == null ? '' : this.Text;
    }
    return;
}

JavaWindow.StatusBar.prototype.SetCursor = function(cursor)
{
    /// <summary modifiers="public">Sets the cursor of the <see cref="JavaWindow.StatusBar"/> to the specified cursor.</summary>
    /// <param name="cursor" type="String" optional="false">The name of the cursor to set.</param>
    if (TypeOf(cursor) != 'String')
    {
        throw new Error('cursor is not a string!');
    }
    this.Cursor = cursor;
    if (this.Visible)
    {
        var v_div = $(this.Id);
        if (v_div == null)
        {
            throw new Error('Element with ID of "' + this.Id + '" does not exist!');
        }
        v_div.style.cursor = this.Cursor;
    }
    return;
}

JavaWindow.StatusBar.prototype.SetVisible = function(value)
{
    /// <summary modifiers="public">Sets the visibility of the <see cref="JavaWindow.StatusBar"/> to the specified visibility.</summary>
    /// <param name="value" type="Boolean" optional="false">The visibility value.</param>
    this.Visible = value;
    var v_div = $(this.Id);
    if (v_div != null)
    {
        v_div.style.display = this.Visible ? 'block' : 'none';
        this.Parent._UpdateContentAreaSize();
    }
    return;
}

JavaWindow.StatusBar.prototype.Refresh = function()
{
    /// <summary modifiers="public">Refreshes the <see cref="JavaWindow.StatusBar"/> instance.</summary>
    var v_div = $(this.Id);
    if (v_div == null)
    {
        throw new Error('Element with ID of "' + this.Id + '" does not exist!');
    }
    if (this.Visible)
    {
        v_div.innerHTML = this.Text == null ? '' : this.Text;
        v_div.style.height = (this.Height - this.Padding.Top - this.Padding.Bottom - this.Parent.Border.Width).ToCssString();
        v_div.style.padding = this.Padding.ToCssString();
        v_div.style.font = this.Font.ToCssString();
        v_div.style.background = this.Background.ToCssString();
        v_div.style.borderTop = this.Parent.Border.ToCssString();
        v_div.style.cursor = this.Cursor;
        v_div.style.color = this.ForeColor;
        v_div.style.display = 'block';
    }
    else
    {
        v_div.style.display = 'none';
    }
    return;
}

JavaWindow.StatusBar.prototype.GetHeight = function()
{
    /// <summary modifiers="public">Gets the render height of the <see cref="JavaWindow.StatusBar"/>.</summary>
    /// <returns type="Number">The render height of the <see cref="JavaWindow.StatusBar"/>.</returns>
    return this.Visible ? this.Height : 0;
}

JavaWindow.StatusBar.prototype.GetDivElement = function()
{
    /// <summary modifiers="private">Internal method that gets a handle to the <see cref="JavaWindow.StatusBar"/> HTML element for the <see cref="JavaWindow"/>.</summary>
    var v_statusbar_div = $(this.Id);
    if (v_statusbar_div == null)
    {
        v_statusbar_div = document.createElement('div');
        v_statusbar_div.setAttribute('id', this.Id);
        v_statusbar_div.setAttribute('onclick', this.Parent.Name + '.StatusBar.OnClick(event, this);');
        v_statusbar_div.setAttribute('ondblclick', this.Parent.Name + '.StatusBar.OnDoubleClick(event, this);');
        v_statusbar_div.setAttribute('onmousedown', this.Parent.Name + '.StatusBar.OnMouseDown(event, this);');
        v_statusbar_div.setAttribute('onmouseup', this.Parent.Name + '.StatusBar.OnMouseUp(event, this);');
        v_statusbar_div.setAttribute('onmouseover', this.Parent.Name + '.StatusBar.OnMouseOver(event, this);');
        v_statusbar_div.setAttribute('onmousemove', this.Parent.Name + '.StatusBar.OnMouseMove(event, this);');
        v_statusbar_div.setAttribute('onmouseout', this.Parent.Name + '.StatusBar.OnMouseOut(event, this);');
        v_statusbar_div.setAttribute('onkeypress', this.Parent.Name + '.StatusBar.OnKeyPress(event, this);');
        v_statusbar_div.setAttribute('onkeydown', this.Parent.Name + '.StatusBar.OnKeyDown(event, this);');
        v_statusbar_div.setAttribute('onkeyup', this.Parent.Name + '.StatusBar.OnKeyUp(event, this);');
        v_statusbar_div.style.overflow = 'hidden';
    }
    if (this.Visible)
    {
        v_statusbar_div.innerHTML = this.Text == null ? '' : this.Text;
        v_statusbar_div.style.height = (this.Height - this.Padding.Top - this.Padding.Bottom - this.Parent.Border.Width).ToCssString();
        v_statusbar_div.style.padding = this.Padding.ToCssString();
        v_statusbar_div.style.font = this.Font.ToCssString();
        v_statusbar_div.style.background = this.Background.ToCssString();
        v_statusbar_div.style.borderTop = this.Parent.Border.ToCssString();
        v_statusbar_div.style.cursor = this.Cursor;
        v_statusbar_div.style.color = this.ForeColor;
        v_statusbar_div.style.display = 'block';
    }
    else
    {
        v_statusbar_div.style.display = 'none';
    }
    return v_statusbar_div;
}

/**************************************************************************/

JavaWindow.TitleBar = function(parentJavaWindow, imageFolderPath)
{
    /// <summary modifiers="public" type="class" extends="BasicEventObjectBase">Represents the title bar of a <see cref="JavaWindow"/>.</summary>
    /// <param name="parentJavaWindow" type="JavaWindow" optional="false">The <see cref="JavaWindow"/> that this <see cref="JavaWindow.TitleBar"/> belongs to.</param>
    /// <field name="Parent"          type="JavaWindow"  modifiers="public">Gets the parent <see cref="JavaWindow"/> that this <see cref="JavaWindow.TitleBar"/> belongs to.</field>
    /// <field name="Id"              type="String"      modifiers="public">Gets the Id of the HTML element that contains the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="Visible"         type="Boolean"     modifiers="public">Gets or sets a value indicating if the <see cref="JavaWindow.TitleBar"/> is visible.</field>
    /// <field name="Text"            type="String"      modifiers="public">Gets or sets the text of the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="Height"          type="Number"      modifiers="public">Gets or sets the height of the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="Background"      type="Background"  modifiers="public">Gets or sets the background of the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="Padding"         type="Padding"     modifiers="public">Gets or sets the padding of the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="Font"            type="Font"        modifiers="public">Gets or sets the font of the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="ForeColor"       type="String"      modifiers="public">Gets or sets the text color of the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="Cursor"          type="String"      modifiers="public">Gets or sets the cursor for the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="ImageFolderPath" type="String"      modifiers="public">Gets or sets the path to the images folder, relative to the root of the site.</field>
    /// <field name="CloseButton"     type="ImageButton" modifiers="public">Gets the close button for the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="MinimizeButton"  type="ImageButton" modifiers="public">Gets the minimize button for the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="MaximizeButton"  type="ImageButton" modifiers="public">Gets the maximize button for the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="HelpButton"      type="ImageButton" modifiers="public">Gets the help button for the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="Icon"            type="ImageIcon"   modifiers="public">Gets the icon for the <see cref="JavaWindow.TitleBar"/>.</field>
    /// <field name="_MousePressed" type="Boolean" modifiers="private">Internal variable used to specify if the a mouse button is currently pressed.</field>
    /// <field name="_MouseOffset"  type="Point"   modifiers="private">Internal variable used to hold the mouse offset when the window is being dragged.</field>
    /// <field name="_DocOnMM"      type="Object"  modifiers="private">Internal variable used to hold a backup of the document.onmousemove event handler.</field>
    /// <field name="_DocOnSS"      type="Object"  modifiers="private">Internal variable used to hold a backup of the document.onselectstart event handler.</field>
    /// <field name="_DocOnMD"      type="Object"  modifiers="private">Internal variable used to hold a backup of the document.onmousedown event handler.</field>
    JavaWindow.TitleBar.baseConstructor.call(this);
    if (parentJavaWindow == null)
    {
        throw new Error('parentJavaWindow is null!');
    }

    this.Parent = parentJavaWindow;
    this.Id = this.Parent.Name + '_titlebar';
    this.Visible = true;
    this.Text = '';
    this.CloseButton = new ImageButton('Close', 'X');
    this.MinimizeButton = new ImageButton('Minimize', '_');
    this.MaximizeButton = new ImageButton('Maximize', '[]');
    this.HelpButton = new ImageButton('Help', '?');
    this.Icon = new ImageIcon();
    this.Height = 25;
    this.Background = new Background('#5b2c86');
    this.Padding = new Padding(0, 0, 0, 0);
    this.Font = new Font('verdana', '12px', 'bold');
    this.ForeColor = '#FFFFFF';
    this.Cursor = 'default';
    this.ImageFolderPath = '';

    this.Icon.Padding.Right = 5;
    this.HelpButton.Visible = false;

    this.CloseButton.Parent = this;
    this.MinimizeButton.Parent = this;
    this.MaximizeButton.Parent = this;
    this.HelpButton.Parent = this;
    this.Icon.Parent = this;

    this.SetImageFolderPath(imageFolderPath);

    this._MousePressed = false;
    this._MouseOffset = new Point(0, 0);
    this._DocOnMM = null;
    this._DocOnSS = null;
    this._DocOnMD = null;
    return;
}

// Inherit from the BasicEventObjectBase object.
Extend(JavaWindow.TitleBar, BasicEventObjectBase);

JavaWindow.TitleBar.prototype.OnDoubleClick = function(e)
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.TitleBar.DoubleClick"/> event.</summary>
    if (this.MaximizeButton.Visible)
    {
        this.Parent.MaxToggle();
    }
    JavaWindow.TitleBar.superClass.OnDoubleClick.call(this, e);
    return;
}

JavaWindow.TitleBar.prototype.OnMouseDown = function(e)
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.TitleBar.MouseDown"/> event.</summary>
    this.Parent.BringToFront();
    var v_mouse_loc = Utils.GetMouseLocation(e);
    if (this.Parent.Moveable)
    {
        this._MousePressed = true;
        this._MouseOffset.Set(v_mouse_loc.X - this.Parent.Location.X, v_mouse_loc.Y - this.Parent.Location.Y);
        document._CurrentJWTB = this;
        this._DocOnSS = document.onselectstart;
        this._DocOnMD = document.onmousedown;
        this._DocOnMM = document.onmousemove;
        document.onselectstart = this._SelectionDisable;
        document.onmousedown = this._SelectionDisable;
        document.onmousemove = this._MouseMoveHandler;
    }
    JavaWindow.TitleBar.superClass.OnMouseDown.call(this, e);
    return;
}

JavaWindow.TitleBar.prototype.OnMouseUp = function(e)
{
    /// <summary modifiers="protected">Raises the <see cref="JavaWindow.TitleBar.MouseUp"/> event.</summary>
    if (this.Parent.Moveable)
    {
        this._MousePressed = false;
        this._MouseOffset.Set(0, 0);
        document.onmousemove = this._DocOnMM;
        document.onselectstart = this._DocOnSS;
        document.onmousedown = this._DocOnMD;
        document._CurrentJWTB = null;
        this.Parent.OnMove();
    }
    JavaWindow.TitleBar.superClass.OnMouseUp.call(this, e);
    return;
}

JavaWindow.TitleBar.prototype.GetType = function()
{
    /// <summary modifiers="public">Gets the current object type.</summary>
    /// <returns type="String">The current object type.</returns>
    return 'JavaWindow.TitleBar';
}
JavaWindow.TitleBar.prototype.GetHashCode = function()
{
    /// <summary modifiers="public">Gets a hash code that represents this object instance.</summary>
    /// <returns type="String">A hash code that represents this object instance.</returns>
    return this.Id;
}
JavaWindow.TitleBar.prototype.ToString = function()
{
    /// <summary modifiers="public">Gets a string that represents this object instance.</summary>
    /// <returns type="String">A string that represents this object instance.</returns>
    return this.Text;
}

JavaWindow.TitleBar.prototype.SetText = function(text)
{
    /// <summary modifiers="public">Sets the text of the <see cref="JavaWindow.TitleBar"/> to the specified text.</summary>
    /// <param name="text" type="String" optional="false">The text to use.</param>
    if (TypeOf(text) != 'String')
    {
        throw new Error('text is not a string.');
    }
    this.Text = text;
    if (this.Parent != null && this.Visible && this.Parent.Visible)
    {
        var v_element = $(this.Id + '_text');
        if (v_element == null)
        {
            throw new Error('Element with ID of "' + this.Id + '_text" does not exist!');
        }
        v_element.innerHTML = this.Text == null ? '' : this.Text;
    }
    return;
}

JavaWindow.TitleBar.prototype.SetCursor = function(cursor)
{
    /// <summary modifiers="public">Sets the cursor of the <see cref="JavaWindow.TitleBar"/> to the specified cursor.</summary>
    /// <param name="cursor" type="String" optional="false">The name of the cursor to use.</param>
    if (TypeOf(cursor) != 'String')
    {
        throw new Error('cursor is not a string.');
    }
    this.Cursor = cursor;
    if (this.Visible)
    {
        var v_table = $(this.Id + '_table');
        if (v_table == null)
        {
            throw new Error('Element with ID of "' + this.Id + '_table" does not exist!');
        }
        v_table.style.cursor = this.Cursor;
    }
    return;
}

JavaWindow.TitleBar.prototype.SetImageFolderPath = function(imageFolderPath)
{
    /// <summary modifiers="public">Sets the path to the image folder that contains the "javawin_images" folder, relative to the root of the website.</summary>
    /// <param name="imageFolderPath" type="String" optional="false">The image folder path, relative to the root of the website.</param>
    if (TypeOf(imageFolderPath) != 'String' || imageFolderPath.length <= 0)
    {
        imageFolderPath = '/images';
    }
    imageFolderPath.replace(/\\/g, '/'); // replace all '\' with '/' to be web friendly.
    if (!imageFolderPath.StartsWith('/'))
    {
        // Make sure the path starts with a '/'.
        imageFolderPath = '/' + imageFolderPath;
    }
    if (imageFolderPath.EndsWith('/'))
    {
        // Remove trailing '/'.
        imageFolderPath = imageFolderPath.substr(0, imageFolderPath.length - 1);
    }
    this.ImageFolderPath = imageFolderPath;
    this.CloseButton.IconNormal = this.ImageFolderPath + '/javawin_images/button_cls.gif';
    this.MinimizeButton.IconNormal = this.ImageFolderPath + '/javawin_images/button_min.gif';
    this.MaximizeButton.IconNormal = this.ImageFolderPath + '/javawin_images/button_max.gif';
    this.HelpButton.IconNormal = this.ImageFolderPath + '/javawin_images/button_hlp.gif';
    if (this.Parent != null && this.Visible && this.Parent.Visible)
    {
        this.CloseButton.Refresh();
        this.MinimizeButton.Refresh();
        this.MaximizeButton.Refresh();
        this.HelpButton.Refresh();
    }
    return;
}

JavaWindow.TitleBar.prototype.Refresh = function()
{
    /// <summary modifiers="public">Refreshes the <see cref="JavaWindow.TitleBar"/> instance.</summary>
    if (this.Visible)
    {
        this.Icon.Refresh();
        this.CloseButton.Refresh();
        this.MinimizeButton.Refresh();
        this.MaximizeButton.Refresh();
        this.HelpButton.Refresh();

        var v_element = $(this.Id + '_text');
        if (v_element == null)
        {
            throw new Error('Element with ID of "' + this.Id + '_text" does not exist!');
        }
        v_element.innerHTML = this.Text == null ? '' : this.Text;

        var v_table = $(this.Id + '_table');
        if (v_table == null)
        {
            throw new Error('Element with ID of "' + this.Id + '_table" does not exist!');
        }
        v_table.style.height = (this.Height - this.Padding.Top - this.Padding.Bottom - this.Parent.Border.Width).ToCssString();
        v_table.style.padding = this.Padding.ToCssString();
        v_table.style.font = this.Font.ToCssString();
        v_table.style.background = this.Background.ToCssString();
        v_table.style.borderBottom = this.Parent.Border.ToCssString();
        v_table.style.cursor = this.Cursor;
        v_table.style.color = this.ForeColor;
    }
    return;
}

JavaWindow.TitleBar.prototype.GetHeight = function()
{
    /// <summary modifiers="public">Gets the render height of the <see cref="JavaWindow.TitleBar"/>.</summary>
    /// <returns type="Number">The render height of the <see cref="JavaWindow.TitleBar"/>.</returns>
    return this.Visible ? this.Height : 0;
}

JavaWindow.TitleBar.prototype._SelectionDisable = function()
{
    /// <summary modifiers="private">Internal method used as the handler to disable selection on the page while the window is being dragged.</summary>
    return false;
}

JavaWindow.TitleBar.prototype._MouseMoveHandler = function(e)
{
    /// <summary modifiers="private">Internal method used as the mouse move handler while the window is being dragged.</summary>
    var _this = document._CurrentJWTB;
    if (_this.Parent.Moveable && _this._MousePressed)
    {
        var v_mouse_loc = Utils.GetMouseLocation(!e ? event : e);
        _this.Parent._MoveInternal(v_mouse_loc.X - _this._MouseOffset.X, v_mouse_loc.Y - _this._MouseOffset.Y);
    }
    return;
}

JavaWindow.TitleBar.prototype.GetDivElement = function()
{
    /// <summary modifiers="private">Internal method that gets a handle to the <see cref="JavaWindow.TitleBar"/> HTML element for the <see cref="JavaWindow"/>.</summary>
    this.Icon.Id = this.Id + '_icon_1';
    this.CloseButton.Id = this.Id + '_buttons_close';
    this.MinimizeButton.Id = this.Id + '_buttons_min';
    this.MaximizeButton.Id = this.Id + '_buttons_max';
    this.HelpButton.Id = this.Id + '_buttons_help';

    var v_titlebar_div = $(this.Id);
    if (v_titlebar_div == null)
    {
        v_titlebar_div = document.createElement('div');
        v_titlebar_div.setAttribute('id', this.Id);
    }
    if (this.Visible)
    {
        var v_sb = (new StringBuilder('<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; border-collapse: collapse;'))
			.Append(' height: ').Append((this.Height - this.Padding.Top - this.Padding.Bottom - this.Parent.Border.Width).ToCssString()).Append(';')
			.Append(' padding: ').Append(this.Padding.ToCssString()).Append(';')
			.Append(' font: ').Append(this.Font.ToCssString()).Append(';')
			.Append(' background: ').Append(this.Background.ToCssString()).Append(';')
			.Append(' border-bottom: ').Append(this.Parent.Border.ToCssString()).Append(';')
			.Append(' cursor: ').Append(this.Cursor).Append(';')
			.Append(' color: ').Append(this.ForeColor).Append(';"')
			.Append(Utils.CreateAttributeString('onclick', this.Parent.Name + '.TitleBar.OnClick(event, this);'))
			.Append(Utils.CreateAttributeString('ondblclick', this.Parent.Name + '.TitleBar.OnDoubleClick(event, this);'))
			.Append(Utils.CreateAttributeString('onmousedown', this.Parent.Name + '.TitleBar.OnMouseDown(event, this);'))
			.Append(Utils.CreateAttributeString('onmouseup', this.Parent.Name + '.TitleBar.OnMouseUp(event, this);'))
			.Append(Utils.CreateAttributeString('onmouseover', this.Parent.Name + '.TitleBar.OnMouseOver(event, this);'))
			.Append(Utils.CreateAttributeString('onmousemove', this.Parent.Name + '.TitleBar.OnMouseMove(event, this);'))
			.Append(Utils.CreateAttributeString('onmouseout', this.Parent.Name + '.TitleBar.OnMouseOut(event, this);'))
			.Append(Utils.CreateAttributeString('onkeypress', this.Parent.Name + '.TitleBar.OnKeyPress(event, this);'))
			.Append(Utils.CreateAttributeString('onkeydown', this.Parent.Name + '.TitleBar.OnKeyDown(event, this);'))
			.Append(Utils.CreateAttributeString('onkeyup', this.Parent.Name + '.TitleBar.OnKeyUp(event, this);'))
			.Append('><tr><td id="').Append(this.Id).Append('_icon" style="width: 1%;">')
			.Append(this.Icon.GetRenderHtml(
				this.Parent.Name + '.TitleBar.Icon.OnClick(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnDoubleClick(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnMouseDown(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnMouseUp(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnMouseOver(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnMouseMove(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnMouseOut(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnKeyPress(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnKeyDown(event, this);',
				this.Parent.Name + '.TitleBar.Icon.OnKeyUp(event, this);'))
			.Append('</td><td id="').Append(this.Id).Append('_text" style="width: 98%;">').Append(this.Text == null ? '' : this.Text)
			.Append('</td><td id="').Append(this.Id).Append('_buttons" style="width: 1%;">')
			.Append('<table border="0" cellpadding="0" cellspacing="0" id="').Append(this.Id).Append('_table" style="font: ')
			.Append(this.Font.ToCssString()).Append('; color: ').Append(this.ForeColor).Append(';"><tr><td>')
			.Append(this.HelpButton.GetRenderHtml(
				this.Parent.Name + '.TitleBar.HelpButton.OnClick(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnDoubleClick(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnMouseDown(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnMouseUp(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnMouseOver(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnMouseMove(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnMouseOut(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnKeyPress(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnKeyDown(event, this);',
				this.Parent.Name + '.TitleBar.HelpButton.OnKeyUp(event, this);'))
			.Append('</td><td style="padding-left: 2px;">')
			.Append(this.MinimizeButton.GetRenderHtml(
				this.Parent.Name + '.MinToggle();' + this.Parent.Name + '.TitleBar.MinimizeButton.OnClick(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnDoubleClick(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnMouseDown(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnMouseUp(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnMouseOver(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnMouseMove(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnMouseOut(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnKeyPress(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnKeyDown(event, this);',
				this.Parent.Name + '.TitleBar.MinimizeButton.OnKeyUp(event, this);'))
			.Append('</td><td>')
			.Append(this.MaximizeButton.GetRenderHtml(
				this.Parent.Name + '.MaxToggle();' + this.Parent.Name + '.TitleBar.MaximizeButton.OnClick(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnDoubleClick(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnMouseDown(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnMouseUp(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnMouseOver(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnMouseMove(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnMouseOut(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnKeyPress(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnKeyDown(event, this);',
				this.Parent.Name + '.TitleBar.MaximizeButton.OnKeyUp(event, this);'))
			.Append('</td><td style="padding-left: 2px; padding-right: 5px;">')
			.Append(this.CloseButton.GetRenderHtml(
				this.Parent.Name + '.Close();' + this.Parent.Name + '.TitleBar.CloseButton.OnClick(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnDoubleClick(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnMouseDown(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnMouseUp(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnMouseOver(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnMouseMove(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnMouseOut(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnKeyPress(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnKeyDown(event, this);',
				this.Parent.Name + '.TitleBar.CloseButton.OnKeyUp(event, this);'))
			.Append('</td></tr></table>')
			.Append('</td></tr></table>');
        v_titlebar_div.innerHTML = v_sb.ToString();
    }
    return v_titlebar_div;
}