$(document).ready(function(){

	$("#frmcarrinho").submit(function(){
		return false;
	});

	$("#frmcarrinho input").change(function(){

		$.blockUI({ message: $("#waitmessage").html(), css: {
            border: 'none',
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: .5,
            color: '#fff'
        } });

		if($(this).attr('name') != 'dest_zip')
		{
			$.get("carrinho.php", { acao: "UPDC", idproduto: $(this).attr('name'), quantidade: $(this).val() },
				function(data){
	    			window.location = "carrinho.php";
	  			}
	  		);
	  	}

  		setTimeout($.unblockUI, 2000);
	});

	$("#finalizar").click(function(){
		//abrir janela para colocar dados do cliente.
		//salvar dados em arquivo xml
	});

	$(".botao_produtos_comprar").click(function(){
		//alert($(this).attr('href') + '&quantidade=' + $("#quantidade").val());
		window.location = $(this).attr('href') + '&quantidade=' + $("#quantidade"+$(this).attr('id')).val();
	});

	$(".frete input, .frete select").change(function(){

		$.blockUI({ message: $("#waitmessage").html(), css: {
            border: 'none',
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: .5,
            color: '#fff'
        } });

		//alert($(this).val() + ' ' + $(this).attr('name'));
		var parentTag = $(this).parent().get(0);

		$.get("calculafrete.php", { nome: $(parentTag).attr('id'), dest_zip: $("#dest_zip").val(), service_type: $("#service_type").val() },
			function(data){
				if(data.erro) {
					$("#fretestatus").html('Status: ' + data.erro);
				}
				else
				{
    				window.location = "carrinho.php";
    			}
  			},"json");

		//$.unblockUI();
  		setTimeout($.unblockUI, 2000);
	});

});
