function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){
			return true;
		}else return false;
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){
			return true;
		}else return false;
	}else{return false;}
}

function ValidarCadastro(){
	
	nome = $("#nome").val();
	sexo = $("#sexo").val();
	endereco = $("#endereco").val();
	numero = $("#numero").val();
	bairro = $("#bairro").val();
	cidade = $("#cidade").val();
	cep = $("#cep").val();
	aniversario = $("#aniversario").val();
	grupoOracao = $("#grupoOracao").val();
	
	ddd = $("#ddd").val();
	tamDdd = ddd.length;
	
	codCidade = $("#codCidade").val();
	tamCodCidade = codCidade.length;
	
	telefone = $("#telefone").val();
	tamTelefone = telefone.length;
	
	dddCel = $("#dddCel").val();
	tamDddCel = dddCel.length;
	
	codCidadeCel = $("#codCidadeCel").val();
	tamCodCidadeCel = codCidadeCel.length;
	
	telefoneCel = $("#telefoneCel").val();
	tamTelefoneCel = telefoneCel.length;
	
	email = $("#email").val();
	email2 = $("#email2").val();
	senha = $("#senha").val();
	senha2 = $("#senha2").val();
	
	msgErro = "";
	if(nome == "") msgErro += "O nome está vazio.\n"
	if(sexo == "") msgErro += "O campo sexo está vazio.\n"
	if(endereco == "") msgErro += "O endereo está vazio\n";
	if(numero == "") msgErro += "O nmero está vazio\n";
	if(bairro == "") msgErro += "O bairro está vazio\n";
	if(cidade == "") msgErro += "A cidade está vazia\n";
	if(cep == "") msgErro += "O CEP está vazio\n";
	if(aniversario == "") msgErro += "A data de aniversrio está vazia\n";
	
	if(ddd == "") msgErro += "Está faltando o DDD do telefone\n";
	if(tamDdd < 2) msgErro += "DDD do telefone deve ter 2 caracteres\n";
	if(codCidade == "") msgErro += "Está faltando o Código do Telefone da Cidade\n";
	if(tamCodCidade < 4) msgErro += "Código do telefone da cidade deve ter 4 caracteres\n";
	if(telefone == "") msgErro += "Está faltando número do telefone\n";
	if(tamTelefone < 4) msgErro += "Telefone deve ter 4 caracteres\n";
		
	if (senha == "") msgErro += "A senha está vazia\n";
	if (email != email2) msgErro += "Repita o email corretamente\n";
	if (senha != senha2) msgErro += "Repita a senha corretamente\n";
	if (senha.length > 8) msgErro += "A senha deve ter no máximo 8 caracteres\n";
	if(email != ""){
		if (checkMail(email) == false) msgErro += "O email parece não estar correto\n";
	}
	
	
	if (msgErro != ""){
		alert(msgErro);
		return false;
	}
	
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}


function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function superTrim(str){return str.replace(/^\s+|\s+$/g,"");}

function ChecarRecados(){
	comentario = $("#comentario").val();
	nome_carismatico = $("#nome_carismatico").val();
	if(comentario == ""){
		alert("ERRO! Você esqueceu o comentário");
		return false;
	}else if(nome_carismatico == ""){
		alert("ERRO! Você esqueceu o seu nome");
		return false;
	}else{
		alert("Muito obrigado!\n\nClique em OK para confirmar o envio de seu comentário.\n\nATENÇÃO: Seu comentário entrará na página principal do site www.rccvicosa.com em pelo menos 24 horas.");
	}
	
}

function validarInscricao(){
	cracha = $("#cracha").val();
	pacote = $("input[@name=pacotes]:checked").val();
	
	seminario1 = $("#seminario1").val();
	seminario2 = $("#seminario2").val();
	seminario3 = $("#seminario3").val();
	
	if (cracha == "") {
		alert("ERRO, você esqueceu do crachá");
		return false;
	}else if((seminario1 == seminario2 || seminario1 == seminario3 || seminario2 == seminario3) && pacote != 3){
		alert("ERRO, deve escolher 3 seminários diferentes");
		return false;
	}else{
		$("form#frmInscricaoSEARA")[0].submit();
	}
}

