function calcula(qtd, preco, nomeCampoTotal) {
		var campoTotal = document.forms[0].elements[nomeCampoTotal];
		if(qtd == "") {
			campoTotal.value = "";
			return;
		}
		if(isNaN(parseInt(qtd))) {
			campoTotal.value = "";
			window.alert("Formato Inválido!");
			return;
		}

		var total = parseInt(qtd) * preco;
		var reais = Math.floor(total);
		var centavos = Math.floor(Math.round(total * 100)) % 100;
		campoTotal.value = "R$ " + reais + "," + (centavos < 10 ? "0" : "") + centavos;
		calculaTotal();
	}

	function calculaTotal() {
		var total = 0.0;
		for(var i = 2; i < 21; i++) {
			var elem = document.forms[0].elements["total" + (i < 10 ? "0" : "") + i];
			if(elem.value != "") {
				var valor = elem.value.substring(3).replace(",", ".");
				total += parseFloat(valor);
			}
		}

		var reais = Math.floor(total);
		var centavos = Math.floor(Math.round(total * 100)) % 100;
		
		var meses = new Array("maio", "junho", "julho", "agosto", "setembro");
		var descontos = new Array(0.45, 0.45, 0.4, 0.35, 0.3);
		
		for (var i = 0; i < meses.length; i++) {
			var tot = total * (1.0 - descontos[i]);
			var parteInteira = Math.floor(tot);
			var parteDecimal = Math.floor(Math.round(tot * 100)) % 100;	
			//alert("totalgeral_" + meses[i]);		
			document.forms[0].elements["totalgeral_" + meses[i]].value = "R$ " + parteInteira + "," + (parteDecimal < 10 ? "0" : "") + parteDecimal;
		}
		
		document.forms[0].elements["totalgeral"].value = "R$ " + reais + "," + (centavos < 10 ? "0" : "") + centavos;
		document.forms[0].elements["totalgeral2"].value = "R$ " + reais + "," + (centavos < 10 ? "0" : "") + centavos;
	}

	function  habilitaPagamento(flag,obj)
	{
		if(!flag)
		{
			document.forms[0].elements["nome_pagamento"].disabled = true;
			document.forms[0].elements["validade_pagamento"].disabled = true;
		}
		else
		{
			document.forms[0].elements["nome_pagamento"].disabled = false;
			document.forms[0].elements["validade_pagamento"].disabled = false;
		}
	}