//nessas arrays sao gravados a ultima aba aberta, por viagem
var lastopen 	= new Array();
var lastopenAba = new Array();

//esconde ou mostra as divs do voucher
function escondeDiv(id_div, id_bt, tipo_bt, id_hr, x){

	var vc_display = document.getElementById(id_div).style.display;

	//verifica a div esta fechada
	if(vc_display == "none"){
		//abre a div
		document.getElementById(id_div).style.height		= "100%";
		document.getElementById(id_div).style.display		= "block";

		//verifica se esta sendo passado a aba interna (tipo="pequeno")
		if(tipo_bt == "pequeno"){
			//chama a funcao para fechar as outras abas
			trocaAba(vc_display, id_div, id_bt, x);
		}

	}else{ //else div fechada
		//fecha a div
		document.getElementById(id_div).style.height		= "0";
		document.getElementById(id_div).style.overflow		= "hidden";
		document.getElementById(id_div).style.display		= "none";

		//verifica se esta sendo passado a aba interna (tipo="pequeno")
		if(tipo_bt == "pequeno"){
			//chama a funcao para fechar as outras abas
			trocaAba(vc_display, id_div, id_bt, x);
		}

	} //fim div fechada

	//chama a funcao que muda os botoes de +-
	mudaBotao(id_div, id_bt, tipo_bt, id_hr);
}

function mudaBotao(id_div, id_bt, tipo_bt, id_hr){
	var vc_comprimento = "0px -11px";
	var vc_display = document.getElementById(id_div).style.display;
	//verifica se a div esta fechada
	if(vc_display == "none"){
		//muda o botao para +
		document.getElementById(id_bt).style.backgroundPosition 	= "0px 0px";

		//verifica se esta sendo passado o hr(borda de baixo) para exibi-lo
		if(typeof(id_hr) != "undefined"){
			document.getElementById(id_hr).style.display 			= "block";
			if(navigator.appName == "Microsoft Internet Explorer" && tipo_bt == "pequeno")
				document.getElementById(id_hr).style.top	 			= "-2px";
		}
	}else{ //else se a div esta fechada
	
		//verifica se esta sendo passado a aba interna (tipo="pequeno")
		if(tipo_bt == "pequeno"){
			//muda estilo da aba para selecionado
			document.getElementById(id_bt).style.backgroundColor 	= "#F8F8F8";
			document.getElementById(id_bt).style.borderBottom	 	= "1px solid #F8F8F8";
		}
		
		//muda botao para -
		document.getElementById(id_bt).style.backgroundPosition 	= vc_comprimento;

		//verifica se esta sendo passado o hr(borda de baixo) para exibi-lo
		if(typeof(id_hr) != "undefined"){
			document.getElementById(id_hr).style.display = "none";
		}
	} //fim se a div esta fechada
	

}

//funcao para zerar as outras abas quando uma é aberta
function trocaAba(vc_display, id_div, id_bt, x){

	//verifica se a div esta fechada
	if (vc_display == "none"){
		//verifica se ha alguma aba selecionada anteriormente
		if(lastopen[parseInt(x)] != null){
			//zera atributos da aba
			lastopen[parseInt(x)].style.height				= "0";
			lastopen[parseInt(x)].style.overflow			= "hidden";
			lastopen[parseInt(x)].style.display				= "none";
			lastopenAba[parseInt(x)].style.backgroundColor 	= "#FFF";
			lastopenAba[parseInt(x)].style.borderBottom	 	= "1px solid #bdbdbd";
		}

		//grava historico da ultima div e ultimo botao abertos
		lastopen[parseInt(x)] 								= document.getElementById(id_div);
		lastopenAba[parseInt(x)]							= document.getElementById(id_bt);
	}
	else{ //else div fechada

		//zera historico
		lastopenAba[parseInt(x)].style.backgroundColor 		= "#FFF";
		lastopenAba[parseInt(x)].style.borderBottom	 		= "1px solid #bdbdbd";
		lastopenAba[parseInt(x)]							= null;
		lastopen[parseInt(x)] 								= null;
		
	} //fim div fechada
}

//abre janela para boletos
function emitirBoleto(id_pagamento){
	var W = 670; 	
	var H = 400;
	var X = Math.ceil( (window.screen.height - H) / 2 ) - 50;
	var Y = Math.ceil( (window.screen.width - W) / 2 ) - 16;

	window.open("pagamentos/itau.asp?pagamentoID="+id_pagamento,"Boletos","width="+W+", height="+H+", top="+X+", left="+Y+", resizeable=no");
}

function abreVoucher(viagemID, passageiroID){
	window.open("voucher/aereo.asp?viagemID="+viagemID+"&passageiroID="+passageiroID,"Voucher","width=600, height=500, top=100, left=100, location=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, directories=no, toolbar=no");
}