<!--
    // *** Funciones para hacer "tabs" por JS
    
    // Función principal: se encarga de hacer todo
    
    function createTabbedPanel (id, nombreNodosTitulo)
    {
        if (nombreNodosTitulo == null)  nombreNodosTitulo = 'h2';
        var tabbed_panel = $(id);
        var paneles = getTabPanels (tabbed_panel);
        var tab_selector = crearHijoInicio (tabbed_panel, 'ul');
        tab_selector.addClassName ('tab_selector');
        for (i=0; i<paneles.length; i++) {
            var panel = $(paneles[i]);
            var panelId = panel.id;
            var nodoTitulo = panel.getElementsBySelector(nombreNodosTitulo)[0];
            var titulo = nodoTitulo.innerHTML;
            nodoTitulo.hide();
            if (i > 0)  panel.hide();
            var nodoLi = addTab (tabbed_panel, tab_selector, panelId, titulo);
            if (i == 0)  nodoLi.addClassName ('current_tab');
        }
    }
    
    function addTab (tabbed_panel, tab_selector, id, etiqueta)
    {
        var nodoLi = crearHijoFin (tab_selector, 'li', 'tab_button_' + id);
        nodoLi.addClassName('tab_button')
        nodoLi.update('<a href="#" onclick="activateTab(\'' + tabbed_panel.id + '\', \'' + id + '\');"><span>' + etiqueta + '</span></a>    ');
        return nodoLi;
    }
    
    function getTabPanels (main_panel)
    {
        main_panel = $(main_panel);
        var hijos = main_panel.childNodes;
        var num = 0;
        var elementCont = null;
        for (i=0; i<hijos.length; i++) {
            if (hijos[i].className && hijos[i].className.indexOf('tab_panel') >= 0) {
                num++;
            } else if ((elementCont == null) && (hijos[i].className && hijos[i].className.indexOf('tabpanel_container') >= 0)) {
                elementCont = hijos[i];
            }
        }

        if ((num == 0) && (elementCont != null)) {
            return getTabPanels (elementCont);
        } else {
            var res = new Array(num);
            num = 0;
            for (i=0; i<hijos.length; i++) {
                if (hijos[i].className && hijos[i].className.indexOf('tab_panel') >= 0) {
                    res[num] = $(hijos[i]);
                    num++;
                }
            }
            return res;
        }
        // getElementsByClassName no funciona bien con IE5.5
    //    return main_panel.getElementsByClassName('tab_panel');
        
    }
    function activateTab (tabbed_panel, tabPanel)
    {
        var tabbed_panel = $(tabbed_panel);
        var paneles = getTabPanels (tabbed_panel);
        var tabPanel = $(tabPanel);
        for (i=0; i<paneles.length; i++) {
            var panel = paneles[i];
            var button = $('tab_button_' + panel.id);
            if (panel != tabPanel) {
                panel.hide();
                button.removeClassName ('current_tab');
            } else {
                panel.show();
                button.addClassName ('current_tab');
            }
        }
    }
    
    function crearHijoInicio (padre, tipo, id)
    {
        var nuevo = $(document.createElement (tipo));
        nuevo.id = id;
        padre = $(padre);
        padre.insertBefore (nuevo, padre.immediateDescendants()[0]);
        return nuevo;
    }
    function crearHijoFin (padre, tipo, id)
    {
        var nuevo = $(document.createElement (tipo));
        nuevo.id = id;
        padre.appendChild (nuevo);
        return nuevo;
    }
    
    
	// Devuelve un objeto por nombre o id - se puede usar $() en su lugar
	function getObj(name)
	{
	  if (document.getElementById) {
	    return document.getElementById(name);
	  } else if (document.all) {
	    return document.all[name];
	  } else if (document.layers) {
	    return document.layers[name];
	  } else {
	  	return false;
	  }
	}

	// Pone uno u otro estilo en el elemento segun el indicador de seleccion
    function cambiarEstilo (obj, claseSel, claseNoSel, sel)
    {
    	if (obj) {
    		if (sel && obj.className) {
	    		obj.className = claseSel;
	    	} else {
	    		obj.className = claseNoSel;
	    	}
    	}
    }

	// Cambia el estilo del primer ancestro que tenga uno de los dados,
	// poniendole el otro
    function cambiarEstiloAncestro (nodo, clase1, clase2)
    {
    	var padre = null;
    	if (nodo.parentNode) {
    	    padre = nodo.parentNode;
    	} else if (nodo.parentElement) {
    	    padre = nodo.parentElement;
    	}
    	if (padre) {
    	    if (padre.className == clase1) {
	    		padre.className = clase2;
    	    } else if (padre.className == clase2) {
	    		padre.className = clase1;
    	    } else {
    	    	cambiarEstiloAncestro (padre, clase1, clase2);
    	    }
    	}
    }

	// Devuelve el contenido HTML del nodo con el id dado
	function getContenido (id)
	{
		var obj = getObj(id);
		if (obj) {
			return obj.innerHTML;
		} else {
			return null;
		}
	}

	// Modifica el contenido HTML del nodo con el id dado
	function cambiarContenido (id, contenido)
	{
		var obj = getObj(id);
		if (obj) {
		    if (document.getElementById||document.all)
		        obj.innerHTML = contenido;
		    else if (document.layers) {
		        document.describe.document.write (contenido);
		        document.describe.document.close();
		    }
		}
	}

// Funciones para elementos intercambiables

var timer = null;
var texto_borrar = "";
var id_borrar = null;

function cambioElemento (id, arrayValores, indice)
{
	borrarElementos();
    clearTimer();
    cambiarContenido (id, (indice==-1)? "" : arrayValores[indice]);
}

function limpiarOnTimeout (id, texto)
{
	if (id != id_borrar)  borrarElementos();
    clearTimer();
    texto_borrar = texto;
    id_borrar = id;
    timer = setTimeout("borrarElementos()", 500);
}

function borrarElementos()
{
    clearTimer();

    if (id_borrar != null) {
	    cambiarContenido (id_borrar, texto_borrar);
	    id_borrar = null;
    }
}

function clearTimer()
{
    if (timer != null) {
        clearTimeout (timer);
        timer = null;
    }
}

//-->

