﻿/*
Javascript WebTab control
*/

var WebTab = Class.create();

WebTab.prototype =
{
    // Constructor
    initialize : function(piTitle)
    {
        try
        {
            // Check if title has been provided and declare variable holding the TabControl's window title
            if((piTitle != null) && (!piTitle.blank()))
            {
                this.Title = piTitle;
            }
            else
            {
                throw ' A tab title must be provided';
            }
            
            // Declare variable holding the tab button
            this._tabButton;
            // Declare variable holding the WebContainer
            this._htmlContainer;
            
            // Call Build function to build the html structure
            this.Build();
        }
        catch(e)
        {
            Logs.WriteException('EXCEPTION_GENERAL', 'initiliaze', arguments, 'WEBTAB', null, e, false)
        }
    },
    
    Build : function()
    {
        try
        {
            // Create the tab button
            this._tabButton = new WebButton(this.Title);
            // Create the tab container
            this._htmlContainer = Builder.node('div');
        }
        catch(e)
        {
            Logs.WriteException('EXCEPTION_GENERAL', 'Build', arguments, 'WEBTAB', null, e, false)
        }
    },
    
    GetButton : function()
    {
        try
        {
            // Return the button's html markup
            var returnElem = this._tabButton.GetHtml();
            returnElem.Title = this.Title;
            
            return returnElem;
        }
        catch(e)
        {
            Logs.WriteException('EXCEPTION_GENERAL', 'GetButton', arguments, 'WEBTAB', null, e, false)
        }
    },
    
    GetContainer : function()
    {
        try
        {
            // Return the container's html markup
            return this._htmlContainer;
        }
        catch(e)
        {
            Logs.WriteException('EXCEPTION_GENERAL', 'GetContainer', arguments, 'WEBTAB', null, e, false)
        }
    },
    
    appendChild : function(piHtmlElem)
    {
        try
        {
            // Check if an html element has been passed and insert it into the html container
            if(piHtmlElem != null)
            {
                this._htmlContainer.appendChild(piHtmlElem);
            }
        }
        catch(e)
        {
            Logs.WriteException('EXCEPTION_GENERAL', 'appendChild', arguments, 'WEBTAB', null, e, false)
        }
    }
}