function limpa_string(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";

	for (var i=0; i<S.length; i++)	{
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0)	{
			temp=temp+digito	}
	} //for

		return temp
}
// fim da funcao

function valida_CPF(s)	{
	var i;
	s = limpa_string(s);
	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 v_formAssociado() {
	        with(document.formAssociado) {

            if (nome.value == "") {
			alert("Digite seu nome!");
			nome.style.backgroundColor='yellow'
			nome.focus();
			return false; }

            if (nome.value.indexOf(" ") == -1){
			alert("Digite seu nome completo!");
			nome.style.backgroundColor='yellow'
            nome.focus();
			return false; }

            if (email.value == "") {
			alert("Digite seu e-mail!");
            email.style.backgroundColor='yellow'
            email.focus();
		    return false; }

            parte1 = email.value.indexOf("@");
            parte2 = email.value.indexOf(".");
            parte3 = email.value.length;
            if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)){
			alert("email inválido!");
            email.style.backgroundColor='yellow'
            email.focus();
		    return false; }

            /* if (assunto.value == "") {
			alert("Qual o assunto de sueu cantato?");
            asssunto.style.backgroundColor='yellow'
            assunto.focus();
			return false; } */

            if (fone.value == "") {
			alert("Digite o número de seu telefone!");
            fone.style.backgroundColor='yellow'
            fone.focus();
			return false; }

            if (endereco.value == "") {
			alert("Preencha o campo endereço!");
            endereco.style.backgroundColor='yellow'
            endereco.focus();
			return false; }
			
		    if (bairro.value == "") {
			alert("Preencha o campo bairro!");
            bairro.style.backgroundColor='yellow'
            bairro.focus();
			return false; }
			
			if (cidade.value == "") {
			alert("Preencha o campo cidade!");
            cidade.style.backgroundColor='yellow'
            cidade.focus();
			return false; }
			
			if (cidade.value == "") {
			alert("Preencha o campo cidade!");
            cidade.style.backgroundColor='yellow'
            cidade.focus();
			return false; }
			
			if (uf.value == "") {
			alert("Preencha o campo uf!");
            uf.style.backgroundColor='yellow'
            uf.focus();
			return false; }
			
			if (data_de_nascimento.value == "") {
			alert("Preencha o campo data de nascimento!");
            data_de_nascimento.style.backgroundColor='yellow'
            data_de_nascimento.focus();
			return false; }
			
			if (sexo.value == "") {
			alert("Selecione um sexo!");
            sexo.style.backgroundColor='yellow'
            sexo.focus();
			return false; }
			
			if (profissao.value == "") {
			alert("Preencha o campo profissão!");
            profissao.style.backgroundColor='yellow'
            profissao.focus();
			return false; }
			
			if (valida_CPF(cpf.value) == false ) {
			alert("CPF Inválido !");
            cpf.style.backgroundColor='yellow'
            cpf.focus();
			return (false);
	    	}
			

            ajaxForm('feedback','formAssociado');

	        }
           }


function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function data(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")    //Coloca barra entre o segundo e o terceiro dígitos
    v=v.replace(/(\d{2})(\d)/,"$1/$2")    //Coloca barra entre o quarto e o quinto dígitos
    return v
}

function icpf(v){
    v=v.replace(/\D/g,"")
    v=v.replace(/(\d{3})(\d)/,"$1.$2")
    v=v.replace(/(\d{3})(\d)/,"$1.$2")
    v=v.replace(/(\d{3})(\d)/,"$1-$2")
    return v
}

