
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function valida_mail(valor) {
	prim = valor.indexOf("@")
	if(prim < 1) return false;
	if(valor.indexOf("@",prim + 1) != -1) return false;
	if(valor.indexOf(".") < 1) return false;
	if(valor.indexOf("zipmeil.com") > 0) return false;
	if(valor.indexOf("hotmeil.com") > 0) return false;
	if(valor.indexOf(".@") > 0) return false;
	if(valor.indexOf("@.") > 0) return false;
	if(valor.indexOf(".com.br.") > 0) return false;
	if(valor.indexOf("/") > 0) return false;
	if(valor.indexOf("[") > 0) return false;
	if(valor.indexOf("]") > 0) return false;
	if(valor.indexOf("(") > 0) return false;
	if(valor.indexOf(")") > 0) return false;
	if(valor.indexOf("..") > 0) return false;
	if(valor.indexOf(",") > 0) return false;
	parte1 = valor.indexOf("@");
	parte3 = valor.length;
	if (!(parte1 >= 1 && parte3 >= 6)) return false;
	return true;

}

function LimitaTamanho( campo , total ) {
    var texto = campo.value;
 
 	if ( texto.length > total ) {
		campo.value = campo.value.substring(0, total);
		alert ("Por favor, o texto não pode conter mais de "+total+" caracteres");
	}
}

function FormataData(campo, evento) {
	var posNumeros = "01346789";
	var posEspacos = "25";
	var strNumeros = '0123456789';	
	
	var keyCode = (isNN) ? evento.which : evento.keyCode;
	
	if (keyCode >= 48 && keyCode <= 57){
		for (i = 0; i < campo.value.length; i++)
			if ((posNumeros.indexOf(i) != -1) && (strNumeros.indexOf(campo.value.substr(i, 1)) == -1)) {
				campo.value = campo.value.substr(0, i);
				return false;
			} else if ((posEspacos.indexOf(i) != -1) && (campo.value.substr(i, 1) != '/')) {
				campo.value = campo.value.substr(0, i);
				return false;
		}

		if (campo.value.length > 10)
			campo.value = campo.value.substr(0, 10);

		if ((campo.value.length == 2) || (campo.value.length == 5))
			campo.value = campo.value + "/";
	}
	else
		if ( keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
}

function validaData(valor) {
	if (valor.length == 0)
		return true;
	else if (valor.length != 10)
		return false;

	var dia = valor.substr(0, 2);
	var mes = valor.substr(3, 2);
	var ano = valor.substr(6, 4);

	if (!validaInteiro(dia)) return false;
	if (!validaInteiro(mes)) return false;
	if (!validaInteiro(ano)) return false;

	if (mes > 12 || mes < 1) return false;
	if (dia < 1) return false;
	if (ano < 1) return false;
	if ((mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12) && dia > 31) return false;
	if ((mes == 4 || mes == 6 || mes == 9 || mes == 11) && dia > 30) return false;
	if (mes == 2 && ano % 4 && dia > 29) return false;
	if (mes == 2 && !(ano % 4) != 0 && dia > 28) return false;
	return true;
}

/*
function FormataInteiro(campo, event) {
	var strNumeros = '0123456789';

	for (i = 0; i < campo.value.length; i++)
		if ((strNumeros.indexOf(campo.value.substr(i, 1)) == -1) && !((i == 0) && (campo.value.substr(i, 1) == '-'))) {
			campo.value = campo.value.substr(0, i);
			return false;
		}
}
*/
function validaInteiro(valor) {
	var strNumeros = '0123456789';

	for (i = 0; i < valor.length; i++)
		if ((strNumeros.indexOf(valor.substr(i, 1)) == -1) && !((i == 0) && (valor.substr(i, 1) == '-')))
				return false;
	return true;
}

function validaDinheiro(valor) {
	var strNumeros = '0123456789,';

	for (i = 0; i < valor.length; i++)
		if ((strNumeros.indexOf(valor.substr(i, 1)) == -1) && !((i == 0) && (valor.substr(i, 1) == '-')))
				return false;
	return true;
}

function valida_cep( CEP ) {
	if ( CEP.length != 8 ) return true;
	for ( var i = 0; i < CEP.length ; i++ ) {
		if ( CEP.substring(i, i+1) < '0' || CEP.substring(i, i+1) > '9'  ) return true;
	}
	return false;
}

function troca_virgula( num ) {
	var aux = "";
    for ( var i = 0; i < num.length ; i++ ) {
    	if ( num.substring(i, i+1) == "," )
			aux += '.';
		else if ( num.substring(i, i+1) != "." )
			aux += num.substring(i, i+1);
    }
    return aux;
}

function troca_ponto( num ) {
	var aux = "";
    for ( var i = 0; i < num.length ; i++ ) {
    	if ( num.substring(i, i+1) == "." )
			aux += ",";
		else
			aux += num.substring(i, i+1);
    }
    return aux;
}

function CGC_OK(Numero_CGC) 
{
  var Parcela;
  var Quociente;
  var Resto;
  var Soma;
  var Fator;
  var I;
  var C1;
  var C2;
  var dv1;
  var dv2;
    
  //Verificação dos dois digitos finais em relação ao número completo
  C1 = parseInt(Numero_CGC.substring(12, 13));  //13º caracter = primeiro dígito verificador
  C2 = parseInt(Numero_CGC.substring(13, 14));  //14º caracter = segundo dígito verificador
    
  //Verificação do primeiro dígito (C1)
  Soma = 0;
  Parcela = 0;
  Fator = 0;
	
  for(I=1; I<=12; I++)
  {
    if(I < 9)
    {
      Fator = I + 1;
	}
	else
	{
      Fator = I - 7;
    }

    Parcela = Fator * parseInt(Numero_CGC.substring(12 - I, 12 - I + 1));
    Soma = Soma + Parcela;
  } //fechando o "for".
    
  dv1 = (Soma % 11); 
  dv1 = 11 - dv1;

  if(dv1 > 9)
  {
    dv1 = 0;
  }
    
  if(C1 != dv1)
  {
    return false;
  }
    
  //Verificação do segundo dígito (C2)
  Soma = 0;
  Parcela = 0;
  Fator = 0;

  for(I=1; I<=13; I++)
  {
     if(I < 9)
     {
        Fator = I + 1;
     }	  
     else
     {
       Fator = I - 7;
     }	  
     Parcela = Fator * parseInt(Numero_CGC.substring(13 - I, 13 - I + 1));
     Soma = Soma + Parcela;
  }
	 
  dv2 = (Soma % 11);
  dv2 = 11 - dv2;
  
  if(dv2 > 9)
  {
    dv2 = 0;
  }

  if(C2 != dv2)
  {
    return false;
  }
return true;
}

function CPF_OK(Numero_CPF) 
{
  var Parcela;
  var Quociente;
  var Resto;
  var Soma;
  var Fator;
  var I;
  var C1;
  var C2;
  var dv1;
  var dv2;
    
  //Verificação dos dois digitos finais em relação ao número completo
  C1 = parseInt(Numero_CPF.substring(9, 10));  //10º caracter = primeiro dígito verificador
  C2 = parseInt(Numero_CPF.substring(10, 11)); //11º caracter = segundo dígito verificador
    
  //Verificação do primeiro dígito (C1)
  Soma = 0;
  Parcela = 0;
  Fator = 0;
	
  for(I=1; I<=9; I++)
  {
    Fator = I + 1;

    Parcela = Fator * parseInt(Numero_CPF.substring(9 - I, 9 - I + 1));
    Soma = Soma + Parcela;
  } //fechando o "for".
    
  dv1 = (Soma % 11); 
  dv1 = 11 - dv1;

  if(dv1 >9 )
  {
    dv1 = 0;
  }
    
  if(C1 != dv1)
  {
    return false;
  }
    
  //Verificação do segundo dígito (C2)
  Soma = 0;
  Parcela = 0;
  Fator = 0;

  for(I=1; I<=10; I++)
  {
    Fator = I + 1;
  
    Parcela = Fator * parseInt(Numero_CPF.substring(10 - I, 10 - I + 1));
    Soma = Soma + Parcela;
  }
	 
  dv2 = (Soma % 11);
  dv2 = 11 - dv2;
  
  if(dv2 > 9)
  {
    dv2 = 0;
  }

  if(C2 != dv2)
  {
    return false;
  }
return true;
}


function valida_cnpj(elemento) {

AuxCPFCGC = elemento.value;
var checkOK = "0123456789";

 if (elemento.value == "" || elemento.value == null || AuxCPFCGC.length != 14 )
  {
    alert("CNPJ deve conter 14 dígitos!");
    elemento.focus();
    return(false);
  }

  for (i = 1; i <= AuxCPFCGC.length ; i++) 
  {
    if (AuxCPFCGC.substring(i-1,i) == " ")
    {
      elemento.focus();	  
      alert("O campo CNPJ não pode conter espaços!");
      return(false);
    }
  }

var checkStr = AuxCPFCGC;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("O CNPJ deve conter apenas números.");
    elemento.focus();
    return(false);
  }
 
    if (!CGC_OK(AuxCPFCGC))
    {
      elemento.focus();
      alert("Número de CNPJ testado e entendido como inválido!");
      return(false);
    }
return(true);

}


function valida_cpf(elemento) {

AuxCPFCGC = elemento.value;
var checkOK = "0123456789";

 if (elemento.value == "" || elemento.value == null || AuxCPFCGC.length != 11 )
  {
    alert("CPF deve conter 11 dígitos!");
    elemento.focus();
    return(false);
  }

  for (i = 1; i <= AuxCPFCGC.length ; i++) 
  {
    if (AuxCPFCGC.substring(i-1,i) == " ")
    {
      elemento.focus();	  
      alert("O campo CPF não pode conter espaços!");
      return(false);
    }
  }

var checkStr = AuxCPFCGC;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("O CPF deve conter apenas números.");
    elemento.focus();
    return(false);
  }
 
    if (!CPF_OK(AuxCPFCGC))
    {
      elemento.focus();
      alert("Número de CPF testado e entendido como inválido!");
      return(false);
    }
return(true);

}

function valida_checkbox_radio(campo) {
	if ( campo.length == 1 ) {
		if (campo.checked == true) 
			return true;
	}
	else{	
		for (var i = 0 ; i < campo.length ; i++) {
			if (campo[i].checked == true) 
				return true;
		}
	}
	return false;
}

function valida_cep_tracao( CEP ) {
	if ( CEP.length != 8 ) return true;
	for ( var i = 0; i < CEP.length ; i++ ) {
		if ( CEP.substring(i, i+1) < '0' || CEP.substring(i, i+1) > '9'  ) return true;
	}
	return false;
}

function conta_caracteres( valor , valor2 , total , nome ) {
    var text1 = valor.value;

	valor2.value = text1.length;
 
 	if ( text1.length > total ) {
		 var aux =  valor.value;
		 valor.value = aux.substring(0, total);
		 text1 = valor.value;
		 valor2.value = text1.length;
		alert ("Por favor, o campo '"+nome+"', não deve ter mais de "+total+" caracteres");
	}
}

function conta_caracteres_faltam( valor , valor2 , total , nome ) {
    var text1 = valor.value;

	valor2.value = total - text1.length;
 
 	if ( text1.length > total ) {
		 var aux =  valor.value;
		 valor.value = aux.substring(0, total);
		 text1 = valor.value;
		 valor2.value = total - text1.length;
		alert ("Por favor, o campo '"+nome+"', não deve ter mais de "+total+" caracteres");
	}
}

function valida_cep_tracao (valor) {

	if ( valor.length != 9 ) return true;
	if ( valor.indexOf("-" )!= 5 ) return true;
	for ( var i = 0; i < valor.length ; i++ ) {
		if ( valor.substring(i, i+1) >= '0' && valor.substring(i, i+1) <= '9'  ) {		
			if ( i == 5 ) return true;
		}
		else { 
			if ( i != 5 )  return true;
		}
	}
	return false;
}

function formata_cep (campo, event)  {
	var posNumeros = "01234678";
	var posEspacos = "5";
	var strNumeros = '0123456789';

	if ((event.keyCode == 8) || (event.keyCode == 46))
		return false;

	for (i = 0; i < campo.value.length; i++)
		if ((posNumeros.indexOf(i) != -1) && (strNumeros.indexOf(campo.value.substr(i, 1)) == -1)) {
			campo.value = campo.value.substr(0, i);
			return false;
		} else if ((posEspacos.indexOf(i) != -1) && (campo.value.substr(i, 1) != '-')) {
			campo.value = campo.value.substr(0, i);
			return false;
	}

	if (campo.value.length > 9)
		campo.value = campo.value.substr(0, 9);

	if (campo.value.length == 5)
		campo.value = campo.value + "-";
}
/*
function FormataFloat(campo, event) {
	var strNumeros = '0123456789';
	var flgVirgula = false;

	for (i = 0; i < campo.value.length; i++)
		if ((strNumeros.indexOf(campo.value.substr(i, 1)) == -1) && !((i == 0) && (campo.value.substr(i, 1) == '-'))) {
			if ((i > 0) && (campo.value.substr(i, 1) == ',') && !flgVirgula)
				flgVirgula = true;
			else if ((i > 0) && (campo.value.substr(i, 1) == '.') && !flgVirgula) {
				flgVirgula = true;
				campo.value = campo.value.replace('.', ',');
			} else {
				campo.value = campo.value.substr(0, i);
				return false;
			}
		}
}*/
function validaFloat(valor) {
	var strNumeros = '0123456789';
	var flgVirgula = false;

	for (i = 0; i < valor.length; i++)
		if ((strNumeros.indexOf(valor.substr(i, 1)) == -1) && !((i == 0) && (valor.substr(i, 1) == '-'))) {
			if ((i > 0) && (valor.substr(i, 1) == ',') && !flgVirgula)
				flgVirgula = true;
			else
				return false;
		}
	return true;
}

function validaMoeda(valor) {

	var valor_aux = '';
	var flag_virgula = false;
    var strCheck = '0123456789';
	
	for(var i = (valor.length-1), y = 1; i >= 0; i--, y++)
	{
		if ( !flag_virgula && y == 3 )
		{
			if ( valor.charAt(i) != "," ) return false;
			flag_virgula = true;
			y = 0;
		}
		else if ( flag_virgula && y == 4 )
		{
			if ( valor.charAt(i) != "." ) return false;
			y = 0;
		}
		else if ( strCheck.indexOf(valor.charAt(i))== -1 ) 
		{
			return false;
		}
		
	}
	
	return true;
}

function FormataHora(campo, evento) {
	var posNumeros = '0134';
	var posEspacos = '25';
	var strNumeros = '0123456789';
	
	var keyCode = (isNN) ? evento.which : evento.keyCode;
	
	if (keyCode >= 48 && keyCode <= 57){
		for (i = 0; i < campo.value.length; i++)
			if ((posNumeros.indexOf(i) != -1) && (strNumeros.indexOf(campo.value.substr(i, 1)) == -1)) {
				campo.value = campo.value.substr(0, i);
				return false;
			} else if ((posEspacos.indexOf(i) != -1) && (campo.value.substr(i, 1) != ':')) {
				campo.value = campo.value.substr(0, i);
				return false;
		}

		if (campo.value.length > 5)
			campo.value = campo.value.substr(0, 5);

		if ((campo.value.length == 2) )
			campo.value = campo.value + ":";
	}
	else
		if ( keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
}

function validaHora(valor) {
	if (valor.length == 0)
		return true;
	else if (valor.length != 5)
		return false;

	var hora = valor.substr(0, 2);
	var minu = valor.substr(3, 2);

	if (!validaNum(hora)) return false;
	if (!validaNum(minu)) return false;

	if (hora > 23 || hora < 0) return false;
	if (minu > 59 || minu < 0) return false;
	return true;
}

function validaNum(NUM) {
	for (var i = 0; i < NUM.length ; i++) {
		if (NUM.substring(i, i + 1) < '0' || NUM.substring(i, i + 1) > '9') {
			return false;
		}
	}
	return true;
}

function valida_login(form)
{
    if(form.txtLogin.value == "")
    {
        alert("O Login é obrigatório!");
        form.txtLogin.focus();
        return false;
    }
    if(form.txtSenha.value == "")
    {
        alert("A Senha é obrigatória!");
        form.txtSenha.focus();
        return false;
    }
    return true;
}

function EditarRegistro(codigo,form)
{
    form.action = "editar.php";
    form.codigo.value = codigo;
    form.submit();
    return true;
}

function ExcluirRegistro(codigo)
{
    if(confirm("Tem certeza que deseja excluir o registro?"))
    {
        document.location = 'acao.aspx?Codigo=' + codigo + '&Acao=Excluir';
    }
}

function ExcluirRegistroSubSecao(codigo)
{
    if(confirm("Tem certeza que deseja excluir o registro?"))
    {
        document.location = 'editar_subsecao.aspx?Codigo=' + codigo + '&Acao=Excluir';
    }
}

function valida_excluir_arquivo (campo)
{
    if ( campo.checked == true )
    {
        if (!confirm("Tem certeza que deseja excluir o arquivo?"))
           campo.checked = false;
    }
}


        
        function FormataFloat(campo,evento) {
			var keyCode = (isNN) ? evento.which : evento.keyCode;
            if ((keyCode >= 48 && keyCode <= 57) || (keyCode == 44)|| (keyCode == 45)){
                var strNumeros = '0123456789';
	            var flgVirgula = false;
	            var liberar
                
	            for (i = 0; i < campo.value.length; i++)
		            if ((strNumeros.indexOf(campo.value.substr(i, 1)) == -1) && !((i == 0) && (campo.value.substr(i, 1) == '-'))) {     
			            if ((i > 0) && (campo.value.substr(i, 1) == ',') && !flgVirgula)
				            flgVirgula = true;
			            else if ((i > 0) && (campo.value.substr(i, 1) == '.') && !flgVirgula) {
				            flgVirgula = true;
				            campo.value = campo.value.replace('.', ',');
			            } else {
				            campo.value = campo.value.substr(0, i);
				            return false;
			            }
		            }
            }
            else
		        if ( keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
        }
        
        function FormataInteiro(campo,evento){
			var keyCode = (isNN) ? evento.which : evento.keyCode;
			if ( (!(keyCode >= 48 && keyCode <= 57)) && keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
        }
        
        function FormataCPF(campo,evento){
			var keyCode = (isNN) ? evento.which : evento.keyCode;
	        if (keyCode >= 48 && keyCode <= 57){
		        separador = '.';
		        separador1 = '-';
		        conjunto1 = 3;
		        conjunto2 = 7;
		        conjunto3 = 11;
		        if (campo.value.length == conjunto1)
			        campo.value = campo.value + separador;

		        if (campo.value.length == conjunto2)
			        campo.value = campo.value + separador;
        				
		        if (campo.value.length == conjunto3)
			        campo.value = campo.value + separador1;	
	        }
	        else
		        if ( keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
        }
        
        function validaCPFNET(source, arguments) {
	        valor = arguments.Value;
	        arguments.IsValid = true;

	        if (!validaCPF(valor)) arguments.IsValid = false;
        }


        function validaCPF(s)
        { 
            s = s.replace('.', '')
            s = s.replace('.', '')
            s = s.replace('-', '')

            if ( s == "00000000000" || s == "11111111111" || s == "22222222222" || s == "33333333333" || s == "44444444444" || s == "55555555555" || s == "66666666666" || s == "77777777777" || s == "88888888888" || s == "99999999999" )
            { 
                return false; 
            } 

            var i; 
            var c = s.substr(0,9); 
            var dv = s.substr(9,2); 
            var d1 = 0; 
              
            for (i = 0; i < 9; i++) 
            { 
	            d1 += c.charAt(i)*(10-i); 
            } 
              
            if (d1 == 0)
            { 
	            return false; 
            } 
              
            d1 = 11 - (d1 % 11); 

            if (d1 > 9) d1 = 0; 
            if (dv.charAt(0) != d1) 
            { 
	            return false; 
            } 
              
            d1 *= 2; 

            for (i = 0; i < 9; i++) 
            { 
	            d1 += c.charAt(i)*(11-i); 
            } 
              
            d1 = 11 - (d1 % 11); 
              
            if (d1 > 9) d1 = 0; 
              
            if (dv.charAt(1) != d1) 
            { 
	            return false; 
            } 
              
            return true; 
        }
        
        function FormataCNPJ(campo, evento){
			var keyCode = (isNN) ? evento.which : evento.keyCode;
	        if (keyCode >= 48 && keyCode <= 57){
		        separador = '.';
		        separador1 = '/';
		        separador2 = '-';
		        conjunto1 = 2;
		        conjunto2 = 6;
		        conjunto3 = 10;
		        conjunto4 = 15;
		        
		        if (campo.value.length == conjunto1)
			        campo.value = campo.value + separador;

		        if (campo.value.length == conjunto2)
			        campo.value = campo.value + separador;
        				
		        if (campo.value.length == conjunto3)
			        campo.value = campo.value + separador1;	
        				
		        if (campo.value.length == conjunto4)
			        campo.value = campo.value + separador2;	
	        }
	        else
				if ( keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
        }
        
        function FormataCNPJCPF(campo, evento, form ){
			if ( form.tipo_pessoa[1].checked == true )
			{
				return FormataCNPJ(campo, evento);
			}
			else
			{
				return FormataCPF(campo, evento);
			}
        }
        
        /*
        function validaCNPJ(valor) {

	        if (!isCNPJ(valor)) 
				return false;
			else
				return true;
        }*/

        function validaCNPJ(CNPJEnviado) {
		    CNPJ = CNPJEnviado;

		    erro = new String;
		    if (CNPJ.length < 18) return false;
		    if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
		    if (erro.length == 0) return false;
		    }
            //substituir os caracteres que não são números
            if(document.layers && parseInt(navigator.appVersion) == 4){
                   x = CNPJ.substring(0,2);
                   x += CNPJ. substring (3,6);
                   x += CNPJ. substring (7,10);
                   x += CNPJ. substring (11,15);
                   x += CNPJ. substring (16,18);
                   CNPJ = x; 
            } else {
                   CNPJ = CNPJ. replace (".","");
                   CNPJ = CNPJ. replace (".","");
                   CNPJ = CNPJ. replace ("-","");
                   CNPJ = CNPJ. replace ("/","");
            }
            var nonNumbers = /\D/;
            if (nonNumbers.test(CNPJ)) return false; 

            if ( CNPJ == "00000000000000" || CNPJ == "11111111111111" || CNPJ == "22222222222222" || CNPJ == "33333333333333" || CNPJ == "44444444444444" || CNPJ == "55555555555555" || CNPJ == "66666666666666" || CNPJ == "77777777777777" || CNPJ == "88888888888888" || CNPJ == "99999999999999" ) return false;

            var a = [];
            var b = new Number;
            var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
            for (i=0; i<12; i++){
               a[i] = CNPJ.charAt(i);
               b += a[i] * c[i+1];
            }
            if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
            b = 0;
            for (y=0; y<13; y++) {
                   b += (a[y] * c[y]); 
            }
            if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
            if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                return false;
            }
            
            return true;
        }
        
        function validaCEPNET(source, arguments) {
	        valor = arguments.Value;
	        arguments.IsValid = true;

	        if (!isCEP(valor)) arguments.IsValid = false;
        }

        function validaCEP(valor) {
	        if ( valor.length != 10 ) return false;
	        if ( valor.indexOf("." )!= 2 ) return false;
	        if ( valor.indexOf("-" )!= 6 ) return false;
	        if ( valor == "11.111-111" || valor == "22.222-222" || valor == "33.333-333" || valor == "44.444-444" || valor == "55.555-555" || valor == "66.666-666" || valor == "77.777-777" || valor == "88.888-888" || valor == "99.999-999" || valor == "00.000-000" ) return false;
	        for ( var i = 0; i < valor.length ; i++ ) {
		        if ( valor.substring(i, i+1) >= '0' && valor.substring(i, i+1) <= '9'  ) {		
			        if ( i == 2 || i == 6 ) return false;
		        }
		        else { 
			        if ( i != 2 && i != 6 )  return false;
		        }
	        }
	        return true;
        }
        
        function FormataCEP(campo,evento){
			 var keyCode = (isNN) ? evento.which : evento.keyCode;
	        if (keyCode >= 48 && keyCode <= 57){
		        separador = '.';
		        separador1 = '-';
		        conjunto = 2;
		        conjunto1 = 6;
		        if (campo.value.length == conjunto)
			        campo.value = campo.value + separador;
		        if (campo.value.length == conjunto1)
			        campo.value = campo.value + separador1;
	        }
	        else
				if ( keyCode != 0 && keyCode != 13 && keyCode != 8 ) return false;
        }
        function ConfirmaExclusao(){
            return confirm('Deseja realmente excluir este registro?');
        }
        
        function FormataHora(campo){
	        if (window.event.keyCode >= 48 && window.event.keyCode <= 57){

		        separador = ':';
		        conjunto1 = 2;
		        if (campo.value.length == conjunto1)
			        campo.value = campo.value + separador;

	        }
	        else
		        window.event.keyCode = 0;
        }
        
        function validaHora (source, arguments) {
	        valor = arguments.Value;
	        arguments.IsValid = true;
	        if (valor.length == 0)
		        arguments.IsValid = false;
	        else if (valor.length != 5)
		        arguments.IsValid = false;

	        var hora = valor.substr(0, 2);
	        var minu = valor.substr(3, 2);
        	
	        if (isNaN(hora)) arguments.IsValid = false;
	        if (isNaN(minu)) arguments.IsValid = false;

	        if (hora > 23 || hora < 0) arguments.IsValid = false;
	        if (minu > 59 || minu < 0) arguments.IsValid = false;
        }
        
   

function DateField(objectId) {

  var data = new String();
  var maxlength = 8;
  var obj = objectId;
  if (document.getElementById(obj).value != "__/__/____") 
      data = document.getElementById(obj).value.replace(/\/|\s/g,"");
  var len = data.length;
  
  function getKey(event) {
    return event?(event.keyCode?event.keyCode:(event.which?event.which:event.charCode)):null;
  }

  this.getLength = function() {
    return data;
  }

  this.mask = function(event) {
      
    var k = getKey(event);
    if (k != 9) {
          if (k > 95 && k < 106) k -= 48;
            
        if (/[0-9]/.test(String.fromCharCode(k))) {
          if (len < maxlength) {
            data += String.fromCharCode(k);
            len++;
          } else return false;
        } else if (k == 8) {
          if (len > 0) data = data.substring(0,--len);
        }
        else return false;
            
        var mask = new String("__/__/____");
        var v = new String();

        if (len <= 2)                 v = data + mask.substring(len,maxlength+2);
        else if (len > 2 && len <= 4) v = data.substring(0,2) + "/" + data.substring(2,len) + mask.substring(len+1,maxlength+2);
        else if (len >= 5)            v = data.substring(0,2) + "/" + data.substring(2,4) + "/" + data.substring(4,len) + (len<(maxlength+2)?mask.substring(len+2,maxlength+2):"");
        
        document.getElementById(obj).value = v;
            
        return false;
    }
    
    return true;    

  }
    
} 
        
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function validaBusca() {
	if ( document.getElementById("txtPalavra").value == "" ) {
		alert("Por favor, digite uma palavra-chave para efetuar a busca.");
		document.getElementById("txtPalavra").focus();
		return false;
	}
	else
		return true;
}

function validaBuscaEntidade() {
	if ( document.getElementById("txtEntidade").value == "" ) {
		alert("Por favor, digite o nome ou a sigla para efetuar a procura.");
		document.getElementById("txtEntidade").focus();
		return false;
	}
	else
		return true;
}

function MostraRelacao(Tipo) {
	if ( Tipo == "cbic" ) {
		document.getElementById("cbic").style.display = "block";
		document.getElementById("outros").style.display = "none";
		document.getElementById("mensagem").style.display = "block";
		document.getElementById("todas_relacao").innerHTML = "<img src=\"../imagens/entidades/cbic_over.gif\" border=\"0\" name=\"imagem_cbic\" id=\"imagem_cbic\">";
		document.getElementById("todas_relacao").innerHTML += "<a href=\"javascript: MostraRelacao('outros');\"><img src=\"../imagens/entidades/demais.gif\" border=\"0\" name=\"imagem_outros\" id=\"imagem_outros\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('imagem_outros','','../imagens/entidades/demais_over.gif',1)\"></a>";
	}
	else {
		document.getElementById("outros").style.display = "block";
		document.getElementById("cbic").style.display = "none";	
		document.getElementById("mensagem").style.display = "block";
		document.getElementById("todas_relacao").innerHTML = "<a href=\"javascript: MostraRelacao('cbic');\"><img src=\"../imagens/entidades/cbic.gif\" border=\"0\" name=\"imagem_cbic\" id=\"imagem_cbic\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('imagem_cbic','','../imagens/entidades/cbic_over.gif',1)\"></a>";
		document.getElementById("todas_relacao").innerHTML += "<img src=\"../imagens/entidades/demais_over.gif\" border=\"0\" name=\"imagem_outros\" id=\"imagem_outros\">";
	}
}

function valida_fale(form) {
	if ( form.nome.value == "" ) {
		alert("Por favor, digite o nome.");
		form.nome.focus();
		return false;
	}
	if ( form.email.value == "" ) {
		alert("Por favor, digite o e-mail.");
		form.email.focus();
		return false;
	}
	if ( !valida_mail(form.email.value)) {
		alert("Por favor, digite o e-mail válido.");
		form.email.focus();
		return false;
	}
	if ( form.mensagem.value == "" ) {
		alert("Por favor, digite a mensagem.");
		form.mensagem.focus();
		return false;
	}
	return true;
}

function valida_solicite_corretor(form) {
	if ( form.empresa.value == "" ) {
		alert("Por favor, digite o nome da empresa.");
		form.empresa.focus();
		return false;
	}
	if ( form.contato.value == "" ) {
		alert("Por favor, digite o nome do contato.");
		form.contato.focus();
		return false;
	}
	if ( form.atividade.value == "" ) {
		alert("Por favor, digite a atividade da empresa.");
		form.atividade.focus();
		return false;
	}
	if ( form.cidade.value == "" ) {
		alert("Por favor, digite o nome da cidade.");
		form.cidade.focus();
		return false;
	}
	if ( form.estado.value == "" ) {
		alert("Por favor, informe o estado.");
		form.estado.focus();
		return false;
	}
	if ( form.DDD.value == "" ) {
		alert("Por favor, digite o DDD.");
		form.DDD.focus();
		return false;
	}
	if ( form.telefone.value == "" ) {
		alert("Por favor, digite o telefone.");
		form.telefone.focus();
		return false;
	}
	if ( form.email.value == "" ) {
		alert("Por favor, digite o e-mail.");
		form.email.focus();
		return false;
	}
	if ( !valida_mail(form.email.value)) {
		alert("Por favor, digite o e-mail válido.");
		form.email.focus();
		return false;
	}
	return true;
}

function valida_solicitacao_material(form) {
	if ( form.nome.value == "" ) {
		alert("Por favor, digite o seu nome.");
		form.nome.focus();
		return false;
	}
	if ( form.email.value == "" ) {
		alert("Por favor, digite o seu e-mail.");
		form.email.focus();
		return false;
	}
	if ( !valida_mail(form.email.value)) {
		alert("Por favor, digite o e-mail válido.");
		form.email.focus();
		return false;
	}
	if ( form.endereco.value == "" ) {
		alert("Por favor, digite o seu endereço.");
		form.endereco.focus();
		return false;
	}
	if ( form.numero.value == "" ) {
		alert("Por favor, digite o número do seu endereço.");
		form.numero.focus();
		return false;
	}
	if ( form.bairro.value == "" ) {
		alert("Por favor, digite o nome do bairro.");
		form.bairro.focus();
		return false;
	}
	if ( form.cidade.value == "" ) {
		alert("Por favor, digite o nome da cidade.");
		form.cidade.focus();
		return false;
	}
	if ( form.estado.value == "" ) {
		alert("Por favor, informe o estado.");
		form.estado.focus();
		return false;
	}
	if ( form.cep.value == "" ) {
		alert("Por favor, digite o CEP.");
		form.cep.focus();
		return false;
	}
	if ( ! validaCEP(form.cep.value)) {
		alert("Por favor, digite um CEP válido.");
		form.cep.focus();
		return false;
	}
	if ( form.DDD.value == "" ) {
		alert("Por favor, digite o DDD.");
		form.DDD.focus();
		return false;
	}
	if ( form.telefone.value == "" ) {
		alert("Por favor, digite o telefone.");
		form.telefone.focus();
		return false;
	}
	if ( form.manual_comercializacao.checked == false && form.formulario_adesao.checked == false && form.formulario_adesao_CBIC.checked == false && form.folder.checked == false && form.folder_CBIC.checked == false && form.cartaz.checked == false && form.declaracao_nao_sinistro.checked == false && form.declaracao_informativo.checked == false && form.pasta.checked == false && form.envelope.checked == false ) {	
		alert("Por favor, escolha pelo menos um material.");
		form.manual_comercializacao.focus();
		return false;
	}
	return true;
}

function valida_proposta(form) {
	if ( form.nome.value == "" ) {
		alert("Por favor, digite o nome.");
		form.nome.focus();
		return false;
	}
	if ( form.cnpj.value == "" ) {
		alert("Por favor, digite o CNPJ.");
		form.cnpj.focus();
		return false;
	}
	if ( ! validaCNPJ(form.cnpj.value)) {
		alert("Por favor, digite um CNPJ válido.");
		form.cnpj.focus();
		return false;
	}
	if ( form.email.value == "" ) {
		alert("Por favor, digite o e-mail.");
		form.email.focus();
		return false;
	}
	if ( !valida_mail(form.email.value)) {
		alert("Por favor, digite o e-mail válido.");
		form.email.focus();
		return false;
	}
	if ( form.DDD.value == "" ) {
		alert("Por favor, digite o DDD.");
		form.DDD.focus();
		return false;
	}
	if ( form.telefone.value == "" ) {
		alert("Por favor, digite o telefone.");
		form.telefone.focus();
		return false;
	}
	if ( form.contato.value == "" ) {
		alert("Por favor, digite o contato.");
		form.contato.focus();
		return false;
	}
	if ( form.cidade.value == "" ) {
		alert("Por favor, digite a cidade.");
		form.cidade.focus();
		return false;
	}
	if ( form.estado.value == "" ) {
		alert("Por favor, informe o estado.");
		form.estado.focus();
		return false;
	}
	if ( form.sindicato.value == "" ) {
		alert("Por favor, digite o nome sindicato.");
		form.sindicato.focus();
		return false;
	}
	if (form.corretor)
	{
		if ( form.corretor.value != "" ) {
			if (form.DDD_corretor)
			{
				if ( form.DDD_corretor.value == "" ) {
					alert("Por favor, digite o DDD do corretor.");
					form.DDD_corretor.focus();
					return false;
				}
			}
			if (form.telefone_corretor)
			{
				if ( form.telefone_corretor.value == "" ) {
					alert("Por favor, digite o telefone do corretor.");
					form.telefone_corretor.focus();
					return false;
				}
			}
			if (form.contato_corretor)
			{
				if ( form.contato_corretor.value == "" ) {
					alert("Por favor, digite o contato do corretor.");
					form.contato_corretor.focus();
					return false;
				}
			}
			if (form.email_corretor)
			{
				if ( form.email_corretor.value == "" ) {
					alert("Por favor, digite o e-mail.");
					form.email_corretor.focus();
					return false;
				}
				if ( !valida_mail(form.email_corretor.value)) {
					alert("Por favor, digite o e-mail válido, para o e-mail do corretor.");
					form.email_corretor.focus();
					return false;
				}
			}
			if ( validaCheckbox(form.comissao,"Por favor, informe a comissão corretor.") )
				return false;
		
		}
	}
	if ( form.capital.value == "" ) {
		alert("Por favor, digite o capital segurado desejado.");
		form.capital.focus();
		return false;
	}
	if ( !validaMoeda(form.capital.value)) {
		alert("Por favor, digite um valor válido para o capital segurado desejado.");
		form.capital.focus();
		return false;
	}
	if ( validacapitalminimo(form.capital.value,form.capital_minino.value)) {
		alert("Por favor, o valor do capital segurado desejado deve ser igual ou superior a R$ " + form.capital_minino.value +".");
		form.capital.focus();
		return false;
	}
	if ( form.numero_vidas_ativas.value == "" ) {
		alert("Por favor, digite o número total de vidas ativas.");
		form.numero_vidas_ativas.focus();
		return false;
	}
	if ( !validaInteiro(form.numero_vidas_ativas.value)) {
		alert("Por favor, digite um valor válido para o número total de vidas ativas.");
		form.numero_vidas_ativas.focus();
		return false;
	}
	if ( form.contributario[0].checked == true && form.valor.value == "" ) {
		alert("Por favor, digite o valor do contributário.");
		form.valor.focus();
		return false;
	}
	if ( form.contributario[0].checked == true && !validaMoeda(form.valor.value)) {
		alert("Por favor, digite um valor válido para o valor do contributário.");
		form.valor.focus();
		return false;
	}
	if ( form.contributario[0].checked == true && form.percentual.value == "" ) {
		alert("Por favor, digite o percentual do contributário.");
		form.percentual.focus();
		return false;
	}
	if ( form.contributario[0].checked == true && !validaMoeda(form.percentual.value)) {
		alert("Por favor, digite um valor válido para o percentual do contributário.");
		form.percentual.focus();
		return false;
	}
	return true;
}


function validaInsercaoSegurado ()
{
	if ( document.getElementById("nome").value == "" ) {
		alert("Por favor, digite o nome do segurado.");
		document.getElementById("nome").focus();
		return false;
	}
	if ( document.getElementById("data").value == "" ) {
		alert("Por favor, digite a data de nascimento do segurado.");
		document.getElementById("data").focus();
		return false;
	}
	if ( document.getElementById("cpf").value == "" ) {
		alert("Por favor, digite o CPF do segurado.");
		document.getElementById("cpf").focus();
		return false;
	}
	return true;
}

function Imprimir(url) {
	window.open(url, "", "toolbar=NO, scroll=NO, scrollbars=NO, resizable=NO, height=550, width=780");
}


function escolhe_tipo_pessoa ( form )
{
	form.cnpj_corretor.value = "";
	
	if ( form.tipo_pessoa[1].checked == true )
	{	
		form.cnpj_corretor.maxLength = 18;
	}
	else
	{
		form.cnpj_corretor.maxLength = 14;	
	}
}

function valida_contrato(form) {
	if ( form.razao.value == "" ) {
		alert("Por favor, digite a razão social.");
		form.razao.focus();
		return false;
	}
	if ( form.cnpj.value == "" ) {
		alert("Por favor, digite o CNPJ.");
		form.cnpj.focus();
		return false;
	}
	if ( ! validaCNPJ(form.cnpj.value)) {
		alert("Por favor, digite um CNPJ válido.");
		form.cnpj.focus();
		return false;
	}
	if ( form.endereco.value == "" ) {
		alert("Por favor, digite o endereço completo da empresa.");
		form.endereco.focus();
		return false;
	}
	if ( form.cbic.value == "true" )
	{	
		if ( form.bairro.value == "" ) {
			alert("Por favor, digite o bairro do endereço da empresa.");
			form.bairro.focus();
			return false;
		}
	}
	if ( form.cep.value == "" ) {
		alert("Por favor, digite o CEP do endereço completo da empresa.");
		form.cep.focus();
		return false;
	}
	if ( ! validaCEP(form.cep.value)) {
		alert("Por favor, digite um CEP válido.");
		form.cep.focus();
		return false;
	}
	if ( form.cidade.value == "" ) {
		alert("Por favor, digite a cidade.");
		form.cidade.focus();
		return false;
	}
	if ( form.estado.value == "" ) {
		alert("Por favor, informe o estado.");
		form.estado.focus();
		return false;
	}
	if ( form.DDD.value == "" ) {
		alert("Por favor, digite o DDD.");
		form.DDD.focus();
		return false;
	}
	if ( form.telefone.value == "" ) {
		alert("Por favor, digite o telefone.");
		form.telefone.focus();
		return false;
	}
	if ( form.contato.value == "" ) {
		alert("Por favor, digite o nome do contato.");
		form.contato.focus();
		return false;
	}
	if ( form.cargo.value == "" ) {
		alert("Por favor, digite o cargo do contato.");
		form.cargo.focus();
		return false;
	}
	if ( form.email.value == "" ) {
		alert("Por favor, digite o e-mail.");
		form.email.focus();
		return false;
	}
	if ( !valida_mail(form.email.value)) {
		alert("Por favor, digite o e-mail válido.");
		form.email.focus();
		return false;
	}
	if ( form.endereco_cobranca.value == "" ) {
		alert("Por favor, digite o endereço de cobrança da empresa.");
		form.endereco_cobranca.focus();
		return false;
	}
	if ( form.cbic.value == "true" )
	{	
		if ( form.bairro_cobranca.value == "" ) {
			alert("Por favor, digite o bairro do endereço de cobrança da empresa.");
			form.bairro_cobranca.focus();
			return false;
		}
	}
	if ( form.cep_cobranca.value == "" ) {
		alert("Por favor, digite o CEP do endereço de cobrança da empresa.");
		form.cep_cobranca.focus();
		return false;
	}
	if ( ! validaCEP(form.cep_cobranca.value)) {
		alert("Por favor, digite um CEP válido.");
		form.cep_cobranca.focus();
		return false;
	}
	if ( form.cidade_cobranca.value == "" ) {
		alert("Por favor, digite a cidade.");
		form.cidade_cobranca.focus();
		return false;
	}
	if ( form.estado_cobranca.value == "" ) {
		alert("Por favor, informe o estado.");
		form.estado_cobranca.focus();
		return false;
	}
	if ( form.nome_corretor.value != "" ) {
		if ( form.tipo_pessoa[0].checked == false && form.tipo_pessoa[1].checked == false ) {
			alert("Por favor, informe se o corretor é pessoa física ou pessoa jurídica.");
			form.tipo_pessoa[0].focus();
			return false;
		}
		if ( form.tipo_pessoa[1].checked == true )
		{
			if ( form.cnpj_corretor.value == "" ) {
				alert("Por favor, digite o CNPJ do corretor.");
				form.cnpj_corretor.focus();
				return false;
			}
			if ( ! validaCNPJ(form.cnpj_corretor.value)) {
				alert("Por favor, digite um CNPJ válido.");
				form.cnpj_corretor.focus();
				return false;
			}
		}
		else
		{
			if ( form.cnpj_corretor.value == "" ) {
				alert("Por favor, digite o CPF do corretor.");
				form.cnpj_corretor.focus();
				return false;
			}
			if ( ! validaCPF(form.cnpj_corretor.value)) {
				alert("Por favor, digite um CPF válido.");
				form.cnpj_corretor.focus();
				return false;
			}
		}
		if ( form.endereco_corretor.value == "" ) {
			alert("Por favor, digite o endereço completo do corretor.");
			form.endereco_corretor.focus();
			return false;
		}
		if ( form.cep_corretor.value == "" ) {
			alert("Por favor, digite o CEP do endereço do corretor.");
			form.cep_corretor.focus();
			return false;
		}
		if ( ! validaCEP(form.cep_corretor.value)) {
			alert("Por favor, digite um CEP válido.");
			form.cep_corretor.focus();
			return false;
		}
		if ( form.cidade_corretor.value == "" ) {
			alert("Por favor, digite a cidade do corretor.");
			form.cidade_corretor.focus();
			return false;
		}
		if ( form.estado_corretor.value == "" ) {
			alert("Por favor, informe o estado do corretor.");
			form.estado_corretor.focus();
			return false;
		}
		if ( form.DDD_corretor.value == "" ) {
			alert("Por favor, digite o DDD do corretor.");
			form.DDD_corretor.focus();
			return false;
		}
		if ( form.telefone_corretor.value == "" ) {
			alert("Por favor, digite o telefone do corretor.");
			form.telefone_corretor.focus();
			return false;
		}
		if ( form.contato_corretor.value == "" ) {
			alert("Por favor, digite o nome do contato do corretor.");
			form.contato_corretor.focus();
			return false;
		}
		if ( form.email_corretor.value == "" ) {
			alert("Por favor, digite o e-mail do corretor.");
			form.email_corretor.focus();
			return false;
		}
		if ( !valida_mail(form.email_corretor.value)) {
			alert("Por favor, digite o e-mail válido.");
			form.email_corretor.focus();
			return false;
		}	
		if ( form.cod_corret_susep.value == "" ) {
			alert("Por favor, digite o cod. corret. SUSEP.");
			form.cod_corret_susep.focus();
			return false;
		}
		if ( form.cod_corret_mapfre.value == "" ) {
			alert("Por favor, digite o cod. corret. MAPFRE.");
			form.cod_corret_mapfre.focus();
			return false;
		}
	}
	if ( form.modulo.value == "" ) {
		alert("Por favor, indique o(s) módulo(s) selecionado(s).");
		form.modulo.focus();
		return false;
	}
	if ( form.capital_segurado.value == "" ) {
		alert("Por favor, digite o capital segurado básico.");
		form.capital_segurado.focus();
		return false;
	}
	if ( !validaMoeda(form.capital_segurado.value)) {
		alert("Por favor, digite um valor válido para o capital segurado básico.");
		form.capital_segurado.focus();
		return false;
	}
	if ( form.custo_modulo.value == "" ) {
		alert("Por favor, digite o custo por segurado.");
		form.custo_modulo.focus();
		return false;
	}
	if ( !validaMoeda(form.custo_modulo.value)) {
		alert("Por favor, digite um valor válido para o custo por segurado.");
		form.custo_modulo.focus();
		return false;
	}
	if ( form.numero_segurados_modulo.value == "" ) {
		alert("Por favor, informe o número de segurados ativos.");
		form.numero_segurados_modulo.focus();
		return false;
	}
	if ( !validaInteiro(form.numero_segurados_modulo.value)) {
		alert("Por favor, digite um valor válido para o número de segurados ativos.");
		form.numero_segurados_modulo.focus();
		return false;
	}
	if ( form.correcao_capital_segurado[0].checked == false && form.correcao_capital_segurado[1].checked == false )
	{
		alert("Por favor, informe qual o tipo de correção anual do capital segurado básico.");
		form.correcao_capital_segurado[0].focus();
		return false;
	}
	if ( form.mes_vigencia.value == "" ) {
		alert("Por favor, informe o mês de início da vigência.");
		form.mes_vigencia.focus();
		return false;
	}
	if ( form.ano_vigencia.value == "" ) {
		alert("Por favor, informe o ano de início da vigência.");
		form.ano_vigencia.focus();
		return false;
	}
	return true;
}

function calcula_custo_segurados ( form ) {
	var total = 0;
	if ( form.custo_modulo.value != "" && form.numero_segurados_modulo.value != "" ) {
		if ( validaFloat(form.custo_modulo.value) && validaInteiro(form.numero_segurados_modulo.value) ) {
			var custo_modulo = troca_virgula(form.custo_modulo.value) * 1000000;
			var numero_segurados_modulo = form.numero_segurados_modulo.value;
			total = (custo_modulo * numero_segurados_modulo) / 1000000;
		}
	}	
	
	if ( total != 0 ) 
	{
		form.valor_total.value = total;
		form.valor_total.value = troca_ponto(form.valor_total.value);
		if ( form.valor_total.value.indexOf(",") == -1 )
			form.valor_total.value = form.valor_total.value + ",00";
		else if ( form.valor_total.value.length-2 == form.valor_total.value.indexOf(",") )
			form.valor_total.value = form.valor_total.value + "0";
			
		document.getElementById("span_valor_total").innerHTML = "R$ " + form.valor_total.value;
	}
	else
	{
		form.valor_total.value = "";
		document.getElementById("span_valor_total").innerHTML = "&nbsp;";
	}
}

function valida_relacao_segurado ( form )
{
	var total = form.total_segurados.value;
	
	for(var i = 1; i <= total; i++)
	{
		var nome = document.getElementById("nome_"+i);
		var data = document.getElementById("data_"+i);
		var cpf = document.getElementById("cpf_"+i);
				
		if ( nome.value == "" ) {
			alert("Por favor, digite o nome do "+ i +"º segurado.");
			nome.focus();
			return false;
		}
		if ( data.value == "" ) {
			alert("Por favor, digite a data de nascimento do "+ i +"º segurado.");
			data.focus();
			return false;
		}
		if ( ! validaData(data.value)) {
			alert("Por favor, digite uma data válida para a data de nascimento do "+ i +"º segurado.");
			data.focus();
			return false;
		}
		if ( cpf.value == "" ) {
			alert("Por favor, digite o CPF do "+ i +"º segurado.");
			cpf.focus();
			return false;
		}
		if ( ! validaCPF(cpf.value)) {
			alert("Por favor, digite um CPF válido para o "+ i +"º segurado.");
			cpf.focus();
			return false;
		}
	
	}
	
	return true;
}


function valida_secao ( ) {
	if (document.getElementById("txtNome").value == "") {
		alert("Por favor, digite o nome da seção!");
		document.getElementById("txtNome").focus();
		return false;
	}
	if (document.getElementById("ddlSubSecao").value == "") {
		alert("Por favor, informe a seção tem sub-seção ou não!");
		document.getElementById("ddlSubSecao").focus();
		return false;
	}
	return true;
}
function valida_subsecao ( ) {
	if (document.getElementById("txtNome").value == "") {
		alert("Por favor, digite o nome da sub-seção!");
		document.getElementById("txtNome").focus();
		return false;
	}
	return true;
}

function valida_entidade ( ) {
	if (document.getElementById("txtNome").value == "") {
		alert("Por favor, digite o nome da entidade!");
		document.getElementById("txtNome").focus();
		return false;
	}
	if (document.getElementById("ddlSetor").value == "") {
		alert("Por favor, informe o setor da entidade!");
		document.getElementById("ddlSetor").focus();
		return false;
	}
	if (document.getElementById("ddlPublicado").value == "") {
		alert("Por favor, informe se a entidade será publicada ou não!");
		document.getElementById("ddlPublicado").focus();
		return false;
	}
	return true;
}

function ValidaCobertura ( ) {
	if (document.getElementById("tbNomeCobertura").value == "") {
		alert("Por favor, digite o nome da cabertura!");
		document.getElementById("tbNomeCobertura").focus();
		return false;
	}
	if (document.getElementById("tbValorCobertura").value == "") {
		alert("Por favor, informe o valor da cabertura!");
		document.getElementById("tbValorCobertura").focus();
		return false;
	}
	return true;
}

function ValidaBeneficio ( ) {
	if (document.getElementById("tbNomeBeneficio").value == "") {
		alert("Por favor, digite o nome do benefício!");
		document.getElementById("tbNomeBeneficio").focus();
		return false;
	}
	if (document.getElementById("tbValorBeneficio").value == "") {
		alert("Por favor, informe a descrição do benefício!");
		document.getElementById("tbValorBeneficio").focus();
		return false;
	}
	return true;
}

function jump_menu(targ,
 selObj,restore){
  eval(targ+".location='"+
   selObj+ "'");
}

function MudaLateral()
{
	var maximo;

	if ( document.getElementById("conteudo").offsetHeight > document.getElementById("lateral").offsetHeight )
		maximo = document.getElementById("conteudo").offsetHeight;
	else
		maximo = document.getElementById("lateral").offsetHeight;
		
	var menu_dir = document.getElementById("menu_dir");
	var tarja_lateral = document.getElementById("imagem_tarja");
	var miolo_conteudo = document.getElementById("miolo_conteudo");

	var teste = document.getElementById("conteudo");


	if (miolo_conteudo)
	{
		if ( miolo_conteudo.offsetHeight < 258 ) miolo_conteudo.style.height = "258px";
	}

	var altura;

	if(menu_dir)
		altura = maximo-menu_dir.offsetHeight;
	else
		altura = maximo;

	tarja_lateral.style.height = altura + "px";
}

function valida_cobertura (Total) {
	for (var i = 1; i <= Total; i++)
	{
		if (document.getElementById("cbCobertura" + i).checked == true) {
			if (document.getElementById("tbNomeCobertura" + i).value == "") {
				alert("Por favor, digite o nome da cobertura.");
				document.getElementById("tbNomeCobertura" + i).focus();
				return false;
			}
			if (document.getElementById("tbCobertura" + i).value == "") {
				alert("Por favor, digite o valor da cobertura.");
				document.getElementById("tbCobertura" + i).focus();
				return false;
			}
			if ( !validaFloat(document.getElementById("tbCobertura" + i).value)) {
				alert("Por favor, digite um valor válido para o valor da cobertura.");
				document.getElementById("tbCobertura" + i).focus();
				return false;
			}/*
			if (document.getElementById("tbOrdemCobertura" + i).value == "") {
				alert("Por favor, digite a ordem da cobertura.");
				document.getElementById("tbOrdemCobertura" + i).focus();
				return false;
			}
			if ( !validaInteiro(document.getElementById("tbOrdemCobertura" + i).value)) {
				alert("Por favor, digite um número inteiro para a ordem da cobertura.");
				document.getElementById("tbOrdemCobertura" + i).focus();
				return false;
			}*/
		}
		if (document.getElementById("tbOrdemCobertura" + i).value != "") {
			if ( !validaInteiro(document.getElementById("tbOrdemCobertura" + i).value)) {
				alert("Por favor, digite um número inteiro para a ordem da cobertura.");
				document.getElementById("tbOrdemCobertura" + i).focus();
				return false;
			}
		}
	}
	return true;
}

function valida_beneficio (Total) {
	for (var i = 1; i <= Total; i++)
	{
		if (document.getElementById("cbBeneficio" + i).checked == true) {
			if (document.getElementById("tbBeneficio" + i).value == "") {
				alert("Por favor, digite o nome do benefício.");
				document.getElementById("tbBeneficio" + i).focus();
				return false;
			}/*
			if (document.getElementById("tbOrdemBeneficio" + i).value == "") {
				alert("Por favor, digite a ordem do benefício.");
				document.getElementById("tbOrdemBeneficio" + i).focus();
				return false;
			}
			if ( !validaInteiro(document.getElementById("tbOrdemBeneficio" + i).value)) {
				alert("Por favor, digite um número inteiro para a ordem do benefício.");
				document.getElementById("tbOrdemBeneficio" + i).focus();
				return false;
			}*/
		}
		if (document.getElementById("tbOrdemBeneficio" + i).value != "") {
			if ( !validaInteiro(document.getElementById("tbOrdemBeneficio" + i).value)) {
				alert("Por favor, digite um número inteiro para a ordem do benefício.");
				document.getElementById("tbOrdemBeneficio" + i).focus();
				return false;
			}
		}
	}
	return true;
}

function validacapitalminimo ( Valor, Minimo )
{
	Valor = troca_virgula(Valor)*1;
	Minimo = troca_virgula(Minimo)*1;
	
	if ( Minimo == "0" ) return false;
	
	if ( Minimo > Valor ) return true;
	
	return false;
}

function validaCheckbox ( campo , alerta )
{
	if(campo.length) {
		var flag_campo = false;
		for (var i = 0; i < campo.length; i++ )
		{
			if (campo[i].checked == true) flag_campo = true;
		}
		if ( !flag_campo ) {
			alert(alerta);
			campo[0].focus();
			return true;		
		}
	}
	else {
		if (campo.checked == false) {
			alert(alerta);
			campo.focus();
			return true;
		}
	}
	
	return false;
}

function valida_curriculo (form) {

	if ( form.nome.value == "" ) {
		alert("Por favor, digite o nome.");
		form.nome.focus();
		return false;
	}
	if ( form.nascimento.value == "" ) {
		alert("Por favor, digite a data de nascimento.");
		form.nascimento.focus();
		return false;
	}
	if ( ! validaData(form.nascimento.value)) {
		alert("Por favor, digite uma data válida para a data de nascimento.");
		form.nascimento.focus();
		return false;
	}
	if ( form.sexo.value == "" ) {
		alert("Por favor, informe o sexo.");
		form.sexo.focus();
		return false;
	}
	if ( form.cpf.value == "" ) {
		alert("Por favor, digite o CPF.");
		form.cpf.focus();
		return false;
	}
	if ( ! validaCPF(form.cpf.value)) {
		alert("Por favor, digite um CPF válido.");
		form.cpf.focus();
		return false;
	}
	if ( form.rg.value == "" ) {
		alert("Por favor, digite o RG.");
		form.rg.focus();
		return false;
	}
	if ( form.estado_civil.value == "" ) {
		alert("Por favor, informe o estado civil.");
		form.estado_civil.focus();
		return false;
	}
	if ( form.naturalidade.value == "" ) {
		alert("Por favor, digite a naturalidade.");
		form.naturalidade.focus();
		return false;
	}
	if ( form.endereco.value == "" ) {
		alert("Por favor, digite o endereço.");
		form.endereco.focus();
		return false;
	}
	if ( form.cep.value == "" ) {
		alert("Por favor, digite o CEP.");
		form.cep.focus();
		return false;
	}
	if ( form.cidade.value == "" ) {
		alert("Por favor, digite a cidade.");
		form.cidade.focus();
		return false;
	}
	if ( form.estado.value == "" ) {
		alert("Por favor, informe o estado.");
		form.estado.focus();
		return false;
	}
	if ( form.DDD.value == "" ) {
		alert("Por favor, digite o ddd do telefone residencial.");
		form.DDD.focus();
		return false;
	}
	if ( form.telefone.value == "" ) {
		alert("Por favor, digite o telefone residencial.");
		form.telefone.focus();
		return false;
	}
	if ( form.email.value == "" ) {
		alert("Por favor, digite o e-mail.");
		form.email.focus();
		return false;
	}
	if ( !valida_mail(form.email.value)) {
		alert("Por favor, digite o e-mail válido.");
		form.email.focus();
		return false;
	}
	if ( form.nivel_escolaridade.value == "" ) {
		alert("Por favor, informe o nível de escolaridade.");
		form.nivel_escolaridade.focus();
		return false;
	}
	
	if ( form.nome_curso1.value != ""  || form.nome_instituicao1.value != ""  || form.data_inicio1.value != ""  || form.data_conclusao1.value != "" ) {	
		if ( form.nome_curso1.value == "" ) {
			alert("Por favor, digite o nome do curso 1.");
			form.nome_curso1.focus();
			return false;
		}
		if ( form.nome_instituicao1.value == "" ) {
			alert("Por favor, digite o nome da instituição do curso 1.");
			form.nome_instituicao1.focus();
			return false;
		}
		if ( form.data_inicio1.value == "" ) {
			alert("Por favor, digite a data de início do curso 1.");
			form.data_inicio1.focus();
			return false;
		}
		if ( ! validaData(form.data_inicio1.value)) {
			alert("Por favor, digite uma data válida para a data de início do curso 1.");
			form.data_inicio1.focus();
			return false;
		}
		if ( form.data_conclusao1.value != "" ) {			
			if ( ! validaData(form.data_conclusao1.value)) {
				alert("Por favor, digite uma data válida para a data de conclusão do curso 1.");
				form.data_conclusao1.focus();
				return false;
			}
		}
	}
	if (form.nome_curso2.value != ""  || form.nome_instituicao2.value != ""  || form.data_inicio2.value != ""  || form.data_conclusao2.value != "" ) {	
		if ( form.nome_curso2.value == "" ) {
			alert("Por favor, digite o nome do curso 2.");
			form.nome_curso2.focus();
			return false;
		}
		if ( form.nome_instituicao2.value == "" ) {
			alert("Por favor, digite o nome da instituição do curso 2.");
			form.nome_instituicao2.focus();
			return false;
		}
		if ( form.data_inicio2.value == "" ) {
			alert("Por favor, digite a data de início do curso 2.");
			form.data_inicio2.focus();
			return false;
		}
		if ( ! validaData(form.data_inicio2.value)) {
			alert("Por favor, digite uma data válida para a data de início do curso 2.");
			form.data_inicio2.focus();
			return false;
		}
		if ( form.data_conclusao2.value == "" ) {
			if ( ! validaData(form.data_conclusao2.value)) {
				alert("Por favor, digite uma data válida para a data de conclusão do curso 2.");
				form.data_conclusao2.focus();
				return false;
			}
		}
	}
	if (form.nome_empresa1.value != ""  || form.segmento1.value != ""  || form.porte1.value != ""  || form.data_entrada1.value != "" || form.data_saida1.value != "" || form.cargo1.value != "" || form.funcao_desenvolvida1.value != "" ) {	
		if ( form.nome_empresa1.value == "" ) {
			alert("Por favor, digite o nome da empresa 1.");
			form.nome_empresa1.focus();
			return false;
		}
		if ( form.segmento1.value == "" ) {
			alert("Por favor, digite o segmento da empresa 1.");
			form.segmento1.focus();
			return false;
		}
		if ( form.porte1.value == "" ) {
			alert("Por favor, digite o porte da empresa 1.");
			form.porte1.focus();
			return false;
		}
		if ( form.data_entrada1.value == "" ) {
			alert("Por favor, digite a data de entreda na empresa 1.");
			form.data_entrada1.focus();
			return false;
		}
		if ( ! validaData(form.data_entrada1.value)) {
			alert("Por favor, digite uma data válida para a data de entreda na empresa 1.");
			form.data_entrada1.focus();
			return false;
		}
		if ( form.data_saida1.value == "" ) {
			if ( ! validaData(form.data_saida1.value)) {
				alert("Por favor, digite uma data válida para a data de saída na empresa 1.");
				form.data_saida1.focus();
				return false;
			}
		}
		if ( form.cargo1.value == "" ) {
			alert("Por favor, digite o cargo na empresa 1.");
			form.cargo1.focus();
			return false;
		}
		if ( form.funcao_desenvolvida1.value == "" ) {
			alert("Por favor, digite a função desenvolvida na empresa 1.");
			form.funcao_desenvolvida1.focus();
			return false;
		}
	}
	if (form.nome_empresa2.value != ""  || form.segmento2.value != ""  || form.porte2.value != ""  || form.data_entrada2.value != "" || form.data_saida2.value != "" || form.cargo2.value != "" || form.funcao_desenvolvida2.value != "" ) {	
		if ( form.nome_empresa2.value == "" ) {
			alert("Por favor, digite o nome da empresa 2.");
			form.nome_empresa2.focus();
			return false;
		}
		if ( form.segmento2.value == "" ) {
			alert("Por favor, digite o segmento da empresa 2.");
			form.segmento2.focus();
			return false;
		}
		if ( form.porte2.value == "" ) {
			alert("Por favor, digite o porte da empresa 2.");
			form.porte2.focus();
			return false;
		}
		if ( form.data_entrada2.value == "" ) {
			alert("Por favor, digite a data de entreda na empresa 2.");
			form.data_entrada2.focus();
			return false;
		}
		if ( ! validaData(form.data_entrada2.value)) {
			alert("Por favor, digite uma data válida para a data de entreda na empresa 2.");
			form.data_entrada2.focus();
			return false;
		}
		if ( form.data_saida2.value == "" ) {
			if ( ! validaData(form.data_saida2.value)) {
				alert("Por favor, digite uma data válida para a data de saída na empresa 2.");
				form.data_saida2.focus();
				return false;
			}
		}
		if ( form.cargo2.value == "" ) {
			alert("Por favor, digite o cargo na empresa 2.");
			form.cargo2.focus();
			return false;
		}
		if ( form.funcao_desenvolvida2.value == "" ) {
			alert("Por favor, digite a função desenvolvida na empresa 2.");
			form.funcao_desenvolvida2.focus();
			return false;
		}
	}
	if (form.nome_empresa3.value != ""  || form.segmento3.value != ""  || form.porte3.value != ""  || form.data_entrada3.value != "" || form.data_saida3.value != "" || form.cargo3.value != "" || form.funcao_desenvolvida3.value != "" ) {	
		if ( form.nome_empresa3.value == "" ) {
			alert("Por favor, digite o nome da empresa 3.");
			form.nome_empresa3.focus();
			return false;
		}
		if ( form.segmento3.value == "" ) {
			alert("Por favor, digite o segmento da empresa 3.");
			form.segmento3.focus();
			return false;
		}
		if ( form.porte3.value == "" ) {
			alert("Por favor, digite o porte da empresa 3.");
			form.porte3.focus();
			return false;
		}
		if ( form.data_entrada3.value == "" ) {
			alert("Por favor, digite a data de entreda na empresa 3.");
			form.data_entrada3.focus();
			return false;
		}
		if ( ! validaData(form.data_entrada3.value)) {
			alert("Por favor, digite uma data válida para a data de entreda na empresa 3.");
			form.data_entrada3.focus();
			return false;
		}
		if ( form.data_saida3.value == "" ) {
			if ( ! validaData(form.data_saida3.value)) {
				alert("Por favor, digite uma data válida para a data de saída na empresa 3.");
				form.data_saida3.focus();
				return false;
			}
		}
		if ( form.cargo3.value == "" ) {
			alert("Por favor, digite o cargo na empresa 3.");
			form.cargo3.focus();
			return false;
		}
		if ( form.funcao_desenvolvida3.value == "" ) {
			alert("Por favor, digite a função desenvolvida na empresa 3.");
			form.funcao_desenvolvida3.focus();
			return false;
		}
	}
	if ( form.trabalhando[0].checked == false && form.trabalhando[1].checked == false ) {
		alert("Por favor, informe se está ou não trabalhando.");
		form.trabalhando[0].focus();
		return false;
	}
	if ( form.area_interesse.value == "" ) {
		alert("Por favor, digite a sua área de interesse.");
		form.area_interesse.focus();
		return false;
	}
	if (form.idioma1.value != ""  || form.nivel_idioma1.value != "" ) {	
		if ( form.idioma1.value == "" ) {
			alert("Por favor, digite o idioma 1.");
			form.idioma1.focus();
			return false;
		}
		if ( form.nivel_idioma1.value == "" ) {
			alert("Por favor, digite o nível do idioma 1.");
			form.nivel_idioma1.focus();
			return false;
		}
	}
	if (form.idioma2.value != ""  || form.nivel_idioma2.value != "" ) {	
		if ( form.idioma2.value == "" ) {
			alert("Por favor, digite o idioma 2.");
			form.idioma2.focus();
			return false;
		}
		if ( form.nivel_idioma2.value == "" ) {
			alert("Por favor, digite o nível do idioma 2.");
			form.nivel_idioma2.focus();
			return false;
		}
	}
	if (form.idioma3.value != ""  || form.nivel_idioma3.value != "" ) {	
		if ( form.idioma3.value == "" ) {
			alert("Por favor, digite o idioma 3.");
			form.idioma3.focus();
			return false;
		}
		if ( form.nivel_idioma3.value == "" ) {
			alert("Por favor, digite o nível do idioma 3.");
			form.nivel_idioma3.focus();
			return false;
		}
	}
	return true;
}

function MesmoEndereco(form) {
	if ( form.mesmo_endereco.checked == true )
	{	
		form.endereco_cobranca.value = form.endereco.value;
		
		if ( form.cbic.value == "true" ) form.bairro_cobranca.value = form.bairro.value;

		form.cep_cobranca.value = form.cep.value;
		form.cidade_cobranca.value = form.cidade.value;
		form.estado_cobranca.value = form.estado.value;
	}
	else {
		if ( form.endereco_cobranca.value == form.endereco.value ) form.endereco_cobranca.value = "";
		
		if ( form.cbic.value == "true" ) {
			if ( form.bairro_cobranca.value == form.bairro.value ) form.bairro_cobranca.value = "";		
		}
		
		if ( form.cep_cobranca.value == form.cep.value ) form.cep_cobranca.value = "";
		if ( form.cidade_cobranca.value == form.cidade.value )	form.cidade_cobranca.value = "";
		if ( form.estado_cobranca.value == form.estado.value ) form.estado_cobranca.value = "";
	}
}

function FormataMoeda(fld, milSep, decSep, e) {
  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;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1 && whichCode != 8) return false;  // Not a valid key
    
  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 FormataPosMoeda(fld, milSep, decSep, e) {
  var i = y = 1;
  var strCheck = '0123456789';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 8) {
    var valor = '';
    var valor_aux = '';
    
   for( i = 0; i < fld.value.length; i++)
	if (strCheck.indexOf(fld.value.charAt(i))!=-1) valor += fld.value.charAt(i);

	var len = valor.length;
	
	if (len == 1) valor_aux = '';
	if (len == 2) valor_aux = '0'+ decSep + '0' + valor;
	if (len == 3) valor_aux = '0'+ decSep + valor;
	if (len > 3) {
		for(i = len-4,y=0; i >= 0; i--,y++)
		{
			if ( y == 3 )
			{
				valor_aux = milSep + valor_aux;
				y=0;
			}
			valor_aux = valor.charAt(i)+ valor_aux;
		}
		valor_aux += decSep + valor.charAt(len-3) + valor.charAt(len-2) + valor.charAt(len-1);
	}
	if ( valor_aux.indexOf("0,00") == 0 ) valor_aux = '';
	fld.value = valor_aux;	
  }
}
