function numeroEnter(){
	enviarPesquisa();
}

function enviarPesquisa(){
	//Adiciona a pesquisa de legislação no campo assunto
	addConsulta()

	var campo_numero 			= document.getElementById("numero");
	var campo_ementa 			= document.getElementById("ementa");
	var campo_ministro			= document.getElementById("ministro");
	var campo_dataInicial		= document.getElementById("dataInicial");
	var campo_tipoBuscaJuris	= document.getElementById("tipoBuscaJuris");	
	var frmPesquisa 			= document.getElementById("frmPesquisa");
	var txtPesquisaLivre		= document.getElementById("txtPesquisaLivre");
	
	if((txtPesquisaLivre.value == "") && (campo_numero.value == "") && (campo_ementa.value == "") && (campo_ministro.value == "") && (campo_dataInicial.value == "") && (campo_tipoBuscaJuris.value == "")){
		alert("Informe o argumento de pesquisa");
		txtPesquisaLivre.focus();
		return false;
	}else{
		
		
			//Verifica se a data esta correta e se data inicial eh inferior a data final
	var data_inicial = document.getElementById('dataInicial');
	var data_final = document.getElementById('dataFinal');
	if(data_inicial.value != ""){
		if(!validarData(data_inicial.value)){
			document.getElementById("msg_data").innerHTML = "A data está incorreta.";
			data_inicial.focus();
			return false;
		}else{
			document.getElementById("msg_data").innerHTML = "";
		}
	}
	if(data_final.value != ""){
		if(!validarData(data_final.value)){
			document.getElementById("msg_data").innerHTML = "A data está incorreta.";
			data_final.focus();
			return false;
		}else{
			document.getElementById("msg_data").innerHTML = "";
		}
	}	
	if((data_inicial.value != "") && (data_final.value != "")){
		if(validarData(data_inicial.value) && (validarData(data_final.value))){
			if(compararData(data_inicial.value, data_final.value) == -1){
				document.getElementById("msg_data").innerHTML = "A data inicial deve ser menor que data final.";
				data_inicial.focus();
				return false;
			}else if(compararData(data_inicial.value, data_final.value) == 0){
				//document.getElementById("msg_data").innerHTML = "As datas informadas são iguais.";
				//data_final.focus();
				//return false;
			}else{
				document.getElementById("msg_data").innerHTML = "";
			}
		}else{
			return false;
		}
	}
	
	
	

		
		
		
		
		
		
		
		
		
		
		
		
		
		//Verifica se existe pelo menos uma base de pesquisa
		qtdBase = 0;
		for(var i = 0; i < document.frmPesquisa.elements.length ; i++) {
			if (document.frmPesquisa.elements[i].name == "base") {
				if(document.frmPesquisa.elements[i].checked == true){
					qtdBase = qtdBase + 1;
				}
			}
		}	
		
		
		
		
		
		
		if(qtdBase == 0){
			alert("Selecione uma base de pesquisa");
			return false;
		}else if(qtdBase == 1){
			document.frmPesquisa.action = "listarJurisprudencia.asp";
			document.frmPesquisa.submit();
		}else{
			document.frmPesquisa.action = "listarConsolidada.asp";
			document.frmPesquisa.submit();
		}
		document.getElementById("divCarregando").innerHTML = "<img src='../util/imagem/loading.gif' width='16' height='16' align='left' alt='' border='0'>&nbsp;Aguarde...";
	}
	
	
	//verifica se o campo é numérico
	/*if(campo_numero.value != ""){
		if(!validarNumero(campo_numero.value)){
			document.getElementById("msg_numero").innerHTML = '<%=mensagemPadrao("campoNumerico")%>';
			campo_numero.focus();
		}else{
			document.getElementById("msg_numero").innerHTML = "";				
		}
	}else{
		alert("OK")			
		document.frmPesquisa.submit();
	}*/
	
			
}

//Função para desabilitar campos que não fazem parte da regra de pesquisa
/*
	arg[0] = Acórdãos 
	arg[1] = Súmulas
	arg[2] = Decisões Monocráticas  
	arg[3] = Decisões da Presidência 
	arg[4] = Questões de Ordem
	arg[5] = Todas
*/
function verificarBase(arg, nomeFrm, i){		
	if (i == 0){			
		for(j = 0; j < 8 ; j++) {
			if(arg[8].checked == true){
				arg[j].checked = true;
			}else{
				arg[j].checked = false;
			}
		}
	}else{			
		if ((arg[0].checked == false) || (arg[1].checked == false) || (arg[2].checked == false) || (arg[3].checked == false) || (arg[4].checked == false) || (arg[5].checked == false) || (arg[6].checked == false) || (arg[7].checked == false)){
			arg[8].checked = false;
		}			
	}
}

//Adiciona os conectores a campo de pesquisa
function addConector(conector){
	campoPesquisa			= document.getElementById("txtPesquisaLivre")
	txtPesquisaLivre		= campoPesquisa.value;
	campoPesquisa.value		= txtPesquisaLivre + conector;
	campoPesquisa.focus();
}

//Adiciona o ano Legislação no campo adicional
function anoLegis(){
	var anoLegislacao = document.getElementById("nomeLegislacao").value;
	anoLegislacao = anoLegislacao.split(",");
	if (anoLegislacao[1]==0) {
	document.getElementById("txtAnoLegislacao").value = "Número";					
	}else{
	document.getElementById("txtAnoLegislacao").value = anoLegislacao[1];		
	};
}
function limparLegis() //função para setar o foco no campo Argumento do formulário
{
	if (document.getElementById("txtAnoLegislacao").value == 'Número') {
		document.getElementById("txtAnoLegislacao").value ='';
	}
}
function addConsulta(){
	//Campo que vai receber os parametros de pesquisa
	campoPesquisa			= document.getElementById("txtPesquisaLivre")
	txtPesquisaLivre		= campoPesquisa.value;
	
	//Tipos de legislação
	nomeLegislacao 		= document.getElementById("nomeLegislacao").value;		

	nomeLegislacao		= nomeLegislacao.split(",");

	if (nomeLegislacao[1]==0 ) { 
		nomeLegislacao[1] = document.getElementById("txtAnoLegislacao").value;
		while (nomeLegislacao[1].length < 6)
			nomeLegislacao[1] = '0' + nomeLegislacao[1];
	}

	if (nomeLegislacao[1]== 'Número' ) { 
		nomeLegislacao[1] = "";
	}
	//nomeLegislacao		= nomeLegislacao[0] + "-" + nomeLegislacao[1]
	
	var tipoLegislacao1 = document.getElementById("tipoLegislacao1").value;
	var tipoLegislacao2 = document.getElementById("tipoLegislacao2").value;
	var tipoLegislacao3 = document.getElementById("tipoLegislacao3").value;
	var tipoLegislacao4 = document.getElementById("tipoLegislacao4").value;
	
	//Campos com valores de legislação
	var valorLegislacao1 = document.getElementById("valorLegislacao1").value;
	var valorLegislacao2 = document.getElementById("valorLegislacao2").value;
	var valorLegislacao3 = document.getElementById("valorLegislacao3").value;
	var valorLegislacao4 = document.getElementById("valorLegislacao4").value;
	
	//Formata Legislação inserindo zeros à esquerda se for do tipo: artigos, incisos e parágrafos	
	/*
	if (valorLegislacao1 != '') {
		if ((tipoLegislacao1 = "PAR") && (!isNaN(valorLegislacao1))) {
			while ((valorLegislacao1.length < 5) && (tipoLegislacao1 != "LET"))
				valorLegislacao1 = '0' + valorLegislacao1;
				document.getElementById("valorLegislacao1").maxLength = 5;
		 }else{
				document.getElementById("valorLegislacao1").maxLength = 7;
		 }
	}	
	*/
	
	if (valorLegislacao1 != '') {
		if (isNaN(valorLegislacao1)) {
			document.getElementById("valorLegislacao1").maxLength = 7;
		 }else{
			while ((valorLegislacao1.length < 5) && (tipoLegislacao1 != "LET"))
				valorLegislacao1 = '0' + valorLegislacao1;
				document.getElementById("valorLegislacao1").maxLength = 5;
		 }
	}
	if (valorLegislacao2 != '') {		
		if (isNaN(valorLegislacao2)) {
				document.getElementById("valorLegislacao2").maxLength = 7;
		 }else{
			while ((valorLegislacao2.length < 5) && (tipoLegislacao2 != "LET"))
				valorLegislacao2 = '0' + valorLegislacao2;
				document.getElementById("valorLegislacao2").maxLength = 5;
		 }
	}
	if (valorLegislacao3 != '') {		
		if (isNaN(valorLegislacao3)) {
			document.getElementById("valorLegislacao3").maxLength = 7;
		}else{
			while ((valorLegislacao3.length < 5) && (tipoLegislacao3 != "LET"))
				valorLegislacao3 = '0' + valorLegislacao3;
				document.getElementById("valorLegislacao3").maxLength = 5;
		 }
	}
	if (valorLegislacao4 != '') {		
		if (isNaN(valorLegislacao4)) {
				document.getElementById("valorLegislacao4").maxLength = 7;
		 }else{
			while ((valorLegislacao4.length < 5) && (tipoLegislacao4 != "LET"))
				valorLegislacao4 = '0' + valorLegislacao4;
				document.getElementById("valorLegislacao4").maxLength = 5;
		 }
	}
	

	
	if(txtPesquisaLivre != ""){
		//Pesquisa "com" argumentos
		if(nomeLegislacao.length == 2 ){
			document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " e " + nomeLegislacao[0]+"-"+nomeLegislacao[1];
		}
		
		if(valorLegislacao1 != ""){
			document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " mesmo " + tipoLegislacao1 + "-" + valorLegislacao1
		}

		if(valorLegislacao2 != ""){
			document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao2 + "-" + valorLegislacao2
		}

		if(valorLegislacao3 != ""){
			document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao3 + "-" + valorLegislacao3
		}

		if(valorLegislacao4 != ""){
			document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao4 + "-" + valorLegislacao4
		}			
	}else{
		//Pesquisa "sem" argumentos
		if(nomeLegislacao.length == 2 ){
			document.getElementById("txtPesquisaLivre").value = nomeLegislacao[0]+"-"+nomeLegislacao[1];
		}

		if(valorLegislacao1 != ""){
			if(nomeLegislacao.length == 1 ){
				if((valorLegislacao1 != "") && (valorLegislacao2 == "") && (valorLegislacao3 == "") && (valorLegislacao4 == "") ){
					document.getElementById("txtPesquisaLivre").value = tipoLegislacao1 + "-" + valorLegislacao1
				}else if(valorLegislacao1 != ""){
					document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao1 + "-" + valorLegislacao1
				}
			}else{
				document.getElementById("txtPesquisaLivre").value = nomeLegislacao[0]+"-"+nomeLegislacao[1] + " mesmo " + tipoLegislacao1 + "-" + valorLegislacao1
			}
		}

		if(valorLegislacao2 != ""){
			if(nomeLegislacao.length == 1 ){
				if((valorLegislacao1 == "") && (valorLegislacao2 != "") && (valorLegislacao3 == "") && (valorLegislacao4 == "") ){
					document.getElementById("txtPesquisaLivre").value = tipoLegislacao2 + "-" + valorLegislacao2
				}else if(valorLegislacao2 != ""){
					document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao2 + "-" + valorLegislacao2
				}
			}else{
				document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao2 + "-" + valorLegislacao2
			}
		}
		
		if(valorLegislacao3 != ""){
			if(nomeLegislacao.length == 1 ){
				if((valorLegislacao1 == "") && (valorLegislacao2 == "") && (valorLegislacao3 != "") && (valorLegislacao4 == "") ){
					document.getElementById("txtPesquisaLivre").value = tipoLegislacao3 + "-" + valorLegislacao3
				}else if(valorLegislacao3 != ""){
					document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao3 + "-" + valorLegislacao3
				}
			}else{
				document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao3 + "-" + valorLegislacao3
			}
		}

		if(valorLegislacao4 != ""){
			if(nomeLegislacao.length == 1 ){
				if((valorLegislacao1 == "") && (valorLegislacao2 == "") && (valorLegislacao3 == "") && (valorLegislacao4 != "") ){
					document.getElementById("txtPesquisaLivre").value = tipoLegislacao4 + "-" + valorLegislacao4
				}else if(valorLegislacao4 != ""){
					document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao4 + "-" + valorLegislacao4
				}
			}else{
				document.getElementById("txtPesquisaLivre").value = document.getElementById("txtPesquisaLivre").value + " adj40 " + tipoLegislacao4 + "-" + valorLegislacao4
			}
		}
	}		
	
	//Apos jogar os valores no campo de pesquisa livre, zera todos os campos
	document.getElementById("nomeLegislacao").value = "";
	txtPesquisaLivre = "";
	document.getElementById("valorLegislacao1").value = "";
	document.getElementById("valorLegislacao2").value = "";
	document.getElementById("valorLegislacao3").value = "";
	document.getElementById("valorLegislacao4").value = "";
	document.getElementById("txtAnoLegislacao").value = "Número";
}

/* Função para trazer todos os ministros */
function todosMinistros(nomeFrm, arg){	
	var frm = document.forms[nomeFrm];
	for(var i = 0; i < frm.elements.length ; i++) {
		if (frm.elements[i].name == "todosrelatores") {
			if(frm.elements[i].checked == true){
				arg = "T";
			}else{
				arg = "A";
			}
		}
	}
	//Carrega o conteudo, 
	xmlhttp.open("GET", "listarMinistro.asp?tipoMinistro="+arg,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){			
			texto = xmlhttp.responseText;
			texto = texto.replace(/\+/g," ");
			texto = unescape(texto)
			document.getElementById("listarMinistro").innerHTML = texto;
		}
	}
	xmlhttp.send(null)	
}