function verificaCPF()
{
	var retorno = false;
	retorno = validaCPF(document.getElementById('formcadastro_txtCPFCadastrado').value);
	if (!retorno)
		window.alert('Preencha um CPF válido!');
	return retorno;
}

function LoginPedido()
{
	var CorErro = '#F00';
    var CorNormal= '#D9DADB';
    var retorno = true;
    var msg = '';
    
    var txtCpf = document.getElementById('txtCpf');
    var txtDia = document.getElementById('txtDia');
    var txtMes = document.getElementById('txtMes');
    var txtAno = document.getElementById('txtAno');
    
    if (!ValidaData(Trim(txtDia.value),Trim(txtMes.value),Trim(txtAno.value)))
    {
		msg = '- Preencha uma data válida';
		MudaCorBorda(txtDia, CorErro);
		MudaCorBorda(txtMes, CorErro);
		MudaCorBorda(txtAno, CorErro);
		retorno =  false;
    }
    else
    {
		if (Trim(txtDia.value)!='' && Trim(txtMes.value)!='' && Trim(txtAno.value)!='')
		{
			MudaCorBorda(txtDia, CorNormal);
			MudaCorBorda(txtMes, CorNormal);
			MudaCorBorda(txtAno, CorNormal);
		}
		else
		{
			msg = '- Preencha uma data válida';
			MudaCorBorda(txtDia, CorErro);
			MudaCorBorda(txtMes, CorErro);
			MudaCorBorda(txtAno, CorErro);
			retorno =  false;
		}
    }
    
    if (Trim(txtCpf.value)=='' || validaCPF(Trim(txtCpf.value))==false)
    {
		MudaCorBorda(txtCpf, CorErro);
		msg = msg + (msg=='' ? '' : '\n') + '- Preencha um CPF válido';
		retorno =  false;
    }
    else
    {
		MudaCorBorda(txtCpf, CorNormal);
    }
    
    if (!retorno)
    {
		window.alert(msg);
    }

	return retorno;
}

function ExperienciaProfissional(flag)
{
	var strStyle = 'none';
	if (flag)
		strStyle = 'block';
	document.getElementById('ddAnos').style.display = strStyle;
	document.getElementById('ddCargo').style.display = strStyle;
	document.getElementById('ddSubordinados').style.display = strStyle;
	document.getElementById('ddFaixa').style.display = strStyle;
	document.getElementById('formcadastro_fldExperienciaSim').checked = flag;
	document.getElementById('formcadastro_fldExperienciaNao').checked = !flag;
}

/*****************************Validação durante o preenchimento*******************************/
function ValidarCPF(campo)
{	
	var CorErro = '#F00';
    var CorNormal= '#D9DADB';	
    
	if(Trim(campo.value) != '' && validaCPF(Trim(campo.value)))
	{
		MudaCorBorda(campo,CorNormal);
	}
	else
	{		
		MudaCorBorda(campo,CorErro);
		window.alert('Preencha um CPF válido!');
	}	
}

function VerificaCPF(campo)
{
	var spanMsgValidacao = document.getElementById('spanMsgValidacaoCPF');
	var CorErro = '#F00';
    var CorNormal= '#D9DADB';	
    
	if(Trim(campo.value) == '' || validaCPF(Trim(campo.value)))
	{
		spanMsgValidacao.innerHTML = '';	
		
		formcadastro.ExisteCPF(Trim(campo.value), callback_ExisteCPF);
	}
	else
	{		
		MudaCorBorda(campo,CorErro);
		window.alert('CPF inválido');
	}	
}

function callback_ExisteCPF(res)
{
	if(!res.error)
	{
		document.getElementById('spanMsgValidacaoCPF').innerHTML = res.value;
		if (res.value!='')
			window.alert(res.value);
	}
	else
	{
		alert(res.error);
	}
}

function VerificaCNPJ(campo)
{
	var spanMsgValidacao = document.getElementById('spanMsgValidacaoCNPJ');
		
	if(Trim(campo.value) == '' || validaCNPJ(Trim(campo.value)))
	{
		spanMsgValidacao.innerHTML = '';	
		
		formcadastro.ExisteCNPJ(Trim(campo.value), callback_ExisteCNPJ);
	}
	else
	{
		spanMsgValidacao.innerHTML = '« CNPJ inválido';
	}
}

function callback_ExisteCNPJ(res)
{
	if(!res.error)
	{
		document.getElementById('spanMsgValidacaoCNPJ').innerHTML = res.value;
	}
	else
	{
		alert(res.error);
	}
}

function VerificaIE()
{
	var spanMsgValidacao	= document.getElementById('spanMsgValidacaoIE');
	var campo				= document.getElementById('formcadastro_txtPJIE');
	var check				= document.getElementById('formcadastro_ckbIsento');
	var retorno				= '';
		
	if(Trim(campo.value) == '' || (Trim(campo.value) == 'Isento' && check.checked) || Number(Trim(campo.value)).toString() != 'NaN')
	{
		spanMsgValidacao.innerHTML = '';	
		
	}
	else
	{
		spanMsgValidacao.innerHTML	= '« IE inválida';
		retorno						= '« IE inválida';
	}
	
	return retorno;
}

function VerificaDataNascimento()
{
	var spanMsgValidacao			= document.getElementById('spanMsgValidacaoDataNascimento');
	var currentTime					= new Date();
	var retorno						= '';

	var dia = document.getElementById('formcadastro_txtPFNascDia');
	var mes = document.getElementById('formcadastro_txtPFNascMes');
	var ano = document.getElementById('formcadastro_txtPFNascAno');
	
	if((Trim(dia.value) == '' && Trim(mes.value) == '' && Trim(ano.value) == '') || ValidaData(Trim(dia.value), Trim(mes.value), Trim(ano.value)))
	{
		if(Number(Trim(ano.value)) > currentTime.getFullYear() || (Number(Trim(ano.value)) == currentTime.getFullYear() && Number(Trim(mes.value)) > (currentTime.getMonth() +1)) || (Number(Trim(ano.value)) == currentTime.getFullYear() && Number(Trim(mes.value)) == (currentTime.getMonth() +1) && Number(Trim(dia.value)) > currentTime.getDate()))
		{
			spanMsgValidacao.innerHTML	= '« Você realmente veio do futuro?';	
			retorno						= '« Você realmente veio do futuro?';	
		}
		else
		{
			spanMsgValidacao.innerHTML = '';	
		}
		if(Trim(dia.value) == '' && Trim(mes.value) == '' && Trim(ano.value) == '')
		{
			retorno						= '« Data de nascimento inválida';
		}
	}
	else
	{
		if(Trim(dia.value) == '' || Trim(mes.value) == '' || Trim(ano.value) == '')
		{
			spanMsgValidacao.innerHTML	= '« Data de Nascimento incompleta';	
			retorno						= '« Data de Nascimento incompleta';	
		}
		else if(Number(Trim(ano.value)) < 1900)
		{
			spanMsgValidacao.innerHTML	= '« Somente nascimentos a partir de 1900';	
			retorno						= '« Somente nascimentos a partir de 1900';	
		}
		else
		{
			spanMsgValidacao.innerHTML	= '« Data de Nascimento inválida';	
			retorno						= '« Data de Nascimento inválida';	
		}
	}
	return retorno;
}

function VerificaCEP(campo)
{
	var spanMsgValidacao	= document.getElementById('spanMsgValidacaoCEP');
	var retorno				= ''
		
	if(Trim(campo.value).replace('-','') == '' || (Number(Trim(campo.value).replace('-','')).toString() != 'NaN' && Trim(campo.value).replace('-','').length == 8))
	{
		retorno = '';
	}
	else
	{
		if(Number(Trim(campo.value).replace('-','')).toString() == 'NaN')
		{
			window.alert('CEP inválido');
			retorno						= '« CEP inválido';	
		}
		else
		{
			window.alert('CEP incompleto');		
			retorno						= '« CEP incompleto';	
		}
	}
	return retorno;
}

function VerificaTelefone(tipo)
{
	var spanMsgValidacao		= document.getElementById('spanMsgValidacaoTel'+tipo);
	var ddd						= document.getElementById('formcadastro_txtTel'+tipo+'Ddd');
	var telefone				= document.getElementById('formcadastro_txtTel'+tipo);
	var ramal					= document.getElementById('formcadastro_txtRamal'+tipo);
	
	if(ddd == null)
	{
		ddd						= document.getElementById('txtTel'+tipo+'Ddd');
		telefone				= document.getElementById('txtTel'+tipo);
		ramal					= document.getElementById('txtRamal'+tipo);
	}
	
	var retorno					= '';
	
	if (ramal == null)
	{
		ramal = '';
	}
	else
	{
		ramal = ramal.value;
	}
	
	if(Trim(ddd.value) == '' || (Number(Trim(ddd.value)).toString() != 'NaN' && Trim(ddd.value).length == 2))
	{
		spanMsgValidacao.innerHTML = '';	
		
		if(Trim(telefone.value).replace('-','') == '' || Number(Trim(telefone.value).replace('-','')).toString() != 'NaN')
		{
			if(!(Trim(ramal) == '' || Number(Trim(ramal)).toString() != 'NaN'))
			{
				spanMsgValidacao.innerHTML	= '« Ramal inválido';
				retorno						= '« Ramal inválido';
			}		
			if(Trim(ddd.value) != '' || Trim(telefone.value) != '' || Trim(ramal) != '')
			{
				if(Trim(ddd.value) == '' || Trim(telefone.value) == '' || Trim(telefone.value).replace('-','').length < 7)
				{
					spanMsgValidacao.innerHTML	= '« Incompleto';
					retorno						= '« Incompleto';					
				}
			}			
		}
		else
		{
			if(tipo == 'Fax')
			{
				spanMsgValidacao.innerHTML	= '« Fax inválido';
				retorno						= '« Fax inválido';
			}
			else if(tipo == 'Cel')
			{
				spanMsgValidacao.innerHTML	= '« Celular inválido';
				retorno						= '« Celular inválido';
			}			
			else
			{
				spanMsgValidacao.innerHTML	= '« Telefone inválido';
				retorno						= '« Telefone inválido';
			}
		}		
	}
	else
	{
		if(Number(Trim(ddd.value)).toString() == 'NaN')
		{
			spanMsgValidacao.innerHTML	= '« DDD inválido';
			retorno						= '« DDD inválido';
		}
		else
		{
			spanMsgValidacao.innerHTML	= '« DDD incompleto';
			retorno						= '« DDD incompleto';
		}
	}
	return retorno;
}

function VerificaEmail()
{
	var spanMsgValidacao	= document.getElementById('spanMsgValidacaoEmail');
	var campo				= document.getElementById('formcadastro_txtEmail');
	var CorErro = '#F00';
    var CorNormal= '#D9DADB';
		
	if(Trim(campo.value) == '' || ValidaEmail(Trim(campo.value)))
	{
		spanMsgValidacao.innerHTML = '';	
		
		formcadastro.ExisteEmail(Trim(campo.value), callback_ExisteEmail);
		
	}
	else
	{		
		MudaCorBorda(campo,CorErro);		
		window.alert('E-mail inválido');
	}
	if(campo != '')
	{
		MudaCorBorda(campo,CorNormal);
	}
}

function callback_ExisteEmail(res)
{
	if(!res.error)
	{
		document.getElementById('spanMsgValidacaoEmail').innerHTML = res.value;
	}
	else
	{
		alert(res.error);
	}
}

function VerificaSenha()
{
	var spanMsgValidacao	= document.getElementById('spanMsgValidacaoSenha');
	var campo				= document.getElementById('formcadastro_txtSenha');
	var retorno				= '';
		
	if(Trim(campo.value) == '' || (Trim(campo.value).length >= 6 && ValidaSenha(Trim(campo.value))))
	{
		spanMsgValidacao.innerHTML = '';	
		
	}
	else
	{
		if(Trim(campo.value).length < 6)
		{
			spanMsgValidacao.innerHTML	= '« No mínimo 6 caracteres';
			retorno						= '« No mínimo 6 caracteres';		
		}
		else
		{
			spanMsgValidacao.innerHTML	= '« A Senha contém algum caractere inválido';
			retorno						= '« A Senha contém algum caractere inválido';
		}
	}
	
	return retorno;
}

function VerificaConfSenha()
{
	var spanMsgValidacao	= document.getElementById('spanMsgValidacaoConfirmacaoSenha');
	var campo				= document.getElementById('formcadastro_txtSenha');
	var campo1				= document.getElementById('formcadastro_txtSenhaConfirmacao');
	
	var retorno				= '';
		
	if(Trim(campo.value) == '' || Trim(campo1.value) == '' || Trim(campo.value) == Trim(campo1.value))
	{
		spanMsgValidacao.innerHTML = '';	
		
	}
	else
	{
		spanMsgValidacao.innerHTML	= '« Confirme corretamente a Senha';
		retorno						= '« Confirme corretamente a Senha';		
	}
	
	return retorno;
}

function VerificaCodigoSeguranca(campo)
{
	formcadastro.ValidaCodigoSeguranca(Trim(campo.value), callback_ValidaCodigoSeguranca);
}

function callback_ValidaCodigoSeguranca(res)
{
	if(!res.error)
	{
		document.getElementById('spanMsgValidacaoCodigoSeguranca').innerHTML = res.value;
	}
	else
	{
		alert(res.error);
	}
}

/*********************************************************************************************/
function ReloadImagemSeguranca()
{
	formcadastro.ReloadImagemSeguranca(callback_ReloadImagemSeguranca);
}

function callback_ReloadImagemSeguranca(res)
{
	if(!res.error)
	{
		document.getElementById('imgSeguranca').src = '../cadastro/codigoImagem.aspx?sc=' + res.value;
	}
	else
	{
		alert(res.error);
	}
}

function AtivarIsento()
{ 
	var ckbIsento = document.getElementById("formcadastro_ckbIsento"); 
	var txtPJIE = document.getElementById("formcadastro_txtPJIE");

	if(ckbIsento.checked) 
	{
		txtPJIE.value		= "Isento" ;
		txtPJIE.readOnly	= true;
	}
	else
	{
		txtPJIE.readOnly	= false;
		
		if(txtPJIE.value == "Isento")
		{
			txtPJIE.value		= "" ;
		}
	}
}


function VerificaTipoPessoa()
{
	try
	{
		var formcadastro_rdnPF		= document.getElementById('formcadastro_rdnPF');
		var formcadastro_rdnPJ		= document.getElementById('formcadastro_rdnPJ');
		
		var DadosPessoaFisica		= document.getElementById('DadosPessoaFisica');
		var DadosPessoaJuridica		= document.getElementById('DadosPessoaJuridica');
		
	    if(formcadastro_rdnPF.checked || (!formcadastro_rdnPF.checked && !formcadastro_rdnPJ.checked))
	    {
			DadosPessoaFisica.style.display		= 'block';	
			DadosPessoaJuridica.style.display	= 'none';
			formcadastro_rdnPF.checked			= true;
	    }	
	    else
	    {
			DadosPessoaFisica.style.display		= 'none';	
			DadosPessoaJuridica.style.display	= 'block';	    

	    }
	}
	catch(err)
	{
		alert(err.description);
	}
}

function VerificaTipoPessoaEdicao()
{
	try
	{
		VerificaTipoPessoa();

		if (document.getElementById('form_container'))
		{
			document.getElementById('form_container').style.display	= "none";
		}
	}
	catch(err)
	{
		alert(err.description);
	}
}

function VerificaTipoPessoaInclusao()
{
	try
	{
		VerificaTipoPessoa();

		if (document.getElementById('form_container'))
		{
			document.getElementById('form_container').style.display	= "block";
		}
	}
	catch(err)
	{
		alert(err.description);
	}
}



function CamposPreenchidos(ParentForm)
{
	var retorno = true;
    
    try
    {
		//var formcadastro_rdnPF					= document.getElementById('formcadastro_rdnPF');
		//var formcadastro_rdnPJ					= document.getElementById('formcadastro_rdnPJ');
        
        var formcadastro_txtPFNome              = document.getElementById('formcadastro_txtPFNome');
        var formcadastro_txtPFSobrenome         = document.getElementById('formcadastro_txtPFSobrenome');
        var formcadastro_txtPFCPF               = document.getElementById('formcadastro_txtPFCPF'); 
        var formcadastro_txtPFRG				= document.getElementById('formcadastro_txtPFRG');
        var formcadastro_txtPFNascDia           = document.getElementById('formcadastro_txtPFNascDia');
        var formcadastro_txtPFNascMes           = document.getElementById('formcadastro_txtPFNascMes');
        var formcadastro_txtPFNascAno           = document.getElementById('formcadastro_txtPFNascAno');
        
       /*
        var formcadastro_txtPJRazaoSocial       = document.getElementById('formcadastro_txtPJRazaoSocial');
        var formcadastro_txtPJCNPJ              = document.getElementById('formcadastro_txtPJCNPJ');
        var formcadastro_txtPJIE				= document.getElementById('formcadastro_txtPJIE');
        var formcadastro_txtPJNomeFantasia		= document.getElementById('formcadastro_txtPJNomeFantasia');
        */
        
        var formcadastro_txtCep					= document.getElementById('formcadastro_txtCep');
        var formcadastro_txtEndereco			= document.getElementById('formcadastro_txtEndereco');
        var formcadastro_txtNumero				= document.getElementById('formcadastro_txtNumero');        
        var formcadastro_txtComplemento			= document.getElementById('formcadastro_txtComplemento');
        var formcadastro_txtBairro				= document.getElementById('formcadastro_txtBairro');
        var formcadastro_txtCidade				= document.getElementById('formcadastro_txtCidade');
        
        var formcadastro_txtTel1Ddd				= document.getElementById('formcadastro_txtTel1Ddd');
        var formcadastro_txtTel1				= document.getElementById('formcadastro_txtTel1');
        var formcadastro_txtRamal1				= document.getElementById('formcadastro_txtRamal1');
		
        var formcadastro_txtTel2Ddd				= document.getElementById('formcadastro_txtTel2Ddd');
        var formcadastro_txtTel2				= document.getElementById('formcadastro_txtTel2');
        var formcadastro_txtRamal2				= document.getElementById('formcadastro_txtRamal2');
        
        var formcadastro_txtTel3Ddd				= document.getElementById('formcadastro_txtTel3Ddd');
        var formcadastro_txtTel3				= document.getElementById('formcadastro_txtTel3');
        var formcadastro_txtRamal3				= document.getElementById('formcadastro_txtRamal3');
                
        var formcadastro_txtTelCelDdd			= document.getElementById('formcadastro_txtTelCelDdd');
        var formcadastro_txtTelCel				= document.getElementById('formcadastro_txtTelCel');
        
        var formcadastro_txtTelFaxDdd			= document.getElementById('formcadastro_txtTelFaxDdd');
        var formcadastro_txtTelFax				= document.getElementById('formcadastro_txtTelFax');
        
        var formcadastro_txtEmail				= document.getElementById('formcadastro_txtEmail');      
        
        var formcadastro_fldExperienciaSim		= document.getElementById('formcadastro_fldExperienciaSim');
        var formcadastro_fldExperienciaNao		= document.getElementById('formcadastro_fldExperienciaNao');        
        var formcadastro_txtAnosExperiencia		= document.getElementById('formcadastro_txtAnosExperiencia');
        var formcadastro_ddlCargo				= document.getElementById('formcadastro_ddlCargo');
        var formcadastro_txtSubordinados		= document.getElementById('formcadastro_txtSubordinados');
        var formcadastro_ddlFormacao			= document.getElementById('formcadastro_ddlFormacao');
        var formcadastro_fldFaixaSalarial1		= document.getElementById('formcadastro_fldFaixaSalarial1');
        var formcadastro_fldFaixaSalarial2		= document.getElementById('formcadastro_fldFaixaSalarial2');        
        var formcadastro_fldFaixaSalarial3		= document.getElementById('formcadastro_fldFaixaSalarial3');
        var formcadastro_fldFaixaSalarial4		= document.getElementById('formcadastro_fldFaixaSalarial4');        
        var formcadastro_fldFaixaSalarial5		= document.getElementById('formcadastro_fldFaixaSalarial5');
        var formcadastro_ddlInstituicao			= document.getElementById('formcadastro_ddlInstituicao');  
        
              
        var formcadastro_ckbTermos				= document.getElementById('formcadastro_ckbTermos');
        var formcadastro_ckbAceiteContrato		= document.getElementById('formcadastro_ckbAceiteContrato');
        
        var MensagemErro = '';
        var CorErro = '#F00';
        var CorNormal= '#D9DADB';
        
        /*
        var formcadastro_txtSenha				= document.getElementById('formcadastro_txtSenha');
        var formcadastro_txtSenhaConfirmacao	= document.getElementById('formcadastro_txtSenhaConfirmacao'); 
        
        var formcadastro_txtCodigoSeguranca		= document.getElementById('formcadastro_txtCodigoSeguranca'); 
        */
              
        for (j=0; j<document.getElementsByTagName("span").length; j++)
		{
			var spanMsgValidacao = document.getElementsByTagName("span")[j];

			if (spanMsgValidacao.id.indexOf('spanMsgValidacao') > -1 && spanMsgValidacao.id.indexOf('spanMsgValidacaoEmail') == -1 && spanMsgValidacao.id.indexOf('spanMsgValidacaoCPF') == -1 && spanMsgValidacao.id.indexOf('spanMsgValidacaoCNPJ') == -1 && spanMsgValidacao.id.indexOf('spanMsgValidacaoCodigoSeguranca') == -1)
			{
				spanMsgValidacao.innerHTML = '';
			}
		}
        
		//if(formcadastro_rdnPF.checked)
		//{   
		if(Trim(formcadastro_txtPFNome.value) == '')           
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Nome';			
			MudaCorBorda(formcadastro_txtPFNome,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtPFNome, CorNormal);
		} 
		
		if(Trim(formcadastro_txtPFSobrenome.value) == '')      
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Sobrenome';				
			MudaCorBorda(formcadastro_txtPFSobrenome,CorErro);
			retorno = false;
		}
		else			
		{
			MudaCorBorda(formcadastro_txtPFSobrenome, CorNormal);
		}

		if(Trim(formcadastro_txtPFCPF.value) == '')            
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o CPF';				
			MudaCorBorda(formcadastro_txtPFCPF,CorErro);
			retorno = false;
		} 
		else
		{
			MudaCorBorda(formcadastro_txtPFCPF,CorNormal);
		}
		
		if(Trim(formcadastro_txtPFRG.value) == '')			   
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o RG';			
			MudaCorBorda(formcadastro_txtPFRG,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtPFRG,CorNormal);
		}
	    
		if(Trim(formcadastro_txtPFNascDia.value) == '' && Trim(formcadastro_txtPFNascMes.value) == '' && Trim(formcadastro_txtPFNascAno.value) == '')        
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha a Data de Nascimento';
			MudaCorBorda(formcadastro_txtPFNascDia,CorErro);
			MudaCorBorda(formcadastro_txtPFNascMes,CorErro);
			MudaCorBorda(formcadastro_txtPFNascAno,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtPFNascDia,CorNormal);
			MudaCorBorda(formcadastro_txtPFNascMes,CorNormal);
			MudaCorBorda(formcadastro_txtPFNascAno,CorNormal);
		}
    
		if(VerificaDataNascimento() != '')
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha a Data de Nascimento';
			MudaCorBorda(formcadastro_txtPFNascDia,CorErro);
			MudaCorBorda(formcadastro_txtPFNascMes,CorErro);
			MudaCorBorda(formcadastro_txtPFNascAno,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtPFNascDia,CorNormal);
			MudaCorBorda(formcadastro_txtPFNascMes,CorNormal);
			MudaCorBorda(formcadastro_txtPFNascAno,CorNormal);
		}
		/*
		}
		else if(formcadastro_rdnPJ.checked)
		{
			if(Trim(formcadastro_txtPJRazaoSocial.value) == '')		
			{
				document.getElementById('spanMsgValidacaoRazaoSocial').innerHTML = '« Preencha a Razão Social';
				retorno = false;
				MudaCorBorda(formcadastro_txtPJRazaoSocial,'red');
			}
			
			if(Trim(formcadastro_txtPJNomeFantasia.value) == '')    
			{
				document.getElementById('spanMsgValidacaoNomeFantasia').innerHTML = '« Preencha o Nome Fantasia';
				retorno = false;
				MudaCorBorda(formcadastro_txtPJNomeFantasia,'red');
			}

			if(Trim(formcadastro_txtPJCNPJ.value) == '')           
			{
				document.getElementById('spanMsgValidacaoCNPJ').innerHTML = '« Preencha o CNPJ';
				retorno = false;
				MudaCorBorda(formcadastro_txtPJCNPJ,'red');
			} 
		
			if(Trim(formcadastro_txtPJCNPJ.value) != '' && document.getElementById('spanMsgValidacaoCNPJ').innerHTML != '')
			{
				retorno = false;
				MudaCorBorda(formcadastro_txtPJCNPJ,'red');
			} 
			
			if(Trim(formcadastro_txtPJIE.value) == '')				
			{
				document.getElementById('spanMsgValidacaoIE').innerHTML = '« Preencha a IE';				
				retorno = false;
				MudaCorBorda(formcadastro_txtPJIE,'red');
			} 
			
			if(Trim(formcadastro_txtPJIE.value) != '' && VerificaIE() != '')				
			{
				retorno = false;
				MudaCorBorda(formcadastro_txtPJIE,'red');
			} 
		} 
	    */
		if(Trim(formcadastro_txtCep.value).replace('-','') == '')				
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o CEP';			
			MudaCorBorda(formcadastro_txtCep,CorErro);
			retorno = false;
		} 
		else
		{
			MudaCorBorda(formcadastro_txtCep,CorNormal);		
		}		
		
		if(VerificaCEP(formcadastro_txtCep) != '')
		{		
			MudaCorBorda(formcadastro_txtCep,CorErro);		
			retorno = false;
		}		
		
		if(Trim(formcadastro_txtEndereco.value) == '')          
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Endereço';			
			MudaCorBorda(formcadastro_txtEndereco,CorErro);
			retorno = false;
		} 
		else
		{
			MudaCorBorda(formcadastro_txtEndereco,CorNormal);
		}
		
		if(Trim(formcadastro_txtNumero.value) == '')			
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Número';			
			MudaCorBorda(formcadastro_txtNumero,CorErro);
			retorno = false;
		} 
		else		
		{
			MudaCorBorda(formcadastro_txtNumero,CorNormal);
		}
		
		if(Trim(formcadastro_txtBairro.value) == '')            
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Bairro';		
			MudaCorBorda(formcadastro_txtBairro,CorErro);
			retorno = false;
		} 
		else
		{
			MudaCorBorda(formcadastro_txtBairro,CorNormal);
		}
		
		if(Trim(formcadastro_txtCidade.value) == '')			
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha a Cidade';			
			MudaCorBorda(formcadastro_txtCidade,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtCidade,CorNormal);
		}
	    
	    if(Trim(formcadastro_txtTel1Ddd.value) == '' || Trim(formcadastro_txtTel1.value) == '')			
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Telefone 1';		
			MudaCorBorda(formcadastro_txtTel1Ddd, CorErro);
			MudaCorBorda(formcadastro_txtTel1, CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtTel1Ddd,CorNormal);
			MudaCorBorda(formcadastro_txtTel1,CorNormal);
		} 
		
		if(VerificaTelefone('1') != '')
		{	
			MudaCorBorda(formcadastro_txtTel1Ddd,CorErro);		
			MudaCorBorda(formcadastro_txtTel1,CorErro);
			retorno = false;
		}		
		
		if(VerificaTelefone('2') != '')
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Telefone 2';			
			MudaCorBorda(formcadastro_txtTel2Ddd,CorErro);		
			MudaCorBorda(formcadastro_txtTel2,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtTel2Ddd,CorNormal);		
			MudaCorBorda(formcadastro_txtTel2,CorNormal);
		}
		
		if(VerificaTelefone('3') != '')
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Telefone 3';			
			MudaCorBorda(formcadastro_txtTel3Ddd,CorErro);		
			MudaCorBorda(formcadastro_txtTel3,CorErro);			
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtTel3Ddd,CorNormal);		
			MudaCorBorda(formcadastro_txtTel3,CorNormal);		
		}		
		
		if(VerificaTelefone('Cel') != '')
		{			
			MudaCorBorda(formcadastro_txtTelCelDdd,CorErro);		
			MudaCorBorda(formcadastro_txtTelCel,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtTelCelDdd,CorNormal);		
			MudaCorBorda(formcadastro_txtTelCel,CorNormal);
		}
		
		if(VerificaTelefone('Fax') != '')
		{			
			MudaCorBorda(formcadastro_txtTelFax,CorErro);		
			MudaCorBorda(formcadastro_txtTelFax,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtTelFax,CorNormal);		
			MudaCorBorda(formcadastro_txtTelFax,CorNormal);
		}

		if(Trim(formcadastro_txtEmail.value) == '')
		{
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o E-mail';			
			MudaCorBorda(formcadastro_txtEmail,CorErro);
			retorno = false;
		}
		else
		{
			MudaCorBorda(formcadastro_txtEmail,CorNormal);
		} 

		/*
		if(ParentForm == 'FormInclusaoCadastro')
		{
			if(Trim(formcadastro_txtSenha.value) == '')				
			{
				document.getElementById('spanMsgValidacaoSenha').innerHTML = '« Preencha a Senha';	
				retorno = false;
				MudaCorBorda(formcadastro_txtSenha,'red');
			} 

			if(Trim(formcadastro_txtSenha.value) != '' && VerificaSenha() != '')				
			{
				retorno = false;
				MudaCorBorda(formcadastro_txtSenha,'red');
			} 
						
			if(Trim(formcadastro_txtSenhaConfirmacao.value) == '')  
			{
				document.getElementById('spanMsgValidacaoConfirmacaoSenha').innerHTML = '« Preencha a Confirmação da Senha';	
				retorno = false;
				MudaCorBorda(formcadastro_txtSenhaConfirmacao,'red');
			} 
			
			if(formcadastro_txtSenhaConfirmacao.value != '' && VerificaConfSenha() != '')
			{
				retorno = false;
				MudaCorBorda(formcadastro_txtSenhaConfirmacao,'red');
			} 
		}
		
		if(document.getElementById('BlocoSeguranca').style.display != 'none')
		{
			if(Trim(formcadastro_txtCodigoSeguranca.value) == '')
			{
				document.getElementById('spanMsgValidacaoCodigoSeguranca').innerHTML = '« Preencha a seqüência';	
				retorno = false;
				MudaCorBorda(formcadastro_txtCodigoSeguranca,'red');
			}
			
			if(Trim(formcadastro_txtCodigoSeguranca.value) != '' && document.getElementById('spanMsgValidacaoCodigoSeguranca').innerHTML != '')
			{
				retorno = false;
				MudaCorBorda(formcadastro_txtCodigoSeguranca,'red');
			} 	
		}
		*/
		
		/* =============== Início Validação Dados Complementares ===================== */
		if (formcadastro_fldExperienciaSim.checked)
		{
			if (Trim(formcadastro_txtAnosExperiencia.value) == '')
			{
				retorno = false;
				MudaCorBorda(formcadastro_txtAnosExperiencia,'red');
				MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha Anos de Experiência';
			}
			else
			{
				if (isNaN(formcadastro_txtAnosExperiencia.value))
				{
					retorno = false;
					MudaCorBorda(formcadastro_txtAnosExperiencia,'red');
					MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha Anos de Experiência';
				}
			}
			
			if(formcadastro_ddlCargo.selectedIndex == 0)
			{
				retorno = false;
				MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Escolha o cargo';
			}
			
			if(Trim(formcadastro_txtSubordinados.value) == '')
			{
				retorno = false;
				MudaCorBorda(formcadastro_txtSubordinados,'red');
				MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Número de Subordinados';
			}
			else
			{
				if (isNaN(formcadastro_txtSubordinados.value))
				{
					retorno = false;
					MudaCorBorda(formcadastro_txtSubordinados,'red');
					MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Preencha o Número de Subordinados';					
				}
			}
			
			if(
				!(formcadastro_fldFaixaSalarial1.checked ||
				formcadastro_fldFaixaSalarial2.checked ||
				formcadastro_fldFaixaSalarial3.checked ||
				formcadastro_fldFaixaSalarial4.checked ||
				formcadastro_fldFaixaSalarial5.checked)
			)
			{
				retorno = false;
				MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Escolha a Faixa Salarial';				
			}
		}
		
		if(formcadastro_ddlInstituicao.selectedIndex == 0)
		{
			retorno = false;
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Escolha a Formação Acadêmica';
		}
		
		if(formcadastro_ddlFormacao.selectedIndex == 0)
		{
			retorno = false;
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Escolha a Instituição de Ensino';
		}
		
		/* =============== Fim Validação Dados Complementares ===================== */
		if(formcadastro_ckbTermos != null)
		{
			if(formcadastro_ckbTermos.checked == false)
			{
				retorno = false;
				MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Para continuar é necessário aceitar os termos de serviço';
			}
		}
		
		if(formcadastro_ckbAceiteContrato.checked == false)
		{
			retorno = false;
			MensagemErro = MensagemErro + (MensagemErro=='' ? '' : '\n') + '- Para continuar é necessário aceitar as cláusulas do contrato';
		}
    }
    catch(err)
    {
        alert(err.description);
    }
    
    if(!retorno)
    {
		alert('Atenção!\n\rHá informações não preenchidas corretamente!\n' + MensagemErro);
    }
    
    return retorno;          
}

function MudaCorBorda(obj, cor)
{
    try
    {        
		if(obj != null)
		{
			var Borda               = '1,9px';
			var BordaEstilo         = 'solid';
	        
			obj.style.border        = Borda;
			obj.style.borderStyle   = BordaEstilo;
			obj.style.borderColor   = cor;        
		}
    }
    catch(err)
    {
        document.write(err.description);
    }    
}

/* CADASTRO */
function validaCPF(cpf) 
{
	var retorno = true;
	

	if(cpf == "")
	{
		retorno = false;
	}
	else
	{
		cpf = cpf.replace(".", "");
		cpf = cpf.replace(".", "");
		cpf = cpf.replace(".", "");
		cpf = cpf.replace(",", "");
		cpf = cpf.replace("-", "");
		cpf = cpf.replace(" ", "");

		erro = new String;
		if (cpf.length < 11) erro += "Sao necessarios 11 dígitos para verificação do CPF! \n\n"; 
		var nonNumbers = /\D/;
		if (nonNumbers.test(cpf)) erro += "A verificação de CPF suporta apenas números! \n\n"; 
		
		/*if(cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")*/
		if(cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
		{
				erro += "Número de CPF inválido!"
		}
	
		var a = [];
		var b = new Number;
		var c = 11;
		
		for (i=0; i<11; i++)
		{
				a[i] = cpf.charAt(i);
				if (i < 9) b += (a[i] * --c);
		}
		
		if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
		
		b = 0;
		c = 11;
		
		for (y=0; y<10; y++) b += (a[y] * c--); 
		
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]))
		{
				erro +="Dígito verificador com problema!";
		}
		
		if (erro.length > 0)
		{
			//alert("Numero de CPF invalido!");
			retorno = false;
		}
		
		if(cpf == "55555555555")
		{
			return true;
		}
	}    

	return retorno;
}


function validaCNPJ(cnpj)
{
	var retorno = true;
	
	CNPJ = Trim(cnpj);
	
	erro = new String;
	
	/*
	if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! "; 
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
	if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! ";
	}
	//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 ("/","");
	}
	*/
	
	CNPJ = CNPJ. replace (".","");
	CNPJ = CNPJ. replace (".","");
	CNPJ = CNPJ. replace ("-","");
	CNPJ = CNPJ. replace ("/","");
			
			
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! "; 
	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])){
			erro +="Dígito verificador com problema!";
	}
	
	if (erro.length > 0)
	{
		//alert("Numero de CNPJ invalido!");
		retorno = false;
	}
				
    return retorno;				
}

function ValidaSenha(senha)
{
	var retorno = true;

	var filter=/((\w)|([@#$%^&+=])){6,}$/i; 
		
	if (!filter.test(senha)) 
	{
		retorno = false;
	}

	return retorno;
}


function Mascara(src, mask) 
{
     var i = src.value.length;
     var saida = mask.substring(0,1);
     var texto = mask.substring(i)
     if (texto.substring(0,1) != saida) 
     {
          src.value += texto.substring (0,1);
     }
}

function ValidaData(dia, mes, ano)
{
	retorno = true;
		
	/* foi encontrado um bug no javascript (IE 6 e Firefox 2) na execucção
	   de parseInt com a string '08' retornando 0.   */
    
	dia = Number(dia);
	mes = Number(mes);
	ano = Number(ano);    

	if(Trim(dia.toString()) == 'NaN' || Trim(mes.toString()) == 'NaN' || Trim(ano.toString()) == 'NaN')
	{
		return false;
	}
	
	if(ano < 1900)
	{
		return false;
	}
	
	switch (mes) 
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        {
            if  (dia > 31) 
            {
                retorno = false;
            }
            break
        }
        
        case 4:        
        case 6:
        case 9:
        case 11:
        {
            if  (dia > 30) 
            {
            
                retorno = false;
            }
            break
        }
        case 2:
        {
			var bissexto = 0;
            /* Validando ano Bissexto / fevereiro / dia */
            if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) 
            { 
                bissexto = 1; 
            } 
            if ((bissexto == 1) && (dia > 29)) 
            { 
                retorno = false;;                 
            } 
            if ((bissexto != 1) && (dia > 28)) 
            { 
                retorno = false; 
            }            
            break                      
		}
		default:
		{
			retorno = false;
			break;
		}
    }

   	return retorno;
}


function ColocaFocoEm(NomeObj, e) 
{ 
	try
	{
		var key; 
		if(window.event) 
		{ 
			key = event.keyCode; 
		}
		else
		{ 
			key = e.which; 
		}
		if(key == 13)
		{
			document.getElementById(NomeObj).focus();
			event.keyCode = 0;
		}
	} 
	catch(err)
	{
		alert(err.description);
	}
	
	return false;
} 

/* Ajax */
function CarregaEndereco(campo)
{
	
	var CEP = campo.replace("-","");
	//TrocaImagem("loading", "visible");
	
	if(Number(CEP).toString() != 'NaN')
	{		
		formcadastro.CarregaEndereco(CEP, CarregaEndereco_CallBack);
	}
}

function CarregaEndereco_CallBack(response)
{
	
	if(!response.error)
	{
		
		var retorno = response.value;
		
		if(retorno[0])
		{
			var Cep = document.getElementById(retorno[5] + "txtCep").value;
			
			if(Cep.indexOf("-") == -1)
			{
				Cep = Cep.substr(0,5) + "-" + Cep.substr(5,3);
			}
			
			document.getElementById(retorno[5] + "txtCep").value		= Cep;
			document.getElementById(retorno[5] + "txtEndereco").value	= retorno[1];
			document.getElementById(retorno[5] + "txtBairro").value		= retorno[2];
			document.getElementById(retorno[5] + "txtCidade").value		= retorno[3];
			
			document.getElementById(retorno[5] + "ddlEstado").value		= retorno[4];
		}
		else
		{
			document.getElementById(retorno[2] + "txtEndereco").value	= "";
			document.getElementById(retorno[2] + "txtBairro").value		= "";
			document.getElementById(retorno[2] + "txtCidade").value		= "";
			document.getElementById(retorno[2] + "ddlEstado").value		= "SP";
		}
	}
	else
	{		
		alert(response.error);
	}
		
	//TrocaImagem("loading", "hidden");
}


