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=Yes,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)
{
   cpf1 = valor.substr(0,3);
   cpf2 = valor.substr(4,3);
   cpf3 = valor.substr(8,3);
   cpf4 = valor.substr(12,2);
   valor = cpf1+cpf2+cpf3+cpf4;

   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)
{
	var cnpj = valor;
  	var i = 0;
   var l = 0;
   var strNum = "";
   var strMul = "6543298765432";
   var character = "";
   var iValido = 1;
   var iSoma = 0;
   var strNum_base = "";
   var iLenNum_base = 0;
   var iLenMul = 0;
   var iSoma = 0;
   var strNum_base = 0;
   var iLenNum_base = 0;

  	if (cnpj == "")
   	{
      	alert("Preencha o campo CNPJ!");
        	return false;
      }

  	l = cnpj.length;
   for (i = 0; i < l; i++)
   	{
   		caracter = cnpj.substring(i,i+1)
      	if ((caracter >= '0') && (caracter <= '9'))
         	strNum = strNum + caracter;
  		}

  	if(strNum.length != 14)
   	{
        	alert("CNPJ inválido!");
        	return false;
      }

   strNum_base = strNum.substring(0,12);
   iLenNum_base = strNum_base.length - 1;
   iLenMul = strMul.length - 1;
   for(i = 0;i < 12; i++)
   	iSoma = iSoma + parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) * parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);

   iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
   if(iSoma == 11 || iSoma == 10)
   	iSoma = 0;

   strNum_base = strNum_base + iSoma;
   iSoma = 0;
   iLenNum_base = strNum_base.length - 1
  	for(i = 0; i < 13; i++)
   	iSoma = iSoma + parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) * parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)

   iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
   if(iSoma == 11 || iSoma == 10)
   	iSoma = 0;

   strNum_base = strNum_base + iSoma;

   if(strNum != strNum_base)
   	{
        	alert("CNPJ inválido!");
        	return false;
      }
  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 MascaraVALOR (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 ) ;
		}
	}
}

function MascaraCPF (formato, objeto)
{
	campo = eval (objeto);
	if (formato=='CPF')
		{
			caracteres = '01234567890';
	      separacao1 = '.';
	      separacao2 = '-';
	      conjuntos = 4;
	      conjunto1 = 3;
	      conjunto2 = 7;
	      conjunto3 = 11;
	      conjunto4 = 14;
	      if ( (caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < (conjunto4) )
	         {
	            if (campo.value.length == conjunto1)
	               campo.value = campo.value + separacao1;
	            else if (campo.value.length == conjunto2)
	               campo.value = campo.value + separacao1;
	            else if (campo.value.length == conjunto3)
	               campo.value = campo.value + separacao2;
	         }
	      else
		      event.returnValue = false;
		}
}

function MascaraCNPJ (formato, objeto)
{
	campo = eval (objeto);
	if (formato=='CNPJ')
		{
			caracteres = '01234567890';
	      separacao1 = '.';
	      separacao2 = '.';
	      separacao3 = '/';
	      separacao4 = '-';
	      conjunto1 = 2;
	      conjunto2 = 6;
	      conjunto3 = 10;
	      conjunto4 = 15;
	      conjunto5 = 18;
	      if ( (caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < (conjunto5) )
	         {
	            if (campo.value.length == conjunto1)
	               campo.value = campo.value + separacao1;
	            else if (campo.value.length == conjunto2)
	               campo.value = campo.value + separacao1;
	            else if (campo.value.length == conjunto3)
	               campo.value = campo.value + separacao3;
	            else if (campo.value.length == conjunto4)
	               campo.value = campo.value + separacao4;
	         }
	      else
		      event.returnValue = false;
		}
}

function MascaraDATA (formato, objeto)
{
	campo = eval (objeto);
	if (formato=='DATA')
		{
			caracteres = '01234567890';
	      separacao1 = '/';
	      separacao2 = '-';
	      conjunto1 = 2;
	      conjunto2 = 5;
	      conjunto3 = 8;
	      conjunto4 = 10;
	      if ( (caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < (conjunto4) )
	         {
	            if (campo.value.length == conjunto1)
	               campo.value = campo.value + separacao1;
	            else if (campo.value.length == conjunto2)
	               campo.value = campo.value + separacao1;
	         }
	      else
		      event.returnValue = false;
		}
}

function MascaraFONE (formato, objeto)
{
	campo = eval (objeto);
	if (formato=='FONE')
		{
			caracteres = '01234567890';
	      separacao1 = '(';
	      separacao2 = ') ';
	      separacao3 = '';
	      separacao4 = '-';
	      conjunto1 = 0;
	      conjunto2 = 3;
	      conjunto3 = 4;
	      conjunto4 = 9;
	      conjunto5 = 14;
	      if ( (caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < (conjunto5) )
	         {
	            if (campo.value.length == conjunto1)
	               campo.value = separacao1 + campo.value;
	            else if (campo.value.length == conjunto2)
	               campo.value = campo.value + separacao2;
	            else if (campo.value.length == conjunto3)
	               campo.value = campo.value + separacao3;
	            else if (campo.value.length == conjunto4)
	               campo.value = campo.value + separacao4;
	         }
	      else
		      event.returnValue = false;
		}
}