function form_validator2(theForm)
{
	// Varre os campos e verifica as quantidades
	qtItens=document.getElementById('qt_itens').value;
	for(i=1; i<qtItens; i++) {
		linhaItem=document.getElementById('qty_'+i);
		if(linhaItem.value < 1) {
			alert("Quantidade inválida!\n("+linhaItem.value+")");
			linhaItem.value=document.getElementById('qty_original_'+i).value;
			linhaItem.focus();
			return(false); 
		}	
	}
}

function calculaTotal()
{
	valorProdutos=eval(document.getElementById('total_produtos').value);
	valorFrete=eval(document.getElementById('valor_frete').value);
	valor=alterError(valorProdutos+valorFrete);
	document.getElementById('total').innerHTML='<span class=\"TabelaCarrinhoMoeda\">R$</span> '+valor;
	document.getElementById('total_pedido').value=valor;
	//exibeFormasPgto();
	return true;
}

function exibeFormasPgto() {
	totalPedido=document.getElementById('total_pedido').value;
	http.open("GET", "ajax_formas_pgto.php?valor_total="+totalPedido, true);
	http.onreadystatechange =  handleHttpResponse_exibeFormasPgto;
	http.send(null);
}

function handleHttpResponse_exibeFormasPgto()
{
  if (http.readyState == 4) {
    results = http.responseText;
	document.getElementById('layerWaiting').style.visibility='hidden'
	if(results.length) {
		document.getElementById('forma_pgto').innerHTML = results;
	}
  } else {
	  document.getElementById('layerWaiting').style.visibility='visible'
  }
}

function atualizaFormaPgto(idPgto) {
	http.open("GET", "ajax_formas_pgto_atualizacao.php?id_pgto="+idPgto, true);
	http.onreadystatechange =  handleHttpResponse_atualizaFormaPgto;
	http.send(null);
}

function handleHttpResponse_atualizaFormaPgto()
{
  if (http.readyState == 4) {
    results = http.responseText;
	document.getElementById('layerWaiting').style.visibility='hidden'
	// faz nada
  } else {
	  document.getElementById('layerWaiting').style.visibility='visible'
  }
}

