$(function($){
	$("#ok_comprar").click(function(){
		var nome = $("#nome").val();
		var email = $("#email").val();
		var mensagem = $("#mensagem").val();
		
		if(nome == ""){
			alert("Nome é obrigatório");
			$("#nome").focus();
			return false;
		}
		
		if(email == ""){
			alert("Email é obrigatório");
			$("#email").focus();
			return false;
		}
		
		if(mensagem == ""){
			alert("Mensagem é obrigatório");
			$("#mensagem").focus();
			return false;
		}
		
		$.post('cadcomprar.php', {nome:nome, email:email, mensagem:mensagem}, function(resp){
			if(resp != false){
				alert("Erro: "+resp);
				$("#nome").focus();
			}else{
				alert("Mensagem enviada com sucesso");
				$("#nome").val('');
				$("#email").val('');
				$("#mensagem").val('');
				$("#nome").focus();
			}
		})
	})
})

$(function($){
	$("#ok_contato").click(function(){
		var assunto = $("#txtAssunto").val();
		var nome = $("#txtNome").val();
		var email = $("#txtEmail").val();
		var telefone = $("#txtTelefone").val();
		var cidade = $("#txtCidade").val();
		var mensagem = $("#txtMensagem").val();
		
		if(assunto == "" || assunto == "nao"){
			alert("É necessário escolher um assunto para prosseguir");
			$("#txtAssunto").click();
			return false;
		}
		
		if(nome == ""){
			alert("Nome é obrigatório");
			$("#txtNome").focus();
			return false;
		}
		
		if(email == ""){
			alert("Email é obrigatório");
			$("#txtEmail").focus();
			return false;
		}
		
		if(telefone == ""){
			alert("Telefone é obrigatório");
			$("#txtTelefone").focus();
			return false;
		}
		
		if(cidade == ""){
			alert("Cidade e/ou UF são obrigatórios");
			$("#txtCidade").focus();
			return false;
		}
		
		if(mensagem == ""){
			alert("Mensagem é obrigatório");
			$("#txtMensagem").focus();
			return false;
		}
		
		$.post('cadcontato.php', {assunto:assunto, nome:nome, email:email, telefone:telefone, cidade:cidade, mensagem:mensagem}, function(resp){
			if(resp != false){
				alert("Erro: "+resp);
				$("#txtNome").focus();
			}else{
				alert("Mensagem enviada com sucesso");
				$("#txtAssunto").val('nao');
				$("#txtNome").val('');
				$("#txtEmail").val('');
				$("#txtTelefone").val('');
				$("#txtCidade").val('');
				$("#txtMensagem").val('');
				$("#txtNome").focus();
			}
		})
	})
})

function categoria(codigo){
	location.href="index.php?pg=view_linha_de_produtos&cd="+codigo;
}

function colecao(codigo,linha){
	location.href="index.php?pg=view_colecao_de_produtos&cd="+codigo;
}
