function mostrarEsconderDataFase(acao) {
	if (acao == "esconder") {
		document.getElementById("lblDataFase").style.display = "none";
		document.getElementById("txtDataFase").style.display = "none";
	} else {
		document.getElementById("lblDataFase").style.display = "block";
		document.getElementById("txtDataFase").style.display = "block";
	}
}
function mostrarEsconderBaixados(acao) {
	if (acao == "esconder") {
		document.getElementById("chkMostrarBaixados").style.display = "none";
		document.getElementById("lblMostrarBaixados").style.display = "none";
	} else {
		document.getElementById("chkMostrarBaixados").style.display = "block";
		document.getElementById("lblMostrarBaixados").style.display = "block";
	}
}
function alterarBaixados() {
	if (document.forms[0].selForma.selectedIndex == 0) {
		mostrarEsconderBaixados("esconder");
	} else if (document.forms[0].selForma.selectedIndex == 1) {
		mostrarEsconderBaixados("mostrar");
	} else if (document.forms[0].selForma.selectedIndex == 2) {
		mostrarEsconderBaixados("mostrar");
	} else if (document.forms[0].selForma.selectedIndex == 3) {
		mostrarEsconderBaixados("mostrar");
	} else if (document.forms[0].selForma.selectedIndex == 4) {
		mostrarEsconderBaixados("mostrar");
	}
}
function alterarLabelValor() {
	if (document.forms[0].selForma.selectedIndex == 0) {
		document.getElementById("lblValor").innerHTML = "<span class=\"infraTeclaAtalho\" id=\"labelValor\">N</span>úmero do Processo:</label>";
		mostrarEsconderDataFase("esconder");
	} else if (document.forms[0].selForma.selectedIndex == 1) {
		document.getElementById("lblValor").innerHTML = "<span class=\"infraTeclaAtalho\" id=\"labelValor\">N</span>ome da Parte:</label>";
		mostrarEsconderDataFase("mostrar");
	} else if (document.forms[0].selForma.selectedIndex == 2) {
		document.getElementById("lblValor").innerHTML = "<span class=\"infraTeclaAtalho\" id=\"labelValor\">N</span>úmero do CPF/CNPJ:</label>";
		mostrarEsconderDataFase("mostrar");
	} else if (document.forms[0].selForma.selectedIndex == 3) {
		document.getElementById("lblValor").innerHTML = "<span class=\"infraTeclaAtalho\" id=\"labelValor\">N</span>úmero da OAB:</label>";
		mostrarEsconderDataFase("mostrar");
	} else if (document.forms[0].selForma.selectedIndex == 4) {
		document.getElementById("lblValor").innerHTML = "<span class=\"infraTeclaAtalho\" id=\"labelValor\">N</span>úm. do Proc. Originário:</label>";
		mostrarEsconderDataFase("esconder");
	}
	alterarBaixados();
}
function validarOAB() {
	var estado = document.forms[0].txtValor.value.substring(0,2);
	estado = estado.toUpperCase();
	var digitos = document.forms[0].txtValor.value.substring(2,document.forms[0].txtValor.value.length);
	var regexEstado = /^(AC|AL|AP|AM|BA|CE|DF|ES|GO|MA|MT|MS|MG|PA|PB|PR|PE|PI|RJ|RN|RS|RO|RR|SC|SP|SE|TO|UF)$/;
	var regexDigitos = /^\d+$/;
	if ((!regexEstado.test(estado)) || (!regexDigitos.test(digitos))) { 
	  return false;
	} else {
	  var oab = "000000"+digitos;
	  document.forms[0].txtValor.value = estado+oab.substring((oab.length-6),oab.length);
	  return true;
	}
}
function validarDigitacao() {
	var strIndice = document.forms[0].selForma.selectedIndex;
	var strValor = document.forms[0].txtValor.value;
	if ((strIndice == 0) || (strIndice == 2) || (strIndice == 4)) {
  	document.forms[0].txtValor.value = document.forms[0].txtValor.value.replace(/[^\d]*/gi,'');
	}
	/*if (strIndice == 0) {
		var strCaracteres5e6 = strValor.charAt(4)+strValor.charAt(5);
		if (strCaracteres5e6 == "04") {
			document.forms[0].selOrigem.selectedIndex = 0;
		} else if (strCaracteres5e6 == "70") {
			document.forms[0].selOrigem.selectedIndex = 3;
		} else if (strCaracteres5e6 == "71") {
			document.forms[0].selOrigem.selectedIndex = 1;
		} else if (strCaracteres5e6 == "72") {
			document.forms[0].selOrigem.selectedIndex = 2;
		}
	}*/
}
function validarFormulario() {
	var strIndice = document.forms[0].selForma.selectedIndex;
	if (strIndice == 3) {
  	if (validarOAB() == true) {
			return true;
		} else {
	  	alert("A OAB deve ser composta por duas letras e pelo menos um número.");
		  return false;
		}
	} else if (strIndice == 1) {
		var strNome = document.forms[0].txtValor.value;
		var arrPartesNome = strNome.split(" ");
		if (arrPartesNome.length > 1) {
			return true;
		} else {
			alert("O nome da parte deve ser composto de ao menos duas partículas.");
			return false;
		}
	} else if (strIndice == 0) {
		var strProcesso = document.forms[0].txtValor.value;
		if (strProcesso.length > 8) {
			return true;
		} else {
			alert("Quantidade inválida de números do processo.");
			return false;
		}
	} else if (strIndice == 2) {
		var strCPF = document.forms[0].txtValor.value;
		if (strCPF.length > 10) {
			return true;
		} else {
			alert("Quantidade inválida de números do CPF/CNPJ.");
			return false;
		}
	} else if (strIndice == 4) {
		return true;
	}
}

function enviarConsulta() 
{ 
  if (validarFormulario())
  {
	  janelaConsulta = window.open('http://www.trf4.gov.br/trf4/processos/acompanhamento/resultado_pesquisa_popup.php','janelaConsulta','location=0,status=1,resizable=1,scrollbars=1,width=652,height=500');	
	   var a = window.setTimeout('document.forms[0].submit()',100); 
	  janelaConsulta.focus();  
  }
  return false;
}
