//
function proximo(atual, next){
	 var element = document.getElementById(atual);
	 maxchr = document.getElementById(element.name).maxLength;
	 if (element.value.length >= maxchr){
	 	document.getElementById(next).focus();
	 }
} 

function Carga() {
	if ((document.getElementById("form:strTpConsulta").value == 3) || (document.getElementById("form:strTpConsulta").value == 5) || (document.getElementById("form:strTpConsulta").value == 6)) {
		document.getElementById("form:radiola").style.visibility = "visible";
	} else {
		     ///pesquisa por documento
			if (document.getElementById("form:strTpConsulta").value == 4) {
				document.getElementById("form:doc").style.visibility = "visible";
				document.getElementById("form:strTpDoc").style.visibility = "visible";
				document.getElementById("form:strTpDocEx").style.visibility = "visible";
				document.getElementById("form:radiola").style.visibility = "visible";
			} else {
				document.getElementById("form:doc").style.visibility = "hidden";
				document.getElementById("form:strTpDoc").style.visibility = "hidden";
				document.getElementById("form:strTpDocEx").style.visibility = "hidden";
				document.getElementById("form:radiola").style.visibility = "hidden";
			}
	}
   
     ///pesquisa por documento
	if (document.getElementById("form:strTpConsulta").value == 4) {
		document.getElementById("form:doc").style.visibility = "visible";
		document.getElementById("form:strTpDoc").style.visibility = "visible";
		document.getElementById("form:strTpDocEx").style.visibility = "visible";
	} else {
		document.getElementById("form:doc").style.visibility = "hidden";
		document.getElementById("form:strTpDoc").style.visibility = "hidden";
		document.getElementById("form:strTpDocEx").style.visibility = "hidden";
	}
	// pesquisa pela nova numeração
	if (document.getElementById("form:strTpConsulta").value == 7) {
		document.getElementById("form:numerocnj").style.visibility = "visible";
		document.getElementById("form:parmprincipal").style.visibility = "hidden";
	} else {
		document.getElementById("form:numerocnj").style.visibility = "hidden";
		document.getElementById("form:parmprincipal").style.visibility = "visible";
	}	
}

//
function trocaComarca() {
	Carga();
}
function ChangeSelect() {

   //pesquisa por nome
	if ((document.getElementById("form:strTpConsulta").value == 5) || (document.getElementById("form:strTpConsulta").value == 6)) {
		document.getElementById("form:radiola").style.visibility = "visible";
	} else {
		document.getElementById("form:radiola").style.visibility = "hidden";
	}
   
     ///pesquisa por documento
	if (document.getElementById("form:strTpConsulta").value == 4) {
		document.getElementById("form:doc").style.visibility = "visible";
		document.getElementById("form:strTpDoc").style.visibility = "visible";
		document.getElementById("form:strTpDocEx").style.visibility = "visible";
	} else {
		document.getElementById("form:doc").style.visibility = "hidden";
		document.getElementById("form:strTpDoc").style.visibility = "hidden";
		document.getElementById("form:strTpDocEx").style.visibility = "hidden";
	}
	// pesquisa pela nova numeração
	if (document.getElementById("form:strTpConsulta").value == 7) {
		document.getElementById("form:numerocnj").style.visibility = "visible";
		document.getElementById("form:parmprincipal").style.visibility = "hidden";
	} else {
		document.getElementById("form:numerocnj").style.visibility = "hidden";
		document.getElementById("form:parmprincipal").style.visibility = "visible";
	}	
}

//
function seleciona(comarca) {
	var strComarca = document.getElementById("form:strCodigoComarca");
	for (var i = 0; i < strComarca.length; i++) {
		if (strComarca.options[i].value == comarca) {
			strComarca.options[i].selected = true;
		}
	}
}

//
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
	if (typeof inputString != "string") {
		return inputString;
	}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") { // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length - 1, retValue.length);
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length - 1);
		ch = retValue.substring(retValue.length - 1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue; // Return the trimmed string back to the user
}

//
function verifica() {
	/* 	2 - NUMERO PROCESSO
	3 - OAB
	4 - DOCUMENTO
	5 - NOME */
	var b = document.getElementById("form:parametroConsulta").value;
	var t = /-/g;
	b = b.replace(t, "");
	t = /%/g;
	b = b.replace(t, "");
	t = /\//g;
	b = b.replace(t, "");
	t = /\\/g;
	b = b.replace(t, "");
	t = /_/g;
	b = b.replace(t, "");
	t = /	/g;
	b = b.replace(t, "");
	t = /\./g;
	b = b.replace(t, "");
	t = /\[/g;
	b = b.replace(t, "");
	t = /\]/g;
	b = b.replace(t, "");
	document.getElementById("form:parametroConsulta").value = b;
	var tipoSelecionado = document.getElementById("form:strTpConsulta").selectedIndex;
	var antigoParametro = document.getElementById("form:parametroConsulta").value;
	var parametro = document.getElementById("form:parametroConsulta");
	var tpConsulta = document.getElementById("form:strTpConsulta");
	var comarca = document.getElementById("form:strCodigoComarca");
	if ((!(tpConsulta.value == 5)) && ((!(tpConsulta.value == 6)))) {
	    // C O N S U L T A   P O R   N Ú M E R O   D E   P R O C E S S O
		var b1 = document.getElementById("form:parametroConsulta").value;
		var t1 = /-/g;
		t1 = / /g;
		b1 = b1.replace(t1, "");
		document.getElementById("form:parametroConsulta").value = b1;
	} else {
		if (parametro.value.length < 5) {
			alert("N\xe3o \xe9 permitido pesquisa com palavras menores de 5 caracteres.");
			return false;
		}
		if (!(isNaN(parametro.value))) {
			parametro.value = parametro.value.replace(/ /g, "");
			if ((parametro.value.length == 20) || (parametro.value.length == 14)) {
				document.getElementById("form:strTpConsulta").value = 2; // pesquisa por número		
				return true;
			} else {
				alert("Verifique se o par\xe2metro digitado confere com o tipo de pesquisa selecionada.");
				return false;
			}
		}
	}
	parametro.value = trim(parametro.value);
	if (parametro.value == "") {
		alert("Informe um parametro para pesquisa!");
		parametro.focus();
		return false;
	}
	if (tpConsulta.value == 2) {
  // C O N S U L T A   P O R   N Ú M E R O   D E   P R O C E S S O
		if (isNaN(parametro.value)) {
		// NÃO É UM NÚEMRO
			nen = confirm("A pesquisa por n\xfamero de Processo deve conter apenas N\xdaMEROS, SEM PONTOS OU TRA\xc7O OU QUALQUER OUTRO CAR\xc1CTER QUE N\xc3O SEJA N\xdaMERICO. \n Se voc\xea digitou um nome, esquecendo-se de mudar para pesquisar por nome,  clique em OK para pesquisar, a palavra ditadada, por Nome da Parte/Advogado automaticamente, sen\xe3o clique em Cancelar para corrigir o n\xfamero do proceso digitado.");
			if (nen) {
	  // retorno da janela Confirme se deseja ou nao pesquisar por nome
				if (parametro.value.length < 4) {
					alert("N\xe3o \xe9 permitido pesquisa com palavras menores de 4 caracteres.");
				} else {
					document.getElementById("form:parametroConsulta").value = antigoParametro;
					document.getElementById("form:strTpConsulta").value = 5; // pesquisa por nome
					trocaComarca();
					return true;
				}
			} else {
				return false;
			}
			return false;
		} else {
			if (parametro.value.indexOf(".") != -1) {
	// ENCONTROU PONTOS
				alert("\n N\xc3O UTILIZE PONTOS ou TRA\xc7OS. A pesquisa por n\xfamero de Processo deve conter apenas N\xdaMEROS.");
				return false;
			} else {
				if ((parametro.value.length < 14) || (parametro.value.length > 20)) {
	// É <> DE 12
					alert("Verifique o N\xfamero digitado pois o n\xfamero de processo no Primeiro grau tem 14 ou 20 digitos num\xe9ricos.");
					return false;
				} else {
					return true;
				}
			}
		}
	}
	return true;

}

