/*
#######################################################################
#validacoes de login
#######################################################################
 */

function valida_login(e) {
	if ($(this).val() != "") {
		$.post('buscas_cadastro.php', {
				email : $(this).val(),
				acao : "login"
			},
			function (resposta) {
				$('#erro_login').fadeOut('slow', function () {
						$('#erro_login').html(resposta).fadeIn('slow');
						setTimeout("$('#erro_login').fadeOut('slow');", 4000);
					});
			});
	}
}

function valida_login_2(e) {
	if ($(this).val() != "") {
		$.post('buscas_cadastro.php', {
				email : $(this).val(),
				acao : "login"
			},
			function (resposta) {
				resposta = jQuery.trim(resposta);
				if(resposta!=''){
					$('#erro_login_2').html("<img src='upArrow.png' style='position: relative; left: 30px;' /><div style='padding:10px 10px 10px 10px; background-color:#6699FF; color:#ffffff; margin-bottom:5px;'>"+resposta+"</div>").fadeIn('slow');
					setTimeout("$('#erro_login').fadeOut('slow');", 4000);
				}
			});

	}
}

function valida_login_3(e) {
	$("#novo_erro_logar").show().html("<img src=\"imagens/ajax-loader.gif\"/>");
	if ($(this).val() != "") {
		$.post('buscas_cadastro.php', {
				email : $(this).val(),
				acao : "login"
			},
			function (resposta) {
				$('#novo_erro_logar').fadeOut('slow', function () {
						$('#novo_erro_logar').html(resposta).fadeIn('slow');
						setTimeout("$('#novo_erro_logar').fadeOut('slow');", 4000);
					});
			});
	}
}

/*
#######################################################################
#validacoes de senhas
#######################################################################
 */
function valida_senha(e) {
	if ($(this).val() != "" + $("input[@name=login]").val() != "") {
		$.post('buscas_cadastro.php', {
				senha : $(this).val(),
				email : $("input[@name=login]").val(),
				acao : "senha"
			},
			function (resposta) {
				$('#erro_login').fadeOut('slow', function () {
						$('#erro_login').html(resposta).fadeIn('slow');
						setTimeout("$('#erro_login').fadeOut('slow');", 4000);
					});
			});
	}
}

//valida_login e senha antes de logar
function valida_login_senha(e) {
	if ($("input[@name=senha]").val() != "" || $("input[@name=login]").val() != "") {
		$.post('buscas_cadastro.php', {
				senha : $("input[@name=senha]").val(),
				email : $("input[@name=login]").val(),
				acao : "senha"
			},
			function (resposta) {
				$('#erro_login').fadeOut('slow', function () {
						$('#erro_login').html(resposta).fadeIn('slow');
						setTimeout("$('#erro_login').fadeOut('slow');", 8000);
					});
			});
	} else {
		$('#erro_login').fadeOut('slow', function () {
				$('#erro_login').html("<img src='upArrow.png' style='position: relative; left: 30px;' /><div style='padding:10px 10px 10px 10px; background-color:#6699FF; color:#ffffff; margin-bottom:5px;'>Informe Login e Senha!</div>").fadeIn('slow');
				setTimeout("$('#erro_login').fadeOut('slow');", 4000);
			});
	}
}

function valida_login_senha_2(e) {
	if ($("input[@name=senha_2]").val() != "" || $("input[@name=login_2]").val() != "") {
		$.post('buscas_cadastro.php', {
				senha : $("input[@name=senha_2]").val(),
				email : $("input[@name=login_2]").val(),
				acao : "logar"
			},
			function (resposta) {
				resposta = jQuery.trim(resposta);
				if(resposta!='<script>history.go(0);</script>' & resposta!=''){
					$('#erro_login_2').html("<img src='upArrow.png' style='position: relative; left: 10px; top:-9px;' /><div style='padding:10px 10px 10px 10px; background-color:#6699FF; color:#ffffff; margin-bottom:5px; margin-top:-9px;'>"+resposta+"</div>").fadeIn('slow');
					setTimeout("$('#erro_login_2').fadeOut('slow');", 4000);
				}else if(resposta=='<script>history.go(0);</script>'){
					$('#erro_login_2').html("<img src=\"imagens/ajax-loader.gif\"/>"+resposta);
				}
			});
	} else {
		$('#erro_login_2').fadeOut('slow', function () {
				$('#erro_login_2').html("<img src='upArrow.png' style='position: relative; left: 10px; top:-9px;' /><div style='padding:10px 10px 10px 10px; background-color:#6699FF; color:#ffffff; margin-bottom:5px; margin-top:-9px;'>Informe E-mail e Senha!</div>").fadeIn('slow');
				setTimeout("$('#erro_login_2').fadeOut('slow');", 4000);
			});
	}
}

function valida_login_senha_3(e) {
	$("#novo_erro_logar").show().html("<img src=\"imagens/ajax-loader.gif\"/>");
	if ($("input[@name=inova_senha]").val() != "" || $("input[@name=novo_login]").val() != "") {
		$.post('buscas_cadastro.php', {
				senha : $("input[@name=inova_senha]").val(),
				email : $("input[@name=novo_login]").val(),
				acao : "logar_novamente"
			},
			function (resposta) {
				resposta = jQuery.trim(resposta);
				if(resposta!=''){
					$('#novo_erro_logar').fadeOut('slow', function () {
						$('#novo_erro_logar').html(resposta).fadeIn('slow');
						setTimeout("$('#novo_erro_logar').fadeOut('slow');", 4000);
					});
				}
			});
	} else {
		$('#novo_erro_logar').fadeOut('slow', function () {
				$('#novo_erro_logar').html("<img src='upArrow.png' style='position: relative; left: 30px;' /><div style='padding:10px 10px 10px 10px; background-color:#6699FF; color:#ffffff; margin-bottom:5px;'>Informe E-mail e Senha!</div>").fadeIn('slow');
				setTimeout("$('#novo_erro_logar').fadeOut('slow');", 4000);
			});
	}
}

function grava_newsletter3(idNome, idEmail, idMsg, idEcreveMsg) {
	var PNome = $('#' + idNome).val();
	var marcaDaguaNome = $('#' + idNome).attr('data-marcadagua');
	var PEmail = $('#' + idEmail).val();
	if (PNome == '' || PNome == marcaDaguaNome) {
		$('#' + idMsg).fadeIn('slow');
		$('#' + idEcreveMsg).html("Informe seu nome!");
	} else {
		if (PEmail.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/)) {
			$('#' + idMsg).fadeIn('slow');
			$('#' + idEcreveMsg).html("Informe um e-mail válido!");
			$('#' + idEmail).focus();
		} else {
			$('#' + idMsg).fadeIn('slow');
			$('#' + idEcreveMsg).html("<img src=\"imagens/ajax-loader.gif\"/>");
			$.post('buscas_cadastro.php', {
					email : PEmail,
					nome : PNome,
					acao : "newsletter"
				}, function (resposta) {
					$('#' + idEcreveMsg).html(resposta);
					$('#' + idNome).val($('#' + idNome).attr('data-marcadagua'));
					$('#' + idEmail).val($('#' + idEmail).attr('data-marcadagua'));
				});
		}
	}
	$('#' + idMsg).delay(1500).fadeOut();
};

