/**
 *	Genera las Pestañas
 */
function paginasGenerarPestanias(idPagina)
{
	if (contenedorPestanias = document.getElementById('paginas-pestanias-' + idPagina))
	{
		if (listaMenu = document.getElementById('paginas-menu-' + idPagina))
		{
			if (enlaces = listaMenu.getElementsByTagName('a'))
			{
				var cantidadEnlaces = enlaces.length;
				for (cont = (cantidadEnlaces - 1); cont >= 0; cont--)
				{
					var unEnlace = enlaces[cont];
					hrefEnlace = unEnlace.href;
					hrefEnlace = hrefEnlace.split('#');
					idPestania = hrefEnlace[1];
					unEnlace.onclick = new Function('paginasMostrarPestania(\'' + idPestania + '\'); return(false);');
				}
			}
		}
		var pestanias = contenedorPestanias.childNodes;
		var cantidadPestanias = pestanias.length;
		var anchoContenedor = contenedorPestanias.clienteWidth;
		var altoContenedor = 0;
		var primeraPestania = '';
		for (cont = (cantidadPestanias - 1); cont >= 0; cont--)
		{
			if (pestanias[cont].tagName == 'DIV')
			{
				/**
				 *	Fix IE6 => clientHeight = 0
				 */
				pestanias[cont].style.display = 'inline-block';

				if (pestanias[cont].clientHeight > altoContenedor)
				{
					altoContenedor = pestanias[cont].clientHeight;
				}
				pestanias[cont].className = pestanias[cont].className + ' pestania';
				pestanias[cont].style.display = 'none';
				pestanias[cont].style.position = 'absolute';
				pestanias[cont].style.top = '0px';
				primeraPestania = pestanias[cont].getAttribute('id');
			}
		}
		contenedorPestanias.style.position = 'relative';
		contenedorPestanias.style.overflow = 'hidden';
		contenedorPestanias.style.height = altoContenedor + 'px';
		paginasPagina = idPagina;

		paginasMostrarPestania(primeraPestania);
	}
}

/**
 *	Cambia las clases del elemento
 */
function paginasCambiarEstadoPestania(elemento, activa)
{
	if (activa)
	{
		paginasAgregarClase(elemento, 'activa');
	}
	else
	{
		paginasQuitarClase(elemento, 'activa');
	}
}

/**
 *	Verifica si un elemento tiene una clase asignada
 */
function paginasVerificarClase(elemento, clase)
{
	var claseElemento = elemento.className;
	return ((claseElemento.length > 0) && ((claseElemento == clase) || (new RegExp("(^|\\s)" + clase + "(\\s|$)").test(claseElemento))));
}

/**
 *	Agrega una clase al elemento
 */
function paginasAgregarClase(elemento, clase)
{
	if (!paginasVerificarClase(elemento, clase))
	{
		elemento.className += ((elemento.className) ? (' ') : ('')) + clase;
	}
}

/**
 *	Quita una clase al elemento
 */
function paginasQuitarClase(elemento, clase)
{
	elemento.className = elemento.className.replace(new RegExp("(^|\\s+)" + clase + "(\\s+|$)"), ' ').replace(/^\s+/, '').replace(/\s+$/, '');
}

/**
 *	Muestra la Inforación de una Pestaña
 */
function paginasMostrarPestania(idPestania)
{
	if ((idPestania.length > 0) && (nuevaPestania = document.getElementById(idPestania)) && (contenedorPestanias = document.getElementById('paginas-pestanias-' + paginasPagina)))
	{
		if ((paginasPestaniaActual.length > 0) && (unaPestania = document.getElementById(paginasPestaniaActual)))
		{
			unaPestania.style.display = 'none';
		}
		nuevaPestania.style.display = 'block';
		contenedorPestanias.style.height = nuevaPestania.clientHeight + 'px';
		paginasPestaniaActual = idPestania;

		/**
		 *	Establezco la pestaña activa en el menú
		 */
		if (listaMenu = document.getElementById('paginas-menu-' + paginasPagina))
		{
			if (opciones = listaMenu.getElementsByTagName('li'))
			{
				var cantidadOpciones = opciones.length;
				for (cont = 0; cont < cantidadOpciones; cont++)
				{
					if ((enlace = opciones[cont].getElementsByTagName('a')) && (enlace.length == 1))
					{
						hrefEnlace = enlace[0].href;
						hrefEnlace = hrefEnlace.split('#');
						paginasCambiarEstadoPestania(opciones[cont], hrefEnlace[1] == idPestania);
					}
				}
			}
		}
	}
}

/**
 *	Variables para las Pestañas
 */
var paginasPagina = '';
var paginasPestaniaActual = '';

