function validacpf(s){
	numcpf=s.value;
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}
	alert ("Numero do CPF inválido");
	return false;
 
} 

function validaCadastre(){
	nome=document.form_cadastre.nome_nome;
	cpf=document.form_cadastre.nome_cpf;
	endereco=document.form_cadastre.nome_endereco;
	numero=document.form_cadastre.nome_numero;
	complemento=document.form_cadastre.nome_complemento;
	
	dddcel=document.form_cadastre.nome_dddcel;
	cel=document.form_cadastre.nome_cel;
	dddres=document.form_cadastre.nome_dddres;
	res=document.form_cadastre.nome_res;
	mail=document.form_cadastre.nome_mail;
	
	aniversario=document.form_cadastre.nome_aniversario;
	profissao=document.form_cadastre.nome_profissao;
	estado_civil=document.form_cadastre.nome_estado_civil;
	
	sms=document.form_cadastre.nome_sms;
	newsletter=document.form_cadastre.nome_newsletter;


	ok=true;
	if (nome.value == "" && ok) {
		alert('Por favor, preencha o nome');
		ok=false;
		nome.focus();
		}
	if (cpf.value == "" && ok) {
		alert('Por favor, preencha o CPF');
		ok=false;
		cpf.focus();
		}
	doDigits(cpf);
	if (cpf.value == "" && ok) {
		ok = false;
		}
	if(ok){
		ok = validacpf(cpf);
		}
	
	if (endereco.value == "" && ok) {
		alert('Por favor, preencha o endereço');
		ok=false;
		endereco.focus();
		}
	if (numero.value == "" && ok) {
		alert('Por favor, preencha o número');
		ok=false;
		numero.focus();
		}
	doDigits(numero);
	
	
	
	
	if (dddcel.value == "" && ok) {
		alert('Por favor, preencha o DDD do celular');
		ok=false;
		dddcel.focus();
		}
	doDigits(dddcel);
	
	if (cel.value == "" && ok) {
		alert('Por favor, preencha o celular');
		ok=false;
		cel.focus();
		}
	doDigits(cel);
		
	if (mail.value == "" && ok) {
		alert('Por favor, preencha um email');
		ok=false;
		mail.focus();
		}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail.value))&& ok){ 
		alert('Por favor, preencha um email correto');
		ok=false;
		mail.focus();
		} 
		
	if (aniversario.value != "" && ok) {
		ok = validarData(aniversario);
		}
	
	if(ok){
		avisoAjaxCarregando=true;
		URL = 'includes/act/act_cadastre.php?nome='+nome.value+'&mail='+mail.value+'&cpf='+cpf.value+'&numero='+numero.value+'&endereco='+endereco.value+'&complemento='+complemento.value+'&dddcel='+dddcel.value+'&cel='+cel.value+'&dddres='+dddres.value+'&res='+res.value+'&profissao='+profissao.value+'&estado_civil='+estado_civil.value+'&aniversario='+aniversario.value+'&newsletter='+newsletter.value+'&sms='+sms.value;
		ajaxGet(URL,document.getElementById("form_aviso2"),true);

		}
	}
	
function validacpf(s){
	numcpf=s.value;
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}
	alert ("Numero do CPF inválido");
	return false;
 
} 

function atualizaCadastre(){
	nome=document.form_cadastre.nome_nome;
	cpf=document.form_cadastre.nome_cpf;
	endereco=document.form_cadastre.nome_endereco;
	numero=document.form_cadastre.nome_numero;
	complemento=document.form_cadastre.nome_complemento;
	conta=document.form_cadastre.nome_conta;
	
	dddcel=document.form_cadastre.nome_dddcel;
	cel=document.form_cadastre.nome_cel;
	dddres=document.form_cadastre.nome_dddres;
	res=document.form_cadastre.nome_res;
	mail=document.form_cadastre.nome_mail;
	
	aniversario=document.form_cadastre.nome_aniversario;
	profissao=document.form_cadastre.nome_profissao;
	estado_civil=document.form_cadastre.nome_estado_civil;
	
	sms=document.form_cadastre.nome_sms;
	newsletter=document.form_cadastre.nome_newsletter;


	ok=true;
	if (nome.value == "" && ok) {
		alert('Por favor, preencha o nome');
		ok=false;
		nome.focus();
		}
	if (cpf.value == "" && ok) {
		alert('Por favor, preencha o CPF');
		ok=false;
		cpf.focus();
		}
	doDigits(cpf);
	if (cpf.value == "" && ok) {
		ok = false;
		}
	if(ok){
		ok = validacpf(cpf);
		}
	
	if (endereco.value == "" && ok) {
		alert('Por favor, preencha o endereço');
		ok=false;
		endereco.focus();
		}
	if (numero.value == "" && ok) {
		alert('Por favor, preencha o número');
		ok=false;
		numero.focus();
		}
	doDigits(numero);
	
	
	
	
	if (dddcel.value == "" && ok) {
		alert('Por favor, preencha o DDD do celular');
		ok=false;
		dddcel.focus();
		}
	doDigits(dddcel);
	
	if (cel.value == "" && ok) {
		alert('Por favor, preencha o celular');
		ok=false;
		cel.focus();
		}
	doDigits(cel);
		
	if (mail.value == "" && ok) {
		alert('Por favor, preencha um email');
		ok=false;
		mail.focus();
		}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail.value))&& ok){ 
		alert('Por favor, preencha um email correto');
		ok=false;
		mail.focus();
		} 
		
	if (aniversario.value != "" && ok) {
		ok = validarData(aniversario);
		}
	
	if(ok){
		URL = 'includes/act/act_cadastre.php?nome='+nome.value+'&mail='+mail.value+'&cpf='+cpf.value+'&numero='+numero.value+'&endereco='+endereco.value+'&complemento='+complemento.value+'&dddcel='+dddcel.value+'&cel='+cel.value+'&dddres='+dddres.value+'&res='+res.value+'&profissao='+profissao.value+'&estado_civil='+estado_civil.value+'&aniversario='+aniversario.value+'&newsletter='+newsletter.value+'&sms='+sms.value+'&atualiza=1&conta='+conta.value;
		ajaxGet(URL,document.getElementById("form_aviso2"),true);

		}
	}