// i-Lojas
function setaValor()
{
	var form       = document.getElementById("cadastro");
	var valor      = form.valor.value;
	var periodo    = form.periodo;
	var cell       = document.getElementById("valorMensal");
	var online     = form.vinculacao[0].checked;
	var impresso   = form.vinculacao[1].checked;
	var valorImpr  = form.valor_impresso.value;
	var valorFinal = form.valor_total;
	var valorTotal;
	// Setando os periodos
	if (impresso == true)
	{
		valor = valorImpr;
	}
	var M = periodo[0].checked;
	var T = periodo[1].checked;
	var S = periodo[2].checked;
	var A = periodo[3].checked;
	
	if (M == true)
	{
		cell.innerHTML = 'Mensal: R$ ' + formataMoeda(valor);
		valorTotal = valor * 1;
	}
	else if (T == true)
	{
		valorTotal = valor * 3;
		valorTotal = valorTotal - (valorTotal * 5 / 100);
		cell.innerHTML = 'Trimestral: R$ ' + formataMoeda(valorTotal);
	}
	else if (S == true)
	{
		valorTotal = valor * 6;
		valorTotal = valorTotal - (valorTotal * 10 / 100);
		cell.innerHTML = 'Semestral: R$ ' + formataMoeda(valorTotal);
	}
	else if (A == true)
	{
		valorTotal = valor * 12;
		valorTotal = valorTotal - (valorTotal * 15 / 100);
		cell.innerHTML = 'Anual: R$ ' + formataMoeda(valorTotal);
	}	
	else
	{
		valorTotal = valor * 1;
	}
	valorFinal.value = formataMoeda(valorTotal);
		
}
function formataMoeda(num) {

   x = 0;

   if(num<0) {
      num = Math.abs(num);
      x = 1;
   }
   if(isNaN(num)) num = "0";
      cents = Math.floor((num*100+0.5)%100);

   num = Math.floor((num*100+0.5)/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));
	ret = num + ',' + cents;
   if (x == 1) ret = ' - ' + ret;return ret;

}
function cartaoIloja()
{
	document.getElementById("cartao").style.visibility = 'visible';
	document.getElementById("cadastro").cartao_iloja.focus();
}
function boleto()
{
	document.getElementById("cartao").style.visibility = 'hidden';
}