var alterado = -1;
function excluir(id_item) {
	parent.location.href='cesta_compras.php?e='+id_item;
}

function comprar(id_item, preco) {
	var qtd = document.getElementById('qtd_'+id_item);

	if(qtd.value == 0) {
		qtd.value=1;
	}
	if(isNaN(qtd.value)) {
		qtd.value=1;
	}
	frames['cesta'].location.href='cesta.php?id_item='+id_item+'&qtd='+qtd.value+'&preco='+preco;
}

function diminueQtd(campo) {
	alterado = 1;
	var qtd = document.getElementById(campo) ;
	if(qtd.value > 0) {
		qtd.value -= 1;
	}
}

function aumentaQtd(campo) {
	alterado = 1;
	var qtd = document.getElementById(campo);
	qtd.value = parseInt(qtd.value) + 1;
}

function comprarLista(id_item, preco) {
	var qtd = document.getElementById('lista_'+id_item);

	if(qtd.value == 0) {
		qtd.value=1;
	}

	if(isNaN(qtd.value)) {
		qtd.value=1;
	}
	frames['cesta'].location.href='cesta.php?id_item='+id_item+'&qtd='+qtd.value+'&preco='+preco;
}

function diminueQtdLista(campo) {
	alterado = 1;
	var qtd = document.getElementById(campo) ;
	if(qtd.value > 0) {
		qtd.value -= 1;
	}
}

function aumentaQtdLista(campo) {
	alterado = 1;
	var qtd = document.getElementById(campo);
	qtd.value = parseInt(qtd.value) + 1;
}

function fechaCompra() {
	var form = document.forms[0];

	var forma = form.formapgto;
	var marcado = false;
	var tipo_pagamento = null;
	if(form.vazia) {
		alert('Sua cesta está vazia!');
		return false;
	}
	for(i = 0; i < forma.length; i++) {
		if (form.formapgto[i].checked) {
			marcado = true;
			tipo_pagamento = form.formapgto[i].value;
		}
	}
	if(!marcado) {
		alert('Selecione a forma de Pagamento!');
	} else {
		if(alterado == -1) {
			location.href='dados_cliente.php?pgto='+tipo_pagamento;
		} else {
			alert('A quantidade de algum produto foi alterada!\nVocê deve recalcular sua cesta!');
		}
	}
}

