//<!--


  function esgotado (bloco, dia) {
    alert('A venda do(a) '+bloco+' está esgotada!');
	return;
  }

  function limpa()
  {
 // return;
    f=document.formAbada;
    totalCompra = 0.0;
    for (x=1; x<=totalParcelas; x++)
	  f.elements["parcela"+x].value = "0,00";

    f.socio[0].checked=false;
    f.socio[1].checked=false;
    //f.parcelas[0].checked=true;
    f.total.value = "0,00";
    cod_bloco = -1;

    list = f.dias;
    for (x=list.length-1; x >= 0; x--) 
      list[x].checked = false;
  }


  function reDefineTaxa() {
    valorTaxa=0;
    document.formAbada.inscricao.value="0,00";
    var x=0;
/*
	var list = document.formAbada.dias;
    for (; x<list.length; x++) {
     if (list[x].checked) {
	  var str = list[x].value;
	  var blccod = str.substring(0, str.indexOf(":"));
	  var taxa = parseFloat(pegaTaxa(blccod));
	  if (taxa > valorTaxa) {
	    valorTaxa = parseFloat(taxa);
      }
     }
	}
*/
     var  taxa = parseFloat (pegaTaxa (cod_bloco));
     valorTaxa = parseFloat (taxa);
  }

  function pegaTaxa(blccod) {
    var x=0;
    for(; x<vet_taxas.length; x++) {
	  var str = vet_taxas[x];
	  var bloco = str.substring(0, str.indexOf(":"));
	  var taxa = str.substr(str.indexOf(":")+1);
	  if (blccod == bloco)
	    return taxa;      
	}                 
	return 0;
  }

  function validar(f)
  {

   var total = 0;
   var cesta = f.pacote;
   var produtos = f.produto;
   var blccod = -1;
   var str = "";

   var cmrt_reinoM = 12, cmrt_reinoF = 11, cb_f_RJ_F = 13, cb_f_RJ_M = 14;
   var tem_cmrt_reinoM = false, tem_cmrt_reinoF = false, tem_cb_f_RJ_F = false, tem_cb_f_RJ_M = false;
   
   var pass_m = 15, pass_f = 16, triv_pf_m = 18, triv_pf_f = 17, viravirou = 21, meama = 26;
   var qt_cmrt_reino_f_PROMO = 0, qt_cmrt_reino_m_PROMO = 0;
   var tem_pass_m = false, tem_pass_f = false, tem_triv_pf_m = false, tem_triv_pf_f = false;
   var podeEnviarTDS = false;

   if (cesta == null || produtos == null)
   {
	   alert("Sem produtos para comprar.");
	   return false;
   } 

   cesta.value = "";

   if (produtos.length == null) { // só tem um produto
		blccod = produtos.value;
		var diasCad = f.elements["dias"+blccod];
		if (diasCad.length == null) {
			//if (diasCad.value != 'TDS' && diasCad.checked)
			  f.pacote.value += zeroLeft(blccod, 3) + diasCad.value;
		} else {
			for (var i=0;i<diasCad.length;i++) {
				if (diasCad[i].value != 'TDS' && diasCad[i].checked)
				  f.pacote.value += zeroLeft(blccod, 3) + diasCad[i].value;
			} // for
		} // else
   } else { // tem mais de um produto
		for (var x=0;x<produtos.length;x++) {
			blccod = produtos[x].value;
			var diasCad = f.elements["dias"+blccod];
			if (diasCad != null) {
				if (diasCad.length == null) {
					if (diasCad.value != 'TDS' && diasCad.checked) {
						f.pacote.value += zeroLeft(blccod, 3) + diasCad.value;
						if (blccod == cb_f_RJ_F)
						  tem_cb_f_RJ_F = (diasCad.checked);
						if (blccod == cb_f_RJ_M)
						  tem_cb_f_RJ_M = (diasCad.checked);
						if (blccod == pass_m)
							tem_pass_m = true;
						if (blccod == pass_f)
							tem_pass_f = true;
						if (blccod == triv_pf_m)
							tem_triv_pf_m = true;
						if (blccod == triv_pf_f)
							tem_triv_pf_f = true;
					}
					if (diasCad.value == 'TDS' && diasCad.checked) {
						podeEnviarTDS = (blccod == viravirou || blccod == meama);//false;
						if (blccod == pass_m) {
							tem_pass_m = true;
							podeEnviarTDS = true; }
						if (blccod == pass_f) {
							tem_pass_f = true;
							podeEnviarTDS = true; }
						if (blccod == triv_pf_m) {
							tem_triv_pf_m = true;
							podeEnviarTDS = true; }
						if (blccod == triv_pf_f) {
							tem_triv_pf_f = true;
							podeEnviarTDS = true; }
						if (podeEnviarTDS)
							f.pacote.value += zeroLeft(blccod, 3) + "TDS"; //diasCad.value;
					}
				} else {
					for (var i=0;i<diasCad.length;i++) {
						if (diasCad[i].value != 'TDS' && diasCad[i].checked)
							f.pacote.value += zeroLeft(blccod, 3) + diasCad[i].value;
						else {
							if (blccod == cmrt_reinoM)
								tem_cmrt_reinoM = (diasCad[i].value == 'TDS' && diasCad[i].checked) ;
							if (blccod == cmrt_reinoF)
								tem_cmrt_reinoF = (diasCad[i].value == 'TDS' && diasCad[i].checked) ;
						}
						if (blccod == cmrt_reinoM && ((diasCad[i].value == 'SEX' && diasCad[i].checked) ||
								(diasCad[i].value == 'DOM' && diasCad[i].checked) ||
								(diasCad[i].value == 'SEG' && diasCad[i].checked))
							)
								qt_cmrt_reino_m_PROMO++;
							if (blccod == cmrt_reinoF && ((diasCad[i].value == 'SEX' && diasCad[i].checked) ||
									(diasCad[i].value == 'DOM' && diasCad[i].checked) ||
									(diasCad[i].value == 'SEG' && diasCad[i].checked)))
									qt_cmrt_reino_f_PROMO ++;
					} // for
				} // else diasCad
			} // diasCad != null
		} // for produtos
   } // else

	if (cesta.value == "")
	{
	  alert("Selecione pelo menos um dia de algum dos produtos disponíveis antes de prosseguir!");
	  return false;
	}

	if (tem_cmrt_reinoF && tem_cmrt_reinoM && (tem_cb_f_RJ_M || tem_cb_f_RJ_F)) {
		alert("Selecionando todos os dias do Camarote do Reino CASAL você não terá direito ao Cocobambu Folia Rio.\nPara ganhar esta promoção, selecione todos os dias do MASCULINO ou FEMININO do Camarote do Reino e o Cocobambu Folia Rio do mesmo sexo.");
		return false;
	}
	if ((tem_cmrt_reinoF && (tem_cb_f_RJ_M)) || (tem_cmrt_reinoM && (tem_cb_f_RJ_F))) {
		alert("Para ganhar o Cocobambu Folia Rio, selecione todos os dias do MASCULINO ou FEMININO do Camarote do Reino e o Cocobambu Folia do mesmo sexo.");
		return false;
	}
	var qt_promosM = 0, qt_promosF = 0;
		if (tem_pass_m)
			qt_promosM ++;
		if (tem_pass_f)
			qt_promosF ++;
		if (tem_triv_pf_m)
			qt_promosM ++; 
		if (tem_triv_pf_f)
			qt_promosF ++;

	if (((tem_pass_m || tem_triv_pf_m) && (qt_cmrt_reino_m_PROMO < qt_promosM)) ||
		((tem_pass_f || tem_triv_pf_f) && (qt_cmrt_reino_f_PROMO < qt_promosF))) {
		alert("REVISE A COMPOSIÇÃO DO SEU PACOTE!\nAqui no site do Camarote do Reino o folião só pode comprar 'pacotes promocionais' do \nCamarote do Reino com o Passaporte Vira Virou e pacotes promocionais do\nCamarote do Reino com a Trivela Praia do Forte.\n\nCaso deseje comprar apenas o Passaporte Vira Virou ou apenas a Trivela Praia do Forte,\npor favor entre em contato com o Reino da Folia no telefone (71) 3245-9166.");
		return false;
	}
	if ((tem_cmrt_reinoF && (tem_cb_f_RJ_M)) || (tem_cmrt_reinoM && (tem_cb_f_RJ_F))) {
		alert("Para ganhar o Cocobambu Folia Rio, selecione todos os dias do MASCULINO ou FEMININO do Camarote do Reino e o Cocobambu Folia do mesmo sexo.");
		return false;
	}

//	alert("OK!");
//	return false;

// Tirado de confirmacao_compras_int.asp
    if ((f.estado.selectedIndex <= 0) || (f.pais.selectedIndex <= 0)) {
	  alert("Você deve informar o estado e o país!");
	  mostrarM("", f);
      f.estado.focus();
	  return false;
	} else
	{
		if ((f.pais.options[f.pais.selectedIndex].value != '5') && 
		    (f.estado.options[f.estado.selectedIndex].value != '-')) {
			alert ("Por favor, verifique a opção de estado!");
			mostrarM("", f);
			f.estado.focus();
			return false;
		}
	}		
// fim de script trocado
/*
    f.compra_reservada.value = eval("compra_reservada_"+cod_bloco);
    if (eval("compra_reservada_"+cod_bloco)) {
     if (f.senha.value == "") {
        alert("O lote para este bloco está reservado\npara vendas a comissários.\n\nPor favor, informe a senha para efetuar a compra.");
	    f.senha.focus();
       return false;
	 }

    }
*/

    f.submit();
	return true;
  }

//  function jaTemOutroNoDia (mix, blccod, diacod, grpcod) {

//  function comprar(blccod, abrev, diacod, blcnome, valor, grupo, flag) {
	function zeroLeft (valor, qtZeros) {
		var retorno = valor;
		if (qtZeros <= valor.length)
			return retorno;
		var i = qtZeros-valor.length;
		for (var x=0;x<i ;x++ )
			retorno = "0" + retorno;
		return retorno;
	}

  function formatNumber(valor)
  {
    v = new String();
	v.value = valor.toString();

	pos = v.value.indexOf(".");
	if (pos == -1)
	  v.value += ",00";
	else
	{
	  v.value = v.value + "0";
	  v.value = v.value.substr(0, pos + 3);
	  v.value = replaceString(".", ",", v.value);
	}
	count = 0;
    for (i = v.value.length - 1; i >= 1; i--)
	{
      if (v.value.charAt(i) == ",")
	    count = 0;
      else
	    if (((count % 2) == 0) && (count > 0))
	    {
	      count = 0;
		  v.value = v.value.substr(0, i) + "." + v.value.substr(i);
	    }
	  else
	    count++;
	}
    v.value = v.value;
	return v.value;
  }

  function defineTotal(f)
  {
    totalPlano = 0.0; subtotal = 0.0;
	if (totalParcelas == 1) {
      if (f.parcelas.checked) {
       s = f.elements["parcela1"].value;
       s = replaceString(".", "", s);
       s = replaceString(",", ".", s);
       totalPlano = s;
       subtotal=parseFloat(totalPlano);
//       reDefineTaxa();

/*	    //para a taxa de inscricao
       if ((!f.socio[0].checked) && (f.socio[1].checked))
         totalPlano+=parseFloat(valorTaxa);
*/
      }
	} else {
      for (i = 0; i < totalParcelas; i++) {
	    if (f.parcelas[i].checked) {
	      s = f.elements["parcela" + (i+1)].value;
          s = replaceString(".", "", s);
          s = replaceString(",", ".", s);
          totalPlano = s * (i+1);
          subtotal=parseFloat(totalPlano);
//          reDefineTaxa();

/*	    //para a taxa de inscricao
          if ((!f.socio[0].checked) && (f.socio[1].checked))
            totalPlano+=parseFloat(valorTaxa);
*/
          break;
        }
      }
    }
/*  // Dtaxa
	if (f.socio[0].checked)
      f.inscricao.value = "0,00";
    else if (f.socio[1].checked)
      f.inscricao.value = formatNumber(valorTaxa);
*/
	s  = totalPlano.toString();
	st = subtotal.toString();

   // s = replaceString(",", "-", s); s = replaceString(".", ",", s); s = replaceString("-", ".", s);
   // st = replaceString(",", "-", st); st = replaceString(".", ",", st); st = replaceString("-", ".", st);

//    f.subtotal.value = formatNumber(st);        
    f.total.value = formatNumber(s);    
  }

  function arredonda(valorParcela)
  {
    hasCents = valorParcela.toString().indexOf(".");
	var ultimoCent = "";
//	if ((hasCents > 0) && (valorParcela.toString().charAt(hasCents+1) >= 5)) 
//      return parseInt(valorParcela+1);
	if (hasCents > 0) {
	  if (valorParcela.toString().charAt(hasCents+3) != "") {
        if (valorParcela.toString().charAt(hasCents+3) >= 5)
	      ultimoCent = parseInt(valorParcela.toString().charAt(hasCents+2)) + 1;
        else
	      ultimoCent = parseInt(valorParcela.toString().charAt(hasCents+2));
      } else {
        if (valorParcela.toString().charAt(hasCents+2) != "")
	      ultimoCent = parseInt(valorParcela.toString().charAt(hasCents+2));
	  }
      return parseFloat(valorParcela.toString().substring(0, hasCents+2)+ultimoCent);
    }
    return parseFloat(valorParcela);
  }

  function potencia(x, y)
  {
    total=x;
	if (y == 0)
	  total=1;
    for (j=2; j<=y; j++) {
	  total *= x;
	}
	return total;
  }

  function aplicaJuros(valor, taxa, parcela)
  {
     fator = (((potencia((1+taxa), (parcela-1)) - 1) / (potencia((1+taxa), (parcela-1)) * taxa)) + 1);
	 return (valor/fator);
  }

  function calcularParcelas(f)
  {
   f.parcela1.value=formatNumber(totalCompra);
//    taxaJuros = 0.0;
//    if (cod_bloco >= 0)
//      taxaJuros = parseFloat (eval("juros_"+cod_bloco));
// POR ENQUANTO...
	calculaAraketu (f);
    defineTotal(f);  
	return true;

	for (j=2; j<=totalParcelas; j++)
	{
	  valorParcela = aplicaJuros(totalCompra, taxaJuros, j);
      valorParcela=arredonda(valorParcela);
	  f.elements["parcela"+j].value= formatNumber(valorParcela);
    }

    defineTotal(f);  
	return true;
  }


  function calculaAraketu (f) {
       for (j=2; j<=totalParcelas; j++)
       {
         valorParcela = totalCompra/j;
         valorParcela=arredonda(valorParcela);
         f.elements["parcela"+j].value= formatNumber(valorParcela);
       }
       defineTotal(f);  
	   return;
  }

  function alterar(blccod, f, opcao) //, valor, flag)
  {
    cod_bloco = blccod;
	if (opcao)
	  mostrarM(blccod, f);
	return;
//movido para a proxima página.
    v = parseFloat(valor);
//	totalCompra +=(v * flag);
	totalCompra =(v * flag);
    calcularParcelas(f);
  }
  function limpaForm(f, blccod) {
//	  f.reset();
      mostrarM("", f);
  }

  function escolheDias (blc, dia, obj) {
    var f = obj.form;
	var opt = f.elements["dias"+blc];
	var diasCad = f.elements["dia_bloco"+blc];
	if (dia != "TDS" && cod_cms != '') {
		obj.checked = true;
		return;
    }
	  if (dia == "TDS") {
		  if (opt.length != null) {
			 for (var i=0;i<opt.length-1;i++)
			  opt[i].checked = obj.checked;
		  } 
		  if (blc == 12 && f.dias14 != null) {
			  f.dias14.disabled = !obj.checked;
			  f.dias14.checked  = false;
		  }
		  if (blc == 11 && f.dias13 != null) {
			  f.dias13.disabled = !obj.checked;
			  f.dias13.checked  = false;
		  }

      } else {
		  var qt_dias = 1;
		  if (diasCad.length != null)
            qt_dias = diasCad.length-1;

          var qt_sel = 0;
		  if (opt.length != null) {
			 for (var i=0;i<opt.length-1;i++)
			  if (opt[i].checked)
				qt_sel++;
		  } 
		  //alert(qt_dias + " " + qt_sel );
		  if (opt.length != null && opt[opt.length-1].value == "TDS") {
			opt[opt.length-1].checked = ((qt_dias == qt_sel) && (opt.length != null));
			if (blc == 12 && f.dias14 != null) {
				f.dias14.disabled = !opt[opt.length-1].checked;
				f.dias14.checked  = false;
			}
			if (blc == 11 && f.dias13 != null) {
				f.dias13.disabled = !opt[opt.length-1].checked;
				f.dias13.checked  = false;
			}
		  }
      } // else de (dia == "TDS") 
  }

//  function delItem(list)


  function abrir (pag, alvo, altura, largura) {
    h=altura; w=largura;
	t=parseInt( (  (screen.height/2)+(h/2) ) /4)+100;
	l=parseInt( (  (screen.width/2)+(w/2)  ) /4);
	act=pag;
	trgt=alvo;
	feat ="border=no,menubar=no,toolbar=no,status=no,scrollbars=yes,title=no,height="+h+",width="+w;
    feat +=",top="+t+",left="+l;
	window.open (act, trgt, feat);
	return;
  }

  function abrirP (pag, alvo, altura, largura) {
    h=altura; w=largura;
	t=parseInt( ((screen.height - (h + 100)) / 2) );
	l=parseInt( ((screen.width  - w) / 2) );
	act=pag;
	trgt=alvo;
//	alert ("screen.h: "+ screen.height +"\nAltura: "+ h +"\nTop :" + t);
//	alert ("screen.w: "+ screen.width +"\nLargura: "+ w +"\nLeft :" + l);
	feat ="border=no,menubar=yes,toolbar=no,status=yes,scrollbars=yes,title=no,height="+h+",width="+w;
    feat +=",top="+t+",left="+l;
	window.open (act, trgt, feat);
	return;
  }

/////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// -->