
function validamajor(nomeform)
{
	if ((nomeform.subscribe.checked) && (nomeform.unsubscribe.checked))
		{
		alert("Não é possível inscrever-se e retirar-se de uma lista ao mesmo tempo.");
		nomeform.subscribe.checked = false;
		nomeform.unsubscribe.checked = false;
		nomeform.subscribe.focus();
		return false;
	}
}

function validamajor2(nomeform)
{
	if ((nomeform.email.value == "") || (!(ehEmail(nomeform.email.value))))
		{
		alert("Digite um endereço válido.");
		nomeform.email.focus();
		return false;
	}
	if (((nomeform.subscribe.checked) || (nomeform.unsubscribe.checked) || (nomeform.who.checked) || (nomeform.info.checked)) && (nomeform.lista.value == 0))
		{
		alert("É necessário escolher uma lista para esta(s) opção(ões).");
		nomeform.lista.focus();
		return false;
	}
	if (!((nomeform.subscribe.checked) || (nomeform.unsubscribe.checked) || (nomeform.who.checked) || (nomeform.info.checked) || (nomeform.lists.checked) || (nomeform.help.checked) || (nomeform.which.checked)))
		{
		alert("Selecione uma das opções.");
		nomeform.subscribe.focus();
		return false;
	}
}

function validaemail(nomeform)
{
	if ((nomeform.email.value == "") || (!(ehEmail(nomeform.email.value))))
		{
		alert("Digite um endereço de email válido.");
		nomeform.email.focus();
		return false;
	}
}	

function ehEmail(valor)
{
        var i = 1;
        var formatoOk = true;      
        var valorLength = valor.length;
        // procurando a @.
        while ((i < valorLength) && (valor.charAt(i) != "@")) 
        {
          i++;
        }
        if ((i >= valorLength) || (valor.charAt(i) != "@")) formatoOk = false;
        else i += 2;
        // procurando pelo .
        while ((i < valorLength) && (valor.charAt(i) != ".")) 
        {
          i++;
        }
        // Deve existir pelo menos um caracter antes do "."
        if ((i >= valorLength - 1) || (valor.charAt(i) != ".")) formatoOk = false;
	return formatoOk;
}

function validaform(nomeform)
{

	if (nomeform.nome.value == "") 
		{
		alert("Digite um nome válido!");
		nomeform.nome.focus();
		return false;
	}

	//if ((nomeform.email.value == "") || (!(ehEmail(nomeform.email.value))))
	//	{
	//	alert("Digite um email válido!");
	//	nomeform.email.focus();
	//	return false;
    //	}

}

// funcao usada para validar cartorios
//function validacart(nomeform)
//{
//cartorio = nomeform.cartorio.value;
//resp = nomeform.resp.value;
//endereco = nomeform.endereco.value;
//cep = nomeform.cep.value;
//fonefax = nomeform.fonefax.value;
//msg=""

//if (cartorio == "") {msg = "\n- O campo 'Cartório' deve ser preenchido"}
//if (resp == "") {msg = msg + "\n- O campo 'Responsavel' deve ser preenchido"}
//if (endereco == "") {msg = msg + "\n- O campo 'Endereco' deve ser preenchido"}
//if (cep == "") {msg = msg + "\n- O campo 'Cep' deve ser preenchido"}
//if (fonefax == "") {msg = msg + "\n- O campo 'Fonefax' deve ser preenchido"}
//if (msg != "")
//	{alert(msg)
//	 return false}
//else {return true}
//}

function isNumber(text)
{
 for (var i = 0; i <= text.length-1; i++) {
    if (isNaN(parseInt(text.substring(i,i+1)))) {
        return (false);
   }
 }

return (true);
}


// função para testar campos de inclusao de processos no push 2o. grau

function testaNPROC2(nomeform)
{
  if (nomeform.vproc1.value=="")
	{
	alert("Digite o número do processo.");
	return false;
	}

   else
      {
       for (i=0; i < nomeform.vproc1.value.length; i++)
           {
            var temp = nomeform.vproc1.value.charAt(i)
            if (isNaN(parseInt(temp)))
                 {
                  alert("O número do processo só pode conter números. Digite novamente");
   	          nomeform.vproc1.select();
	          return false;
	          }
        }
             
        if (isNaN(parseInt(nomeform.vproc2.value)))
	   	{
	    alert("Dígito incorreto (dv). Digite novamente.");
	    nomeform.vproc2.select();
	    return false;
	  	 }
 	
 	
 		if (!(nomeform.vproc3.value==""))
 	   	{
 	    	for (i=0; i < 2; i++)
               {
                var temp = nomeform.vproc3.value.charAt(i)
                if (isNaN(parseInt(temp)))
        	       {
                    alert("Número de subprocesso incorreto (sp). Digite novamente.");
	        	    nomeform.vproc3.select();
	            	return false;
	            }
            }
         }
	}
}  

// funcao para testar campos de inclusao do numero do processo no push 1o. grau
function testaNPROC1(nomeform){
	// funcao para testar campos de inclusao do numero do processo no push 1o. grau

	if (nomeform.cm.value=="")
		{
		alert("Digite o número da comarca.");
		nomeform.cm.select();
		return false;
		}
	
	else 
		{
		if ((nomeform.cm.value.substring(0,3)!="001") && (nomeform.cm.value.substring(0,3)!="247") && (nomeform.cm.value.substring(0,3)!="402") && (nomeform.cm.value.substring(0,3)!="205") && (nomeform.cm.value.substring(0,3)!="206") && (nomeform.cm.value.substring(0,3)!="208") && (nomeform.cm.value.substring(0,3)!="209") && (nomeform.cm.value.substring(0,3)!="210") && (nomeform.cm.value.substring(0,3)!="246") && (nomeform.cm.value.substring(0,3)!="213") && (nomeform.cm.value.substring(0,3)!="217") && (nomeform.cm.value.substring(0,3)!="218") && (nomeform.cm.value.substring(0,3)!="219") && (nomeform.cm.value.substring(0,3)!="220") && (nomeform.cm.value.substring(0,3)!="424") && (nomeform.cm.value.substring(0,3)!="463") && 
			(nomeform.cm.value.substring(0,3)!="486") && (nomeform.cm.value.substring(0,3)!="222") && (nomeform.cm.value.substring(0,3)!="223") && (nomeform.cm.value.substring(0,3)!="431") && (nomeform.cm.value.substring(0,3)!="224") && (nomeform.cm.value.substring(0,3)!="225") && (nomeform.cm.value.substring(0,3)!="226") && (nomeform.cm.value.substring(0,3)!="230") && (nomeform.cm.value.substring(0,3)!="231") && (nomeform.cm.value.substring(0,3)!="233") && (nomeform.cm.value.substring(0,3)!="444") && (nomeform.cm.value.substring(0,3)!="237") && (nomeform.cm.value.substring(0,3)!="248") && (nomeform.cm.value.substring(0,3)!="240") && (nomeform.cm.value.substring(0,3)!="241") && (nomeform.cm.value.substring(0,3)!="455") && 
			(nomeform.cm.value.substring(0,3)!="243") && (nomeform.cm.value.substring(0,3)!="235") && (nomeform.cm.value.substring(0,3)!="232") && (nomeform.cm.value.substring(0,3)!="203") && (nomeform.cm.value.substring(0,3)!="228") && (nomeform.cm.value.substring(0,3)!="214") && (nomeform.cm.value.substring(0,3)!="410") && (nomeform.cm.value.substring(0,3)!="204") && (nomeform.cm.value.substring(0,3)!="441") && (nomeform.cm.value.substring(0,3)!="207") && (nomeform.cm.value.substring(0,3)!="216") && (nomeform.cm.value.substring(0,3)!="422") && (nomeform.cm.value.substring(0,3)!="430") && (nomeform.cm.value.substring(0,3)!="215") && (nomeform.cm.value.substring(0,3)!="234") && (nomeform.cm.value.substring(0,3)!="451") && 
			(nomeform.cm.value.substring(0,3)!="427") && (nomeform.cm.value.substring(0,3)!="479") && (nomeform.cm.value.substring(0,3)!="201") && (nomeform.cm.value.substring(0,3)!="459") && (nomeform.cm.value.substring(0,3)!="221") && (nomeform.cm.value.substring(0,3)!="415") && (nomeform.cm.value.substring(0,3)!="435") && (nomeform.cm.value.substring(0,3)!="426") && (nomeform.cm.value.substring(0,3)!="244") && (nomeform.cm.value.substring(0,3)!="227") && (nomeform.cm.value.substring(0,3)!="439") && (nomeform.cm.value.substring(0,3)!="403") && (nomeform.cm.value.substring(0,3)!="491") && (nomeform.cm.value.substring(0,3)!="487") && (nomeform.cm.value.substring(0,3)!="401") && (nomeform.cm.value.substring(0,3)!="436") &&
			(nomeform.cm.value.substring(0,3)!="484") && (nomeform.cm.value.substring(0,3)!="460") && (nomeform.cm.value.substring(0,3)!="447") && (nomeform.cm.value.substring(0,3)!="421") && (nomeform.cm.value.substring(0,3)!="437") && (nomeform.cm.value.substring(0,3)!="406") && (nomeform.cm.value.substring(0,3)!="238") && (nomeform.cm.value.substring(0,3)!="456") && (nomeform.cm.value.substring(0,3)!="420") && (nomeform.cm.value.substring(0,3)!="409") && (nomeform.cm.value.substring(0,3)!="423") && (nomeform.cm.value.substring(0,3)!="229") && (nomeform.cm.value.substring(0,3)!="211") && (nomeform.cm.value.substring(0,3)!="412") && (nomeform.cm.value.substring(0,3)!="462") && (nomeform.cm.value.substring(0,3)!="474") &&
			(nomeform.cm.value.substring(0,3)!="475") && (nomeform.cm.value.substring(0,3)!="489") && (nomeform.cm.value.substring(0,3)!="450") && (nomeform.cm.value.substring(0,3)!="245") && (nomeform.cm.value.substring(0,3)!="434") && (nomeform.cm.value.substring(0,3)!="447") && (nomeform.cm.value.substring(0,3)!="490") && (nomeform.cm.value.substring(0,3)!="491") && (nomeform.cm.value.substring(0,3)!="466") && (nomeform.cm.value.substring(0,3)!="467") && (nomeform.cm.value.substring(0,3)!="408") && (nomeform.cm.value.substring(0,3)!="419") && (nomeform.cm.value.substring(0,3)!="461") && (nomeform.cm.value.substring(0,3)!="449") && (nomeform.cm.value.substring(0,3)!="468") && (nomeform.cm.value.substring(0,3)!="212") &&
			(nomeform.cm.value.substring(0,3)!="494") && (nomeform.cm.value.substring(0,3)!="495") && (nomeform.cm.value.substring(0,3)!="469") && (nomeform.cm.value.substring(0,3)!="485") && (nomeform.cm.value.substring(0,3)!="497") && (nomeform.cm.value.substring(0,3)!="411") && (nomeform.cm.value.substring(0,3)!="432") && (nomeform.cm.value.substring(0,3)!="477") && (nomeform.cm.value.substring(0,3)!="472"))
		

		{
<!--			alert("Só estão disponíveis processos das comarcas de Recife (001), Olinda (226), Paulista (231), Jaboatao (222), Caruaru (213), Goiana (218), Petrolina (233), Aliança (402), Macaparana (431), Igarassu (220), Itamaracá (463), Toritama (455), Limoeiro (223), Surubim (240), Cabo (210), Timbaúba (241), Glória do Goitá (217), Nazaré da Mata (225) ou Vitória (243), Brejo da madre de Deus (409), Inajá (423), Panelas (229)");
					<!--(07/05/07) - TerraNova (489), Serrita (450), Salgueiro (245), Parnamirim (434)
					<!-- 06/08/2007 - São josé do Belmonte (447), Verdejante (490), Mirandiba (491)-->
					<!-- 28/08/2008 - Buenos aires e Tracunhaém -->
					
			alert("Só estão disponíveis processos das comarcas constantes na Caixa de Seleção de Comarca - cm.");
			nomeform.cm.select();
			return false;
			}
		}
		
	if (nomeform.ano.value=="")	{
		alert("Digite o Ano.");
		nomeform.ano.select();
		return false;
	} else { 
		if ((isNaN(nomeform.ano.value))){
			alert("Digite o ano correto.");
			nomeform.ano.select();
			return false;
		}
	}	
	
	if (isNaN(nomeform.vproc1.value))
		{
		if (nomeform.vproc1.value.length!=6)
 			{
			alert("O número do processo deve ter 6 dígitos.");
			nomeform.vproc1.select();
			return false;
			}
		
	else
		{
		alert("O dado para esta pesquisa deve ser numérico.");
		nomeform.vproc1.select();
		return false;
		}	
	}	
	
	if (isNaN(nomeform.dv.value)){
	 	alert("Dígito incorreto (dv). Digite novamente.");
	 	nomeform.dv.select();
		return false;
	}
	
	if (isNaN(nomeform.sp.value)){
	 	alert("Número incorreto de subprocesso (sp). Digite novamente.");
	 	nomeform.sp.select();
		return false;
	}
}

// função para testar campos de oab no cadastramento de oabs no push 20. grau
function testaOAB(nomeform)
{
if ((nomeform.voab.value.length<8) || (nomeform.voab.value.length>9))
	{
	alert("OAB inválida. Digite a sigla do estado, o número da OAB com 6 dígitos e, apenas para processos do 1º Grau, uma letra se houver. Exs.: PE000001 ou PE000001B.");
	return false;
	}
estados = new Array("AC","AL","AM","AP","BA","CE","DF","ES","GO","MA","MS","MG","MT","PA","PB","PE","PI","PR","RJ","RO","RN","RR","SC","SE","SP","TO");
var achou=false;
for (var j=0; j<=25; j++) 
	{ 
	if (nomeform.voab.value.substring(0,2).toUpperCase()==estados[j]) 	
		{
		achou=true;
		}
	}
var numeroOAB = nomeform.voab.value.substr(2,6)
//var numeroOAB = nomeform.voab.value.substr(2,nomeform.voab.value.length)
if (!achou) 
	{
	alert("OAB inválida. Verifique a sigla do estado. Clique no botão AJUDA para obter maiores informações.");
	return false;
	}
else
	{
	if (isNaN(numeroOAB))
		{
		alert("OAB inválida. Digite a sigla do estado, o número da OAB com 6 dígitos e, apenas para processos do 1º Grau, uma letra se houver. Exs.: PE000001 ou PE000001B.");
		return false;
		}
	}

if (nomeform.voab.value.substring(8) != "")
	{
	var letraOAB = nomeform.voab.value.substring(8);
	if (!isNaN(letraOAB))
		{
		alert("OAB inválida. Verifique o final da sua OAB: há um espaço em branco ou o último caracter deverá ser uma letra (válido apenas para o 1º Grau. Ex.: PE000001B).");
	   	return false;
		}
	}
}

// função de abre_janela - parâmetros: url e nome da janela
function abre_janela(url,nome) 
{
  window.open(url, nome, 'toolbar=no,scrollbars=no,resizable=no,menubar=no,width=470,height=300');
  return false;
}

// função de abre_janela2 - parâmetros: url e nome da janela
function abre_janela2(url,nome) 
{
  window.open(url, nome, 'toolbar=no,scrollbars=yes,resizable=no,menubar=no,width=490,height=360');
  return false;
}


// função para não deixar campos em branco
function campobranco(nomeform,nomecampo)
{
  if (document.nomeform.nomecampo.value=="")
	{
	alert("O campo não pode ser vazio.");
	document.nomeform.nomecampo.focus();
	return false;
	}
}

// valida hora
function validahoram(form,hora){
 
var vhora = eval('document.'+form+'.'+hora)

	if (hora.value==""){
		alert("Entre com a hora");
		vhora.focus();
		return false;
	}

	if (vhora.value.length != 5){
    	alert("O campo hora requer 5 dígitos no formato: hh:mm");
		vhora.focus();
		return false;
    }

	if ((vhora.value.substring(0, 2) < 0)  ||  (vhora.value.substring(0, 2) > 24)){
    	alert("Hora incorreta.");
		vhora.focus();
		return false;
    }
	
	if ((vhora.value.substring(3, 5) < 0)  ||  (vhora.value.substring(3, 5) > 59)){
	    alert("Minutos incorretos.");
		vhora.focus();
		return false;
    }	
	
	if ( vhora.value.substring(2, 3) != ":"  ){
    alert("Entre com :(dois pontos) entre a hora e os minutos");
	vhora.focus();
    return false;
    }

}
//fim da função validahoram

// valida data
function validadatam(form,data)
{

	var vdata2 = eval('document.'+form+'.'+data)

	if (vdata2.value==""){
		alert("Entre com a data")
		vdata2.focus()
		return false
	}


	if (vdata2.value.length < 10)
   	 {
    		alert("O campo DATA requer 10 dígitos no formato: DD/MM/AAAA");
		vdata2.focus();
		return false;
     	}
	

	// Verifica se os caracteres são números e barra.
     for (var i = 0; i < vdata2.value.length; i++) 
       	{
            var ch = vdata2.value.substring(i, i + 1);
            if ((ch < "0" || "9" < ch) && ch != "/") 
               {
               alert("O campo DATA aceita somente números e um barra no formato: DD/MM/AAAA");
				vdata2.focus();
               return false;
               }
         }
		
	if ((vdata2.value.substring(0, 2) < 1)  ||  (vdata2.value.substring(0, 2) > 31)  ) 
	{
    	alert("Dia incorreto.");
		vdata2.focus();
		return false;
    }	
	
	// Verifica o valor do dia no valor do mês.
   		// Fevereiro
   			if ( (vdata2.value.substring(3, 5) == 2 )  &&  (vdata2.value.substring(0, 2) > 29)  )
       			  {
                  alert("Fevereiro não tem mais que 29 dias.");
                  return false;
                  }



               if ( (vdata2.value.substring(3, 5) == 2 )  &&  (vdata2.value.substring(0, 2) == 29)  && (vdata2.value.substring(6,10)%4 != 0) )
                  {
					  alert("Você entrou com 29 de Fevereiro. Esse ano não é bissexto"); 
    	              vdata2.focus();
        	          return false;
				  }
			 // Abril
               if ( (vdata2.value.substring(3, 5) == 4 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Abril não tem mais que 30 dias.");
				  vdata2.focus();		
                  return false;
                  }
            // Junho
               if ( (vdata2.value.substring(3, 5) == 6 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Junho não tem mais que 30 dias..");
				  vdata2.focus();	
                  return false;
                  }
			// Setembro
               if ( (vdata2.value.substring(3, 5) == 9 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Setembro não tem mais que 30 dias..");
				  vdata2.focus();	
                  return false;
                  }
            // Novembro
               if ( (vdata2.value.substring(3, 5) == 11 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Novembro não tem mais que 30 dias.");
				  vdata2.focus();
                  return false;
                  }
		// Verifica o valor do mês.
       if ( (vdata2.value.substring(3, 5) < 1)  ||  (vdata2.value.substring(3, 5) > 12)  )
        {
            alert("Mês incorreto.");
			vdata2.focus();
            return false;
        }

		// Verifica posicionamento da barra.
         if ( vdata2.value.substring(3, 4) == "/"  || vdata2.value.substring(4, 5) == "/" )
            {
            alert("Barra misturada com o mês.");
			vdata2.focus();
            return false;
            }
         if ( vdata2.value.substring(0, 1) == "/"  || vdata2.value.substring(1, 2) == "/" )
            {
            alert("Barra misturada com o dia.");
			vdata2.focus();
            return false;
            }
         if ( vdata2.value.substring(6, 7) == "/"  || vdata2.value.substring(7, 8) == "/" )
            {
            alert("Barra misturada com o ano.");
			vdata2.focus();
            return false;
            }
         if ( vdata2.value.substring(2, 3) != "/"  ||  vdata2.value.substring(5, 6) != "/" )
            {
            alert("Barra misturada com a data.");
			vdata2.focus();
            return false;
            }
       var ano = new Date()
		// Verifica o valor do ano.
       if ( /*(vdata2.value.substring(6, 10) < 2003)  || */ (vdata2.value.substring(6, 10) > ano.getFullYear()))
	     //if ( /*(vdata2.value.substring(6, 10) < 2003)  || */ (vdata2.value.substring(6, 10) > 2005))
            {
            alert("Ano incorreto.");
			vdata2.focus();
            return false;
            }

}
// fim da função validadatam


// funcao para invalidar campos com aspas ", < e aspas simples '
function valida_c(nomeform,campo)
{
	var vcampo = eval('document.'+nomeform+'.'+campo)
	// Verifica se os caracteres são números e barras
     for (var i = 0; i < vcampo.value.length; i++)
       	{
            var ch = vcampo.value.substring(i, i + 1);
            if (ch == "<" || ch == "'" || ch == '"' || ch ==">" )
               {
               alert("Login inválido");
				vcampo.focus();
               return false;
               }
         }
}

// Verifica se um campo do formulario esta em branco
function campobrancom(form,campo){
	var vcampo = eval('document.'+form+'.'+campo);
	if (vcampo.value==""){
		alert("O campo não pode ser vazio!!");
		vcampo.focus();
		return false;
	}
}//fim da função campobranco

// Função para validar Telefone
function validaFone(fone){
	var i;
	var resp;
	resp = true;
		for (i=0;i<fone.length;i++){

			if ((!(fone.charAt(i)=='/')) && (!(fone.charAt(i)=='-')) && (!(fone.charAt(i)==')')) && (!(fone.charAt(i)=='(')) && (!(isNumber(fone.charAt(i)))) ) {
				resp = false;
				break;
			}
		}
	return resp;
}

//função para validar TODOS os campos em branco de um formulário
    function validaTodosCampos(form1) {
		 var resp;
 		 var a=0;
		 resp=true;
 		 for(a=0;a<document.form1.elements.length;a++)
 			{ 		
  				if (document.form1.elements[a].value=="") {
					if (document.form1.elements[a].disabled){
					}else{
						alert("Existe algum campo em branco");
						document.form1.elements[a].focus();
						resp = false;
						break;
					}					
					
					 }
				//valida se tiver alguma DATA no formulário
				if (document.form1.elements[a].name=="data") {
					resp = validadatam('form1','data');
					if (resp==false) { 
					break ;
					}
				}
				if (document.form1.elements[a].name=="dataSol") {
					resp = validadatam('form1','dataSol');
					if (resp==false) { 
					break; 
					}
				}
				if (document.form1.elements[a].name=="dataSolicitacao") {
					resp = validadatam('form1','dataSolicitacao');
					if (resp==false) {
					 break; 
					 }
				}
				//Valida o email do campo de nome = email
				
                                
                    if (document.form1.elements[a].name=="email") {
					    resp = ehEmail(document.form1.email.value);
					if (resp==false) {
						alert("Email Inválido");
						document.form1.elements[a].focus();
						break;
					}
				}
				
				
				
				//Verifica se o campo é número
				if (document.form1.elements[a].name=="matricula") {					
					resp = isNumber(document.form1.matricula.value);
					if (resp==false) {
						alert("Matricula Inválida");
						document.form1.elements[a].focus();
						break;
					}
				}
				if (document.form1.elements[a].name=="cpf") {										
					resp = verificarCPF(document.form1.cpf.value);
					if (resp==false) {						
						document.form1.elements[a].focus();
						break;
					}
				}
				if (document.form1.elements[a].name=="fone") {					
					resp = validaFone(document.form1.fone.value);
					if (resp==false) {
						alert("Telefone Inválido");
						document.form1.elements[a].focus();
						break;
					}
				}
				
			}//fim do for geral	
				
		return resp;
	}					


//fim validaTodosCampos ©Copyright2002 Thiago Henrique


//funcao para validar CPF
function verificarCPF(value) {	

   var i;
   var soma = 0, mult = 1, resto1 = 0, resto2 = 0;
   var cpfOK = true;

   if(!isNumber(value)) {
	alert("Digite apenas numeros no CPF");
	cpfOK = false;	
   }
   else if(value.length!=11) {
	     alert("O CPF tem que ter 11 digitos");
	     cpfOK = false;	
   	}
	else {
		 var facaVerificacao = false ;

		//VERIFICAR SE A PESSOA DIGITOU O MESMO NUMERO
		 for (i=0; i<8; i++) {
			if(value.charAt(i)!=value.charAt(i+1)){
				facaVerificacao = true;
			}
		}

		if(facaVerificacao){

			//***************** PRIMEIRO DIGITO VERIFICADOR DO CPF ******//  		
			for (i=0; i<9; i++) {
				if(value.charAt(i)!=0){
					soma += value.charAt(i)*(10-i);
				}
			}		
			resto1 = soma%11;
	
			//Se o resto for igual a 0 ou igual a 1 o primeiro digito verificador
			//do CPF devera ser igual a 0.
			if(resto1==0 || resto1==1) { 
				if(value.charAt(9)!=0){
					cpfOK = false;
				}
			} 
			//Se o resto for maior que 1 entao deve-se subtrair o resto 
			//de 11 para conseguir o primeiro digito verificador.
			//Depois disto o primeiro digito do CPF devera ser igual ao novo resto.
			else{
				resto1 = 11 - resto1;
				if(value.charAt(9)!=resto1){
					cpfOK = false;
				}
			}

			soma = 0, mult = 0;

			//***************** SEGUNDO DIGITO VERIFICADOR DO CPF ******//
			for (i=0; i<9; i++) {
				if(value.charAt(i)!=0) {
					soma += value.charAt(i)*(11-i);
				}
			}
			soma = soma + (value.charAt(9)*2);
			resto2 = soma%11;
	
			//Se o resto for igual a 0 ou igual a 1 o segundo digito verificador
			//do CPF devera ser igual a 0.
			if(resto2==0 || resto2==1) { 
				if(value.charAt(10)!=0) {
					cpfOK = false;
				}
			}
			//Se o resto for maior que 1 entao deve-se subtrair o resto
			//de 11 para conseguir o segundo digito verificador.
			//Depois disto o segundo digito verificador do CPF devera ser igual ao novo resto.
			else{
				resto2 = 11 - resto2;
				if(value.charAt(10)!=resto2) {
					cpfOK = false;
				}
			}

		  }//fim do if 'facaVerificacao'
		  else{
			cpfOK = false ;
		  }


		if(!cpfOK) {
			alert("CPF Inválido");
		}

	    }//fim do else


	return cpfOK;

}//fim da funcao validaFr CPF ©TJPE Janeiro de 2003
function isLoginValido(){
	window.status = "==========> MODIFIQUE ESTA FUNÇAO ";
	return true;
}

function isCampoVazio(){
	window.status = "==========> MODIFIQUE ESTA FUNÇAO ";
	return false;
}



function fnRemoveTags(obj){

	// by Alessandro
	// Baseado na funcao valica_c, remove caracteres nocivos numa consulta slq.
	var ch;
	var retorno = false;
	var texto = "";
	texto = obj.value;	
	for (var i = 0; i < texto.length; i++){
		ch = texto.substring(i, i + 1);
        if (ch == "<" || ch == "'" || ch == '"' || ch ==">" ){
			alert("O campo tem símbolos não permitido");
			obj.focus();
            return true;
		}
	}
}

function isLoginValido(){
	window.status = "==========> MODIFIQUE ESTA FUNÇAO ";
	return true;
}

function fnEstaVazio(obj){
	var r;
	if (obj.value == "") 
		r = true
	else
		r = false;	
	return r;
}

/// escolhe_para_alterar
function fnVerificaCheckBoxOLD(){
	var radios = document.all.tags("input");
	var selecionado = false;
	for (i = 0; i < radios.length; i++){
		if (radios(i).type == "radio"){
			if(radios(i).checked == true){
				selecionado = true;
			}
		}
	}
	if (!selecionado) alert("Você precisa selecionar uma opção");
	return selecionado;	
}
// ============================================================================

function fnValidaBranco(){
	window.status = "validando campo em branco";
}

function fnValidaData(){
	window.status = "validando data";
}

function fnValidaHora(){
	window.status = "validando hora";
}

function checabranco(form,campo) {
  var vcampo = eval('document.'+form+'.'+campo);
  if (vcampo.value == "") {
	alert("Preencha o campo nome!");
	vcampo.focus();
	return false;
  }
  return true;
}

function fnChecaCamposVazios(){

	var campos;
	var retorno;
	
	campos = document.all.tags("input");
	retorno = true;

	for (i = 0; i < campos.length; i++){
		if(campos(i).type == "text"){
			if (fnRemoveTags(campos(i))){
				retorno = false;
				break;
			}
		}
		if(fnEstaVazio(campos(i))){
			campos(i).focus();
			retorno = false;
			break;
		}
	}
	
/*	if ((document.all.fldTexto.value == "") || (fnRemoveTags(document.all.fldTexto) == true)) {
		retorno = false;
		document.all.fldTexto.focus();
	}
	*/
	
	return retorno;
}

function fnQuantosCheckBoxesSelecionados(){
	var checks = document.all.tags("input");
	var selecionados = 0;
	for (i = 0; i < checks.length; i++){
		if (checks(i).type == "checkbox"){
			if(checks(i).checked == true){
				selecionados++;
			}
		}
	}
	return selecionados;
}

function fnQuantosRadioButtonsSelecionados(){
	var radios = document.all.tags("input");
	var selecionados = 0;
	for (i = 0; i < radios.length; i++){
		if (radios(i).type == "radio"){
			if(radios(i).checked == true){
				selecionados++;
			}
		}
	}
	return selecionados;
}

function fnChecaTagsNosCampos(){

	var campos;
	var retorno;
	
	campos = document.all.tags("input");
	retorno = true;

	for (i = 0; i < campos.length; i++){
		if(campos(i).type == "text"){
			if (fnRemoveTags(campos(i))){
				retorno = false;				
				campos(i).focus();
				alert('O campo possui caracteres não permitidos');
				break;
			}
		}
	}
	return retorno;
}

function validaData2(form,data)
{

	var vdata2 = eval('document.'+form+'.'+data)

	if (vdata2.value==""){
		alert("Entre com a data")
		vdata2.focus()
		return false
	}


	if (vdata2.value.length < 10)
   	 {
    		alert("O campo DATA requer 10 dígitos no formato: DD/MM/AAAA");
		vdata2.focus();
		return false;
     	}


	// Verifica se os caracteres são números e barra.
     for (var i = 0; i < vdata2.value.length; i++)
       	{
            var ch = vdata2.value.substring(i, i + 1);
            if ((ch < "0" || "9" < ch) && ch != "/")
               {
               alert("O campo DATA aceita somente números e um barra no formato: DD/MM/AAAA");
				vdata2.focus();
               return false;
               }
         }

	if ((vdata2.value.substring(0, 2) < 1)  ||  (vdata2.value.substring(0, 2) > 31)  )
	{
    	alert("Dia incorreto.");
		vdata2.focus();
		return false;
    }

    //vERIFICA SE O ANO É INFERIOR A 2000
	if ((vdata2.value.substring(6, 7) < 2))
	{
    	alert("O ano não pode ser inferior a 2000.");
		document.form.data.focus();
		return false;
    }
	// Verifica o valor do dia no valor do mês.
   		// Fevereiro
   			if ( (vdata2.value.substring(3, 5) == 2 )  &&  (vdata2.value.substring(0, 2) > 29)  )
       			  {
                  alert("Fevereiro não tem mais que 29 dias.");
                  return false;
                  }



               if ( (vdata2.value.substring(3, 5) == 2 )  &&  (vdata2.value.substring(0, 2) == 29)  && (vdata2.value.substring(6,10)%4 != 0) )
                  {
					  alert("Você entrou com 29 de Fevereiro. Esse ano não é bissexto");
    	              vdata2.focus();
        	          return false;
				  }
			 // Abril
               if ( (vdata2.value.substring(3, 5) == 4 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Abril não tem mais que 30 dias.");
				  vdata2.focus();
                  return false;
                  }
            // Junho
               if ( (vdata2.value.substring(3, 5) == 6 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Junho não tem mais que 30 dias..");
				  vdata2.focus();
                  return false;
                  }
			// Setembro
               if ( (vdata2.value.substring(3, 5) == 9 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Setembro não tem mais que 30 dias..");
				  vdata2.focus();
                  return false;
                  }
            // Novembro
               if ( (vdata2.value.substring(3, 5) == 11 )  &&  (vdata2.value.substring(0, 2) > 30)  )
                  {
                  alert("Novembro não tem mais que 30 dias.");
				  vdata2.focus();
                  return false;
                  }
		// Verifica o valor do mês.
       if ( (vdata2.value.substring(3, 5) < 1)  ||  (vdata2.value.substring(3, 5) > 12)  )
        {
            alert("Mês incorreto.");
			vdata2.focus();
            return false;
        }

		// Verifica posicionamento da barra.
         if ( vdata2.value.substring(3, 4) == "/"  || vdata2.value.substring(4, 5) == "/" )
            {
            alert("Barra misturada com o mês.");
			vdata2.focus();
            return false;
            }
         if ( vdata2.value.substring(0, 1) == "/"  || vdata2.value.substring(1, 2) == "/" )
            {
            alert("Barra misturada com o dia.");
			vdata2.focus();
            return false;
            }
         if ( vdata2.value.substring(6, 7) == "/"  || vdata2.value.substring(7, 8) == "/" )
            {
            alert("Barra misturada com o ano.");
			vdata2.focus();
            return false;
            }
         if ( vdata2.value.substring(2, 3) != "/"  ||  vdata2.value.substring(5, 6) != "/" )
            {
            alert("Barra misturada com a data.");
			vdata2.focus();
            return false;
            }

}
// fim da função validaData
function ajeitarTelefone(obj){

	var novo = "";
	var numero = obj.value;
	var r = true;
	for (i = 0; i < numero.length; i++){
		n = numero.charCodeAt(i);
		if ((n >= 48) && (n <=57)){
			novo += numero.charAt(i);
		}
	}
	n = novo.length;

	if (n == 8){
		novo = novo.substr(0, 4) + "-" + novo.substr(4, 7);
	} else {
		if (n == 10){
			novo = novo.substr(0, 2) + " " + novo.substr(2, 4) + "-" + novo.substr(6, 10);	
		} else {
			r = false;
		}	
	}
	obj.value = novo;	
	return r;
}
