////////////////////////////////
// fonctions pour les onglets de navigation
////////////////////////////////

function class_onglet()
{
        var iframe_handler;
        var URL;
        var params;
        var is_closable;
        var title;
        var squelette;
        var container_handler;
        var css;
        var parent;
        var parent_name;
        var is_scrollable;
        var calling_document_handler;


        this.create_onglet = function(parent_name,URL,params,is_closable,title,is_scrollable,calling_document_handler)
        {
                this.parent_name = parent_name;
                this.title = title;
                this.is_closable = is_closable;
                this.URL = URL;
                this.params = params;
                this.is_scrollable = is_scrollable;
                this.calling_document_handler = calling_document_handler;
                //alert(this.calling_document_handler);

                this.iframe_handler = creerElement('iframe');

                this.iframe_handler.src = URL;
                this.iframe_handler.setAttribute('frameborder','0');
                this.iframe_handler.setAttribute('scrolling',((this.is_scrollable == true)?'yes':'no'));
                setAttributeStyle('width:100%;height:100%;margin-left:0px; border:0px solid black;',this.iframe_handler);
                this.container_handler = creerElement(this.squelette.container.type);

                this.draw_onglet();

        }

        this.close_onglet = function()
        {
                //alert('close_onglet');
        }

        this.select_onglet = function(event)
        {
                //alert('select_onglet');
                eval(this.parent_name).swap_onglets(this);
        }

        this.draw_onglet = function()
        {
                //alert('draw_onglet');
                this.container_handler.innerHTML = '';
                for(element in this.squelette.elements)
                {
                        var new_element = creerElement(this.squelette.elements[element][0]);
                        if((this.squelette.elements[element]) && (this.squelette.elements[element][2] != ''))
                        {
                                setAttributeStyle(this.squelette.elements[element][2],new_element);
                        }

                        switch(this.squelette.elements[element][0])
                        {
                                case "img":
                                        if(this.squelette.elements[element][3])
                                        {
                                                new_element.setAttribute('alt',this.squelette.elements[element][3]);
                                        }
                                        new_element.setAttribute('src',this.squelette.elements[element][1]);
                                        break;
                                case "a":
                                        new_element.setAttribute('title',this.title);
                                        new_element.setAttribute('href','javascript:void(0);');
                                        if (document.addEventListener){
                                                new_element.addEventListener('click', createDelegate(this, this.select_onglet), false);
                                        } else if (document.attachEvent){
                                                new_element.attachEvent('onclick', createDelegate(this, this.select_onglet));
                                        }
                                        new_element.innerHTML = this.title;
                                        break;

                        }
                        this.container_handler.appendChild(new_element);
                }
        }

        this.get_iframe_handler = function()
        {
                //alert('get_iframe_handler');
                return this.iframe_handler;
        }

        this.get_container_handler = function()
        {
                return this.container_handler;
        }

        this.set_css = function(css)
        {
                if(this.container_handler)
                {
                        //alert(css);
                        this.container_handler.className = css;
                }
                this.css = css;
        }

        this.set_squelette = function(squelette)
        {
                this.squelette = squelette;
        }

        this.set_title = function()
        {

        }
}

function class_bar_onglets()
{
        var onglets_container;
        var iframe_container_id;
        var list_of_onglets;
        var nb_onglets;
        var actual_selected_onglet;
        var former_selected_onglet;
        var squelette_first_onglet;
        var squelette_last_onglet;
        var squelette_onglet;
        var css_selected_onglet;
        var css_hidden_onglet;
        var object_name;
        var onglet_title_bar_close_picture;
        var onglet_title_bar_innerHTML;

        this.init_bar_onglets = function(iframe_container_id,object_name,onglet_tittle_bar_id)
        {
                this.nb_onglets = 0;
                this.list_of_onglets = new Array();
                this.iframe_container_id = iframe_container_id;
                this.object_name = object_name;
                this.onglet_tittle_bar_id = onglet_tittle_bar_id;
        }

        this.add_onglet = function(URL,params,is_closable,title,is_scrollable,calling_document_handler)
        {
                //alert('add_onglet');
                calling_document_handler = (calling_document_handler)?calling_document_handler:document;
                this.list_of_onglets[this.nb_onglets] = new class_onglet();
                switch(this.nb_onglets)
                {
                        case 0:
                                this.list_of_onglets[this.nb_onglets].squelette = this.squelette_first_onglet;
                                break;
                        case 1:
                                this.list_of_onglets[this.nb_onglets].squelette = this.squelette_last_onglet;
                                break;
                        default:
                                this.list_of_onglets[this.nb_onglets-1].squelette = this.squelette_onglet;
                                this.list_of_onglets[this.nb_onglets-1].draw_onglet();
                                this.list_of_onglets[this.nb_onglets].squelette = this.squelette_last_onglet;
                                break;
                }
                this.list_of_onglets[this.nb_onglets].create_onglet(this.object_name,URL,params,is_closable,title,is_scrollable,calling_document_handler);
                document.getElementById(this.onglets_container).appendChild(this.list_of_onglets[this.nb_onglets].get_container_handler());
                document.getElementById(this.iframe_container_id).appendChild(this.list_of_onglets[this.nb_onglets].get_iframe_handler());
                this.swap_onglets(this.list_of_onglets[this.nb_onglets]);
                this.nb_onglets++;
        }

        this.remove_onglet = function(event)
        {
                //alert('remove_onglet');

                document.getElementById(this.onglets_container).removeChild(this.actual_selected_onglet.get_container_handler());
                document.getElementById(this.iframe_container_id).removeChild(this.actual_selected_onglet.get_iframe_handler());

                var list_of_onglets_temp = new Array();
                for(onglets_index in this.list_of_onglets)
                {
                        if(this.list_of_onglets[onglets_index] != this.actual_selected_onglet)
                        {
                                list_of_onglets_temp.push(this.list_of_onglets[onglets_index]);
                        }
                }
                this.list_of_onglets = list_of_onglets_temp;
                this.nb_onglets = this.list_of_onglets.length;
                this.list_of_onglets[this.nb_onglets-1].squelette = this.squelette_last_onglet;
                this.list_of_onglets[this.nb_onglets-1].draw_onglet();
                if(this.nb_onglets > 0)
                {
                        this.former_selected_onglet = this.list_of_onglets[0];
                        this.swap_onglets(this.former_selected_onglet);
                }
        }

        this.swap_onglets = function(new_selected_onglet)
        {
                //alert('sawp_onglets');

                if(this.actual_selected_onglet)
                {
                        this.former_selected_onglet = this.actual_selected_onglet;
                        this.former_selected_onglet.set_css(this.css_hidden_onglet);
                        former_selected_onglet_iframe_handler = this.former_selected_onglet.get_iframe_handler();
                        former_selected_onglet_iframe_handler.style.display = "none"
                }
                else
                {
                        this.former_selected_onglet = new_selected_onglet;
                }
                this.actual_selected_onglet = new_selected_onglet;
                this.actual_selected_onglet.set_css(this.css_selected_onglet);
                actual_selected_onglet_iframe_handler = this.actual_selected_onglet.get_iframe_handler();
                actual_selected_onglet_iframe_handler.style.display = "block";

                document.getElementById(this.onglet_tittle_bar_id).innerHTML = '';
                if(this.actual_selected_onglet.is_closable == true)
                {
                        new_onglet_tile_bar_close_picture = creerElement("img");
                        new_onglet_tile_bar_close_picture.setAttribute('src',this.onglet_title_bar_close_picture[0]);
                        setAttributeStyle(this.onglet_title_bar_close_picture[1],new_onglet_tile_bar_close_picture);
                        if (document.addEventListener){
                                new_onglet_tile_bar_close_picture.addEventListener('click', createDelegate(this, this.remove_onglet), false);
                        } else if (document.attachEvent){
                                new_onglet_tile_bar_close_picture.attachEvent('onclick', createDelegate(this, this.remove_onglet));
                        }
                        document.getElementById(this.onglet_tittle_bar_id).appendChild(new_onglet_tile_bar_close_picture);
                }


                new_onglet_title_bar_text = creerElement(this.onglet_title_bar_innerHTML[0],null,null,this.actual_selected_onglet.title);
                setAttributeStyle(this.onglet_title_bar_innerHTML[1],new_onglet_title_bar_text);
                document.getElementById(this.onglet_tittle_bar_id).appendChild(new_onglet_title_bar_text);

        }

        this.set_squelettes = function(first_onglet, last_onglet, normal_onglet)
        {
                //alert('set_squelettes');
                this.squelette_first_onglet = first_onglet;
                this.squelette_last_onglet = last_onglet;
                this.squelette_onglet = normal_onglet;
        }

        this.set_css = function(selected_onglet, hidden_onglet)
        {
                //alert('set_css');
                this.css_selected_onglet = selected_onglet;
                this.css_hidden_onglet = hidden_onglet;
        }

        this.set_onglets_container = function(onglets_container_id)
        {
                //alert('set_container');
                this.onglets_container = onglets_container_id;
        }

        this.set_onglet_title_bar_model = function(onglet_title_bar_close_picture,onglet_title_bar_innerHTML)
        {
                //alert('set_onglet_title_bar_model');
                this.onglet_title_bar_close_picture = onglet_title_bar_close_picture;
                this.onglet_title_bar_innerHTML = onglet_title_bar_innerHTML;
        }
}

/////////////////////////////////////////
// fontions pour les onglets dans les onglets
////////////////////////////////////////
function class_onglet_contenu()
{
        var div_handler;
        var URL;
        var params;
        var is_closable;
        var title;
        var squelette;
        var container_handler;
        var css;
        var parent;
        var parent_name;
        var is_scrollable;
        var calling_document_handler;


        this.create_onglet = function(parent_name,title,is_scrollable,onglets_content_container_id)
        {
                this.parent_name = parent_name;
                this.title = title;
                this.is_scrollable = is_scrollable;

                this.div_handler = document.getElementById(onglets_content_container_id);
                //alert(onglets_content_container_id);

                this.container_handler = creerElement(this.squelette.container.type);

                if (document.addEventListener){
                        this.container_handler.addEventListener('click', createDelegate(this, this.select_onglet), false);
                } else if (document.attachEvent){
                        this.container_handler.attachEvent('onclick', createDelegate(this, this.select_onglet));
                }

                if(this.squelette.container.style != '')
                {
                        setAttributeStyle(this.squelette.container.style,this.container_handler);
                }

                this.draw_onglet();

        }

        this.select_onglet = function(event)
        {
                //alert('select_onglet');
                eval(this.parent_name).swap_onglets(this);
        }

        this.draw_onglet = function()
        {
                //alert('draw_onglet');
                //alert(this.title);
                this.container_handler.innerHTML = '';
                for(element in this.squelette.elements)
                {
                        var new_element = creerElement(this.squelette.elements[element][0]);
                        if((this.squelette.elements[element]) && (this.squelette.elements[element][2] != ''))
                        {
                                //alert('attributes = ' + this.squelette.elements[element][2]);
                                setAttributeStyle(this.squelette.elements[element][2],new_element);
                        }
                        switch(this.squelette.elements[element][0])
                        {
                                case "img":
                                        if(this.squelette.elements[element][3] != '')
                                        {
                                                new_element.setAttribute('alt',this.squelette.elements[element][3]);
                                        }
                                        new_element.setAttribute('src',this.squelette.elements[element][1]);
                                        break;
                                case "a":
                                        new_element.setAttribute('title',this.title);
                                        new_element.setAttribute('href','javascript:void(0);');
                                        new_element.innerHTML = this.title;
                                        break;

                        }
                        this.container_handler.appendChild(new_element);
                }
        }

        this.get_div_handler = function()
        {
               // alert('get_div_handler');
                return this.div_handler;
        }

        this.get_container_handler = function()
        {
                return this.container_handler;
        }

        this.set_css = function(css)
        {
                if(this.container_handler)
                {
                        //alert(css);
                        this.container_handler.className = css;
                }
                this.css = css;
        }

        this.set_squelette = function(squelette)
        {
                //alert('set_squelette');
                this.squelette = squelette;
        }

        this.set_title = function()
        {

        }
}

function class_bar_onglets_contenu()
{
        var onglets_container;
        var div_container_id;
        var list_of_onglets;
        var nb_onglets;
        var actual_selected_onglet;
        var former_selected_onglet;
        var squelette_selected_onglet;
        var squelette_hidden_onglet;
        var squelette_onglet;
        var css_selected_onglet;
        var css_hidden_onglet;
        var object_name;
        var type_of_visibility;

        this.init_bar_onglets = function(div_container_id,object_name)
        {
                this.nb_onglets = 0;
                this.list_of_onglets = new Array();
                this.div_container_id = div_container_id;
                this.object_name = object_name;
                this.type_of_visibility = 'visibility';
        }

        this.add_onglet = function(title,is_scrollable,onglets_content_container_id)
        {
                //alert('add_onglet');
                this.list_of_onglets[this.nb_onglets] = new class_onglet_contenu();
                this.list_of_onglets[this.nb_onglets].squelette = this.squelette_hidden_onglet;
                this.list_of_onglets[this.nb_onglets].create_onglet(this.object_name,title,is_scrollable,onglets_content_container_id);
                document.getElementById(this.onglets_container).appendChild(this.list_of_onglets[this.nb_onglets].get_container_handler());
                //document.getElementById(this.div_container_id).appendChild(this.list_of_onglets[this.nb_onglets].get_div_handler());
                this.swap_onglets(this.list_of_onglets[this.nb_onglets]);
                this.nb_onglets++;
        }

        this.swap_onglets = function(new_selected_onglet)
        {
                //alert('swap_onglets');

                if(this.actual_selected_onglet)
                {
                        this.former_selected_onglet = this.actual_selected_onglet;
                        this.former_selected_onglet.set_css(this.css_hidden_onglet);
                        this.former_selected_onglet.set_squelette(this.squelette_hidden_onglet);
                        this.former_selected_onglet.draw_onglet();
                        former_selected_onglet_iframe_handler = this.former_selected_onglet.get_div_handler();
                        if(this.type_of_visibility == 'display')
                        {
                                former_selected_onglet_iframe_handler.style.display = "none";
                        }
                        else
                        {
                                former_selected_onglet_iframe_handler.style.visibility = "hidden";
                        }
                }
                else
                {
                        this.former_selected_onglet = new_selected_onglet;
                }
                this.actual_selected_onglet = new_selected_onglet;
                this.actual_selected_onglet.set_css(this.css_selected_onglet);
                this.actual_selected_onglet.set_squelette(this.squelette_selected_onglet);
                this.actual_selected_onglet.draw_onglet();

                actual_selected_onglet_iframe_handler = this.actual_selected_onglet.get_div_handler();
                if(this.type_of_visibility == 'display')
                {
                        actual_selected_onglet_iframe_handler.style.display = "block";
                }
                else
                {

                        actual_selected_onglet_iframe_handler.style.visibility = "visible";
                }
        }

        this.set_squelettes = function(selected_onglet, hidden_onglet)
        {
                //alert('set_squelettes');
                this.squelette_selected_onglet = selected_onglet;
                this.squelette_hidden_onglet = hidden_onglet;
        }

        this.set_css = function(selected_onglet, hidden_onglet)
        {
                //alert('set_css');
                this.css_selected_onglet = selected_onglet;
                this.css_hidden_onglet = hidden_onglet;
        }

        this.set_onglets_container = function(onglets_container_id)
        {
                //alert('set_container');
                this.onglets_container = onglets_container_id;
        }

        this.set_type_of_visibility = function(type_of_visibility)
        {
                //alert('set_type_of_visibility');
                this.type_of_visibility = type_of_visibility;
        }

}


