WTabControl76.prototype = new WContainer76();
WTabControl76.prototype.constructor = WTabControl76;
WTabControl76.superclass = WContainer76.prototype;  

function WTabControl76(ControlID, Prefix, controls_xml)
{
    this.owner = null;
    this.level_gather_of_state = 0;
    this.is_link_state = false;
    this.url_to_images = '';
    
    this.linked_children = new Array();
}

WTabControl76.prototype.init = function(ControlID, Prefix, controls_xml)
{
    
    WTabControl76.superclass.init.call(this, ControlID, Prefix, controls_xml);
    this.active_index = -1;
    this.tab_count = 0;
    this.tabstrip = document.getElementById(this.Prefix + '_ts');
}

WTabControl76.prototype.select_tab = function(index, is_refresh_cont)
{
    1;
    if (this.active_index != index)
    {
        this.old_act_index = this.active_index;
        this.set_active_index(index);
        this.active_index = index;
        if (is_refresh_cont == null || is_refresh_cont == true)
            this.refresh_content(index);
    }
}

WTabControl76.prototype.refresh_content = function(index)
{
    1;
    var cb_cont = this;
    var doc = this.newXMLDOM();
    this.loadDoc(doc, this.controls_xml);
    var ctrls = doc.selectNodes('packet/controls/control');
    
    var obj_attr = ctrls[this.old_act_index + 1].attributes.getNamedItem('obj_id').value;
    if (obj_attr != this.JSObject)
    {
        var client_obj = null;
        try { client_obj = eval(obj_attr); }
        catch(ex) { client_obj = null; }
        
        if (client_obj && client_obj.level_gather_of_state > 0)
        {
            client_obj.CallServer(this.ControlID, 'RefreshContent', index, this, this.on_callback_refresh_method, this.on_callback_error_);
            return;
        }
    }
    WTabControl76.superclass.CallServer.call(cb_cont, '', 'RefreshContent', index, this, this.on_callback_refresh_method, this.on_callback_error_);
}

WTabControl76.prototype.set_active_index = function(index)
{

    if (this.tabstrip)
    {
        //var a = this.tabstrip.rows[0].cells[0].childNodes[0];//table first group
        
        var active_tab = null;
        if (this.active_index > -1)
            //active_tab = a.rows[0].cells[this.active_index].childNodes[0];
            active_tab = this.tabstrip.rows[0].cells[this.active_index*2].childNodes[0];
        
        var activating_tab = null;
        if (index > -1)    
          //  activating_tab = a.rows[0].cells[index].childNodes[0];
            activating_tab = this.tabstrip.rows[0].cells[index*2].childNodes[0];
        if (activating_tab) this.set_active_tab(activating_tab);
        if (active_tab) this.set_deactive_tab(active_tab);
    }
}

WTabControl76.prototype.set_tabs_visibility = function(vis_line)
{
    if (this.tabstrip)    
    {
        for(var i = 0; i < vis_line.length; i++)
        {
            this.tabstrip.rows[0].cells[i*2].style.display = vis_line.substring(i, i+1) == '1' ? '' : 'none';
            
            if (this.tabstrip.rows[0].cells.length > i*2 + 1)
                this.tabstrip.rows[0].cells[i*2 + 1].style.display = vis_line.substring(i, i+1) == '1' ? '' : 'none';
                
         }       
    }
}

WTabControl76.prototype.set_active_tab = function(tab)
{
   tab.className = "WTabItem_MainTable_Selected";
   tab.rows[0].cells[0].className = "WTabItem_Left_Selected";
   tab.rows[0].cells[1].className = "WTabItem_Center_Selected";
   tab.rows[0].cells[2].className = "WTabItem_Right_Selected";
}

WTabControl76.prototype.set_deactive_tab = function(tab)
{
 
    //SNV[-]tab.style.backgroundImage = 'url(' + this.url_to_images + 'tab_bg.gif)';
    //SNV[-]tab.rows[0].cells[0].childNodes[0].src = this.url_to_images + 'tab_left_icon.gif';
    //SNV[-]tab.rows[0].cells[2].childNodes[0].src = this.url_to_images + 'tab_right_icon.gif';
    tab.className = "WTabItem_MainTable";
    tab.rows[0].cells[0].className = "WTabItem_Left";
    tab.rows[0].cells[1].className = "WTabItem_Center";
    tab.rows[0].cells[2].className = "WTabItem_Right";
}

WTabControl76.prototype.set_hover_on_index = function(index, is_hover)
{
    if (!this.tabstrip)
        return;
    //SNV[-]var a = this.tabstrip.rows[0].cells[0].childNodes[0];//table first group
    
    
    //SNV[-]var tab = a.rows[0].cells[index].childNodes[0];
    var tab = this.tabstrip.rows[0].cells[index * 2].childNodes[0];

    if (is_hover)
    {
        if (index != this.active_index)
            this.set_hover_on_tab(tab);
    }
    else 
    {
        if (index != this.active_index)
            this.set_deactive_tab(tab);
    }
}

WTabControl76.prototype.set_hover_on_tab = function(tab)
{
   
    //SNV[-]tab.style.backgroundImage = 'url(' + this.url_to_images + 'hover_tab_bg.gif)';
    //SNV[-]tab.rows[0].cells[0].childNodes[0].src = this.url_to_images + 'hover_tab_left_icon.gif';
    //SNV[-]tab.rows[0].cells[2].childNodes[0].src = this.url_to_images + 'hover_tab_right_icon.gif';
    tab.rows[0].cells[0].className = "WTabItem_Left_Hover";
    tab.rows[0].cells[1].className = "WTabItem_Center_Hover";
    tab.rows[0].cells[2].className = "WTabItem_Right_Hover";
}


WTabControl76.prototype.set_tab_count = function(count)
{
    this.set_tab_count = count;
}

WTabControl76.prototype.on_callback_refresh_method_ = function(val, context)
{
}

WTabControl76.prototype.on_callback_error_ = function(val, context)
{
    context.show_message_box('WTabControl76.prototype.on_callback_error: ' + val, 'error');
    
    context.set_active_index(context.old_act_index);
    context.active_index = context.old_act_index;
}

function Controls76_WTabControl76_Builder(name, obj_id)
{
    this.name = name;
    try { this.obj = eval(obj_id); }
    catch (ex) { this.obj = null; }
    
    this.properties = new Array('ActiveIndex', 'TabsVisibility'/*, 'IsNeedRefresh'*/);
    
    this.get_prop = function(prop_name)
    {
        if (this.obj != null)
        {
            switch(prop_name)
            {
                case 'ActiveIndex':
                    return this.obj.active_index;
            }
        }
        return '';
    }
    
    this.set_prop = function(prop_name, prop_value)
    {
        if (this.obj != null)
        {
            switch(prop_name)
            {
                case 'ActiveIndex':
                    this.obj.select_tab(parseInt(prop_value), false);
                    break;
                case 'TabsVisibility':
                    this.obj.set_tabs_visibility(prop_value);
                    break;
            }
        }
    }
}

