//####################################################################################################
//******************************* FUNÇÕES PARA O FORMULÁRIO DE INSCRIÇÃO *****************************
//####################################################################################################
function valida(){ 			
	//############## CAMPO NOME #####################			
	if (document.cadastro.vcND_Nome.value == "" || document.cadastro.vcND_Nome.value.length < 5 || Replace(document.cadastro.vcND_Nome.value,",","") == "" || Replace(document.cadastro.vcND_Nome.value,"'","") == "" || Replace(Replace(document.cadastro.vcND_Nome.value,"'","")," ","") == "") 
	{
			alert("O Campo Nome é de preenchimento obrigatório. Preencha-o corretamente.");
			document.cadastro.vcND_Nome.focus();
			return false;
	} 
	
	//############## CAMPO EMAIL #####################
	if (Trim(document.cadastro.vcND_Email.value) != "") {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.cadastro.vcND_Email.value)) && document.cadastro.vcND_Email.value != "") 
		{ 
			alert("Favor informar um E-mail válido.");
			document.cadastro.vcND_Email.focus();
			return false;
		}		
	}
	
	//############## CAMPO EMAIL #####################
	if (Trim(document.cadastro.vcND_Email.value) == "") 
	{				
		alert("O Campo E-mail é de preenchimento obrigatório. Preencha-o corretamente.");
		document.cadastro.vcND_Email.focus();
		return false;
	}
				
	//############## CAMPO CPF #####################	
	if (!checaCPF(document.cadastro.chND_CPF.value)) 
	{
		 errors="1";
		 if (errors) alert('Informe o seu CPF corretamente. Preencha-o corretamente.');
		 document.cadastro.chND_CPF.focus();
		 return false;
	}
	
	//############## CAMPO SEXO #####################	
	if (document.cadastro.chFl_Sexo.selectedIndex == 0) 
	{
		alert("Selecione o Campo Sexo.");
		document.cadastro.chFl_Sexo.focus();
		return false;
	}
	
	//############## ESTADO CIVIL #####################
	if (document.cadastro.vcND_EstadoCivil.selectedIndex == 0) 
	{
		alert("Selecione seu Estado Civil.");
		document.cadastro.vcND_EstadoCivil.focus();
		return false;
	}
	
	//############## DIA NASCIMENTO #####################
	if (document.cadastro.inNR_Dia.selectedIndex == 0) 
	{
		alert("Selecione o Dia de seu nascimento.");
		document.cadastro.inNR_Dia.focus();
		return false;
	}
	
	//############## MÊS NASCIMENTO #####################
	if (document.cadastro.inNR_Mes.selectedIndex == 0) 
	{
		alert("Selecione o Mês de seu nascimento.");
		document.cadastro.inNR_Mes.focus();
		return false;
	}
	
	//############## ANO NASCIMENTO #####################
	if (document.cadastro.inNR_Ano.selectedIndex == 0) 
	{
		alert("Selecione o Ano de seu nascimento.");
		document.cadastro.inNR_Ano.focus();
		return false;
	}
	
	//############## CAMPO ENDEREÇO #####################
	if (document.cadastro.vcND_Endereco.value == "" || document.cadastro.vcND_Endereco.value.length < 5 || Replace(document.cadastro.vcND_Endereco.value,",","") == "" || Replace(document.cadastro.vcND_Endereco.value,"'","") == "" || Replace(Replace(document.cadastro.vcND_Endereco.value,"'","")," ","") == "") 
	{
			alert("O Campo Endereço é de preenchimento obrigatório. Preencha-o corretamente.");
			document.cadastro.vcND_Endereco.focus();
			return false;
	} 	
	
	//############## CAMPO CEP #####################
	if (Trim(document.cadastro.chND_CEP.value) == "")
	{
		 alert("O Campo CEP é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.chND_CEP.focus();
		 return false;
	}
	
	//############## CAMPO CIDADE #####################
	if (document.cadastro.vcND_Cidade.value == "" || document.cadastro.vcND_Cidade.value.length < 3 || Replace(document.cadastro.vcND_Cidade.value,",","") == "" || Replace(document.cadastro.vcND_Cidade.value,"'","") == "" || Replace(Replace(document.cadastro.vcND_Cidade.value,"'","")," ","") == "") 
	{
			alert("O Campo Cidade é de preenchimento obrigatório. Preencha-o corretamente.");
			document.cadastro.vcND_Cidade.focus();
			return false;
	} 
	
	//############## CAMPO ESTADO #####################
	if (document.cadastro.chND_UF.selectedIndex == 0) 
	{
		alert("Selecione o Campo Estado.");
		document.cadastro.chND_UF.focus();
		return false;
	}
							
	//############## CAMPO DDD RESIDENCIAL #####################	
	if (Trim(document.cadastro.chND_DDD.value) == "")
	{
		 alert("O Campo DDD é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.chND_DDD.focus();
		 return false;
	}
	
	//############## CAMPO TEL RESIDENCIAL #####################
	if (Trim(document.cadastro.chND_Telefone.value) == "")
	{
		 alert("O Campo Telefone é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.chND_Telefone.focus();
		 return false;
	}
	
	//############## CAMPO PROFISSÃO ##############	
	if (Trim(document.cadastro.vcND_Profissao.value) == "")
	{
		 alert("O Campo Profissão é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.vcND_Profissao.focus();
		 return false;
	}
	
	//############## CAMPO ESCOLARIDADE #####################
	if (document.cadastro.vcND_Escolaridade.selectedIndex == 0) 
	{
		alert("Selecione o Campo Escolaridade.");
		document.cadastro.vcND_Escolaridade.focus();
		return false;
	}
	
	//############## CAMPO DDD PESSOA PROBLEMA #####################	
	if (Trim(document.cadastro.vcND_Historia.value) == "")
	{
		 alert("O Campo História é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.vcND_Historia.focus();
		 return false;
	}
			
	//############## CAMPO FOTO #####################
	if (Trim(document.cadastro.uploadArquivo.value) == "") {
		alert("Favor selecionar uma foto para completar o cadastro.");
		document.cadastro.uploadArquivo.focus();
		return false;
	}
				
	 return true;
 }

function checaCPF (CPF) 
{
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999" || CPF == "00000000191")
		{
		return false;
		}
	soma = 0;
	for (i=0; i < 9; i ++)
		{
		soma += parseInt(CPF.charAt(i)) * (10 - i);
		}
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		{
		resto = 0;
		}
	if (resto != parseInt(CPF.charAt(9)))
		{
		return false;
		}
	soma = 0;
	for (i = 0; i < 10; i ++)
		{
		soma += parseInt(CPF.charAt(i)) * (11 - i);
		}
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		{
		resto = 0;
		}
	if (resto != parseInt(CPF.charAt(10)))
		{
		return false;
		}
	else
		{
//        alert('Correto');
		return true;
		}
}

function soNumeros(fld, e) 
{
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789,';
	
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	key = String.fromCharCode(whichCode);  
	if (strCheck.indexOf(key) == -1) return false;  
}
function soLetras(fld, e) 
{
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = 'abcdefghijlmnopqrstuxvyzwykABCDEFGHIJLMNOPQRSTUVXZWYKÀÁÂÃáàâãÉÈÊéèêÍÌíìÔÕÓÒôõóÚÙÜúùüÇç1234567890&+-ºª°@. ';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	key = String.fromCharCode(whichCode);  
	if (strCheck.indexOf(key) == -1) return false;  
}

function soLetrasNumeros(fld, e) 
{
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = 'abcdefghijlmnopqrstuxvyzwykABCDEFGHIJLMNOPQRSTUVXZWYK1234567890- ';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	key = String.fromCharCode(whichCode);  
	if (strCheck.indexOf(key) == -1) return false;  
}

function soData(fld, e) 
{
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '1234567890/';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	key = String.fromCharCode(whichCode);  
	if (strCheck.indexOf(key) == -1) return false;  
}


function Trim(STRING){
	STRING = LTrim(STRING);
	return RTrim(STRING);
}

function RTrim(STRING){
	while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}


function LTrim(STRING){
	while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}

function Replace(STRING,REPLACE_THIS,REPLACE_WITH){
	while(STRING.indexOf(REPLACE_THIS) > -1){
		STRING = STRING.replace(REPLACE_THIS,REPLACE_WITH);
	}
	return STRING;
}