	var CatEscolhidas = new Array(0);
	var table_categoria = "cat";

	
	function Categoria(Desc, Codigo, Superior){
		this.Desc = Desc;
		this.Codigo = Codigo;
		this.Superior = Superior;
	}

	function CategoriaEscolhida(Cod, Descricao){
		this.Cod = Cod;
		this.Descricao = Descricao;
	}
    
    function preenchePrincipais(){
    	for (loop=1; loop < Principais.length; loop++)
  		{
   			choose_category.options[loop].text =Principais[loop].Desc;
   			choose_category.options[loop].value =Principais[loop].Codigo;
  		}
    }
    
	function swapOptions(the_pather_id, the_child)
	{
 	 	var numbers_select = eval(the_child);
  		var the_pather = the_pather_id;
  		setOptionText(numbers_select, "Secundarias", the_pather);
	}

	function changeOptions(the_pather_id)
	{
  		var numbers_select = window.document.categoria.the_options;
  		var the_pather = eval(the_pather_id);
  		setOptionText(window.document.categoria.the_options, "Ternarias", the_pather);
	}

	function setOptionText(the_select, the_array, the_pather)
	{
		limpaLista(the_select);
		var arrayEscolhido = eval(the_array);
 		the_select.length = arrayEscolhido.length;
		ct = 1;
	 	for (loop=0; loop < arrayEscolhido.length; loop++)
  		{  			
			superiorAtual = arrayEscolhido[loop].Superior;
  			if(superiorAtual == the_pather){
		   		the_select.options[ct].text = arrayEscolhido[loop].Desc;
		   		the_select.options[ct].value = arrayEscolhido[loop].Codigo;		   		
		   		ct ++;
		   	}
  		}
  		the_select.length = ct;
	}	
	
	function setChoices(param1, param2)
        {
                var tam = CatEscolhidas.length;
                var novoTam = tam+1;
                var temp = new Array(novoTam);
                for(loop=0; loop < CatEscolhidas.length; loop++){
                        temp[loop] = CatEscolhidas[loop];
                }
                var cat1Selected = document.categoria.choose_category.selectedIndex;
                var cat1 = document.categoria.choose_category.options[cat1Selected].text;
                var cat2Selected = document.categoria.the_examples.selectedIndex;
                var cat2 = document.categoria.the_examples.options[cat2Selected].text;
                //var cat3Selected = document.categoria.the_options.selectedIndex;
                //var cat3 = document.categoria.the_options.options[cat3Selected].text;
                
                var cod =  document.categoria.the_examples.options[cat2Selected].value;              
               	//var dsc_categoria = cat1+" - "+cat2+" - "+cat3;
               	var dsc_categoria = cat1+" - "+cat2;
               
                temp[tam] = new CategoriaEscolhida(cod, dsc_categoria);
                CatEscolhidas = temp;
                
                preencheEscolhas();

                //swapOptions(param1, param2);
        }

        function preencheEscolhas()
        {
        		table_categoria = "<table>";
        		limpaLista(document.categoria.the_choices);
                for (loop=0; loop < CatEscolhidas.length; loop++)
                {
                        document.categoria.the_choices.options[loop].text = CatEscolhidas[loop].Descricao;
                        document.categoria.the_choices.options[loop].value = CatEscolhidas[loop].Descricao;
                        // construindo tabela com as categorias
                        table_categoria = table_categoria+" <tr><td><input type=&#34;checkbox&#34; name=&#34;key&#34; value=&#34;"+CatEscolhidas[loop].Codigo+"&#34;></td>";
                        table_categoria = table_categoria+" <td>"+CatEscolhidas[loop].Descricao+"</td></tr>";
                }
        		table_categoria = table_categoria+"</table>";
                limpaLista(document.categoria.the_examples);
                //limpaLista(document.categoria.the_options);                
        }

        function excluirSelecionada(param1, param2)
        {
                var selecionada = document.categoria.the_choices.selectedIndex;
                var temp = new Array(CatEscolhidas.length-1);
                var count = 0;
                for (loop=0; loop < CatEscolhidas.length; loop++)
                {
                        if(loop!=selecionada){
                                temp[count] = CatEscolhidas[loop];
                                count++;
                        }
                }
                CatEscolhidas = temp;
                preencheEscolhas();
                
                swapOptions(param1, param2);
        }

        function limpaLista(lista){
                for(loop=0; loop <lista.length; loop++)
                {
                        lista.options[loop].text = "";
                }
        }
        
        function selecionarEscolhidas()
        {
                var catEsc="";
                for (loop=0; loop < CatEscolhidas.length; loop++)
                {
                                catEsc = catEsc + CatEscolhidas[loop].Cod+"#";
                }
                document.categoria.categorias_escolhidas.value = catEsc;
        }
        