function VAR1()
   {
      document.FrmLogin.TxLogin.focus();
   }

function FECHARWIN(url)
	{
		parent.location=url;
   }

function NOVAWIN(url)
	{
		parent.location=url;
   }

function BIBLIOTECA(url)
	{
		window.open(url,'','toolbar=No,menubar=No,location=No,scrollbars=Yes,resizable=No,status=Yes,width=350,height=500,left=200,top=25');
   }

function INFOJANELA(url,w,h)
	{
   	var conf;
      conf = 'toolbar=No,menubar=No,location=No,scrollbars=No,resizable=No,status=No,width='+w+',height='+h+',left=200,top=125'
		window.open(url,'',conf);
   }

function JANELA(url,w,h)
	{
   	var conf;
//		conf = 'toolbar=No,menubar=No,location=No,scrollbars=No,resizable=No,status=No,width='+w+',height='+h+',left=200,top=125'
//		window.open(url,'',conf);
      conf = 'status:false;dialogWidth:'+w+'px;dialogHeight:'+h+'px'
		showModalDialog(url,window,conf);
   }

function JANELASOM(url,w,h)
	{
   	var conf;
		conf = 'toolbar=No,menubar=No,location=No,scrollbars=No,resizable=No,status=No,width='+w+',height='+h+',left=200,top=125'
		window.open(url,'',conf);
//      conf = 'status:false;dialogWidth:'+w+'px;dialogHeight:'+h+'px'
//		showModalDialog(url,window,conf);
   }

function MOSTRAHELP(url)
	{
		showModalDialog(url,window,'status:false;dialogWidth:550px;dialogHeight:200px');
//--		showHelp(url);

   }

function WINPEDIDO(url)
	{
		showModalDialog(url,window,'status:false;dialogWidth:700px;dialogHeight:500px');
   }

function WINMSGUSEROK(url)
	{
		showModalDialog(url,window,'status:false;dialogWidth:300px;dialogHeight:200px');
   }

function VERIFICA_CPF(valor)
	{
	   erro = 0;
	   aux1 = 0;
	   aux2 = 0;
	   aux3 = 1;
	   for (i=0;i<valor.length-2;i++)
	      {
	         if ((valor.substr(i,1) != "/") && (valor.substr(i,1) != "-") && (valor.substr(i,1) != "."))
	            {
	               aux1 = aux1+(11-aux3)*valor.substr(i,1);
	               aux2 = aux2+(12-aux3)*valor.substr(i,1);
	               aux3++;
	            }
	      }
	   resto = aux1-((Math.floor(aux1/11))*11);
	   (resto < 2) ? dig1=0 : dig1=11-resto;
	   aux2 = aux2+(2*dig1);
	   resto = aux2-((Math.floor(aux2/11))*11);
	   (resto < 2) ? dig2=0 : dig2=11-resto;
	   aux = dig1+" "+dig2;
	   aux = aux.substr(0,1)+aux.substr(2,1);
	   if (aux != valor.substr(valor.length-2))
      	{
         	alert('Erro no CPF, verifique!');
	      	return false;
         }
	   else
	      if ((valor == "00000000000") || (valor == "11111111111") || (valor == "22222222222") || (valor == "33333333333") || (valor == "44444444444") || (valor == "55555555555") || (valor == "66666666666") || (valor == "77777777777") || (valor == "88888888888") || (valor == "99999999999"))
	         {
	            alert('Erro no CPF, verifique!');
	            return false;
	         }
	      else
	         return true;
	}

function VERIFICA_CNPJ(valor)
	{
	   aux1 = 0;
	   aux2 = 0;
	   aux3 = 1;
	   aux4 = 0;
	   for (i=0;i<valor.length-2;i++)
	      {
	         if ((valor.substr(i,1) != "/") && (valor.substr(i,1) != "-") && (valor.substr(i,1) != "."))
	            {
	               (aux3 < 5) ? aux4 = 6-aux3 : aux4 = 14-aux3;
	               aux1 = aux1+(valor.substr(i,1)*aux4);
	               (aux3 < 6) ? aux4 = 7-aux3 : aux4 = 15-aux3;
	               aux2 = aux2+(valor.substr(i,1)*aux4);
	               aux3++;
	            }
	      }
	   resto = aux1-((Math.floor(aux1/11))*11);
	   (resto < 2) ? dig1=0 : dig1=11-resto;
	   aux2 = aux2+(2*dig1);
	   resto = aux2-((Math.floor(aux2/11))*11);
	   (resto < 2) ? dig2=0 : dig2=11-resto;
	   aux = dig1+" "+dig2;
	   aux = aux.substr(0,1)+aux.substr(2,1);
	   if (aux != valor.substr(valor.length-2))
      	{
         	alert('Erro no CNPJ, verifique!');
	      	return false;
         }
	   else
	      if ( (valor == "99999999999962") || (valor == "00000000000000") )
      	{
         	alert('Erro no CNPJ, verifique!');
	      	return false;
         }
	      else
	         return true;
	}

function POPUP(url)
	{
	   showModalDialog(url,window,"status:false;dialogWidth:650px;dialogHeight:500px");
   }

function TEXTOS(url)
	{
		window.open(url,'','toolbar=No,menubar=No,location=No,scrollbars=No,resizable=No,status=No,width=650,height=450,left=200,top=155');

   }

function MSG_ENVIAR_EMAIL(url)
	{
		showModalDialog(url,window,'status:false;dialogWidth:400px;dialogHeight:300px');
   }

function DELETA()
	{
   	if ( confirm('Deseja excluir este registro?'))
      	return true;
      else
      	return false;
   }



function Limpar(valor, validos)
   {
      // retira caracteres invalidos da string
      var result = "";
      var aux;
      for (var i=0; i < valor.length; i++)
         {
            aux = validos.indexOf(valor.substring(i, i+1));
            if (aux>=0)
               {
                  result += aux;
               }
         }
      return result;
   }

function Formata(campo,tammax,teclapres,decimal)
   {
      var tecla = teclapres.keyCode;
      vr = Limpar(campo.value,"0123456789");
      tam = vr.length;
      dec=decimal

      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 <= dec )
               { campo.value = vr ; }

            if ( (tam > dec) && (tam <= 5) )
               { campo.value = vr.substr( 0, tam - 2 ) + "." + vr.substr( tam - dec, tam ) ; }

            if ( (tam >= 6) && (tam <= 8) )
               {
                  campo.value = vr.substr( 0, tam - 5 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
               }

            if ( (tam >= 9) && (tam <= 11) )
               {
                  campo.value = vr.substr( 0, tam - 8 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
               }

            if ( (tam >= 12) && (tam <= 14) )
               {
                  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 - dec, tam ) ;
               }

            if ( (tam >= 15) && (tam <= 17) )
               {
                  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 FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.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.form[campo].value = vr ;
	 		event.srcElement.value = vr ;
		}
	 	if ( (tam > 2) && (tam <= 5) ){
	 		//document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ;
	 		event.srcElement.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ;
		}
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		//document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
	 		event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
		}
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		//document.form[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
	 		event.srcElement.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.form[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 ) ;
	 		event.srcElement.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.form[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 ) ;
	 		event.srcElement.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 ) ;
		}
	}

}