//####################################################################################################
//******************************* 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 SEXO #####################	
	if (document.cadastro.chFl_Sexo.selectedIndex == 0) 
	{
		alert("Selecione o Campo Sexo.");
		document.cadastro.chFl_Sexo.focus();
		return false;
	}
	
	//############## DIA NASCIMENTO #####################
	if (document.cadastro.nas_dia.selectedIndex == 0) 
	{
		alert("Selecione o Dia de seu nascimento.");
		document.cadastro.nas_dia.focus();
		return false;
	}
	
	//############## MÊS NASCIMENTO #####################
	if (document.cadastro.nas_mes.selectedIndex == 0) 
	{
		alert("Selecione o Mês de seu nascimento.");
		document.cadastro.nas_mes.focus();
		return false;
	}
	
	//############## ANO NASCIMENTO #####################
	if (document.cadastro.nas_ano.selectedIndex == 0) 
	{
		alert("Selecione o Ano de seu nascimento.");
		document.cadastro.nas_ano.focus();
		return false;
	}
	
	//############## PROFISSAO #####################
	if (document.cadastro.vcND_Profissao.value == "" || document.cadastro.vcND_Profissao.value.length < 5 || Replace(document.cadastro.vcND_Profissao.value,",","") == "" || Replace(document.cadastro.vcND_Profissao.value,"'","") == "" || Replace(Replace(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 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 BAIRRO #####################
	if (Trim(document.cadastro.vcND_Bairro.value) == "")
	{
		 alert("O Campo Bairro é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.vcND_Bairro.focus();
		 return false;
	}
	
	//############## CAMPO CEP #####################
	if (Trim(document.cadastro.vcND_CEP.value) == "")
	{
		 alert("O Campo CEP é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.vcND_CEP.focus();
		 return false;
	}
	
	//############## CAMPO CIDADE #####################
	if (document.cadastro.vcND_Cidade.value == "" || document.cadastro.vcND_Cidade.value.length < 5 || 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.vcND_DDDResidencial.value) == "")
	{
		 alert("O Campo DDD é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.vcND_DDDResidencial.focus();
		 return false;
	}
	
	//############## CAMPO TEL RESIDENCIAL #####################
	if (Trim(document.cadastro.vcND_TelResidencial.value) == "")
	{
		 alert("O Campo Telefone é de preenchimento obrigatório. Preencha-o corretamente.");
		 document.cadastro.vcND_TelResidencial.focus();
		 return false;
	}
	
	//############## PROFISSAO #####################
	if (document.cadastro.vcND_Caso.value == "" || document.cadastro.vcND_Caso.value.length < 5 || Replace(document.cadastro.vcND_Caso.value,",","") == "" || Replace(document.cadastro.vcND_Caso.value,"'","") == "" || Replace(Replace(document.cadastro.vcND_Caso.value,"'","")," ","") == "") 
	{
			alert("O Campo Caso é de preenchimento obrigatório. Preencha-o corretamente.");
			document.cadastro.vcND_Caso.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 fDataValida(data){
   var err=0;
   if (data.length != 10) {
      err=1;
   }
 
   dia     = data.substring(0, 2); // dia
   barra_1 = data.substring(2, 3); // '/'
   mes     = data.substring(3, 5); // mes
   barra_2 = data.substring(5, 6); // '/'
   ano     = data.substring(6, 10); // ano


	if (isNaN(dia) != false && dia != "") err = 1;
	if (isNaN(mes) != false && mes != "") err = 1;
	if (isNaN(ano) != false && ano != "") err = 1;


   //check de erros b&aacute;sicos
   if (mes<1 || mes>12) err = 1;
   if (barra_1 != '/') err = 1;
   if (dia<1 || dia>31) err = 1;
   if (barra_2 != '/') err = 1;
   if (ano<1900 || ano>2999) err = 1;
 
   // meses com 30 dias
   if (mes==4 || mes==6 || mes==9 || mes==11){
      if (dia==31) err=1;
   }
 
   // tratamento para fevereiro
   if (mes==2){
      var aux=parseInt(ano/4);
      if (isNaN(aux)) {
         err=1;
      }
 
      if (dia>29) err=1;
      if (dia==29 && ((ano/4)!=parseInt(ano/4))) err=1;
   }
 
   if (err==1){
      return false;
   } else {
      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;
}
