	<!--

// ------------------------------------------------------------------------------------------ //
// Acrescenta algumas propriedades aos controles:
// .Indice			: indica o índice na tela para o controle
// .IndiceAnterior	: indica o índice do controle anterior
// .IndicePosterior	: indica o índice para o controle posterior
// .Tam				: tamanho máximo para digitação
// .AutoSkip		: indica se pula para o próximo campo após completar o tamanho do campo
// .Tipo			: indica o tipo de dado
//						'D' -> só dígitos de 0(zero) a 9(nove)
//						'T' -> só dígitos de 0(zero) a 9(nove) e /
//						'N' -> dígitos de 0(zero) a 9(nove), "."(ponto) e ","(vírgula)
//						'C' -> caracteres de 'a' até 'z' e de 'A' até 'Z'
//						'P' -> só dígitos de 0(zero) a 9(nove) e -
//						outro -> qualquer caracter entre ascii 32 e ascii 127
// .Saltar			: (reservado) indica o momento de saltar de campo
// ------------------------------------------------------------------------------------------ //

// Carrega índices para o próximo controle e controle anterior

function InicializarIndices()
{
	if (document.CargaInicial==null)
	{
		document.CargaInicial=false;		// Seta para só fazer uma vez por documento
		var ctrlAnterior=null;
		var IndAnt=0;
		for ( var i=0; i<document.forms[0].elements.length;i++)
		{
			var e=document.forms[0].elements[i];
			if ( e.type!="hidden" && e.type!="image" )		
			{
				if ( ctrlAnterior != null )
					ctrlAnterior.IndicePosterior=i;
				ctrlAnterior=e;
				e.Indice=i;
				e.IndiceAnterior=IndAnt;
			}
		}
		//if ( ctrlAnterior!=null )
		//{
		//	ctrlAnterior.IndicePosterior=i-1;
		//}
	}
}

// Colocar o foco em determinado campo
function SetarFoco ( ind )
	{
	InicializarIndices();
	if ( isNaN(ind) && document.forms[0].elements[ind].type!="hidden" )
		document.forms[0].elements[ind].focus();
	else
		for (;ind<document.forms[0].elements.length;ind++)
			if ( document.forms[0].elements[ind].type!="hidden" )
				break;
		if ( ind<=document.forms[0].elements.length )
			document.forms[0].elements[ind].focus();
	}

// Limpar o conteúdo do(s) campo(s)
function LimparCampo ( ind )
	// Para -1, limpa todos os elementos
	{
	if (isNaN(ind))			// Limpa pelo nome
		document.forms[0].elements[ind].value="";
	else if (ind != -1 )	// Limpa o elemento "ind" ( só considera "text" e "password" )
		for ( var i=ind; i < document.forms[0].elements.length;i++ )
			if ( document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password")		// Só limpa campo "text"
				{
				document.forms[0].elements[i].value="";
				break;
				}
	else					// Limpa todos os elementos "text" e "password"
		for ( var i=0; i < document.forms[0].elements.length; i++ )
			if ( document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password" )
				document.forms[0].elements[i].value="";
		
	}

// Verificar qual navegador
function QualNavegador() 
{
	var s = navigator.appName;
	if ( s == "Microsoft Internet Explorer" )
		return "IE";
	else if ( s == "Netscape" )
		return "NE";
	else
		return "";
}

// Verificar qual a versão do navegador
function QualVersao()
{
	var s = navigator.appVersion;
	if ( QualNavegador() == "IE" )
	{
		var i = s.search("MSIE");
		s=s.substring(i+5);
		i=s.search(".");
		return parseInt(s.substring(0,i+1));
	}
	else if ( QualNavegador() == "NE" )
		return parseInt(s.substring(0,1));
	else
		return 0;
}

var tamanho;

// Setar o evento
function SetarEvento(ctrl, Tam, Tipo, AutoSkip )
{
	// Filtra navegadores conhecidos
	var s = QualNavegador();
	if ( s.length==0 )
		return;
//	if ( s=="IE" && QualVersao()>5 )
//		return;
	if ( s=="NE" && QualVersao()>4 )
		return;

	if (ctrl.onkeypress==null)
	{
    if (AutoSkip==null)
			AutoSkip=true;
		if (Tipo!=null)
			Tipo.toUpperCase();
		ctrl.Tam=Tam;
                tamanho=Tam;
		ctrl.Tipo=Tipo;
		ctrl.AutoSkip=AutoSkip;
		ctrl.Saltar=false;
		InicializarIndices();
                ctrl.onkeypress=ValidarTecla;
		if (QualNavegador()=="IE" && QualVersao() > 5)
			ctrl.onkeyup=SaltarCampo;

	}
}

function SaltarCampo(ctrl)
{
	if (ctrl==null)
		ctrl=this;
	if ( ctrl.AutoSkip && ctrl.Saltar)
		if (ctrl.Saltar)
		{
			ctrl.Saltar=false;
      if ( ctrl.IndicePosterior != null )
				SetarFoco(ctrl.IndicePosterior);
		}
}

// Fazer o salto de campo
function ValidarTecla (evnt)
{
	var tk;
    var c;
	// Recebe a tela pressionada
	tk = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
    c=String.fromCharCode(tk);
	c=c.toUpperCase();

	// -- Este trecho faz com que o <Enter> tenha a função de <Tab>, mas acho inviável, pois não é possível
	//       colocar o foco em campos do Tipo "image", e, neste caso, nunca seria possível fazer a submissão
	//       do formulário
	// if ( tk == 13 )
	// {
	//	this.Saltar=true;
	//	SaltarCampo(this);
	//	return false;
	// }
	
	// Só aceita teclas alfanuméricas. Não aceita teclas de controle
	if ( tk < 32 )
		return true;

	// Aceita também caracteres acentuados
	if ( ((tk>127) && (tk<192)) || (tk>252) )
		return false;

	// Não aceita o apostrofo
	if ( c == "'")
		return false;

	switch ( this.Tipo )
	{
	case "T":
//		if (( c<"0" || c>"9") && c!="/")
		if (( c<"0" || c>"9"))
			return false;
		break;
	case "D":
		if ( c<"0" || c>"9" )
			return false;
		break;
	case "N":
		if ( (c<"0" || c>"9") && (c!="." && c!=",") )
			return false;
		if ( (c==",") && ((this.value.search(",")>-1) || (this.value.length==0)) )
			return false;
		if ( (c==".") && (this.value.length==0) )
			return false;
		break;
//testar aqui
	case "C":
                if (( c<"A" || c>"Z" ) && (c!="-") && (c!=".") && (c!="/") && (c!=" ") && (c!=",")) 
			return false;
		break;
        case "P":
                if ((c<"0" || c>"9") && (c!="-")) 
			return false;
		break;		
	case "G":
		if (( c<"0" || c>"9") && (c!="/") && (c!="-") && (c!="."))
                        return false;
		break;
	default:
		break;
	}

//minha inclusao

        if ( this.Tipo == "T" )
           {

             if (this.value.length==2)
               {
                 this.value = this.value+'/';
               }

             if (this.value.length==5)
               {
                 this.value = this.value+'/';
               }

           }

//        if ( this.Tipo == "C" )
//           {
//
//             if (tamanho==this.value.length)
//                {
//                   return false;
//                }
//
//             this.value = this.value.substring(0,this.value.length)+c;
//             return false;
//
//           }
//

//final da minha inclusao

	this.Saltar=(this.value.length==this.Tam-1);
	if ( ((QualNavegador()=="IE") && QualVersao()<5) || (QualNavegador()!="IE") )
		SaltarCampo(this);

	return true;
}

//*********************************************
// Validar a data passada como parametro
//*********************************************

function ValidarData(digitada)
{

  if (digitada.length == '')
   {
      return true;
   }

  if (digitada.length != 10)
   {
      alert("A data deve ser formatada com 10 caracteres - DD/MM/AAAA");
      return false;
   }

  //verifica deslocamento da primeira barra de divisao da data
  if (digitada.substring(2,3)!="/")
   {
      alert("Data inválida - DD/MM/AAAA");
      return false;
   }

  //verifica deslocamento da segunda barra de divisao da data
  if (digitada.substring(5,6)!="/")
   {
      alert("Data inválida - DD/MM/AAAA");
      return false;
   }

  // carrega variaveis para análise completa da data
  var dia = digitada.substring(0,2);
  var mes = digitada.substring(3,5);
  var ano = digitada.substring(6,10);

//  alert(dia)
//  alert(mes)
//  alert(ano)

//  validação do dia

    if (dia<1 || dia>31)
       {
          alert('Dia inválido');
          return false;
       }
	 	else if (mes==4 || mes==6 || mes==9 || mes==11 )
	 		{
                        	if (dia==31)
	 				{
	   					alert('Esse mês não possui dia 31');
	   					return false;
	   				}
	   		}
	   		else if (mes==2)
	   			{

	   				if (dia==31)
	   					{
	   						alert('Esse mês não possui dia '+dia);
	   						return false;
	   					}
	   					else if (dia==30)
	   						{
	   						alert('Esse mês não possui dia '+dia);
	   						return false;
	   						}
	   						else if (dia==29)
	   							{
                                                                  if (!((ano % 4 == 0) && ((ano % 100 != 0) || (ano % 400 == 0))))
                                                                   {
                                                                      alert('Esse mês, neste ano não possui dia '+dia);
                                                                      return false;
                                                                   }
	   							}
	   			}

// validação do mes

  if (mes<1 || mes>12)
       {
          alert('Mês inválido');
          return false;
       }

// validação do ano

  if (ano<1900 || ano>2020)
       {
          alert('Ano inválido');
          return false;
       }

  return true;

}


//*********************************************
// Validar o CGC data passado como parametro
//*********************************************

	function ltrim(s)
	{
	  var aux;
	  aux = "";
	  for (var i = 0; i < s.length; i++)
	    if (escape(s.substring(i, i+1)) != '%20') {
		 	 aux = s.substring(i, s.length);
			 break;  
		 }	 
	  return aux;  
	}

	function rtrim(s)
	{
	  var aux;
	    aux = "";
	  for (var i = s.length - 1; i >= 0; i--)
	    if (escape(s.substring(i, i+1)) != '%20') {
		 	 aux = s.substring(0, i + 1);
			 break;  
		 }	 
	  return aux;
	}


	function alltrim(s)
	{
	  return rtrim(ltrim(s));
	}

	function isdigit(c)
	{
		if(isNaN(c))
			return false;
		else
			return true;
	}

	function ValidaCGC(s)
	{
	var c;
	var	Soma1, Soma2, Digito1, Digito2, i;
	var	CGC;
	var V;

//        alert("pelo menos chamou");

	function CriaArray (n)
	{
		this.length = n
	}

//        alert("apos a funcao");

	V = new CriaArray(14)

//        alert("usou a funcao");

	CGC = "";
	Soma1 = 0;
	Soma2 = 0;
	Digito1 = 0;
	Digito2 = 0;

	for (i = 0; i < s.length; i++)
	{
	 	 c = s.substring(i, i+1);
		 if (isdigit(c))
		 	CGC = CGC + c;

	}

//        alert(alltrim("        apos o for       "));

	if ((alltrim(CGC) != " ") && (CGC.length == 14))
	{

//                alert("entrou para análise");

		for (i = 0; i < CGC.length; i++)
		{
			V[i] = parseFloat(CGC.substring(i, i + 1));
	    }
		Soma1 = (V[11] * 2) + (V[10] * 3) + (V[9] * 4) + (V[8] * 5) +
	             (V[7] * 6) + (V[6] * 7) + (V[5] * 8) + (V[4] * 9) +
	             (V[3] * 2) + (V[2] * 3) + (V[1] * 4) + (V[0] * 5);
	    Soma2 = (V[12] * 2) + (V[11] * 3) + (V[10] * 4) + (V[9] * 5) +
	             (V[8] * 6) + (V[7] * 7) + (V[6] * 8) + (V[5] * 9) +
	             (V[4] * 2) + (V[3] * 3) + (V[2] * 4) + (V[1] * 5) +
	             (V[0] * 6);

		Digito1 = Soma1 - parseInt(Soma1 / 11) * 11;
		if ((Digito1 == 0) || (Digito1 == 1))
			Digito1 = 0;
		else
			Digito1 = 11 - Digito1;

		Digito2 = Soma2 - parseInt(Soma2 / 11) * 11;
		if ((Digito2 == 0) || (Digito2 == 1))
			Digito2 = 0;
		else
			Digito2 = 11 - Digito2;

		if ((Digito1 == V[12]) && (Digito2 == V[13]) && (Soma1 != 0) && (Soma2 != 0))
		{
//                        alert("antes do true");
			return true;
		}
	}
//        alert("antes do false");
	return false;
	}

function ValidaCPF(exp) {
		var regExp = /\d{11}/;
		if (regExp.test(exp)) {
			var varFirstChr = exp.charAt(0);
			var vaCharCPF = false;
			for(var i=0;i<=10;i++){
				var c = exp.charAt(i);
			    if(c!=varFirstChr)
					vaCharCPF = true;
			}

			if(!vaCharCPF)
				return false;

			var soma=0;

			for(i=0;i<9; i++)
				soma += (10-i) * ( eval(exp.charAt(i)) );

			digito_verificador = 11-(soma % 11);

			if((soma % 11) < 2)
				digito_verificador = 0;

			if (eval(exp.charAt(9)) != digito_verificador)
				return false;

			soma=0;

			for(i=0;i<9; i++)
				soma += (11-i)*(eval(exp.charAt(i)));

			soma += 2*(eval(exp.charAt(9)));

			digito_verificador = 11-(soma % 11);

			if((soma % 11)<2)
				digito_verificador = 0;

			if(eval(exp.charAt(10)) != digito_verificador)
				return false;

			return true;

		} else {
			return false;
		}
	}

//validações de datas do formulário - orcamento_agricola_agropecuário

function data_validade()
 {

   if (document.FORMULARIO.dt_validad.value=="")
    {
      return true;
    }

   hoje = new Date()
   dia = document.FORMULARIO.dt_validad.value.substring(0,2);
   mes = parseInt(document.FORMULARIO.dt_validad.value.substring(3,5))-1;
   ano = document.FORMULARIO.dt_validad.value.substring(6,10);
   compara = new Date(ano,mes,dia)

   if (compara<hoje)
    {
        alert("A data de validade não pode ser inferior a data de hoje");
        document.FORMULARIO.dt_validad.focus();
        document.FORMULARIO.dt_validad.select();        
    }

 }

function data_previsao()
 {

   if (document.FORMULARIO.dt_previsa.value=="")
    {
      return true;
    }

   hoje = new Date()
   dia = document.FORMULARIO.dt_previsa.value.substring(0,2);
   mes = parseInt(document.FORMULARIO.dt_previsa.value.substring(3,5))-1;
   ano = document.FORMULARIO.dt_previsa.value.substring(6,10);
   compara = new Date(ano,mes,dia)

   if (compara<hoje)
    {
        alert("A data da previsão de entrega dos equipamentos não pode ser inferior a data de hoje");
        document.FORMULARIO.dt_previsa.focus();
        document.FORMULARIO.dt_previsa.select();
    }


 }

function data_pagamento()
 {

   if (document.FORMULARIO.dt_pagamen.value=="")
    {
      return true;
    }

   hoje = new Date()
   dia = document.FORMULARIO.dt_pagamen.value.substring(0,2);
   mes = parseInt(document.FORMULARIO.dt_pagamen.value.substring(3,5))-1;
   ano = document.FORMULARIO.dt_pagamen.value.substring(6,10);
   compara = new Date(ano,mes,dia)

   if (compara<hoje)
    {
        alert("A data prevista para o primeiro pagamento de principal não pode ser inferior a data de hoje");
        document.FORMULARIO.dt_pagamen.focus();
        document.FORMULARIO.dt_pagamen.select();
    }

 }



//-->
