$(function (){
	$('#filtrar').submit(function (){
		var action = $(this).attr('action');
		$('#but').hide();
		$('#load').show();
		$.ajax({
			type: 'POST',
			url: action,
			data: $(this).serialize(),
			success: function(html) {
				$('#left').html(html);
				$('#but').show();
				$('#load').hide();					
			}
		});
		return false;
	});
	$("input[type='checkbox']").click(function(){
		var dados = Array();
		dados = $('#select_quant').val().split('#');
		qtde = dados[0].replace('.', '');
		peso = dados[2]
		valor = dados[1];
		if ($('.preco').text().length <= 6) {
			var price = $('.preco').text().replace(/^\s+|\s+$/g,"").replace('R$ ', '').replace(",", ".");
		} else {
			var price = $('.preco').text().replace(/^\s+|\s+$/g,"").replace('R$ ', '').replace(".", "").replace(',', '.');
		}
		var id_price = $(this).attr('id');
		var ate_quanto = $(this).attr('rel');
		var a = parseInt(qtde / ate_quanto);
		if (a > 0) {
			var vezes = a;
		} else {
			var vezes = 1;
		}		
		if ($(this).is(':checked')) {
			var calc = parseFloat(price) + (parseFloat(id_price) * vezes);
			$('.alert').show();
		} else {
			var calc = parseFloat(price) - (parseFloat(id_price) * vezes);
		}
		$('.preco').html(float2moeda(calc));
		$('#change_preco').attr('value', calc);
	});
	$('#indique').submit(function() {
		$('.s').hide();
		$('.i').show();			
		var action = $(this).attr('action');
		$.ajax({
			type: 'POST',
			data: $(this).serialize(),
			url: action,
			success: function(html) {
				$('#r_indique').html(html);
				$('.s').show();
				$('.i').hide();	
				$('#ProdutoNome').attr('value', '');
				$('#ProdutoDestinatario').attr('value', '');
				$('#ProdutoEmail').attr('value', '');										
			}
		});
		return false;
	});
	$('#post_comment').submit(function() {
		$('.s').hide();
		$('.i').show();
		var action = $(this).attr('action');
		$.ajax({
			type: 'POST',
			data: $(this).serialize(),
			url: action,
			success: function(html) {
				if (html == 'ok') {
					$('#r_comment').html('<div class="success" style="width: 717px; margin-bottom: 0; margin-top: 10px;">Coment&aacute;rio postado com sucesso, aguade a aprova&ccedil;&atilde;o da administra&ccedil;&atilde;o.');
					$('#ComentarioNome').attr('value', '');
					$('#ComentarioDescricao').attr('value', '');
					$('#ComentarioSite').attr('value', 'http://');
				} else {
					$('#r_comment').html(html);
				}
				$('.s').show();
				$('.i').hide();					
			}
		});
		return false;
	});
	$('ul.relacionado li').click(function() {
		window.location = $(this).attr('link-data');
	});
	$('#select_quant').change(function(){
		var dados = Array();
		dados = $(this).val().split('#');
		qtde = dados[0];
		peso = dados[2]
		valor = dados[1];
		$('.close').hide();
		$('input[type=checkbox]').attr('checked', false);
		$('.box_peso').html(peso);
		$('.ext').hide();
		$('.box_quant').html(qtde);
		$('.quant_' + qtde.replace('.', '')).show();
		$('.preco').html(float2moeda(valor));
		$('#change_preco').attr('value', valor);							
	});
});
