
  	//Autor: Diogo(Zio)
  	//Exemplo no final do arquivo
  	
	var cont_sheet = 0;

	function TabSheet()
	{
		this.id_div_principal = "";
		this.id_open = "";
		this.vet_id = [];
		this.vet_nome = [];
		this.vet_onclick = [];
		this.cont_item = 0;
		this.id_sheet = cont_sheet++;
		
		this.class_tabela = "pad_sheet";
		this.class_selecionado = "pad_sheet_selecionado";
		this.class_nao_selecionado = "pad_sheet_nao_selecionado";
		
		this.SetPrincipal = function(id_div)
		{
			this.id_div_principal = id_div;
		}
		
		this.AddItem = function (nome, id)
		{
			this.vet_id[this.cont_item] = id;
			this.vet_nome[this.cont_item] = nome;
			this.cont_item++;
		}

		this.SetOnclickItem = function (id, funcao)
		{
			if (this.GetNumeroItem(id) >= 0)
			{
				this.vet_onclick[this.GetNumeroItem(id)] = funcao;
			}
		}
		
		this.GetNumeroItem = function (id)
		{
			var ret = -1;
			for (var i = 0; i < this.vet_id.length; i++)
			{
				if (this.vet_id[i] == id)
				{
					ret = i;
				}
			}
			return ret;
		}

		this.SetItemOpen = function (id)
		{
			this.id_open = id;
		}
		
		this.SetClassTabela = function (nome_class)
		{
			this.class_tabela = nome_class;
		}
		this.SetClassSelecionado = function (nome_class)
		{
			this.class_selecionado = nome_class;
		}
		this.SetClassNaoSelecionado = function (nome_class)
		{
			this.class_nao_selecionado = nome_class;
		}
		
		this.GeraTabSheet = function ()
		{
			this.GeraTabelaIndice();
		}
		
		this.GeraTabelaIndice = function()
		{
			var temp = document.getElementById(this.id_div_principal);
			if (temp)
			{
				var tab = cria_elemento(temp, "table", this.id_div_principal+"_tab"," class = '"+this.class_tabela+"' cellpadding = '0' cellspacing = '0'","");
					var tbody = cria_elemento(tab, "tbody",this.id_div_principal+"_tbody","","");
						var tr = cria_elemento(tbody, "tr",this.id_div_principal+"_tr","","");
							var cont_temp = this.cont_item;
							for (var ind = 0; ind < cont_temp; ind++)
							{
								var td = cria_elemento(tr, "td","td_sheet_"+this.vet_id[ind]," height = '20' align = 'center' class = 'pad_sheet_nao_selecionado' onclick = '"+this.vet_onclick[ind]+"; ativa_aba_tab_sheet(\"td_sheet_"+this.vet_id[ind]+"\",\""+this.vet_id[ind]+"\", "+this.id_sheet+",\""+ind+"\", \""+this.vet_nome[ind]+"\")'",this.vet_nome[ind]);
								if (ind == 0 && this.id_open == "")
								{
									ativa_aba_tab_sheet("td_sheet_"+this.vet_id[ind], this.vet_id[ind], this.id_sheet, ind, this.vet_nome[ind]);
								}
								else if (this.id_open == this.vet_id[ind])
								{
									ativa_aba_tab_sheet("td_sheet_"+this.vet_id[ind], this.vet_id[ind], this.id_sheet, ind, this.vet_nome[ind]);
								}
							}
			}
		}
	}


	var nom_td_aberto_tab_sheet = [];
	var nom_div_aberta_tab_sheet = [];
	var nom_td_antigo = "";
	var nom_div_antigo = "";
	var num_sheet_antigo = "";
	var label_sheet_antigo = "";
	var num_elemento_antigo = -1;
	function ativa_aba_tab_sheet(nom_td, nom_div, num_sheet, num_elemento, label_sheet)
	{
		var muda = true;
		try{
			muda = verifica_muda_tab_sheet(num_elemento, label_sheet, num_elemento_antigo, label_sheet_antigo);
			nom_div_antigo = nom_div;
		}catch(e){
			muda = true;		
		}

		if (muda || nom_div_antigo == "")
		{
			if (!nom_td_aberto_tab_sheet[num_sheet])
			{
				nom_td_aberto_tab_sheet[num_sheet] = "";
			}
			if (!nom_div_aberta_tab_sheet[num_sheet])
			{
				nom_div_aberta_tab_sheet[num_sheet] = "";
			}
	
			if (nom_td != nom_td_aberto_tab_sheet[num_sheet] && nom_div != nom_div_aberta_tab_sheet[num_sheet])
			{
				var id_div = document.getElementById(nom_div);
		
				if (id_div)
				{
					id_div.style.display = "";
				}
				if (nom_div_aberta_tab_sheet[num_sheet] != "" && document.getElementById(nom_div_aberta_tab_sheet[num_sheet]))
				{
					document.getElementById(nom_div_aberta_tab_sheet[num_sheet]).style.display = "none";
				}
				nom_div_aberta_tab_sheet[num_sheet] = nom_div;
		
				//coluna nao selecionada
				if (document.getElementById(nom_td_aberto_tab_sheet[num_sheet]) && nom_td != nom_td_aberto_tab_sheet[num_sheet])
				{
					var td = document.getElementById(nom_td_aberto_tab_sheet[num_sheet]);
					altera_filtro_tab_sheet(nom_td_aberto_tab_sheet[num_sheet], false);
				}
				
				//coluna selecionada
				if (document.getElementById(nom_td))
				{				
					var td1 = document.getElementById(nom_td);
					altera_filtro_tab_sheet(nom_td, true);
				}
				nom_td_aberto_tab_sheet[num_sheet] = nom_td;
			}
	
			nom_td_antigo = nom_td;
			nom_div_antigo = nom_div;
			num_sheet_antigo = num_sheet;
			label_sheet_antigo = label_sheet;
			num_elemento_antigo = num_elemento;
		}
	}

	function altera_filtro_tab_sheet(id_td, ativo)
	{
		var tabela_td = document.getElementById(id_td);

		if (ativo)
		{
			tabela_td.className = "pad_sheet_selecionado";
		}
		else
		{
			tabela_td.className = "pad_sheet_nao_selecionado";
		}
	}	
	
	
  /*
  
  Exemplo
 
<div id=Principal></div>
<div style="display:none" id="id_1">Texto a ser exibido</div>
<div style="display:none" id="id_2">Outro texto a ser exibido</div>
<SCRIPT>
	var tab = new TabSheet();
	tab.SetPrincipal("Principal");
	tab.AddItem("Nome 1", "id_1");
	tab.AddItem("Nome 2", "id_2");
	tab.GeraTabSheet();
</SCRIPT>
  
  
  */