try{
	xmlhttp = new XMLHttpRequest();
}catch(ee){
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
		}
	}
}



function carrega_concurso(no_concurso){

	document.getElementById("carregando1").style.display = "block";
	
	if (!no_concurso)
	{
		//Abre a url
		v_d = new Date();
		_dadoNull = v_d.getTime();
		xmlhttp.open("GET", "quina_pesquisa_new.asp?f_quina=" + _dadoNull ,true);	
	}
	else
	{
		//Abre a url
		xmlhttp.open("GET", "quina_pesquisa_new.asp?submeteu=sim&opcao=concurso&txtConcurso="+no_concurso,true);
	}

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

		if (xmlhttp.readyState==4)
		{
			var inner_conc = "";
			var inner_acumulou = "";

            //Lê o texto
            var texto=xmlhttp.responseText;

            //Desfaz o urlencode
			texto = texto.split("|");
			var inner_tab_ganhadores;
			
			document.getElementById("dtitcrescenteDiv").style.display = "none";
			document.getElementById("dtitsorteioDiv").style.display = "none";
			
			
			
			if(texto[0] == ""){//Se não existir nenhum concurso
				//alert ('NAUM EXISTE CONCURSO COM ESSE NUMERO!');
				document.getElementById("span_conc").innerHTML = texto[1];
				document.getElementById("menu_concurso").style.display = "none";
				document.getElementById("detalhes_resultado").style.display = "none";
				document.getElementById("primeiro_sorteio").style.display = "none";
				document.getElementById("tab_ganhadores").style.display = "none";
				document.getElementById("observacao").style.display = "none";
				document.getElementById("msg_concurso").style.display = "block";
				document.getElementById("msg_concurso").innerHTML = "<div id=\"div_msg_concurso\">Não existe concurso!</div>";
				document.getElementById("ganhadores_estado").style.display = "none";
				document.getElementById("observacoes").style.display = "none";
				document.getElementById("vr_arrecadado").style.display = "none";
			}else{
				//Verificação se houve resultado de sorteio
				if(texto[14] == "0" ||  texto[14] == "")
				{
					//alert('NAUM EXISTE RESULTADO COM ESSE NUMERO');
					document.getElementById("span_conc").innerHTML = texto[0];
					document.getElementById("msg_concurso").style.display = "none";
					document.getElementById("detalhes_resultado").style.display = "none";
					document.getElementById("primeiro_sorteio").style.display = "none";
					//document.getElementById("btn_imprimir").innerHTML = "<img src=\"/loterias/_images/button/btn_imprimir_resultadojogo_off.jpg\" width=\"148\" height=\"73\" border=\"0\" />";
					// Imprime o campo de observação no local onde eh mostrado o valor do resultado
					document.getElementById("observacao").innerHTML = texto[15];
					document.getElementById("observacao").style.display = "block";
					document.getElementById("tab_ganhadores").innerHTML = "";
					document.getElementById("ganhadores_estado").style.display = "none";
					document.getElementById("observacoes").style.display = "none";
					document.getElementById("vr_arrecadado").style.display = "none";
					loca_data = "";
				}else{
					document.getElementById("observacoes").style.display = "block";
					document.getElementById("msg_concurso").style.display = "none";
					document.getElementById("menu_concurso").style.display = "block";
					document.getElementById("primeiro_sorteio").style.display = "block";
					document.getElementById("detalhes_resultado").style.display = "block";
					document.getElementById("tab_ganhadores").style.display = "block";
					//document.getElementById("observacao").style.display = "none";
					document.getElementById("imagem_posterior").value = texto[1];
					document.getElementById("imagem_anterior").value = texto[5];
					document.getElementById("auditorio").value = texto[4];
					document.getElementById("data_conc").value = texto[16];
					document.getElementById("span_conc").innerHTML = texto[0];
			
					var acumulou = texto[13];
					var auditorio = texto[4];


			
					/* local do sorteio */
					if (auditorio == "A"){
						auditorio = "Auditório da CAIXA";
					}else{
						if(auditorio == "C"){
							auditorio = "Caminhão da Sorte";
						}else{
							auditorio = "";
						}
					}
				
				
					var loca_data = ""
					loca_data += "<div id=\"menu_concurso_bt_data\">"
					loca_data += "<a href=\"#\" onclick=\"return false;\" class=\"tooltip\"><b>"+ texto[16] +"</b> (" + auditorio.substring(0,9) + "...)";
					
					if(texto[2] != ""){
						//loca_data += "<br /><b>Realizado em " +texto[2].substring(0,9) + "../" + texto[3] + "</b>";
						loca_data += "<br /><b>Realizado em " + texto[2].substring(0,5) + ".../" + texto[3] + "</b>";
					}
					
					if(texto[2] != ""){
						loca_data += "<span style=\"font-size:13px;\"><b>"+ texto[16] +"</b> (" + auditorio + ")";
						loca_data += "<br /><b>Realizado em " + texto[2] + "/" + texto[3] + "</b></span>";
					}
					loca_data += "</a></div>"
				
				
					//alert(texto[17]);
					//ACUMULOU
					//Se não existe estimativa
					if (texto[17]=="0,00" || texto[17]==""){
						//Verifica se ñ houve acumulo de premio
						if (acumulou == "0,00")
						{//alert('sem acumulo, sem estimativa');
							document.getElementById("detalhes_resultado").style.display = "none";
							document.getElementById("ganhadores_estado").style.display = "block";
							document.getElementById("ganhadores_estado").innerHTML = texto[19];
						}
						else
						{//alert('com acumulo, sem estimativa');
							inner_acumulou += "<strong class=\"img_acumulou\" style=\"font-size:20px;\">Acumulou</strong><br /><br />";
							inner_acumulou += "Valor Acumulado:<br />";
							inner_acumulou += "<span style=\"color: #666; font-size: 20px;\">R$ </span><span style=\"font-size: 26px; color: #4C2D7E; font-weight:bold;\">" + acumulou + "</span>";

							document.getElementById("detalhes_resultado").style.display = "block";
							document.getElementById("detalhes_resultado").innerHTML = inner_acumulou;
							document.getElementById("ganhadores_estado").style.display = "none";
						}
					}else{//Se existe estimativa
						if (acumulou == "0,00")
						{//alert('sem acumulo, com estimativa');
							inner_acumulou = "<strong><span style=\"font-size: 14px;\">Estimativa de Prêmio </span></strong><br />";
							inner_acumulou += "<span style=\"color:#666; font-size: 24px; font-weight: bold;\"> R$ </span><span style='color:#4C2D7E; font-size: 24px; font-weight: bold;'>" + texto[17] + "</span><br/>";
							inner_acumulou += "<span style=\"font-size: 13px;\">*para o próximo concurso, a ser realizado em " + texto[18]+"</span>";
							document.getElementById("ganhadores_estado").style.display = "block";
							document.getElementById("ganhadores_estado").innerHTML = texto[19];
						}
						else
						{//alert('com acumulo, com estimativa');

							inner_acumulou = "<br><strong class=\"img_acumulou\" style=\"font-size:20px;\">Acumulou</strong><br/><br/>";
						
							inner_acumulou += "<strong><span style=\"font-size: 14px;\">Estimativa de Prêmio </span></strong><br />";
							inner_acumulou += "<strong><span style=\"color:#666; font-size: 24px; \"> R$ </span><span style='color:#4C2D7E; font-size: 22px;'>" + texto[17] + "</span></strong><br/>";
							inner_acumulou += "<span style=\"font-size: 13px;\">*para o próximo concurso, a ser realizado em " + texto[18]+"</span><br /><br />";
							inner_acumulou += "<div id=\"valoracumulado\" style=\"border-top:1px solid #CCC; margin-bottom:1px; padding-bottom: 5px;font-size:13px\"><br />";
							inner_acumulou += "Valor Acumulado para a Quina:<br>";
							inner_acumulou += "<span style='color:#666; font-size: 16px; font-weight: bold'> R$ </span><span style='color:#4C2D7E; font-size: 18px; font-weight: bold;'>" + acumulou + "</span>";
							inner_acumulou += "</div>";
							
							document.getElementById("ganhadores_estado").style.display = "none";
						}
						document.getElementById("detalhes_resultado").style.display = "block";
						document.getElementById("detalhes_resultado").innerHTML = inner_acumulou;
					}
					
					
				
					//Tabela com numeros de ganhadores
					inner_tab_ganhadores = "<div id=\"titulo_premiacao\"></div>";
					inner_tab_ganhadores +=  "<table id=\"tabela_premiacao\" summary=\"Premiações\" cellspacing=\"0\" cellpadding=\"2\"><tr><td colspan=\"3\" height=\"10\"></td></tr><tr><th class=\"meio\">Faixa de premiação</th><th class=\"meio\">Nº de ganhadores</th><th class=\"direita\">Valor do Prêmio (R$)</th></tr><tr><td class=\"meio\">Quina</td>";
					inner_tab_ganhadores += "<td class=\"meio\">" + texto[6] + "</td>";
					inner_tab_ganhadores += "<td class=\"direita\">" + texto[7] + "</td>";
					inner_tab_ganhadores += "</tr><tr><td class=\"meio\">Quadra</td>";
					inner_tab_ganhadores += "<td class=\"meio\">" + texto[8] +  "</td>";
					inner_tab_ganhadores += "<td class=\"direita\">" + texto[9] + "</td>";
					inner_tab_ganhadores += "</tr><tr><td class=\"meio\">Terno</td><td class=\"meio\">"+ texto[10] + "</td><td class=\"direita\">" + texto[11] + "</td></tr><tr><td colspan=\"3\" height=\"10\"></td></tr></table>";
					
					document.getElementById("primeiro_sorteio").innerHTML = texto[14];
					document.getElementById("tab_ganhadores").innerHTML = inner_tab_ganhadores;


					mostra_crescente();	//17.09.2006 - ordem sorteio
					//alert(texto[14])

					
					//document.getElementById("div_tabela_premiacao").innerHTML = "<div style=\"display:block;\">";
					document.getElementById("btn_imprimir").innerHTML = "<a class=\"btn_impressaoLoterias\" href=\"javascript:imprimir_quina(); void(null);\" title=\"Imprimir\"></a>";

					//Valor Arrecadado 
					if ((texto[20] == "") || (parseInt(texto[20]) == 0)){
						document.getElementById("vr_arrecadado").style.display = "none";
					}else{
						document.getElementById("vr_arrecadado").style.display = "block";
						document.getElementById("vr_arrecadado").innerHTML = "<span style=\"font-size:16px; font-weight: bold;\">Arrecadação Total:</span> <span style=\"color: rgb(102, 102, 102); font-size: 20px; font-weight:bold;\"> R$</span> <span style=\"font-size: 18px; color:#4C2D7E; font-weight: bold;\">" + texto[20] + "</span>";
					}
				}
				
				var imagem_posterior = texto[1];
				var imagem_anterior = texto[5];

				//Monta o menu de navegação entre os resultados
				if (imagem_posterior == "")
				{
					inner_conc += "<div id=\"menu_concurso_bt_ant\">" + imagem_anterior + "</div>";
					inner_conc += loca_data;
					inner_conc += "</div> <div id=\"menu_concurso_bt_prx\"><span class=\"btn_off_prx_conc\"></div>";
				}
				else
				{
					if (imagem_anterior == "")
					{
						inner_conc += "<div id=\"menu_concurso_bt_ant\"><span class=\"btn_off_ant_conc\"></div>";
						inner_conc += loca_data;
						inner_conc += "<div id=\"menu_concurso_bt_prx\">" + imagem_posterior + " </div>";
					}
					else
					{
						inner_conc += "<div id=\"menu_concurso_bt_ant\">" + imagem_anterior + "</div>";
						inner_conc += loca_data;
						inner_conc += "<div id=\"menu_concurso_bt_prx\">" + imagem_posterior + "</div>";
					}
				}
				document.getElementById("menu_concurso").style.display = "block";
				document.getElementById("menu_concurso").innerHTML = inner_conc;
				//OBSERVACAO
				document.getElementById("observacao").style.display = "block";
				document.getElementById("observacao").innerHTML = texto[15];
				if(texto[19]!=""){
					document.getElementById("ganhadores_estado").style.display = "block";
					document.getElementById("ganhadores_estado").innerHTML = texto[19];
				}

			}
			document.getElementById("carregando1").style.display = "none";
        }
    }
    xmlhttp.send(null);
	if (!no_concurso){
		//document.getElementById('destaque_publicitario').innerHTML = document.getElementById('flashpublicidade').value;
	}
}

function submete_div(concurso) {
	document.frmPortal1.submeteu.value = "sim"
	document.frmPortal1.opcao.value = "concurso"
	document.frmPortal1.txtConcurso.value = concurso
	document.frmPortal1.submit()
} 	

function mostra_sorteio() {
	document.getElementById("dtitcrescenteDiv").style.display = "none";
	document.getElementById("dtitsorteioDiv").style.display = "block";
	document.getElementById("sorteio2").style.display = "none";
	document.getElementById("sorteio1").style.display = "block";

}

function mostra_crescente() {
	document.getElementById("dtitsorteioDiv").style.display = "none";
	document.getElementById("dtitcrescenteDiv").style.display = "block";
	document.getElementById("sorteio1").style.display = "none";
	document.getElementById("sorteio2").style.display = "block";

}


function imprimir_quina()
{
	var numero_concurso = document.getElementById("span_conc").innerHTML;
	
	window.open('/loterias/loterias/quina/quina_impressao_new.asp?submeteu=sim&opcao=concurso&txtConcurso='+numero_concurso,"", 'width=800,height=620');
}

