function consistencia(form){
    
	var erro = 0;
    var tamanho_form = 10;
	var str_erro = "";
	var data = 1;
	var foco = "-1";

	for (cont=0; cont<tamanho_form; cont++){
		switch(form[cont].id){
			case "branco": 
				if(form[cont].value == ""){
					str_erro = str_erro + "Campo " + form[cont].lang + " está em branco.\n" ;
					form[cont].focus();
					if( foco == "-1" ){ foco = cont; }
					erro = 1;
				 }else{
					if( erro != 1 ) { erro = 0; }
				 }
			break;
		}
	}

	if(erro){
		alert( "Ocorreu o seguinte erro:\n\n"+str_erro );
		return erro;
	}
	
	
		document.compra.submit();

		
}



function isNum( caractere ) 
{ 
         var strValidos = "0123456789" 
         if ( strValidos.indexOf( caractere ) == -1 ) 
                 return false; 
         return true; 
} 

function validaTecla(campo, event) 
{ 
         var BACKSPACE=  8; 
         var key; 
         var tecla; 


         CheckTAB=true; 
         if(navigator.appName.indexOf("Netscape")!= -1) 
                 tecla= event.which; 
         else 
                 tecla= event.keyCode; 


         key = String.fromCharCode( tecla); 
         

         if ( tecla == 13 ) 
                 return false; 
         if ( tecla == BACKSPACE ) 
                 return true; 
         return ( isNum(key)); 
} 

function FormataCNPJ( el ) 
{ 
         vr = el.value; 
         tam = vr.length; 


      if ( vr.indexOf(".") == -1 ) 
      { 
      if ( tam <= 2 ) 
              el.value = vr; 
      if ( (tam > 2) && (tam <= 6) ) 
              el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
      if ( (tam >= 7) && (tam <= 10) ) 
              el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' 
+ vr.substr( 5, 3 ) + '/'; 
      if ( (tam >= 11) && (tam <= 18) ) 
             el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + 
vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
      } 
      return true; 
}

