$(document).ready(function(){
						   
	$('#lkMostraReenviarAtivacao').click(function(e){ 
		e.preventDefault();
		$('#reenviarAtivacao').fadeIn();
	});
						   
	$("#formCadastro").bind("submit", function(evento){ 
		evento.preventDefault();
		var erro='';
		if( $('#nomeCadastro').val()==""){
			erro += '\n - Seu nome deve ser informado.';
		}
	});
	
	$("#frmReenviarAtivacao").bind("submit", function(ev){
		ev.preventDefault();
		$.post('/ajax/checaEmailAtivacao.php', {email: $('#emailAtivacao').val()}, function(resp){
			if(resp!=""){
				$('#emailErro').html(resp);
				$('#emailErro').fadeIn();
			}else{
				$('#emailErro').fadeOut();
				$('#emailErro').html('');
				$.post('/ajax/reenviaAtivacao.php', {email: $('#emailAtivacao').val()}, function(r){
					if(r=='ok'){
						location.href='/ativacao_reenviada';
					}else{
						$('#emailErro').html(r);
						$('#emailErro').fadeIn();
					}
				});
			}
		});
	});

	$('#nomeCadastro').blur(function(e){
		e.preventDefault();
		if( $('#nomeCadastro').val().length < 3){
			$('#nomeErro').html('Atenção: - Tem certeza que seu nome possui somente essa quantidade de caracteres?');
			$('#nomeErro').fadeIn();
		}else{
			$('#nomeErro').fadeOut();
			$('#nomeErro').html('');
		}
	});
	
	$('#emailCadastro').blur(function(ev){
		ev.preventDefault();
		$.post('/ajax/checaEmailCadastro.php', {email: $('#emailCadastro').val()}, function(resp){
			if(resp!=""){
				$('#emailErro').html(resp);
				$('#emailErro').fadeIn();
			}else{
				$('#emailErro').fadeOut();
				$('#emailErro').html('');
			}
		});

	});
	
	$('#loginCadastro').blur(function(eve){
		eve.preventDefault();
		$.post('/ajax/checaLoginCadastro.php', {login: $('#loginCadastro').val()}, function(resp){
			if(resp!=""){
				$('#loginErro').html(resp);
				$('#loginErro').fadeIn();
			}else{
				$('#loginErro').fadeOut();
				$('#loginErro').html('');
			}
		});

	});
	
	$('#senhaCadastro').keyup(function(even){
		even.preventDefault();
		checaSenha();
	});
	
	$('#confirmSenhaCadastro').keyup(function(evenn){
		evenn.preventDefault();
		checaSenha();
	});
	
	$('#cadastroSubmit').click(function(a){
		a.preventDefault();
		$.post(
			   '/ajax/cadastro_sub.php', 
			   {
				   nomeCadastro:	$('#nomeCadastro').val(),
				   emailCadastro:	$('#emailCadastro').val(),
				   loginCadastro:	$('#loginCadastro').val(),
				   senha:			$('#senhaCadastro').val(),
				   confirmacao:		$('#confirmSenhaCadastro').val(),
				   termosUso:		$('#cadastroTermosUso').attr('checked'),
				   informativos:	$('#cadastroInformativos').attr('checked')
				}, 
				function(resp){
					if(resp=='ok'){
						//alert('Cadastro realizado com sucesso!');
						location.href='/confirmacao_cadastro';
					} else {
						$('#nomeErro').fadeOut();
						$('#emailErro').fadeOut();
						$('#loginErro').fadeOut();
						$('#senhaErro').fadeOut();
						$('#errosSub').html("<b>Atenção, erro(s) encontrado(s) :</b>" + resp);
						$('#errosSub').fadeIn();
					}
				}
			);
	});
	
	$('#cadastroSubmit').blur(function(a){
		a.preventDefault();
		$('#nomeErro').fadeOut();
		$('#emailErro').fadeOut();
		$('#senhaErro').fadeOut();
		$('#errosSub').fadeOut();
	});
	
});

function checaSenha(){
	var erro='';
	if( $('#senhaCadastro').val().length <= 3 )
		erro += '<br> - A senha deve possuir 4 ou mais caracteres, tente novamente.';
	if( $('#confirmSenhaCadastro').val()=='' )
		erro += '<br> - A confirmação deve ser informada.';
	if( $('#senhaCadastro').val() != $('#confirmSenhaCadastro').val() )
		erro += '<br> - A senha e a confirmação não coincidem.';
	
	if(erro!=''){
		$('#senhaErro').html('Atenção: <br>' + erro);
		$('#senhaErro').fadeIn();		
	}else{
		$('#senhaErro').fadeOut();
		$('#senhaErro').html('');
	}
}
