
    
    
    //*********************************** Tab control API class *************************************
    var CTabctrlAPI = function(){
        //buttons array
        this.instances = new Array(); //[0] => name ; [1] => object
    }
    
    CTabctrlAPI.prototype.get_instance = function(name)
    {
        for(var i = 0; i < this.instances.length; i++){
            if(this.instances[i][0] == name) return this.instances[i][1];
        }
        return null;
    }
    
    CTabctrlAPI.prototype.add_instance = function(name, instance)
    {
        this.instances[this.instances.length] = new Array(name, instance);
    }
    
    //creating api object
    var TabctrlAPI = new CTabctrlAPI();
    
    
    
    
    
    //******************************* tabbed button events *********************************************
    function tabctrl_on_mouse_over(instance_name, name){
    	//getting instance object
        var instance = TabctrlAPI.get_instance(instance_name);   
        if(instance.get_active_btn_name() != name) 
            document.getElementById(instance.get_btn_prefix() + name).className = 'tabctrl_notactive_hot';
        //firing event
       	if(instance.on_mouse_over)
       		instance.on_mouse_over(instance);
    }
    
    function tabctrl_on_mouse_out(instance_name, name){ 
    	//getting instance object
        var instance = TabctrlAPI.get_instance(instance_name);  
        if(instance.get_active_btn_name() != name)        
            document.getElementById(instance.get_btn_prefix() + name).className = 'tabctrl_notactive';
        //firing event
       	if(instance.on_mouse_out)
       		instance.on_mouse_out(instance);
    }
    
    function tabctrl_on_change(instance_name, name){ 
    	var instance = TabctrlAPI.get_instance(instance_name);  
    	//before change
    	if(instance.on_before_change)
       		instance.on_before_change(instance);    	
    	//change
        instance.set_active_btn(name);   
        //firing event
       	if(instance.on_change)
       		instance.on_change(instance);
       	//after change	
       	if(instance.on_after_change)
       		instance.on_after_change(instance);
    }

    
    
    //**************************************** Tab control class *************************************
    //Tab control object
    var CTabctrl = function(instance_name, btn_prefix){
    	//instance_name
        this.instance_name = instance_name;
        //buttons array
        this.buttons = new Array();
        //button name prefix     
        this.btn_prefix = btn_prefix; 
        //active button name   
        this.active_btn_name = '';
        //events
        this.on_mouse_over = null; 
        this.on_mouse_out = null;
        this.on_before_change = null; 
        this.on_after_change = null;
        this.on_change = null;
        this.on_load = null;
        //custom data
        this.data = null;
        //adding instance to API array
        TabctrlAPI.add_instance(instance_name, this);
    }
    
    CTabctrl.prototype.get_instance_name = function()
    {
        return this.instance_name;
    }
    
    CTabctrl.prototype.set_btn_prefix = function(prefix)
    {
        this.btn_prefix = prefix;
    }
    
    CTabctrl.prototype.get_btn_prefix = function()
    {
        return this.btn_prefix;
    }
    
    CTabctrl.prototype.add_button = function(name, caption, active_caption, hot_caption, action)
    {
        this.buttons[this.buttons.length] = new Array(name, caption, active_caption, hot_caption, action);
    }
    
    CTabctrl.prototype.get_button = function(name)
    {
        for(var i = 0; i < this.buttons.length; i++){
            if(name == this.buttons[i][0]) return this.buttons[i];
        }
        return null;
    }
    
    CTabctrl.prototype.set_active_btn = function(name)
    {
        if(curr_active_btn = document.getElementById(this.btn_prefix + this.active_btn_name)){
            curr_active_btn.className = 'tabctrl_notactive'; 
            curr_active_btn.innerHTML = this.get_button(this.active_btn_name)[1]; //caption
        }   
        if(new_active_btn = document.getElementById(this.btn_prefix + name)){
            new_active_btn.className = 'tabctrl_active'; 
            new_active_btn.innerHTML = this.get_button(name)[2]; //active_caption
        }
        this.active_btn_name = name;
    }
    
    CTabctrl.prototype.get_active_btn = function()
    {
        return this.get_button(this.active_btn_name);
    }
    
    CTabctrl.prototype.get_active_btn_name = function()
    {
        return this.active_btn_name;
    }
    
    CTabctrl.prototype.get_html = function()
    {                                                                          
        var html = '';
        //creating html output
        html += '<table border="0" cellspacing="0" cellpadding="0">';
        html += '<tr>'; 
        for(var i = 0; i < this.buttons.length; i++){
            name = this.buttons[i][0];
            if(this.buttons[i][0] == this.active_btn_name){
                classname = 'tabctrl_active';
                btncaption = this.buttons[i][2];
            } else {
                classname = 'tabctrl_notactive';
                btncaption = this.buttons[i][1];                                                                             
            }
            html += '<td>';
            html += '<div id="' + this.btn_prefix + name + '" class="' + classname + '" onMouseOver="javascript: tabctrl_on_mouse_over(\'' + this.instance_name + '\',\''  + name + '\');" onMouseOut="javascript: tabctrl_on_mouse_out(\'' + this.instance_name + '\',\''  + name + '\');" onClick="javascript: tabctrl_on_change(\'' + this.instance_name + '\',\''  + name + '\', \'' + this.buttons[i][4] + '\');">' + btncaption + '</div>';
            html += '</td>';               
        }
        html += '</tr>';
        html += '</table>';       
        return html;
    }
    
    
    CTabctrl.prototype.output = function()
    {                                                                          
        document.write(this.get_html());
        //firing on_output event
        if(instance.on_load)
       		instance.on_load(this);
    }
    
    CTabctrl.prototype.set_data = function(data)
    {                                                                          
        this.data = data;
    }
    
    CTabctrl.prototype.get_data = function()
    {                                                                          
        return this.data;
    }

    
    
   
