function alterarQuantidade(){
	$('#fieldAcao').val('2');
	$('#frmCarrinho').submit();
}

function excluirCarrinho(prod1_cod){
	if (confirm('Deseja realmente retirar este item de seu carrinho de compras?')){
		$('#fieldProd').val(prod1_cod);
		$('#fieldAcao').val('3');
		
		$('#frmCarrinho').submit();
	}
}

function finalizarCarrinho(logado){
	if (logado == 0){
		$("#dialog-login").dialog('open');
	}
	else {
		$("#fieldGo").val('1');
		$("#fieldAcao").val('2');
		$('#frmCarrinho').submit();
	}
}

function abrirJanelaLogin(){
	tela = parseInt(screen.width / 2);
	pos = tela - 300;
	
	$("#janelaLogin").css('left',pos+'px');
	$("#janelaLogin").css('display','block');
}

function fecharJanelaLogin(){
	$("#janelaLogin").css('display','none');
}

function inteiro(e){
	var tecla = (window.event)?event.keyCode:e.which;

    if((tecla > 47 && tecla < 58) || (tecla > 95 && tecla < 106) || tecla == 0){
		return (true);
	}
	else{
		if (tecla != 8){
			return (false);
		}
		else {
			return (true);
		}
	}
}

function calcularFrete(root_path, cep){
	if (cep == 0){
		cep = $('#fldCep').val();
	}
	
	if (cep != ''){
		$("#formasPagamento").css('display','none');
		
		$("#radioPac").removeAttr("checked");
		$("#radioSedex").removeAttr("checked");
		
		$("#opcoesFrete").css('display','block');
		$("p.valorSedex").html('<img src="'+root_path+'/img/common/ajax-loader.gif" />');
		$("p.valorPac").html('<img src="'+root_path+'/img/common/ajax-loader.gif" />');
		
		$.ajax({
			url: root_path + "/ajax/calcularFrete/"+ cep +"/",
			cache: false,
			success: function(html){
				valores = html.split(';;');
				
				if (valores[0] == 'Peso não atendido.'){
					$("p.valorSedex").html('50,00');
					$("#valorSedex").val('50,00');
				}
				else {
					$("p.valorSedex").html(valores[0]);
					$("#valorSedex").val(valores[0]);
				}
				
				if (valores[1] == 'Peso não atendido.'){
					$("p.valorPac").html('50,00');
					$("#valorPac").val('50,00');
				}
				else {
					$("p.valorPac").html(valores[1]);
					$("#valorPac").val(valores[1]);
				}
			}
		});
	}
}

function buscarValores(root_path,tipo){
	valorFrete = $("#valor"+tipo).val();
		
	$.ajax({
		url: root_path + "/ajax/buscarValores/"+valorFrete+"/",
		cache: false,
		success: function(html){
			$("#formasPagamento").css('display','block');
			$("#formasPagamento").html(html);
		}
	});
}

function finalizarPedido(){
	//if ((document.frmPagamentos.opcaoFrete[0].checked) || (document.frmPagamentos.opcaoFrete[1].checked)){
	//	document.frmPagamentos.submit();
	//}
        if ($('input[type=radio][name=opcaoFrete]:checked').val()) {
            document.frmPagamentos.submit();
        }
	else {
		alert('Selecione a opção de frete desejada.');
	}
}
