﻿// Tab Functions
function tab(id, pnl, cont) {

    this.id = id;
    this.pnl = pnl;   
    this.container = cont;  
        
   this._onClickHandler = null;  
}

tab.prototype = {

    init:  function() {              
        this._onClickHandler = Function.createDelegate(this, this._onClick);        
        var e = $get(this.get_id());
        $addHandler(e, "click", this._onClickHandler);        
    },
   
    _onClick: function() {
        this.container._onTabClick(this.get_id());
    },  
   
    get_tabOnClickHandler: function() {
        return this._onClickHandler;
    },   
    
    get_id: function() {
        return this.id;
    },
    set_id: function(id) {
        this.id = id;
    },
   
   get_pnl: function() {
        return this.pnl;
    },
    set_pnl: function(pnl) {
        this.pnl = pnl;
    }    
    
}


// Tabs collection functions
function tabs() {
     this.page_tabs = new Array();
     this._tabOnClickHandler = null;  
}

tabs.prototype = {

    init:  function() {    

         var _items = this.page_tabs; 
         for (x=0; x < _items.length; ++x)
         {       
            var pnl = $get(_items[x].pnl);
            pnl.style.display = "none" 
         }         
    },
   
   add:  function(tab) {
                
       tab.init();       
       this.page_tabs[this.get_length()] = tab;

   },
   
   _onTabClick: function(id) {

      this.tab_activate(id);
       
   },
   
   tab_activate: function(e) {
        var _items = this.page_tabs;
       
        for (x=0; x < _items.length; ++x)
         {        
            var pnl = $get(_items[x].pnl);
            var tb = $get(_items[x].id);
            var _children = tb.childNodes;
            
            if( _items[x].id == e ) {         
                  
                pnl.style.display = "block";                
                _children[0].className = 'inactive'; 
                _children[1].className = 'active'; 
            }     
            else  {

                pnl.style.display = "none";
                _children[0].className = 'offstate'; 
                _children[1].className = 'onstate';  
            }
         }   
     } ,
     
     items: function() {
        return this.page_tabs;
     },
     
     get_length: function() {
        return this.page_tabs.length;
     }

}


