//executar todas as funcoes
function fazer_tudo() {
	somar_qtds();
	somar_valores();
	calcular_valores();
	verif_total();
	}
	
//checar se todos os campos OBRIGATORIOS foram preenchidos:


//checar se o valor total eh maior que R$ 10,00:
function verif_total() {
	var total_valores ;
	total_valores = parseFloat(document.form_pedido.total_valores.value);
	if(total_valores > 0.00) {
		document.form_pedido.enviar.disabled = false;
		}
	else {
		document.form_pedido.enviar.disabled = true;
		}
	}

//mostrar a soma de todas as qtds dos itens
function somar_qtds() {
	var total_itens = 25;
	var total_qtds = 0;
	var qtd = 0;
	
	for (x=0; x<total_itens; x++) {
		//qtd = document.form_pedido.qtd[x].value;
		qtd = document.getElementsByName("qtd[" + x + "]")[0].value;
		//document.getElementsByName("qtd_prod[" + x + "]")[0].value = qtd;
		//alert(qtd);
		if (qtd == null) { qtd = 0; } //se nao tiver valor deixa como 0
		else if (qtd == "")  { qtd = 0; } //se nao tiver valor deixa como 0
		parseInt(qtd);
		
		total_qtds = total_qtds + parseInt(qtd);
		}
	document.form_pedido.total_qtds.value = total_qtds;
	calcular_valores();
	}
	
	

//mostrar a soma de todos os valores dos itens
function somar_valores() {
	var total_itens = 25;
	var total_valores;
	var vlr_tot;
	total_valores = 0;
	for (x=0; x<total_itens; x++) {
		//vlr_tot = parseFloat(document.form_pedido.vlr_tot[x].value);
		vlr_tot = parseFloat(document.getElementsByName("vlr_tot[" + x + "]")[0].value);
		total_valores = total_valores + vlr_tot;
		} 
	document.form_pedido.total_valores.value = parseFloat(total_valores).toFixed(2);
	calcular_valores();
	}
	


//calcula os valores totais de todos os itens
function calcular_valores() {
	var total_itens = 25;
	var vlr;
	var vlr_tot;
	var qtd;
	
	vlr_tot = 0;
	for (x=0; x<total_itens; x++) {
		//qtd = document.form_pedido.qtd[x].value;
		qtd = document.getElementsByName("qtd[" + x + "]")[0].value;
		if (qtd == null) { qtd = 0; } //se nao tiver valor deixa como 0
		else if (qtd == "")  { qtd = 0; } //se nao tiver valor deixa como 0
		parseInt(qtd);
		
		vlr = document.getElementsByName("vlr[" + x + "]")[0].value; //pega o valor de VLR[x]
		vlr = Arredonda(vlr, 2); //arredonda o VLR[x] para somente 2 casas atras da virgula
		vlr_tot = Arredonda(vlr * parseInt(qtd), 2); //qtd * vlr = vlr total
		//document.getElementsByName("vlr_tot[" + x + "]")[0].value = deci(vlr_tot);
		document.getElementsByName("vlr_tot[" + x + "]")[0].value = parseFloat(vlr_tot).toFixed(2);
		}
	}
	
	
	
	
	
<!-- Original:  Mario Costa (mariocosta@openlink.com.br) -->
<!-- Bug fix:   John Kiernan  -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 8) return true;  // Delete (Bug fixed)
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
				}
			aux2 += aux.charAt(i);
			j++;
			}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
		}
	return false;
	}
//  End -->




//arredonda o valor 
function Arredonda(valor, casas){
	var novo = Math.round( valor * Math.pow( 10 , casas ) ) / Math.pow( 10 , casas );
	return(novo);
	}