// JavaScript Document
var origem_selecionada;
var qtd=0;
function montaOrigem()
{
	var k =0;
	var p =0;
	var option  = new Array;
	var select_origem = document.getElementById('OrigemShow');
	var checked = document.getElementById('Origem').value;
	
	option[p] = document.createElement('option');
	option[p].text = "-";
	option[p].value = "";
	try
	{
		select_origem.add(option[p],null);
		p++;
	}
	catch(ex)
	{
		select_origem.add(option[p]);
		p++;
	}

	for(k in origem)
	{
		//alert(origem[k][0]);
		option[p] = document.createElement('option');
		option[p].text = origem[k][0];
		option[p].value = origem[k][1];
		try
		{
			select_origem.add(option[p],null);
			if(checked == option[p].value) 
				select_origem.selectedIndex = p;
			p++;			
		}
		catch(ex)
		{
			select_origem.add(option[p]);
			if(checked == option[p].value) 
				select_origem.selectedIndex = p;			
			p++;
		}
		k++;
	}

	montaDestino();
}

function montaDestino()
{
	//alert('aaa');
	var k =0;
	var p;
	var n = 0;
	var option = new Array;
	var select_destino = document.getElementById('DestinoShow');
	var checked = document.getElementById('Destino').value;	

	origem_selecionada = document.getElementById('OrigemShow').value;
	option[n] = document.createElement('option');
	
	if(origem_selecionada == 0)
	{
		option[n].text = "Selecione uma origem";
		option[n].value = "";
		try
		{
			select_destino.add(option[n],null);
		}
		catch(ex)
		{
			select_destino.add(option[n]);
		}		
		document.getElementById('DestinoShow').disabled = true;
		qtd++;
	}
	else
	{
		document.getElementById('DestinoShow').disabled = false;	
		
		option[n].text = "-";
		option[n].value = "";
		try
		{
			select_destino.add(option[n],null);
			n++;			
		}
		catch(ex)
		{
			select_destino.add(option[n]);
			n++;			
		}

		for(k in origem)
		{
			 if(origem[k][1]==origem_selecionada)
			 {
				for(p=0;p<origem[k][2].length;p++)
				{
					option[n] = document.createElement('option');
					option[n].text = origem[k][2][p][0];
					option[n].value = origem[k][2][p][1];
					try
					{
						select_destino.add(option[n],null);
						if(checked == option[n].value) 
							select_destino.selectedIndex = n;							
					}
					catch(ex)
					{
						select_destino.add(option[n]);
						if(checked == option[n].value) 
							select_destino.selectedIndex = n;	
					}
					qtd++;
					n++;
				}
				k++;
			}
		}
	}
}

function limpaOption()
{
	var k;
	//alert(qtd);
	for(k=0;k<qtd;k++)
		document.getElementById('DestinoShow').remove(0);
	montaDestino();
}

/*montaOrigem();*/