	document.getElementById('form').validadorMestre = new ValidadorMestre(); 


function criarValidadorCNJ(){
	var mensagem = new Mensagem(idTxtNumeracaoUnicaParte1 , 'mensagemCNJ' , true , true , false, true ); ""; 
	document.getElementById('form').validadorMestre.mensageiro.adicionarMensagem(mensagem);  
	validador = new Validador("Número de processo inválido", "errorSummary", idTxtNumeracaoUnicaParte1); 
	validador.testar = function (){ 
                 if(!isEscolhidaNumeracaoUnica()){
                      return true;
                }
                
                else{
                  var numero = document.getElementById(idTxtNumeracaoUnicaParte1).value;
                  var NNNNNNN = numero.substring(0,7);
                  var DD = numero.substring(8,10);
                  var AAAA = numero.substring(11,15);
                  var JTR = "819";
                  var OOOO = document.getElementById(idTxtNumeracaoUnicaParte2).value;
                  if (!processoCNJValido (NNNNNNN, DD, AAAA, JTR, OOOO)){			
                        	return false;
                  }
                  else return true;
                }
            }
	        document.getElementById('form').validadorMestre.adicionarValidador(validador);
	        validador = undefined;
  }
  
criarValidadorCNJ();

	
	validador = new Validador("Número de processo inválido", "errorSummary", idNumero); 
	validador.testar = function (){ 
               if(isEscolhidaNumeracaoUnica()){
                  return true;
              }
              
		this.testaCaracteres = function (numero){
			var padrao = "([a-zA-Z0-9\\.\\-\\\\////\\s]){"+ numero.length+"}";
			var oREGEXP = new RegExp(padrao);
		
			if (oREGEXP.test(numero))
				return true;
			else
				return false		
		}
		
		this.testaComarca = function (numero, comarca){
			var coma;
			if (comarca != null) {
			   if (numero.substring(4, 5) == ".") {
					  coma = numero.substring(5, 8);
				} else	{
					  coma = numero.substring(4, 7);
				}
			   if (comarca == coma)
				   return true;
			   else
					return false
			}
			else 
				return true;
		}
		this.testaPrimeiraInstancia = function (numero){
			var padrao = "(((^[0-9]{4}\\.[0-9]{3}\\.[0-9]{6}\\-[0-9])|(^[0-9]{14})).?[a-zA-Z0-9]?[a-zA-Z0-9]?[a-zA-Z0-9]?)$";
	
			var oREGEXP = new RegExp(padrao);
			
			if (oREGEXP.test(numero))
				return true;
			else
				return false
		}
	
		this.testaSegundaInstancia = function (numero){
			var padrao = "((^[0-9]{4}\\.[0-9]{3}\\.[0-9]{5})$|(^[0-9]{12})$)";
	
			var oREGEXP = new RegExp(padrao);
			
			if (oREGEXP.test(numero))
				return true;
			else
				return false
		}
		
		this.testaPrecatorio = function (numero){
			var padrao =  "((^[0-9]{4}\\.[0-9]{5}\\-[0-9])$|(^[0-9]{10})$|(^[0-9]{9})$|(^[0-9]{4}\.[0-9]{5})$)";
	
			var oREGEXP = new RegExp(padrao);
			
			if (oREGEXP.test(numero))
				return true;
			else
				return false
		}	
	
		this.CAMPO = idNumero; 
		this.CAMPOORIGEM = selOrigem; 
		this.ctr = null; // 
		this.valor = document.getElementById(this.CAMPO).value; 
          
		if (this.ctr == null){
			this.ctr = document.getElementById(this.CAMPOORIGEM).value;
		}
		if ((this.valor != null) && (this.valor != "")){
			if (this.ctr == "1"){
	            if (!(this.testaPrimeiraInstancia(this.valor)) || (!(this.testaComarca(this.valor, this.COMARCA))) || (!(this.testaCaracteres(this.valor))))
					return false;
				else 
					return true;
			}
			if ((this.ctr == "4") || (this.ctr == "3") || (this.ctr == "7")  ){
	            if (!(this.testaSegundaInstancia(this.valor)) || (!(this.testaComarca(this.valor, this.COMARCA))) || (!(this.testaCaracteres(this.valor))))
					return false;
				else 
					return true;
			}
			if ( (this.ctr == "5")){
	            if (!(this.testaPrecatorio(this.valor)) || (!(this.testaCaracteres(this.valor))))
					return false;
				else 
					return true;
			}		
		}
	
	}
	document.getElementById('form').validadorMestre.adicionarValidador(validador);
	validador = undefined;
	
	var mensagem = new Mensagem(idNumero , 'form:mensagem' , true , true , false, true ); ""; 
	document.getElementById('form').validadorMestre.mensageiro.adicionarMensagem(mensagem);  
	validador = new Validador("Número de processo inválido", "errorSummary", idNumero); 
	validador.testar = function (){ 
          if(isEscolhidaNumeracaoUnica()){
                      return true;
        }
	            var numero = document.getElementById(idNumero).value;
	            if ((getOrigem() == '2')  && (isProtocolo() == false)){
	                var padrao = "((^[0-9]{4}\\.[0-9]{3}\\.[0-9]{5})$|(^[0-9]{12})$)";
			var oREGEXP = new RegExp(padrao);
			
			if (oREGEXP.test(numero))
				return true;
			else
				return false
	            }
	        }
	        document.getElementById('form').validadorMestre.adicionarValidador(validador);
	        validador = undefined;
			
	validador = new Validador("Número de processo obrigatório", "errorSummary", idNumero); 
	validador.testar = function (){ 
              if(isEscolhidaNumeracaoUnica()){
                      return true;
        }
	            var numero = document.getElementById(idNumero).value;
	            if (numero == ""){
	                var ctr = document.getElementById(selOrigem).value;
	                if ( (ctr == 1) || (ctr == 2) || (ctr == 3) || (ctr == 4) || (ctr == 5) || (ctr == 7) || (ctr == 8 ) )
	                    return false;
	                else
	                    return true;
	            }
	        }
	        document.getElementById('form').validadorMestre.adicionarValidador(validador);
	        validador = undefined;        
	        
	
	validador = new Validador("Número de protocolo inválido", "errorSummary", idNumero); 
	validador.testar = function (){ 
        
         if(isEscolhidaNumeracaoUnica()){
                  return true;
                  }
                  
	            var numero = document.getElementById(idNumero).value;
	            if ((getOrigem() == '2')  && (isProtocolo() == true)){
	                var padrao2 = "((^[0-9]{4}\\.[0-9]{6})$|(^[0-9]{10})$)";
			var oREGEXP2 = new RegExp(padrao2);
			
			if (oREGEXP2.test(numero))
				return true;
			else
				return false
	            }            
	        }
	        document.getElementById('form').validadorMestre.adicionarValidador(validador);
	        validador = undefined;
