function isEmpty() 
{
    var countrySelect = document.getElementById("ddlbPais"); 
    var strCountry = countrySelect.options[countrySelect.selectedIndex].value; 

    //change "field1, field2 and field3" to your field names
    if ( (!document.forms[0].txtSenha.disabled )&& (document.forms[0].txtSenha.value == "" || document.forms[0].txtSenha.length == 0 ))
    {
        alert("Por favor preencher a Senha.");
        return false;
    }
    if ( (!document.forms[0].txtSenha.disabled ) && (document.forms[0].txtSenhaConfirma.value == "" || document.forms[0].txtSenhaConfirma.length == 0 ))
    {
        alert("Por favor preencher Confirmação de Senha.");
        return false;
    }
    if (document.forms[0].txtNome.value == "" || document.forms[0].txtNome.length == 0 )
    {
        alert("Por favor preencher a Nome Completo.");
        document.forms[0].txtNome.focus();
        return false;
    }
    if ((!document.forms[0].txtRazaoSocial.disabled )&&( document.forms[0].txtRazaoSocial.value == "" || document.forms[0].txtRazaoSocial.length == 0 ))
    {
        alert("Por favor preencher a Razão Social.");
        document.forms[0].txtRazaoSocial.focus();
        return false;
    }
    if ( document.forms[0].txtNomeCracha.value == "" || document.forms[0].txtNomeCracha.length == 0 )
    {
        alert("Por favor preencher o Nome para impressão do CRACHA.");
        document.forms[0].txtNomeCracha.focus();
        return false;
    }
    
    if ( document.forms[0].txtEmpresaCracha.value == "" || document.forms[0].txtNomeCracha.length == 0 )
    {
        
        if (document.getElementById("tipoCadastro").value == "PJ" ){
            alert("Por favor preencher a Empresa para impressão do CRACHA.");
            document.forms[0].txtEmpresaCracha.focus();
            return false;
        }
    }
    
    
     if ( document.forms[0].txtLogradouro.value == "" || document.forms[0].txtLogradouro.length == 0 )
    {
        alert("Por favor preencher o endereço.");
        document.forms[0].txtLogradouro.focus();
        return false;
    }
    
      if ( (!document.forms[0].txtNumero.disabled ) && ( document.forms[0].txtNumero.value == "" ) || (document.forms[0].txtNumero.length == 0) )
    {
        alert("Por favor preencher o número do logradouro.");
        document.forms[0].txtNumero.focus();
        return false;
    }
    
      if ( (strCountry == "BR") && (!document.forms[0].txtBairro.disabled ) && ( ( document.forms[0].txtBairro.value == "" ) || (document.forms[0].txtBairro.length == 0)) )
    {
        alert("Por favor preencher o bairro do endereço.");
        document.forms[0].txtBairro.focus();
        return false;
    }
    
       if ( (strCountry == "BR") && (document.forms[0].txtCEP.value == "") || (document.forms[0].txtCEP.value.length < 8) )
    {
        alert("Por favor preencher o CEP Corretamente.");
        document.forms[0].txtCEP.focus();
        return false;
    }
    
       if ( (strCountry == "BR") && (!document.forms[0].txtCidade.disabled ) && (( document.forms[0].txtCidade.value == "") || (document.forms[0].txtCidade.length == 0 )) )
    {
        alert("Por favor preencher a Cidade.");
        document.forms[0].txtCidade.focus();
        return false;
    }
       if ( (strCountry == "BR") && (!document.forms[0].ddlbEstado.disabled ) && ((document.forms[0].ddlbEstado.value == "") || (document.forms[0].ddlbEstado.length == 0 )) )
    {
        alert("Por favor preencher o Estado.");
        document.forms[0].ddlbEstado.focus();
        return false;
    }
    
       if ( (!document.forms[0].txtTelDDI.disabled ) && ((document.forms[0].txtTelDDI.value == "") || (document.forms[0].txtTelDDI.length == 0)) )
    {
        alert("Por favor preencher o DDI do telefone.");
         document.forms[0].txtTelDDI.focus();
        return false;
    }
       if ( document.forms[0].txtTelDDD.value == "" || document.forms[0].txtTelDDD.length == 0 )
    {
        alert("Por favor preencher o DDD do telefone.");
         document.forms[0].txtTelDDD.focus();
        return false;
    }
       if ( document.forms[0].txtTelNumero.value == "" || document.forms[0].txtTelNumero.length == 0 )
    {
        alert("Por favor preencher o número do telefone.");
        document.forms[0].txtTelNumero.focus();
        return false;
    }
    

    return true;
}
 
/*********************************************************************/
function Mascara (formato, objeto)
			{ 
				if (window.event.keyCode != 13)
				{
					campo = eval (objeto); 
					if (formato=='DDMMYYYY')
					{ 
						separador = '/'; 
						conjunto1 = 2; 
						conjunto2 = 5; 
						if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
						{ 
							if (campo.value.length == conjunto1)
							{ 
								campo.value = campo.value + separador; 
							} 
							if (campo.value.length == conjunto2)
							{ 
								campo.value = campo.value + separador; 
							} 
							}
							else
							{ 
								window.event.keyCode = 0;
							} 
						} 
					}
			} 


// Tipo de Cadastro
// ********************************************************* 
function TrocaTipoCadastro(){
    

    var frm = document.form1;
    var rbTpPessoa = frm.elements["rbTipoPessoa"];
    
    var countrySelect = document.getElementById("ddlbPais"); 
    var strCountry = countrySelect.options[countrySelect.selectedIndex].value; 
    
    for (i=0;i<rbTpPessoa.length;i++)
    {
        if (rbTpPessoa[i].checked == true)
        { 
            if (strCountry == "BR" )
	        {
                if (rbTpPessoa[i].value == "PF"){
                   document.getElementById("lbDOC").innerHTML = "CPF";
                   document.getElementById('txtDOC').setAttribute("maxlength", "14");
                   document.getElementById('txtDOC').setAttribute("size","14");
                } else {
                    document.getElementById("lbDOC").innerHTML = "CNPJ";
                   document.getElementById('txtDOC').setAttribute("maxlength", "18");
                   document.getElementById('txtDOC').setAttribute("size","18");
                }
            } else {
                document.getElementById("lbDOC").innerHTML = "Document";
                document.getElementById('txtDOC').setAttribute("maxlength", "20");
                document.getElementById('txtDOC').setAttribute("size","20");
            }
        }
        document.getElementById("txtDOC").value = "";
    }
   
}


function FormataCPFCNPJ(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	var countrySelect = document.getElementById("ddlbPais"); 
    var strCountry = countrySelect.options[countrySelect.selectedIndex].value; 
    
	if ( (tecla != 13) && (strCountry == "BR") )
	{

	    var rbTpPessoa;
	    var frm = document.form1;
	    var rbTpPessoa = frm.elements["rbTipoPessoa"];
	    

	    for (i=0;i<rbTpPessoa.length;i++)
	    {
	        if (rbTpPessoa[i].checked == true)
	        { 
	            
                if (rbTpPessoa[i].value == "PF"){
                    FormataCPF(Campo, teclapres);
                  
                    document.getElementById('txtDOC').setAttribute("maxlength", "14");
                    document.getElementById('txtDOC').setAttribute("size","14");
                } else {
                    FormataCNPJ(Campo, teclapres)
                    
                    document.getElementById('txtDOC').setAttribute("maxlength", "18");
                    document.getElementById('txtDOC').setAttribute("size","18");
                }
	        }
	    }
	} else {
	     document.getElementById('txtDOC').setAttribute("maxlength", "20");
         document.getElementById('txtDOC').setAttribute("size","20");
	}
}


function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	
	var countrySelect = document.getElementById("ddlbPais"); 
    var strCountry = countrySelect.options[countrySelect.selectedIndex].value; 
  
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	if (strCountry == "BR" && tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}


function FormataCPF(Campo, teclapres){
	
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1;
	
	
	 	if (tecla != 9 && tecla != 8){
			if (tam > 3 && tam < 7)
				Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
			if (tam >= 7 && tam <10)
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + 			vr.substr(9,tam-9);
		}
}



// Validação do CPF / CNPJ
// ********************************************************* 



function checkcpfcnpj(source, arguments)
{ 
    var frm = document.form1;
    var rbTpPessoa = frm.elements["rbTipoPessoa"];
    var countrySelect = document.getElementById("ddlbPais"); 
    var strCountry = countrySelect.options[countrySelect.selectedIndex].value; 
    
    if ( strCountry != "BR" ){
        arguments.IsValid=true;
    } else {
    
        for (i=0;i<rbTpPessoa.length;i++)
        {
            if (rbTpPessoa[i].checked == true)
            { 
                if (rbTpPessoa[i].value == "PF")
                {
                    if(VerificarCPF(arguments.Value) == 1) 
                    {
                        arguments.IsValid=true;
                    }else{
                        arguments.IsValid=false;
                        alert('Documento Invalido');
                    }
                    
                } else {
                    if(VerificaCNPJ(arguments.Value) == 1) 
				    {
				        arguments.IsValid=true;
				    } else{ 
				        arguments.IsValid=false;
				        arguments.value = "";
				        alert('Documento Invalido');
                    }
                }
            }
        }
    }
	/*    if(VerificarCPF(arguments.Value) == 1) 
			{
			arguments.IsValid=true;
			}
		else 
			{
			if(VerificaCNPJ(arguments.Value) == 1) 
				{
				arguments.IsValid=true;
				}
			else
				{ 
				arguments.IsValid=false;
				arguments.value = "";
				alert('Documento Invalido');
				
				}
			}
			*/
 } 
/////////////////////////////////////////////////////////////////
function checkcnpjMSG(source, arguments)
{ 
    var countrySelect = document.getElementById("ddlbPais"); 
    var strCountry = countrySelect.options[countrySelect.selectedIndex].value; 
  
    if (strCountry == 'BR')
    {
        if(VerificaCNPJ(arguments.Value) == 1) 
        {
            arguments.IsValid=true;
        } else{ 
            arguments.IsValid=false;
            alert('Documento Invalido');
            document.getElementById('txtEmpresaCNPJ').value="";
        }
    }
    
}


/////////////////////////////////////////////////////////////////
function checkcnpj(source, arguments)
	{ 
		if(VerificaCNPJ(arguments.Value) == 1) 
			arguments.IsValid=true;
		else 
			arguments.IsValid=false;
	} 
/////////////////////////////////////////////////////////////////
function checkcpf(source, arguments)
	{ 
		if(VerificarCPF(arguments.Value) == 1) 
			arguments.IsValid=true;
		else 
			arguments.IsValid=false;
	} 

/////////////////////////////////////////////////////////////////
function isNUMB(c) 
 { 
 if((cx=c.indexOf(","))!=-1) 
  { 
  c = c.substring(0,cx)+"."+c.substring(cx+1); 
  } 
 if((parseFloat(c) / c != 1)) 
  { 
  if(parseFloat(c) * c == 0) 
   { 
   return(1); 
   } 
  else 
   { 
   return(0); 
   } 
  } 
 else 
  { 
  return(1); 
  } 
 } 
/////////////////////////////////////////////////////////////////
function LIMP(c) 
 { 
 while((cx=c.indexOf("-"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("/"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(","))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("."))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("("))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(")"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(" "))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 return(c); 
 } 
/////////////////////////////////////////////////////////////////
function VerificaCNPJ(CNPJ) 
 { 
 CNPJ = LIMP(CNPJ); 
 if(isNUMB(CNPJ) != 1) 
  { 
  return(0); 
  } 
 else 
  { 
  if(CNPJ == 0) 
   { 
   return(0); 
   } 
  else 
   { 
   g=CNPJ.length-2; 
   if(RealTestaCNPJ(CNPJ,g) == 1) 
    { 
    g=CNPJ.length-1; 
    if(RealTestaCNPJ(CNPJ,g) == 1) 
     { 
     return(1); 
     } 
    else 
     { 
     return(0); 
     } 
    } 
   else 
    { 
    return(0); 
    } 
   } 
  } 
 } 
/////////////////////////////////////////////////////////////////
function RealTestaCNPJ(CNPJ,g) 
 { 
 var VerCNPJ=0; 
 var ind=2; 
 var tam; 
 for(f=g;f>0;f--) 
  { 
  VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind; 
  if(ind>8) 
   { 
   ind=2; 
   } 
  else 
   { 
   ind++; 
   } 
  } 
  VerCNPJ%=11; 
  if(VerCNPJ==0 || VerCNPJ==1) 
   { 
   VerCNPJ=0; 
   } 
  else 
   { 
   VerCNPJ=11-VerCNPJ; 
   } 
 if(VerCNPJ!=parseInt(CNPJ.charAt(g))) 
  { 
  return(0); 
  } 
 else 
  { 
  return(1); 
  } 
 } 
/////////////////////////////////////////////////////////////////
function VerificarCPF(CPF) {
	CPF = LIMP(CPF);
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		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)))
		return 0;
	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)))
		return false;
	return 1;
 }
  
////////////////////////////////////////////////////////////////////////// 
 function habilita(source, arguments)
	{ 
		if(arguments.value.length == '0')
			document.forms[0].txt_codigo.value = 1;
		else
			document.forms[0].txt_codigo.value = 0;
	} 			

////////////////////////////////////////////////////////////////////////// 
function FormataTel(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace("(", "");
	vr = vr.replace(")", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 1 && tam < 3)
			Campo.value = vr.substr(0, 0) + '(' + vr.substr(0, tam);
		if (tam >= 3 && tam < 5)
			Campo.value = vr.substr(0, 0) + '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-2);
		if (tam >= 5 && tam < 9)
			Campo.value = vr.substr(0, 0) + '(' + vr.substr(0,2) + ')' + vr.substr(2,7) + '-' + vr.substr(9,tam-9);
		
		}
}

//////////////////////////////////////////////////////////////////////////
function FormataCep(objeto){
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){ objeto.value = ""; }
	if (objeto.value.length == 5){
		objeto.value += "-";
	}
}

//////////////////////////////////////////////////////////////////////////

function FormataIE(objeto) { //Abre a função
	var c = objeto.value.length; /*Cria a variavel que verifica a quantidade de caractes 	digitados no primeiro formulariio da pagina que tenha um campo que se chama isdsc */
	if(c == 3){ /* Verifica se o que foi digitado no campo é igual a 3, se for igual.. */
	objeto.value += "."; /*Adiciona na frente do que estiver ja digitado um ponto */
	} //Fecha a verificação
	if(c == 7){ /* Verifica novamente se o valor a quantidade digitada no campo é igual a 7, se for igua.. */
	objeto.value += "."; /*Adiciona na frente do que estiver ja digitado um ponto */
	} //Fecha a verificação
	if(c == 11){ /* Verifica novamente se o valor a quantidade digitada no campo é igual a 7, se for igua.. */
	objeto.value += "."; /*Adiciona na frente do que estiver ja digitado um ponto */
	} 
} //Fecha a função

//////////////////////////////////////////////////////////////////////////

function FormataIM(objeto) { //Abre a função
	var c = objeto.value.length; /*Cria a variavel que verifica a quantidade de caractes 	digitados no primeiro formulariio da pagina que tenha um campo que se chama isdsc */
	if(c == 6){ /* Verifica se o que foi digitado no campo é igual a 3, se for igual.. */
	objeto.value += "/"; /*Adiciona na frente do que estiver ja digitado um ponto */
	} //Fecha a verificação
	if(c == 10){ /* Verifica novamente se o valor a quantidade digitada no campo é igual a 7, se for igua.. */
	objeto.value += "."; /*Adiciona na frente do que estiver ja digitado um ponto */
	} //Fecha a verificação
} //Fecha a função


//////////////////////////////////////////////////////////////////////////

function filtrarNumeros(Objeto) {
	x=window.event.keyCode;
	if (x!=13)
	{
		if (!(x>=48 && x<=57))
	        { 
        	   window.event.keyCode=0; 
	        }
	}
}


//////////////////////////////////////////////////////////////////////////

function SemEspacos(Objeto) {
	x=window.event.keyCode;
	if (x==32)
        { 
           window.event.keyCode=0; 
        }
}


//////////////////////////////////////////////////////////////////////////

function MascaraValor(fld, e) 
			{ 
			var milSep = ""; 
			var decSep = ","; 
			var sep = 0; 
			var key = ''; 
			var i = j = 0; 
			var len = len2 = 0; 
			var strCheck = '-0123456789'; 
			var aux = aux2 = ''; 
			var whichCode = (window.Event) ? e.which : e.keyCode; 

			if (whichCode == 13) 
			return true; 

			key = String.fromCharCode(whichCode); 

			if (strCheck.indexOf(key) == -1) 
			return false; 

			len = fld.value.length; 

			for (i = 0; i < len; i++) 
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) 
			break; 

			aux = ''; 

			for (; i < len; i++) 
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
			aux += fld.value.charAt(i); 

			aux += key; 
			len = aux.length; 

			if (len == 0) 
			fld.value = ''; 

			if (len == 1) 
			fld.value = '0'+ decSep + '0' + aux; 

			if (len == 2) 
			fld.value = '0'+ decSep + aux; 

			if (len > 2){ 
			aux2 = ''; 

			for (j = 0, i = len - 3; i >= 0; i--){ 
			if (j == 3){ 
			aux2 += milSep; 
			j = 0; 
			} 
			aux2 += aux.charAt(i); 
			j++; 
			} 

			fld.value = ''; 
			len2 = aux2.length; 

			for (i = len2 - 1; i >= 0; i--) 
			fld.value += aux2.charAt(i); 
			fld.value += decSep + aux.substr(len - 2, len); 
			} 

			return false; 
			}

/////////////////////////////////////////////////////////////////////////////////////////////////////////// -+

function FormataValor(objeto,teclapres,tammax,decimais){
var tecla = teclapres.keyCode;
var tamanhoObjeto = objeto.value.length;
if((tecla == 8)&&(tamanhoObjeto == tammax)){
tamanhoObjeto = tamanhoObjeto - 1 ;
}
if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || 
tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
{
vr = objeto.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 > 1)){
tam = tam - 1 ;
vr = objeto.value;
vr = vr.replace( "/", "" );
vr = vr.replace( "/", "" );
vr = vr.replace( ",", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
}
//Cálculo para casas decimais setadas por parametro
if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 
&& tecla <= 105 ){
if (decimais > 0){
if ( (tam <= decimais) ){
objeto.value = ("0," + vr) ;
}
if( (tam == (decimais + 1)) && (tecla == 
8)){
objeto.value = vr.substr( 0, (tam - 
decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;
}
if ( (tam > (decimais + 1)) && (tam <= 
(decimais + 3)) && ((vr.substr(0,1)) == "0")){
objeto.value = vr.substr( 1, (tam - 
(decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
}
if ( (tam > (decimais + 1)) && (tam <= 
(decimais + 3)) && ((vr.substr(0,1)) != "0")){
objeto.value = vr.substr( 0, tam - 
decimais ) + ',' + vr.substr( tam - decimais, tam ) ;
}
if ( (tam >= (decimais + 4)) && (tam <= 
(decimais + 6)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + 
vr.substr( tam - decimais, tam ) ;
}
if ( (tam >= (decimais + 7)) && (tam <= 
(decimais + 9)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + 
vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, 
tam ) ;
}
if ( (tam >= (decimais + 10)) && (tam <= 
(decimais + 12)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + 
vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 
3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
}
if ( (tam >= (decimais + 13)) && (tam <= 
(decimais + 15)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + 
vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 
6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( 
tam - decimais, tam ) ;
}
}else if(decimais == 0){
if ( tam <= 3 ){
objeto.value = vr ;
}
if ( (tam >= 4) && (tam <= 6) ){
if(tecla == 8)
{
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr(0, tam - 3) 
+ '.' + vr.substr( tam - 3, 3 );
}
if ( (tam >= 7) && (tam <= 9) ){
if(tecla == 8)
{
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr( 0, tam - 
6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 );
}
if ( (tam >= 10) && (tam <= 12) ){
if(tecla == 8)
{
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr( 0, tam - 
9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + 
vr.substr( tam - 3, 3 );
}
if ( (tam >= 13) && (tam <= 15) ){
if(tecla == 8){
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr( 0, tam - 
12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' 
+ vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
}
}
}
}else if((window.event.keyCode != 8) && (window.event.keyCode != 9) 
&& (window.event.keyCode != 13) && (window.event.keyCode != 35) && 
(window.event.keyCode != 36) && (window.event.keyCode != 46)){
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////// -+

function FormataValor2(objeto,teclapres,tammax,decimais){
var tecla = teclapres.keyCode;
var tamanhoObjeto = objeto.value.length;

if((tecla == 8)&&(tamanhoObjeto == tammax)){
tamanhoObjeto = tamanhoObjeto - 1 ;
}
if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla == 45 || tecla == 43 ||
tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax)){
vr = objeto.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 > 1)){
tam = tam - 1 ;
vr = objeto.value;
vr = vr.replace( "/", "" );
vr = vr.replace( "/", "" );
vr = vr.replace( ",", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
}
//Cálculo para casas decimais setadas por parametro
if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 
&& tecla <= 105 ){
if (decimais > 0){
if ( (tam <= decimais) ){
objeto.value = ("0," + vr) ;
}
if( (tam == (decimais + 1)) && (tecla == 
8)){
objeto.value = vr.substr( 0, (tam - 
decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;
}
if ( (tam > (decimais + 1)) && (tam <= 
(decimais + 3)) && ((vr.substr(0,1)) == "0")){
objeto.value = vr.substr( 1, (tam - 
(decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
}
if ( (tam > (decimais + 1)) && (tam <= 
(decimais + 3)) && ((vr.substr(0,1)) != "0")){
objeto.value = vr.substr( 0, tam - 
decimais ) + ',' + vr.substr( tam - decimais, tam ) ;
}
if ( (tam >= (decimais + 4)) && (tam <= 
(decimais + 6)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + 
vr.substr( tam - decimais, tam ) ;
}
if ( (tam >= (decimais + 7)) && (tam <= 
(decimais + 9)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + 
vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, 
tam ) ;
}
if ( (tam >= (decimais + 10)) && (tam <= 
(decimais + 12)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + 
vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 
3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
}
if ( (tam >= (decimais + 13)) && (tam <= 
(decimais + 15)) ){
objeto.value = vr.substr( 0, tam - 
(decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + 
vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 
6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( 
tam - decimais, tam ) ;
}
}else if(decimais == 0){
if ( tam <= 3 ){
objeto.value = vr ;
}
if ( (tam >= 4) && (tam <= 6) ){
if(tecla == 8)
{
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr(0, tam - 3) 
+ '.' + vr.substr( tam - 3, 3 );
}
if ( (tam >= 7) && (tam <= 9) ){
if(tecla == 8)
{
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr( 0, tam - 
6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 );
}
if ( (tam >= 10) && (tam <= 12) ){
if(tecla == 8)
{
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr( 0, tam - 
9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + 
vr.substr( tam - 3, 3 );
}
if ( (tam >= 13) && (tam <= 15) ){
if(tecla == 8){
objeto.value = vr.substr(0, 
tam);
window.event.cancelBubble = 
true;
window.event.returnValue = 
false;
}
objeto.value = vr.substr( 0, tam - 
12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' 
+ vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
}
}
}
}else if((window.event.keyCode != 8) && (window.event.keyCode != 9) 
&& (window.event.keyCode != 13) && (window.event.keyCode != 35) && 
(window.event.keyCode != 36) && (window.event.keyCode != 46)){
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function isDate(strData)
{
  var dia, mes, ano;
  if(strData.length < 10) 
    return false;
  
  mes = strData.substr(3,2);
  if(mes > "12" || mes == "00")
    return false;
  
  dia = strData.substr(0,2);
  if(dia=="00") 
    return false;
  
  ano = strData.substr(6,4);
  if (ano < "0200") 
    return false;
  
  if (mes=="01"||mes=="03"||mes=="05"||mes=="07"||mes=="08"||mes=="10"||mes=="12")
  {
    if (dia > "31")
      return false;
  }

  if(mes=="04"||mes=="06"||mes=="09"||mes=="11")
  {
    if (dia > "30")
      return false;
  }
  
  if(mes=="02")
  {
    if((parseInt(ano) % 4) ==0)
    {
      if (dia > "29")
        return false;
    }
    else
    if (dia > "28") 
      return false;
  }
  return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function CriticaData(source, arguments)
{
  if (arguments.Value == "" || arguments.Value == "Indefinido")
  {
    arguments.IsValid=true;
  }
  else
  {
    var resultado = isDate(arguments.Value);
    if (resultado == false)
    {
      arguments.IsValid=false;
      alert('Data Invalida!');
    }
    else
    {
      arguments.IsValid=true; 
    }
  }
}

//mascara para validar email. //onblur="return validaEmail(this,'#{msg['MN063']}');"
function validaEmail(source,arguments) {
 	var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if(!reEmail3.test(arguments.Value)) {
		alert('e-Mail Invalido!');
		arguments.IsValid=false;
	}
	arguments.IsValid=true;
}

//mascara para validar email. //onblur="return validaEmail(this,'#{msg['MN063']}');"
function validaVazio(source,arguments) {
	if(arguments.Value == "") {
		alert('Campo Obrigatório');
		arguments.IsValid=false;
	}
	arguments.IsValid=true;
}

//valida opção outros do DropDownListBox - 
function abilitaDigitarOutros(objDDLB, campoOutros){
    var campo = campo = eval (campoOutros);
    if (objDDLB.value == "Outros"){
        campo.disabled = false;
    } else {
        campo.disabled = true;
        campo.value = "";
    }
}

function avisoAguarde()
{
    if(document.getElementById('divProcessando'))
    {
        document.getElementById('divProcessando').style.display='';
        return;
    }
    oDiv = document.createElement("div");
    with (oDiv)
    {
	    id = "divProcessando";
	}
	document.body.appendChild(oDiv);
}

function ConfirmaExclusao(){
        return confirm('Deseja excluir este registro?');
}

function isEmptyEvento() 
{

    if (document.forms[0].txtCodigo_Evento.value == "" || document.forms[0].txtCodigo_Evento.length == 0 )
    {
        alert("Por favor preencher o código do evento.");
        
        return false;
    }
    
    if (document.forms[0].txtNome_Evento.value == "" || document.forms[0].txtNome_Evento.length == 0 )
    {
        alert("Por favor preencher o nome do evento.");
        
        return false;
    }
    
     if (document.forms[0].txtData_Vigencia.value == "" || document.forms[0].txtData_Vigencia.length == 0 )
    {
        alert("Por favor preencher a data de vigencia.");
        
        return false;
    }
}

function isEmptyQuestionario() 
{

    if (document.forms[0].txtCodigoQuestionario.value == "" || document.forms[0].txtCodigoQuestionario.length == 0 )
    {
        alert("Por favor preencher o código do questionario.");
        
        return false;
    }
    
    if (document.forms[0].txtNomeQuestionario.value == "" || document.forms[0].txtNomeQuestionario.length == 0 )
    {
        alert("Por favor preencher o nome do questionario.");
        
        return false;
    }
}

function isEmptyPergunta() 
{

    if (document.forms[0].txtCodigoPergunta.value == "" || document.forms[0].txtCodigoPergunta.length == 0 )
    {
        alert("Por favor preencher o código da pergunta.");
        
        return false;
    }
    
    if (document.forms[0].txtPergunta.value == "" || document.forms[0].txtPergunta.length == 0 )
    {
        alert("Por favor preencher a pergunta.");
        
        return false;
    }
}

function isEmptyResposta() 
{

    if (document.forms[0].txtCodigoResposta.value == "" || document.forms[0].txtCodigoResposta.length == 0 )
    {
        alert("Por favor preencher o código da resposta.");
        
        return false;
    }
    
    if (document.forms[0].txtResposta.value == "" || document.forms[0].txtResposta.length == 0 )
    {
        alert("Por favor preencher a resposta.");
        
        return false;
    }
}

