<!--

//====================== Monta Data Atual  =========================
//Pega Data Atual
//Pode ser usada em qualquer função
var DataAtual = new Date(); 
var dia = DataAtual.getDate();
//soma 1 pois esta função Retorna o mês do objeto Date, um inteiro entre 0 e 11 (0 janeiro, 1 fevereiro, etc).
var mes = DataAtual.getMonth()+1;
var ano = DataAtual.getFullYear();
//monta data atual 
DataAtual = dia + '/' + mes + '/' + ano ;
//====================== Monta Data Atual  =========================


function SetHelp(txt) { help.innerText = txt ; }

function main(campofoco) { 
	var i;
	if (campofoco == '') 
		return false;
	if (document.form.elements.length != 0)
		for (i = 0; i < document.form.elements.length; i++){
		   	if (campofoco == document.form[i].name)
				document.form[campofoco].focus();  }
}

function Apaga(){
	if (document.form.elements.length != 0)
	   for (i = 0; i < document.form.elements.length; i++){
			document.form[i].value="";  }
}

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length ;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }
			
	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			document.form[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
}

function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;

	vr = document.Formulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.Formulario[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	
}

function FormataValor1(campo,tammax,teclapres) {

	var tecla = teclapres.keyCode;

	vr = document.Formulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 1 ){ 
	 		document.Formulario[campo].value = vr ; }
	 	if ( (tam > 1) && (tam <= 4) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 1 ) + ',' ; }
	 	if ( (tam >= 5) && (tam <= 7) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 4 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ; }
	 	if ( (tam >= 8) && (tam <= 10) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 7 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ; }
	 	if ( (tam >= 11) && (tam <= 13) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 10 ) + '.' + vr.substr( tam - 10, 3 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ; }
	 	if ( (tam >= 14) && (tam <= 16) ){
	 		document.Formulario[campo].value = vr.substr( 0, tam - 13 ) + '.' + vr.substr( tam - 13, 3 ) + '.' + vr.substr( tam - 10, 3 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ;}
	}		
}

function FormataValor3(campo,tammax,teclapres) {
//Formata Números com 3 casas decimais
	var tecla = teclapres.keyCode;
	vr = document.Formulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length + 1; }
	if (tecla == 8 ){ tam = tam - 1; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 3 ){
	document.Formulario[campo].value = vr; }
	if ( (tam > 3) && (tam <= 7) ){
	document.Formulario[campo].value = vr.substr( 0, tam - 3 ) + ',' + vr.substr( tam - 3, tam ); }
	if ( (tam >= 8) && (tam <= 10) ){
	document.Formulario[campo].value = vr.substr( 0, tam - 7 ) + '.' + vr.substr( tam - 7, 3 ) + ',' + vr.substr( tam - 3, tam ); }
	if ( (tam >= 11) && (tam <= 14) ){
	document.Formulario[campo].value = vr.substr( 0, tam - 10 ) + '.' + vr.substr( tam - 10, 3 ) + '.' + vr.substr( tam - 7, 3 ) + ',' + vr.substr( tam - 3, tam ); }
	}
}

function funLarguraTotal(teclapres, funcao)
{
	if (funcao == 'calcula')
	{	
		if (	document.Formulario["txtNUMLarguraVeiculo"].value.length >= 4			||
				document.Formulario["txtNUMExcessoDireitoVeiculo"].value.length >= 4	||	
				document.Formulario["txtNUMExcessoEsquerdoVeiculo"].value.length >= 4	)
		{		var varLarguraVeiculo = 0;
				var varExcessoDireito = 0;
				var varExcessoEsquerdo = 0;
				var varLarguraTotal = 0;
		
				if (document.Formulario["txtNUMLarguraVeiculo"].value != '')
				{	varLarguraVeiculo = document.Formulario["txtNUMLarguraVeiculo"].value;	
					varLarguraVeiculo = varLarguraVeiculo.replace( ".", "" ).replace( ",", "." )	}

				if (document.Formulario["txtNUMExcessoDireitoVeiculo"].value != '')
				{	varExcessoDireito = document.Formulario["txtNUMExcessoDireitoVeiculo"].value;	
					varExcessoDireito = varExcessoDireito.replace( ".", "" ).replace( ",", "." )	}

				if (document.Formulario["txtNUMExcessoEsquerdoVeiculo"].value != '')
				{	varExcessoEsquerdo = document.Formulario["txtNUMExcessoEsquerdoVeiculo"].value;	
					varExcessoEsquerdo = varExcessoEsquerdo.replace( ".", "" ).replace( ",", "." )	}

				varLarguraTotal = ( eval(varLarguraVeiculo) + eval(varExcessoDireito) + eval(varExcessoEsquerdo) );
				varLarguraTotal = varLarguraTotal.toFixed(2);
				
				var vr = varLarguraTotal.toString();
				vr = vr.replace( ".", "" );
				vr = vr.replace( ",", "" );
				tam = vr.length;

				if ( tam <= 2 ){
					varLarguraTotal = vr.substr( 0, tam - 1 ) + ',' + vr.substr( tam - 1, tam ) + '0'; }
				if ( (tam > 2) && (tam <= 5) ){
					varLarguraTotal = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
				if ( (tam >= 6) && (tam <= 8) ){
					varLarguraTotal = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
				if ( (tam >= 9) && (tam <= 11) ){
					varLarguraTotal = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
				if ( (tam >= 12) && (tam <= 14) ){
					varLarguraTotal = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
				if ( (tam >= 15) && (tam <= 17) ){
					varLarguraTotal = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}

				document.Formulario["txtNUMLarguraTotalConjunto"].value = '';
				document.Formulario["txtNUMLarguraTotalConjunto"].value = varLarguraTotal;
		}		
	}
	else
	{	var tecla = teclapres.keyCode;
		if( tecla != 9)
		{	alert('A largura total é a soma da Largura do Veículos e os Excessos Direito e Esquerdo.');
			return false;	
		}
	}
}

function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	


		
	 	if (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )	
				document.form[prox].focus() ;	}
}

function ComparaDatas(data1, data2) {
//Função para comparar se uma data é menor que a outra
//Data deve vir no formato DDMMYYYY
//Autor: José Wilson B. Rodrigues 
//Data: 08/05/2005

	var d1 = data1;
	var d2 = data2;

	d1 = d1.split('/');
	d1 = -((-d1[2]*100-d1[1])*100-d1[0]);
	d2 = d2.split('/');
	d2 = -((-d2[2]*100-d2[1])*100-d2[0]);

	if (d1 > d2) 
		return true;
	else
		return false;
}

function ComparaDataAtual(Campo) {
//Função para comparar se uma data é maior que a data atual
//Data deve vir no formato DDMMYYYY
//Autor: José Wilson B. Rodrigues 
//Data: 08/05/2005
	var data1 = document.Formulario[Campo].value;
	var data2 = DataAtual;
		
	if (ComparaDatas(data1, data2) == true)
	{	alert('Data não pode ser maior que data atual.')
		document.Formulario[Campo].focus();
		return false;
	}
}

function ComparaAno(Campo) {
//Função para comparar se um ano é maior que o ano atual
//Data deve vir no formato YYYY
//Autor: José Wilson B. Rodrigues 
//Data: 05/06/2005
	var ano1 = document.Formulario[Campo].value;
	var ano2 = ano;
		
	if (ano1 > ano2)
	{	alert('Ano não pode ser maior que ano atual.')
		document.Formulario[Campo].focus();
		return false;
	}
}

function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.Formulario[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.Formulario[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.Formulario[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}
function VerificaJava()
 	{
	if (navigator.javaEnabled())
		document.form.javas.value="sim"
	}

//Funções desenvolvidas implementadas por José Wilson
function ValidaBR(Campo)
{ //Valida número da BR com três posições.
	var vr = document.Formulario[Campo].value;
	
	if (vr == '') {return false};
	
	if (vr.length < 3)
	{	alert('Informe o número da BR com três posições');
		document.Formulario[Campo].focus();
		return false;
	}
}

//17/01/2002
function IsFormComplete(FormName)
{
var x       = 0
var FormOk  = true

while ((x < document.forms[FormName].elements.length) && (FormOk))
   {
	 if (document.forms[FormName].elements[x].value == '' && document.forms[FormName].elements[x].disabled == false && document.forms[FormName].elements[x].id == 'sim')
     { 
		alert(document.forms[FormName].elements[x].title)
        if (document.forms[FormName].elements[x].type != "hidden")
			document.forms[FormName].elements[x].focus();
        FormOk = false 
     }
     x ++
   }
return FormOk
}

//-------------------------------
function isDigit (c){   
	
	    return ((c >= "0") && (c <= "9"))
    }  
//-------------------------------
function isInteger (s) {
    var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
     
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

function RetiraCaracteresInvalidos(strCampo,tam) {
	nTamanho = strCampo.length;
	szCampo = "";
	j=0;

    // Verifica se os caracteres são números e barra.
    for (var i = 0; i < strCampo.length; i++) {
       var ch = strCampo.substring(i, i + 1);
       if ((ch < "0" || "9" < ch) && ch != "/"  && ch != "-"  && ch != ".") {
			return false;
       }
    }

	//Retira os caracteres inválidos
	for (i = nTamanho-1;i>=0;i--) 
	{
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
			if (j > tam) break;
		}
	}
	if (szCampo.length < tam) {
		for (i = szCampo.length;i<tam;i++) 
		{
			//szCampo = "0" + szCampo;
			szCampo = szCampo;
		}
	}
    return szCampo;
}

function FormataCEP(Campo,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.Formulario[Campo].value;
	tam = vr.length

	if (tecla != 8 && tecla != 46){
		if (tam + 1 == 3)
			document.Formulario[Campo].value = document.Formulario[Campo].value + '.';
		if (tam + 1 == 7)
			document.Formulario[Campo].value = document.Formulario[Campo].value + '-';
	}
}

function FormataCNPJ(Campo,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.Formulario[Campo].value;
	tam = vr.length

	if (tecla != 8 && tecla != 46){
		if (tam + 1 == 3)
			document.Formulario[Campo].value = document.Formulario[Campo].value + '.';
		if (tam + 1 == 7)
			document.Formulario[Campo].value = document.Formulario[Campo].value + '.';
		if (tam + 1 == 11)
			document.Formulario[Campo].value = document.Formulario[Campo].value + '/';
		if (tam + 1 == 16)
			document.Formulario[Campo].value = document.Formulario[Campo].value + '-';
	}
}

function funVerificaCnpjCpf(Campo){
	var aux = RetiraCaracteresInvalidos(document.Formulario[Campo].value,18);
	if (aux.length == 0)
		return false;
	else if (aux.length == 11)
		validaCPF(Campo, RetiraCaracteresInvalidos(document.Formulario[Campo].value,18));
	else if (aux.length == 14){
		validaCNPJ(Campo, RetiraCaracteresInvalidos(document.Formulario[Campo].value,18));}
	//else {
		//alert("Informe o CNPJ em caso de Pessoa Jurídica ou o CPF em caso de Pessoa Física.");
		//document.Formulario[Campo].focus();
	//}
}

function funVerificaCnpj(Campo){
	var aux = RetiraCaracteresInvalidos(document.Formulario[Campo].value,18);
	if (aux.length == 0)
		return false;
	else if (aux.length == 11)
		validaCPF(Campo, RetiraCaracteresInvalidos(document.Formulario[Campo].value,18));
	else if (aux.length == 14){
		validaCNPJ(Campo, RetiraCaracteresInvalidos(document.Formulario[Campo].value,18));}
	else {
		alert("Informe o CNPJ de sua empresa.");
		document.Formulario[Campo].focus();
	}
}


//FUNÇÃO PARA VALIDAR CPF
 function validaCPF(Campo, Valor) {
 var CPF = Valor;
	if (CPF.length == 0)
		return false;

	if (CPF.length != 11){
		alert("CPF inválido!");
		document.Formulario[Campo].focus();
		return false;
	}
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9))){
		alert("CPF inválido!");
		document.Formulario[Campo].focus();
		return false;
	}
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10))){
		alert("CPF inválido!");
		document.Formulario[Campo].focus();
		return false;
	}
	return true;
 }

//  TRECHO JAVASCRIPT PARA VERIFICAR O CAMPO "CNPJ" --- INÍCIO
function validaCNPJ(Campo, Valor) {
	var StrCNPJ = Valor;
	if (StrCNPJ.length == 0){
		return false}

	var DataPat  = /^(\d{2}).(\d{3}).(\d{3})\/(\d{4})-(\d{2})/;
	var DataPat2 = /^(\d{14})/;

	var matchArray   = StrCNPJ.match(DataPat);
	var matchArray2  = StrCNPJ.match(DataPat2);

	if (matchArray == null && matchArray2 == null) {
	alert('Formato incorreto\nO número do CNPJ deve ser informado incluindo-se os 14 dígitos.\nNão são necessários os separadores ou zeros à esquerda.\n\nExemplo: 99999999999999 ou 99.999.999\/9999-99');
	document.Formulario[Campo].focus();
	return false;
	} 
	else if(matchArray != null) {
	StrCNPJ = matchArray[1] + matchArray[2] + matchArray[3] + matchArray[4] + matchArray[5] ;
	}
	else if(matchArray2 != null) {
	StrCNPJ = matchArray2[1];
	}   

      var Ref_String="1234567890";
      for (Count=0; Count < StrCNPJ.length; Count++)
      {
       TempChar= StrCNPJ.substring (Count, Count+1);
       if (Ref_String.indexOf (TempChar, 0)==-1)
        {
        alert("Digite somente Números em seu CNPJ!");
        document.Formulario[Campo].value = "";
        document.Formulario[Campo].focus();
            return false ;
         }
      }

      var vaCharCNPJ;
      var varFirstChr = StrCNPJ.charAt(0);
      var vlMult,vlControle,s1, s2 = "";
      var i,j,vlDgito,vlSoma = 0;
      for ( var i=0; i<=13; i++ ) {

        var c = StrCNPJ.charAt(i);
        if( ! (c>="0")&&(c<="9") )
        {
      alert("CNPJ incorreto!");
         document.Formulario[Campo].focus();
      return false; }
        if( c!=varFirstChr ) { vaCharCNPJ = true; }
      }
      if( ! vaCharCNPJ ) {

      alert("Digite seu CNPJ Corretamente!");
      document.Formulario[Campo].focus();
      return false ;
      }

      s1 = StrCNPJ.substring(0,12);
      s2 = StrCNPJ.substring(12,15);
      vlMult = "543298765432";
      vlControle = "";
      for ( j=1; j<3; j++ ) {

       vlSoma = 0;
       for ( i=0; i<12; i++ )
        { vlSoma += eval( s1.charAt(i) )* eval( vlMult.charAt(i) );}
         if( j == 2 ){ vlSoma += (2 * vlDgito); }
         vlDgito = ((vlSoma*10) % 11);
         if( vlDgito == 10 ){ vlDgito = 0; }
         vlControle = vlControle + vlDgito;
         vlMult = "654329876543";
      }
      if( vlControle != s2 ) {
      alert("CNPJ inválido!");
      document.Formulario[Campo].focus();
      return false; 
      }
      else {
      return true; 
      }      
}

//  TRECHO JAVASCRIPT PARA VERIFICAR O CAMPO "DATA" --- INICIO
//  Verifica o campo DATA.
function VerificaData(Campo)
{
	var str = document.Formulario[Campo].value

	// Verifica se o usuário não digitou nada
	if (str.length == 0){
		return false}
	// Verifica se foram digitados 10 caracteres.
    if (str.length != 10){
       alert("\nO campo DATA requer 10 dígitos no formato:\n\nDD/MM/AAAAA")
       document.Formulario[Campo].focus();
       return false;
    }

    // Verifica se os caracteres são números e barra.
    for (var i = 0; i < str.length; i++) {
       var ch = str.substring(i, i + 1);
       if ((ch < "0" || "9" < ch) && ch != "/") {
			alert("\nO campo DATA aceita somente números e barra no formato:\n\nDD/MM/AAAA");
			document.Formulario[Campo].focus();
			return false;
       }
    }
    // Verifica o valor do dia.
    if ( (str.substring(0, 2) < 1) || (str.substring(0, 2) > 31) ) {
       alert("\nDia incorreto.");
       document.Formulario[Campo].focus();
       return false;
    }
    // Verifica o valor do dia no valor do mês.
    // Fevereiro
    if ( (str.substring(3, 5) == 2 ) && (str.substring(0, 2) > 29) ) {
       alert("\nFevereiro não tem mais que 29 dias.");
       document.Formulario[Campo].focus();
       return false;
    }
    if ( (str.substring(3, 5) == 2 ) && (str.substring(0, 2) == 29) )
       { alert("\nVocê entrou com 29 de Fevereiro...\n\nVocê tem certeza de que é ano bissexto?"); 
       document.Formulario[Campo].focus();}
    // Abril
    if ( (str.substring(3, 5) == 4 ) && (str.substring(0, 2) > 30) ) {
       alert("\nO mês de Abril tem somente 30 dias.");
       document.Formulario[Campo].focus();
       return false;
    }
    // Junho
    if ( (str.substring(3, 5) == 6 ) && (str.substring(0, 2) > 30) ) {
       alert("\nO mês de Junho tem somente 30 dias.");
       document.Formulario[Campo].focus();
       return false;
    }
    // Setembro
    if ( (str.substring(3, 5) == 9 ) && (str.substring(0, 2) > 30) ) {
       alert("\nO mês de Setembro tem somente 30 dias.");
       document.Formulario[Campo].focus();
       return false;
    }
    // Novembro
    if ( (str.substring(3, 5) == 11 ) && (str.substring(0, 2) > 30) ) {
       alert("\nO mês de Novembro tem somente 30 dias.");
       document.Formulario[Campo].focus();
       return false;
    }
    // Verifica o valor do mês.
    if ( (str.substring(3, 5) < 1) || (str.substring(3, 5) > 12) ) {
       alert("\nMês incorreto.");
       document.Formulario[Campo].focus();
       return false;
    }
    // Verifica o valor do ano.
    if ( (str.substring(6, 10) < 1900) ) {
       alert("\nAno incorreto.");
       document.Formulario[Campo].focus();
       return false;
    }
    // Verifica posicionamento da barra.
    if ( str.substring(3, 4) == "/" || str.substring(4, 5) == "/" ) {
       alert("\nFormato de Data incorreto.");
       document.Formulario[Campo].focus();
       return false;
    }
    if ( str.substring(0, 1) == "/" || str.substring(1, 2) == "/" ) {
       alert("\nFormato de Data incorreto.");
       document.Formulario[Campo].focus();
       return false;
    }
    if ( str.substring(6, 7) == "/" || str.substring(7, 10) == "/" ) {
       alert("\nFormato de Data incorreto.");
       document.Formulario[Campo].focus();
       return false;
    }
    if ( str.substring(2, 3) != "/" || str.substring(5, 6) != "/" )  {
       alert("\nFormato de Data incorreto.");
       document.Formulario[Campo].focus();
       return false;
    }
    return true;
}
//  TRECHO JAVASCRIPT PARA VERIFICAR O CAMPO "DATA" --- FINAL

//Verifica se o Ano digitado é válido
function VerificaAno(Campo){
	if(document.Formulario[Campo].value == '')
		return true;

	var str = document.Formulario[Campo].value;

	if( document.Formulario[Campo].value < 1900 || str.length != 4 ) {
	   alert("\nAno incorreto.");
	   document.Formulario[Campo].focus();
	   return false;
	}
}


//Verifica se o campo digitado é um valor válido
function Valor(Campo, casas){
	
	if(document.Formulario[Campo].value == '')
		return;

	var str = document.Formulario[Campo].value;
	//Umacasa decimal
	if(casas == 1){
		// Verifica se número foi digitado com duas casas decimais
		if (str.length < 3){
			alert('Formato inválido! Este valor deve ser digitado com uma casa decimal.');
			document.Formulario[Campo].focus();
			return false;
		}
		if ( str.substring( str.length-2, (str.length-2)+1 ) != "," ){
			alert('Formato inválido! Este valor deve ser digitado com duas casas decimais.');
			document.Formulario[Campo].focus();
			return false;
		}
	}
	//Duas casas decimais
	if(casas == 2){
		// Verifica se número foi digitado com duas casas decimais
		if (str.length < 4){
			alert('Formato inválido! Este valor deve ser digitado com duas casas decimais.');
			document.Formulario[Campo].focus();
			return false;
		}
		if ( str.substring( str.length-3, (str.length-3)+1 ) != "," ){
			alert('Formato inválido! Este valor deve ser digitado com duas casas decimais.');
			document.Formulario[Campo].focus();
			return false;
		}
	}

	//Três casas decimais
	if(casas == 3){
		// Verifica se número foi digitado com três casas decimais
		if ( str.substring( str.length-4, (str.length-4)+1 ) != "," ){
			alert('Formato inválido! Este valor deve ser digitado com três casas decimais.');
			document.Formulario[Campo].focus();
			return false;
		}
	}
}

function SoNumero(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;

	if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else
		{
			if (tecla != 8) // backspace
				event.keyCode = 0;
				//return false;
			else
				return true;
		}
}

//definição de variáveis para as funções funAbreJanela e funAnimarJanela
var url;
var altura_janela=100;
var largura_janela=100;
var yj=5;
var xj=5;
if(document.layers && !document.getElementById) down=70; else down=3;
if(document.all) right=5; else right=20;
var nome_janela;

function funAbreJanela(nome_janela, url_janela){
	url = url_janela;
	nome_janela=window.open("","","menubar=no,scrollbars=yes,status=no,toolbar=no");
	//interceptacao de erro na abertura da janela
	text = "Se a janela nao estava abrindo\ntalvez seja porque voce tenha um\nprograma bloqueador de pop-up!\nObservacao » O windows XP service pack 2\nbloqueia pop-ups!";
	 if(nome_janela == null) { alert(text); return; }
	 //fim
	 nome_janela.resizeTo(100,100);
	 nome_janela.moveTo(0,0);
	 funAnimarJanela(nome_janela);
}

function funAnimarJanela(nome_janela){
	altura_maxima = screen.availHeight - 200
	largura_maxima = screen.width - 200
	
	if (altura_janela >= altura_maxima-down) yj=0; 
	nome_janela.resizeBy(xj,yj);
	altura_janela+=5;
	largura_janela+=5;
	if (largura_janela>=largura_maxima-right){
		nome_janela.location=url;
		altura_janela=100;
		largura_janela=100;
		xj=5;
		yj=5;
		return;
	}
	setTimeout("funAnimarJanela(nome_janela)",5);
}

function funAbreJanela2(nome_janela, url_janela){
	janela=window.open("","","menubar=no,scrollbars=yes,status=no,toolbar=no,width=750,height=550");
	//interceptacao de erro na abertura da janela
	text = "Se a janela nao estava abrindo\ntalvez seja porque voce tenha um\nprograma bloqueador de pop-up!\nObservacao » O windows XP service pack 2\nbloqueia pop-ups!";
	 if(janela == null) { alert(text); return; }
	 //fim
	 janela.moveTo(0,0);
	 janela.location=url_janela
}

//-->


function NovaJanela(target)
{
	var x =0;
	var y =0;
	x = (screen.height - 450) / 4
	y = (screen.width - 750) / 2

window.open('',target,'width=750,height=450,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,top='+ x +', left=' + y)
}


function NovaJanela2(target)
{
	var x =0;
	var y =0;
	x = (screen.height - 450) / 4
	y = (screen.width - 760) / 2

window.open('',target,'width=760,height=450,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,top='+ x +', left=' + y)
}

function NovaJanela3(target)
{
	var x =0;
	var y =0;
	x = (screen.height - 250) / 4
	y = (screen.width - 710) / 2

window.open('',target,'width=710,height=250,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,top='+ x +', left=' + y)
}

function NovaJanelaClipping(target)
{
	var x =0;
	var y =0;
	x = (screen.height - 150) / 4
	y = (screen.width - 300) / 2

window.open('',target,'width=300,height=150,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,top='+ x +', left=' + y)
}