function formataNum(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + 'R$ ' + num + ',' + cents);
}


function recalcula(){
	var total = 0;
	//alert(frmCesta.unitario.length);
	if(document.frmCesta.unitario.length != undefined){
		for(i=0;i<document.frmCesta.unitario.length;i++){
			//document.frmCesta.unitario[i].value = formataNum(document.frmCesta.unitario[i].value);
			valor = document.frmCesta.quantidade_sel[i].value;
			document.all.resultado[i].innerHTML = formataNum(valor * document.frmCesta.unitario[i].value);
			total += valor * document.frmCesta.unitario[i].value;; 
		}
	}else{
			valor = document.frmCesta.quantidade_sel.value;
			document.all.resultado.innerHTML = formataNum(+ valor * document.frmCesta.unitario.value);
			total += valor * document.frmCesta.unitario.value;; 

	}
	document.all.total.innerHTML = formataNum(total);
}

function habilita(frete){
	//alert(frete);
	if (frete == 'sedex'){
		//alert('huu');
		//document.frmCesta.local_normal.value = "";
		//document.all.frete_normal.innerHTML = "";
		//document.frmCesta.local_normal.disabled = true;
		document.frmCesta.local_sedex.disabled = false;
		totalGeral();		
	}else{
		//alert('haa');
		document.frmCesta.local_sedex.value = "";
		document.all.frete_sedex.innerHTML = "";
		document.frmCesta.local_normal.disabled = false;
		document.frmCesta.local_sedex.disabled = true;
		totalGeral();
	}
}
function verForm(){
	if (document.frmCesta.local_sedex.value == ""){
		alert('Entre com a Região para calculo do Frete.');
	}else if(!document.frmCesta.tipo_pagamento[0].checked && !document.frmCesta.tipo_pagamento[1].checked){
		alert('Entre a forma de Pagamento desejado.');
	}else if(document.frmCesta.Nome.value == "" || document.frmCesta.email.value == "" || document.frmCesta.Telefone.value == "" || document.frmCesta.Rua.value == "" || document.frmCesta.Numero.value == "" || document.frmCesta.CEP.value == "" || document.frmCesta.Cidade.value == "" || document.frmCesta.Estado.value == "" || document.frmCesta.Pais.value == "" || document.frmCesta.CPF.value == ""){
		alert('Preencha todos os campos do cadastro.');
	}else{
		document.frmCesta.submit();
	}
}
