// JavaScript Document

function atualizarPagina(){
	window.location.reload();
}

//Validar cadastro de contato
function enviarContato(nome, email, telefone, endereco, cidade, estado, assunto, mensagem, localContato){
	
	if (nome == ""){
		jAlert("Informe seu nome por favor!", "Alerta", 
			function(){
				$("#nome").focus();
			});
		return false;
	}
	if (email == ""){
		jAlert("Informe seu e-mail por favor!", "Alerta", 
			function(){
				$("#email").focus();
			});
		return false;
	}
	if (email.indexOf('@') < 0 || email.indexOf('.') < 0){
		jAlert("Informe um e-mail v&aacute;lido!", "Alerta", 
			function(){
				$("#email").focus();
			});
		return false;
	}
	if (telefone == ""){
		jAlert("Informe seu telefone por favor!", "Alerta", 
			function(){
				$("#telefone").focus();
			});
		return false;
	}
	if (endereco == ""){
		jAlert("Informe seu endereco por favor!", "Alerta", 
			function(){
				$("#endereco").focus();
			});
		return false;
	}
	if (cidade == ""){
		jAlert("Informe sua cidade por favor!", "Alerta", 
			function(){
				$("#cidade").focus();
			});
		return false;
	}
	if (estado == ""){
		jAlert("Informe seu estado por favor!", "Alerta", 
			function(){
				$("#email").focus();
			});
		return false;
	}
	if (assunto == ""){
		jAlert("Informe o assunto por favor!", "Alerta", 
			function(){
				$("#assunto").focus();
			});
		return false;
	}
	if (mensagem == ""){
		jAlert("Digite a mensagem por favor!", "Alerta", 
			function(){
				$("#mensagem").focus();
			});
		return false;
	}
	
	//alert(nome+" - "+email+" - "+endereco+" - "+telefone+" - "+estado+" - "+cidade+" - "+assunto+" - "+mensagem); return;
	$("#carregando").show();
	$.post("http://www.restaurante3t.com.br/pesqueiro/includes/dao/contatoDAO.php?acao=contato", {nome:nome, email:email, telefone:telefone, endereco:endereco, cidade:cidade, estado:estado, assunto:assunto, mensagem:mensagem, local_contato:localContato }, 
		function(retorno) {				
			$("#carregando").hide();
			
			if(retorno.indexOf('contato_erro_bd') > 0){				
				jAlert("<div align=center><span style='color:#f00;'>Houve um erro ao registrar seu contato.</span> <br />Tente novamente!</div>", "Erro!!!", function(){ document.frm_contato.reset(); });				
			}
			else if(retorno.indexOf('contato_erro_email') > 0){
				jAlert("<div align=center>O contato foi efetuado com sucesso. Aguarde retorno! <br /><em>O contato ficar&aacute; armazenado no sistema at&eacute; ser consultado.</em></div>", "Alerta", function(){ document.frm_contato.reset(); });
			}
			else if(retorno.indexOf('contato_ok') > 0){
				jAlert("<div align=center><span style='color: #390'>Contato efetuado com sucesso.</span> <br /> Em breve retornaremos. <strong>Obrigado!</strong></div>", "Alerta", function(){ document.frm_contato.reset(); });
			}
		}
	);

}


//Validar cadastro de contato para eventos
function enviarContatoEventos(nome, email, telefone, endereco, cidade, estado, assunto, mensagem, localEvento){
	
	if (nome == ""){
		jAlert("Informe seu nome por favor!", "Alerta", 
			function(){
				$("#nome").focus();
			});
		return false;
	}
	if (email == ""){
		jAlert("Informe seu e-mail por favor!", "Alerta", 
			function(){
				$("#email").focus();
			});
		return false;
	}
	if (email.indexOf('@') < 0 || email.indexOf('.') < 0){
		jAlert("Informe um e-mail v&aacute;lido!", "Alerta", 
			function(){
				$("#email").focus();
			});
		return false;
	}
	if (telefone == ""){
		jAlert("Informe seu telefone por favor!", "Alerta", 
			function(){
				$("#telefone").focus();
			});
		return false;
	}
	if (endereco == ""){
		jAlert("Informe seu endereco por favor!", "Alerta", 
			function(){
				$("#endereco_contato").focus();
			});
		return false;
	}
	if (cidade == ""){
		jAlert("Informe sua cidade por favor!", "Alerta", 
			function(){
				$("#cidade").focus();
			});
		return false;
	}
	if (estado == ""){
		jAlert("Informe seu estado por favor!", "Alerta", 
			function(){
				$("#email").focus();
			});
		return false;
	}
	if (assunto == ""){
		jAlert("Informe o assunto por favor!", "Alerta", 
			function(){
				$("#assunto").focus();
			});
		return false;
	}
	if (mensagem == ""){
		jAlert("Digite a mensagem por favor!", "Alerta", 
			function(){
				$("#mensagem").focus();
			});
		return false;
	}
	
	$("#carregando").show();
	$.post("http://www.restaurante3t.com.br/pesqueiro/includes/dao/contatoDAO.php?acao=evento", {nome:nome, email:email, telefone:telefone, endereco:endereco, cidade:cidade, estado:estado, assunto:assunto, mensagem:mensagem, local_evento:localEvento }, 
		function(retorno) {				
			$("#carregando").hide();
			
			if(retorno.indexOf('contato_erro_bd') > 0){				
				jAlert("<div align=center><span style='color:#f00;'>Houve um erro ao registrar seu contato.</span> <br />Tente novamente!</div>", "Erro!!!", function(){ document.frm_contato_eventos.reset(); });
			}
			else if(retorno.indexOf('contato_erro_email') > 0){
				jAlert("<div align=center>O contato foi efetuado com sucesso. Aguarde retorno! <br /><em>O contato ficar&aacute; armazenado no sistema at&eacute; ser consultado.</em></div>", "Alerta", function(){ document.frm_contato_eventos.reset(); });
			}
			else if(retorno.indexOf('contato_ok') > 0){
				jAlert("<div align=center><span style='color: #390'>Contato efetuado com sucesso.</span> <br /> Em breve retornaremos. <strong>Obrigado!</strong></div>", "Alerta", function(){ document.frm_contato_eventos.reset(); });
			}
		}
	);
	
}
