ajaxQtde = new Array();

function VerDetalhesProdutos(idProduto) {
    if (idProduto.length > 0) {
        if (document.frmParte != undefined) {
            location.href = "shopping.jsp?idProduto=" + idProduto + "&Loja=CavZodiaco&Categoria=" + document.frmParte.Categoria.value + "&TextoProduto=" + document.frmShopping.TextoProduto.value;
        } else {
            location.href = "shopping.jsp?idProduto=" + idProduto + "&Loja=CavZodiaco";
        }
    }
}

function VoltarShopping() {
    document.frmVoltar.submit();
}

function AmpliarFotoShopping(idProduto) {
   Foto = document.getElementById("foto_shopping").src;
   JanelaFoto = window.open("/ampliarfoto_shopping.jsp?idProduto=" + idProduto + "&Foto=" + Foto + "#Atual", "JanelaFoto", "width=750,height=690,scrollbars=yes,top=0,left=0,status=0");
   JanelaFoto.focus();   
}

function MudaFotoProduto(Foto,idProduto) {
    document.getElementById("foto_shopping").src = "produtos/" + idProduto + "/thumb_" + Foto;
    document.getElementById("foto_shopping").width = 104;
    document.getElementById("foto_shopping").height = 120;
}

function RemoverShopping(idProduto) {
    if (idProduto.length > 0) {
		if (confirm("Deseja realmente remover este produto do seu Carrinho de Compras?")) {
           location.href = "shopping_carrinho.jsp?idProduto=" + idProduto + "&Opcao=Remover";
		}
    }
}

function RemoverShopping2(idProduto,idTipo) {
    if ((idProduto.length > 0) && (idTipo.length > 0)) {
        if (confirm("Deseja realmente remover este produto do seu Carrinho de Compras?")) {
            location.href = "shopping_carrinho.jsp?idProduto=" + idProduto + "&idTipo=" + idTipo + "&Opcao=Remover";
        }
    }
} 

function ajaxInit() {
   var req;
   try {
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } catch(e) {
      try {
         req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(ex) {
         try {
            req = new XMLHttpRequest();
         } catch(exc) {
            alert("Esse browser não tem recursos para uso do Ajax");
            req = null;
         }
      }
   }
   return req;
}

function AtualizaPreco(Objeto,idProduto,Figura) {
   if (Objeto.value == "0") {
       if (confirm("Deseja realmente remover este produto do seu Carrinho de Compras?") == false) {
           document.getElementById("Qtde_" + idProduto).value = document.getElementById("QtdeAnt_" + idProduto).value;
           return;
       } else {
           location.href = "shopping_carrinho.jsp?idProduto=" + idProduto + "&Opcao=Remover";
           return;
       }
   }
   document.frmCarrinho.CEP.disabled = true;
   document.frmCarrinho.Cupom.disabled = true;
   CamposTexto = document.getElementsByTagName("input");
   for (x = 0; x < CamposTexto.length; x++) {
      if (Objeto.name != CamposTexto[x].name) {
	     if (CamposTexto[x].name.substring(0,5) == "Qtde_") {
			 CamposTexto[x].disabled = true;
		 }
	  }
   }
   CEP = document.frmCarrinho.CEP.value;
   if (CEP.length > 0) {
      document.getElementById("Frete").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";	   
   }
   document.getElementById("total_" + idProduto).innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/" + Figura + "' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
   document.getElementById("ValorTotalGeral").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
   ajaxQtde[idProduto] = ajaxInit();
   resultado = "";
   if (ajaxQtde[idProduto]) {
      ajaxQtde[idProduto].open("GET", "atualiza_preco.jsp?idProduto=" + idProduto + "&CEP=" + CEP + "&Quantidade=" + Objeto.value + "&Rand=" + Math.ceil(Math.random() * 100000), true);
      ajaxQtde[idProduto].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      ajaxQtde[idProduto].onreadystatechange = function() {
          if (ajaxQtde[idProduto].readyState == 4) {
              if (ajaxQtde[idProduto].status == 200) {
                  resultado = ajaxQtde[idProduto].responseText;
                  if (resultado == "0|") {
                      alert("ERRO:\n\nProduto Inválido!");
                      if (CEP.length > 0) {
                          document.frmCarrinho.CEP.value = "";
                          document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                      }
                      document.getElementById("total_" + idProduto).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + document.getElementById("ValorTotalAnt_" + idProduto).value + "</b></font></center>";
                      document.getElementById("Qtde_" + idProduto).value = document.getElementById("QtdeAnt_" + idProduto).value;
                      document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                  }
                  if (resultado == "1|") {
                      AtualizaFrete(document.frmCarrinho.CEP.value);
                      alert("ATENÇÃO:\n\nA quantidade que você informou não está disponível para este produto no momento!");
                      document.getElementById("total_" + idProduto).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + document.getElementById("ValorTotalAnt_" + idProduto).value + "</b></font></center>";
                      document.getElementById("Qtde_" + idProduto).value = document.getElementById("QtdeAnt_" + idProduto).value;
                      document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                  }
                  if (resultado.substring(0, 2) == "2|") {
                      splitResultado = resultado.split("|");
                      document.getElementById("total_" + idProduto).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + splitResultado[1] + "</b></font></center>";
                      document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                      document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                      document.getElementById("QtdeAnt_" + idProduto).value = document.getElementById("Qtde_" + idProduto).value;
                      if (CEP.length > 0) {
                          if (splitResultado[3].length > 0) {
                              if (splitResultado[3] == 0) {
                                  //document.frmCarrinho.CEP.value = "";
                                  document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>grátis</b></font></center>";
                              } else {
                                  document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>R$ " + splitResultado[3] + "</b> (+)</font></center>";
                              }
                          } else {
                              document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                          }
                      }
                  }
                  document.frmCarrinho.CEP.disabled = false;
                  CamposTexto = document.getElementsByTagName("input");
                  for (x = 0; x < CamposTexto.length; x++) {
                      if (Objeto.name != CamposTexto[x].name) {
                          if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                              CamposTexto[x].disabled = false;
                          }
                      }
                  }
                  document.frmCarrinho.Cupom.disabled = false;
              } else {
                  alert("ERRO:\n\Dados Inválidos!");
                  if (CEP.length > 0) {
                      document.frmCarrinho.CEP.value = "";
                      document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                  }
                  document.getElementById("total_" + idProduto).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + document.getElementById("ValorTotalAnt_" + idProduto).value + "</b></font></center>";
                  document.getElementById("Qtde_" + idProduto).value = document.getElementById("QtdeAnt_" + idProduto).value;
                  document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                  document.frmCarrinho.CEP.disabled = false;
                  CamposTexto = document.getElementsByTagName("input");
                  for (x = 0; x < CamposTexto.length; x++) {
                      if (Objeto.name != CamposTexto[x].name) {
                          if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                              CamposTexto[x].disabled = false;
                          }
                      }
                  }
                  document.frmCarrinho.Cupom.disabled = false;
              }
          }
      }
	  ajaxQtde[idProduto].send(null);
   }
}

function AtualizaPreco2(Objeto, idProduto, Figura, idTipo) {
    if (Objeto.value == "0") {
        if (confirm("Deseja realmente remover este produto do seu Carrinho de Compras?") == false) {
            document.getElementById("Qtde_" + idProduto + "_" + idTipo).value = document.getElementById("QtdeAnt_" + idProduto + "_" + idTipo).value;
            return;
        } else {
            location.href = "shopping_carrinho.jsp?idProduto=" + idProduto + "&idTipo=" + idTipo + "&Opcao=Remover";
            return;
        }
    }
    document.frmCarrinho.CEP.disabled = true;
    document.frmCarrinho.Cupom.disabled = true;
    CamposTexto = document.getElementsByTagName("input");
    for (x = 0; x < CamposTexto.length; x++) {
        if (Objeto.name != CamposTexto[x].name) {
            if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                CamposTexto[x].disabled = true;
            }
        }
    }
    CEP = document.frmCarrinho.CEP.value;
    if (CEP.length > 0) {
        document.getElementById("Frete").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    }
    document.getElementById("total_" + idProduto + "_" + idTipo).innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/" + Figura + "' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    document.getElementById("ValorTotalGeral").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    ajaxQtde[idProduto] = ajaxInit();
    resultado = "";
    if (ajaxQtde[idProduto]) {
        ajaxQtde[idProduto].open("GET", "atualiza_preco2.jsp?idProduto=" + idProduto + "&idTipo=" + idTipo + "&CEP=" + CEP + "&Quantidade=" + Objeto.value + "&Rand=" + Math.ceil(Math.random() * 100000), true);
        ajaxQtde[idProduto].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajaxQtde[idProduto].onreadystatechange = function() {
            if (ajaxQtde[idProduto].readyState == 4) {
                if (ajaxQtde[idProduto].status == 200) {
                    resultado = ajaxQtde[idProduto].responseText;
                    if (resultado == "0|") {
                        alert("ERRO:\n\nProduto Inválido!");
                        if (CEP.length > 0) {
                            document.frmCarrinho.CEP.value = "";
                            document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                        }
                        document.getElementById("total_" + idProduto + "_" + idTipo).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + document.getElementById("ValorTotalAnt_" + idProduto + "_" + idTipo).value + "</b></font></center>";
                        document.getElementById("Qtde_" + idProduto + "_" + idTipo).value = document.getElementById("QtdeAnt_" + idProduto + "_" + idTipo).value;
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    }
                    if (resultado == "1|") {
                        AtualizaFrete3(document.frmCarrinho.CEP.value);
                        alert("ATENÇÃO:\n\nA quantidade que você informou não está disponível para este produto no momento!");
                        document.getElementById("total_" + idProduto + "_" + idTipo).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + document.getElementById("ValorTotalAnt_" + idProduto + "_" + idTipo).value + "</b></font></center>";
                        document.getElementById("Qtde_" + idProduto + "_" + idTipo).value = document.getElementById("QtdeAnt_" + idProduto + "_" + idTipo).value;
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    }
                    if (resultado.substring(0, 2) == "2|") {
                        splitResultado = resultado.split("|");
                        document.getElementById("total_" + idProduto + "_" + idTipo).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + splitResultado[1] + "</b></font></center>";
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                        document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                        document.getElementById("QtdeAnt_" + idProduto + "_" + idTipo).value = document.getElementById("Qtde_" + idProduto + "_" + idTipo).value;
                        if (CEP.length > 0) {
                            if (splitResultado[3].length > 0) {
                                if (splitResultado[3] == 0) {
                                    //document.frmCarrinho.CEP.value = "";
                                    document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>grátis</b></font></center>";
                                } else {
                                    document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>R$ " + splitResultado[3] + "</b> (+)</font></center>";
                                }
                            } else {
                                document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                            }
                        }
                    }
                    document.frmCarrinho.CEP.disabled = false;
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (Objeto.name != CamposTexto[x].name) {
                            if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                                CamposTexto[x].disabled = false;
                            }
                        }
                    }
                    document.frmCarrinho.Cupom.disabled = false;
                } else {
                    alert("ERRO:\n\Dados Inválidos!");
                    if (CEP.length > 0) {
                        document.frmCarrinho.CEP.value = "";
                        document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                    }
                    document.getElementById("total_" + idProduto + "_" + idTipo).innerHTML = "<center><font style='font-size: 13px;' color='black'><b>R$ " + document.getElementById("ValorTotalAnt_" + idProduto + "_" + idTipo).value + "</b></font></center>";
                    document.getElementById("Qtde_" + idProduto + "_" + idTipo).value = document.getElementById("QtdeAnt_" + idProduto + "_" + idTipo).value;
                    document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    document.frmCarrinho.CEP.disabled = false;
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (Objeto.name != CamposTexto[x].name) {
                            if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                                CamposTexto[x].disabled = false;
                            }
                        }
                    }
                    document.frmCarrinho.Cupom.disabled = false;
                }
            }
        }
        ajaxQtde[idProduto].send(null);
    }
}

function AtualizaFrete(CEP) {
   document.getElementById("Frete").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
   document.getElementById("ValorTotalGeral").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
   ajaxCEP = ajaxInit();
   resultado = "";
   document.frmCarrinho.Cupom.disabled = true;
   CamposTexto = document.getElementsByTagName("input");
   for (x = 0; x < CamposTexto.length; x++) {
      if (CamposTexto[x].name.substring(0,5) == "Qtde_") {
		 CamposTexto[x].disabled = true;
	  }
   }			   			      
   if (ajaxCEP) {
      ajaxCEP.open("GET", "atualiza_correio.jsp?CEP=" + CEP + "&Rand=" + Math.ceil(Math.random() * 100000), true);
      ajaxCEP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      ajaxCEP.onreadystatechange = function() {
          if (ajaxCEP.readyState == 4) {
              if (ajaxCEP.status == 200) {
                  resultado = ajaxCEP.responseText;
                  if (resultado == "-1|") {
                      alert("ERRO:\n\nCEP Inválido!");
                      document.frmCarrinho.CEP.value = "";
                      document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                      document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                      document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
                  }                  
                  if (resultado == "0|") {
                      alert("ERRO:\n\nProduto Inválido!");
                      document.frmCarrinho.CEP.value = "";
                      document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                      document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                      document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
                  }
                  if ((resultado.substring(0, 2) == "4|") || (resultado.substring(0, 2) == "3|")) {
                      if (document.frmCarrinho.CEP.value.length > 0) {
                          alert("ERRO:\n\nCEP Inválido!");
                      }
                      document.frmCarrinho.CEP.value = "";
                      document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                      splitResultado = resultado.split("|");
                      document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                      document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                      document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
                  }
                  if (resultado.substring(0, 2) == "2|") {
                      splitResultado = resultado.split("|");
                      if (splitResultado[1] == "0,00") {
                          document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>grátis</b></font></center>";
                      } else {
                          if (document.frmCarrinho.CEP.value.length == 0) {
                              document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                          } else {
                              document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>R$ " + splitResultado[1] + "</b> (+)</font></center>";
                          }
                      }
                      document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                      document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                      document.getElementById("FecharPedidoBotao").innerHTML = "<a href='javascript:FecharPedido();'><img src='images09/fecharpedido.gif' width='156' height='50' alt='Fechar Pedido' border='0' /></a>";
                  }
                  CamposTexto = document.getElementsByTagName("input");
                  for (x = 0; x < CamposTexto.length; x++) {
                      if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                          CamposTexto[x].disabled = false;
                      }
                  }
                  document.frmCarrinho.Cupom.disabled = false;
              } else {
                  alert("ERRO:\n\Dados Inválidos!");
                  document.frmCarrinho.CEP.value = "";
                  document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                  document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                  CamposTexto = document.getElementsByTagName("input");
                  for (x = 0; x < CamposTexto.length; x++) {
                      if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                          CamposTexto[x].disabled = false;
                      }
                  }
                  document.frmCarrinho.Cupom.disabled = false;
                  document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
              }
          }
      }
	  ajaxCEP.send(null);
   }
}

function AtualizaFrete3(CEP) {
    document.getElementById("Frete").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    document.getElementById("ValorTotalGeral").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    ajaxCEP = ajaxInit();
    resultado = "";
    document.frmCarrinho.Cupom.disabled = true;
    CamposTexto = document.getElementsByTagName("input");
    for (x = 0; x < CamposTexto.length; x++) {
        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
            CamposTexto[x].disabled = true;
        }
    }
    if (ajaxCEP) {
        ajaxCEP.open("GET", "atualiza_correio3.jsp?CEP=" + CEP + "&Rand=" + Math.ceil(Math.random() * 100000), true);
        ajaxCEP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajaxCEP.onreadystatechange = function() {
            if (ajaxCEP.readyState == 4) {
                if (ajaxCEP.status == 200) {
                    resultado = ajaxCEP.responseText;
                    if (resultado == "-1|") {
                        alert("ERRO:\n\nCEP Inválido!");
                        document.frmCarrinho.CEP.value = "";
                        document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                        document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
                    }
                    if (resultado == "0|") {
                        alert("ERRO:\n\nProduto Inválido!");
                        document.frmCarrinho.CEP.value = "";
                        document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                        document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
                    }
                    if ((resultado.substring(0, 2) == "4|") || (resultado.substring(0, 2) == "3|")) {
                        if (document.frmCarrinho.CEP.value.length > 0) {
                            alert("ERRO:\n\nCEP Inválido!");
                        }
                        document.frmCarrinho.CEP.value = "";
                        document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                        splitResultado = resultado.split("|");
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                        document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                        document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
                    }
                    if (resultado.substring(0, 2) == "2|") {
                        splitResultado = resultado.split("|");
                        if (splitResultado[1] == "0,00") {
                            document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>grátis</b></font></center>";
                        } else {
                            if (document.frmCarrinho.CEP.value.length == 0) {
                                document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                            } else {
                                document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>R$ " + splitResultado[1] + "</b> (+)</font></center>";
                            }
                        }
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                        document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                        document.getElementById("FecharPedidoBotao").innerHTML = "<a href='javascript:FecharPedido2();'><img src='images09/fecharpedido.gif' width='156' height='50' alt='Fechar Pedido' border='0' /></a>";
                    }
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                            CamposTexto[x].disabled = false;
                        }
                    }
                    document.frmCarrinho.Cupom.disabled = false;
                } else {
                    alert("ERRO:\n\Dados Inválidos!");
                    document.frmCarrinho.CEP.value = "";
                    document.getElementById("Frete").innerHTML = "<center><font style='font-size: 15px;' color='black'><b>--------</b></font></center>";
                    document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                            CamposTexto[x].disabled = false;
                        }
                    }
                    document.frmCarrinho.Cupom.disabled = false;
                    document.getElementById("FecharPedidoBotao").innerHTML = "<img src='images09/fecharpedido2.gif' width='156' height='50' alt='Fechar Pedido' border='0' />";
                }
            }
        }
        ajaxCEP.send(null);
    }
}

function AtualizaFrete2(CEP, ValorTotal) {
    if (CEP.length > 0) {
        document.getElementById("preco_outrocep").style.display = "block";
        document.getElementById("preco_outrocep").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading1.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde, carregando informações ...</font></td></tr></table></center><br />";
        ajaxCEP = ajaxInit();
        resultado = "";
        if (ajaxCEP) {
            ajaxCEP.open("GET", "atualiza_correio2.jsp?CEP=" + CEP + "&Rand=" + Math.ceil(Math.random() * 100000), true);
            ajaxCEP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajaxCEP.onreadystatechange = function() {
                if (ajaxCEP.readyState == 4) {
                    if (ajaxCEP.status == 200) {
                        resultado = ajaxCEP.responseText;
                        if (resultado == "-1|") {
                            alert("ERRO:\n\nCEP Inválido!");
                            document.frmPedido2.CEP.value = "";
                            document.getElementById("preco_outrocep").style.display = "none";
                        }
                        if (resultado == "0|") {
                            alert("ERRO:\n\nProduto Inválido!");
                            document.frmPedido2.CEP.value = "";
                            document.getElementById("preco_outrocep").style.display = "none";
                        }
                        if ((resultado.substring(0, 2) == "4|") || (resultado.substring(0, 2) == "3|")) {
                            if (document.frmPedido2.CEP.value.length > 0) {
                                alert("ERRO:\n\nCEP Inválido!");
                            }
                            document.frmPedido2.CEP.value = "";
                            document.getElementById("preco_outrocep").style.display = "none";
                            splitResultado = resultado.split("|");
                        }
                        if (resultado.substring(0, 2) == "2|") {
                            splitResultado = resultado.split("|");
                            document.getElementById("preco_outrocep").innerHTML = "<table cellspacing=\"1\" cellpadding=\"2\" border=\"0\">";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<tr>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<td align=\"center\" width=\"150\" valign=\"middle\" bgcolor=\"#ffffff\">";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 12px;\">Neste caso, o preço do<br />frete será de<br />";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 15px;\"><b>R$ " + splitResultado[1] + "</b></font><br />e o total do seu pedido<br />será de<br />";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 17px;\"><b>R$ " + splitResultado[2] + "</b></font><br />";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 11px;\">";
                            ValorTotal = ValorTotal.replace(".", "#");
                            ValorTotal = ValorTotal.replace(",", ".");
                            ValorTotal = ValorTotal.replace("#", ",");
                            ValorTotalNovo = splitResultado[2];
                            ValorTotalNovo = ValorTotalNovo.replace(".", "#");
                            ValorTotalNovo = ValorTotalNovo.replace(",", ".");
                            ValorTotalNovo = ValorTotalNovo.replace("#", ",");
                            if (parseFloat(ValorTotal) - parseFloat(ValorTotalNovo) < 0) {
                                document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font color=\"green\">diferença de R$ " + FormatarMoeda(parseFloat(ValorTotalNovo) - parseFloat(ValorTotal)) + " (+)</font><br />"
                            } else if (parseFloat(ValorTotal) - parseFloat(ValorTotalNovo) == 0) {
                                document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font color='blue'>não há diferença de preço</font><br />"
                            } else {
                                document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font color=\"red\">diferença de  R$ " + FormatarMoeda(parseFloat(ValorTotal) - parseFloat(ValorTotalNovo)) + " (-)</font><br />"
                            }
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</font></font>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</td>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</tr>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</table><br /><br />";
                            document.frmPedido2.Estado.value = splitResultado[3];
                            document.frmPedido2.Cidade.value = splitResultado[4];
                            document.frmPedido2.Bairro.value = splitResultado[5];
                            document.frmPedido2.Endereco.value = splitResultado[6];
                            if (splitResultado[3].length == 0) {
                                document.getElementById("preco_outrocep").style.display = "none";
                                alert("ERRO:\n\nCEP inválido!");
                                document.frmPedido2.CEP.value = "";
                            }
                        }
                    } else {
                        alert("ERRO:\n\Dados Inválidos!");
                        document.frmPedido2.CEP.value = "";
                        document.getElementById("preco_outrocep").style.display = "none";
                    }
                }
            }
            ajaxCEP.send(null);
        }
    }
}

function AtualizaFrete4(CEP, ValorTotal) {
    if (CEP.length > 0) {
        document.getElementById("preco_outrocep").style.display = "block";
        document.getElementById("preco_outrocep").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading1.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde, carregando informações ...</font></td></tr></table></center><br />";
        ajaxCEP = ajaxInit();
        resultado = "";
        if (ajaxCEP) {
            ajaxCEP.open("GET", "atualiza_correio4.jsp?CEP=" + CEP + "&Rand=" + Math.ceil(Math.random() * 100000), true);
            ajaxCEP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajaxCEP.onreadystatechange = function() {
                if (ajaxCEP.readyState == 4) {
                    if (ajaxCEP.status == 200) {
                        resultado = ajaxCEP.responseText;
                        resultado = unescape(resultado);
                        if (resultado == "-1|") {
                            alert("ERRO:\n\nCEP Inválido!");
                            document.frmPedido2.CEP.value = "";
                            document.getElementById("preco_outrocep").style.display = "none";
                        }
                        if (resultado == "0|") {
                            alert("ERRO:\n\nProduto Inválido!");
                            document.frmPedido2.CEP.value = "";
                            document.getElementById("preco_outrocep").style.display = "none";
                        }
                        if ((resultado.substring(0, 2) == "4|") || (resultado.substring(0, 2) == "3|")) {
                            if (document.frmPedido2.CEP.value.length > 0) {
                                alert("ERRO:\n\nCEP Inválido!");
                            }
                            document.frmPedido2.CEP.value = "";
                            document.getElementById("preco_outrocep").style.display = "none";
                            splitResultado = resultado.split("|");
                        }
                        if (resultado.substring(0, 2) == "2|") {
                            splitResultado = resultado.split("|");
                            document.getElementById("preco_outrocep").innerHTML = "<table cellspacing=\"1\" cellpadding=\"2\" border=\"0\">";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<tr>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<td align=\"center\" width=\"150\" valign=\"middle\" bgcolor=\"#ffffff\">";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 12px;\">Neste caso, o preço do<br />frete será de<br />";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 15px;\"><b>R$ " + splitResultado[1] + "</b></font><br />e o total do seu pedido<br />será de<br />";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 17px;\"><b>R$ " + splitResultado[2] + "</b></font><br />";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font style=\"font-size: 11px;\">";
                            ValorTotal = ValorTotal.replace(".", "#");
                            ValorTotal = ValorTotal.replace(",", ".");
                            ValorTotal = ValorTotal.replace("#", ",");
                            ValorTotalNovo = splitResultado[2];
                            ValorTotalNovo = ValorTotalNovo.replace(".", "#");
                            ValorTotalNovo = ValorTotalNovo.replace(",", ".");
                            ValorTotalNovo = ValorTotalNovo.replace("#", ",");
                            if (parseFloat(ValorTotal) - parseFloat(ValorTotalNovo) < 0) {
                                document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font color=\"green\">diferença de R$ " + FormatarMoeda(parseFloat(ValorTotalNovo) - parseFloat(ValorTotal)) + " (+)</font><br />"
                            } else if (parseFloat(ValorTotal) - parseFloat(ValorTotalNovo) == 0) {
                                document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font color='blue'>não há diferença de preço</font><br />"
                            } else {
                                document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "<font color=\"red\">diferença de  R$ " + FormatarMoeda(parseFloat(ValorTotal) - parseFloat(ValorTotalNovo)) + " (-)</font><br />"
                            }
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</font></font>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</td>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</tr>";
                            document.getElementById("preco_outrocep").innerHTML = document.getElementById("preco_outrocep").innerHTML + "</table><br /><br />";
                            document.frmPedido2.Estado.value = splitResultado[3];
                            document.frmPedido2.Cidade.value = splitResultado[4];
                            document.frmPedido2.Bairro.value = splitResultado[5];
                            document.frmPedido2.Endereco.value = splitResultado[6];
                            if (splitResultado[3].length == 0) {
                                document.getElementById("preco_outrocep").style.display = "none";
                                alert("ERRO:\n\nCEP inválido!");
                                document.frmPedido2.CEP.value = "";
                            }
                        }
                    } else {
                        alert("ERRO:\n\Dados Inválidos!");
                        document.frmPedido2.CEP.value = "";
                        document.getElementById("preco_outrocep").style.display = "none";
                    }
                }
            }
            ajaxCEP.send(null);
        }
    }
}

function FormatarMoeda(Valor) {
    Valor = "" + Valor;
    if (Valor.indexOf(".") > 0) {
        Valor = Valor.substring(0, Valor.indexOf(".")) + "," + Valor.substring(Valor.indexOf(".")+1, Valor.indexOf(".")+3);
    } else {
        Valor = Valor + ",00";
    }
    return Valor;
}

function AtualizaCupom(Valor) {
    document.getElementById("DivCupom").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    document.getElementById("ValorTotalGeral").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    document.frmCarrinho.CEP.disabled = true;    
    ajaxCUPOM = ajaxInit();
    resultado = "";
    CamposTexto = document.getElementsByTagName("input");
    for (x = 0; x < CamposTexto.length; x++) {
        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
            CamposTexto[x].disabled = true;
        }
    }
    if (ajaxCUPOM) {
        ajaxCUPOM.open("GET", "atualiza_cupom.jsp?Cupom=" + Valor + "&Rand=" + Math.ceil(Math.random() * 100000), true);
        ajaxCUPOM.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajaxCUPOM.onreadystatechange = function() {
            if (ajaxCUPOM.readyState == 4) {
                if (ajaxCUPOM.status == 200) {
                    resultado = ajaxCUPOM.responseText;
                    if (resultado == "0|") {
                        alert("ERRO:\n\nProduto Inválido!");
                        document.frmCarrinho.Cupom.value = "";
                        document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    }
                    if ((resultado.substring(0, 2) == "4|") || (resultado.substring(0, 2) == "3|")) {
                        if (document.frmCarrinho.Cupom.value.length > 0) {
                            alert("ERRO:\n\nCupom Inválido!");
                        }
                        document.frmCarrinho.Cupom.value = "";
                        document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                        splitResultado = resultado.split("|");
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                        document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                    }
                    if (resultado.substring(0, 2) == "2|") {
                        splitResultado = resultado.split("|");
                        if (splitResultado[1] == 0) {
                            document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                        } else {
                            if (document.frmCarrinho.Cupom.value.length == 0) {
                                document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                            } else {
                                document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>R$ " + splitResultado[1] + "</b> (-)</font></center>";
                            }
                        }
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                        document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                    }
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                            CamposTexto[x].disabled = false;
                        }
                    }
                    document.frmCarrinho.CEP.disabled = false;
                } else {
                    alert("ERRO:\n\Dados Inválidos!");
                    document.frmCarrinho.Cupom.value = "";
                    document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                    document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                            CamposTexto[x].disabled = false;
                        }
                    }
                    document.frmCarrinho.CEP.disabled = false;
                }
            }
        }
        ajaxCUPOM.send(null);
    }
}

function AtualizaCupom2(Valor) {
    document.getElementById("DivCupom").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    document.getElementById("ValorTotalGeral").innerHTML = "<center><table cellspacing='1' cellpadding='2' border='0'><tr><td valign='middle' align='right'><img src='images09/loading3.gif' width='16' height='16' alt='' border='0' /></td><td align='left' valign='middle'><font style='font-size: 10px; color: #999999;'>aguarde</font></td></tr></table></center>";
    document.frmCarrinho.CEP.disabled = true;
    ajaxCUPOM = ajaxInit();
    resultado = "";
    CamposTexto = document.getElementsByTagName("input");
    for (x = 0; x < CamposTexto.length; x++) {
        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
            CamposTexto[x].disabled = true;
        }
    }
    if (ajaxCUPOM) {
        ajaxCUPOM.open("GET", "atualiza_cupom2.jsp?Cupom=" + Valor + "&Rand=" + Math.ceil(Math.random() * 100000), true);
        ajaxCUPOM.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajaxCUPOM.onreadystatechange = function() {
            if (ajaxCUPOM.readyState == 4) {
                if (ajaxCUPOM.status == 200) {
                    resultado = ajaxCUPOM.responseText;
                    if (resultado == "0|") {
                        alert("ERRO:\n\nProduto Inválido!");
                        document.frmCarrinho.Cupom.value = "";
                        document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    }
                    if ((resultado.substring(0, 2) == "4|") || (resultado.substring(0, 2) == "3|")) {
                        if (document.frmCarrinho.Cupom.value.length > 0) {
                            alert("ERRO:\n\nCupom Inválido!");
                        }
                        document.frmCarrinho.Cupom.value = "";
                        document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                        splitResultado = resultado.split("|");
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                        document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                    }
                    if (resultado.substring(0, 2) == "2|") {
                        splitResultado = resultado.split("|");
                        if (splitResultado[1] == 0) {
                            document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                        } else {
                            if (document.frmCarrinho.Cupom.value.length == 0) {
                                document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                            } else {
                                document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>R$ " + splitResultado[1] + "</b> (-)</font></center>";
                            }
                        }
                        document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + splitResultado[2] + "</b></font></center>";
                        document.frmCarrinho.ValorTotalGeralAnt.value = splitResultado[2];
                    }
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                            CamposTexto[x].disabled = false;
                        }
                    }
                    document.frmCarrinho.CEP.disabled = false;
                } else {
                    alert("ERRO:\n\Dados Inválidos!");
                    document.frmCarrinho.Cupom.value = "";
                    document.getElementById("DivCupom").innerHTML = "<center><font style='font-size: 15px;' color='red'><b>--------</b></font></center>";
                    document.getElementById("ValorTotalGeral").innerHTML = "<center><font style='font-size: 19px;' color='black'><b>R$ " + document.getElementById("ValorTotalGeralAnt").value + "</b></font></center>";
                    CamposTexto = document.getElementsByTagName("input");
                    for (x = 0; x < CamposTexto.length; x++) {
                        if (CamposTexto[x].name.substring(0, 5) == "Qtde_") {
                            CamposTexto[x].disabled = false;
                        }
                    }
                    document.frmCarrinho.CEP.disabled = false;
                }
            }
        }
        ajaxCUPOM.send(null);
    }
}

function FecharPedido() {
    if (document.getElementById("ValorTotalGeral").innerHTML.indexOf("loading") > 0) {
        alert("Aguarde, atualizando preços!");
    } else {
        if (confirm("Atenção: Deseja realmente Fechar o Pedido agora?")) {
            location.href = "shopping_carrinho.jsp?Opcao=FecharPedido";
        }
    }
}

function FecharPedido2() {
    if (document.getElementById("ValorTotalGeral").innerHTML.indexOf("loading") > 0) {
        alert("Aguarde, atualizando preços!");
    } else {
        if (confirm("Atenção: Deseja realmente Fechar o Pedido agora?")) {
            location.href = "shopping_carrinho.jsp?Opcao=FecharPedido";
        }
    }
}

function MudarLoja(Valor) {
    if (Valor != "Fas") {
        document.frmParte.submit();
    } else {
        alert("Aguade, em breve lançaremos o serviço para os fãs venderem seus produtos e montarem suas lojas virtuais!");
        document.frmParte.Loja.selectedIndex = 0;
    }
}

function EfetuarPagamento() {
   Visa = document.frmPagamento.meio_pagamento[0].checked;
   Mastercard = document.frmPagamento.meio_pagamento[1].checked;
   Diners = document.frmPagamento.meio_pagamento[2].checked;
   Aura = document.frmPagamento.meio_pagamento[3].checked;
   Hipercard = document.frmPagamento.meio_pagamento[4].checked;
   AmericanExpress = document.frmPagamento.meio_pagamento[5].checked;
   Boleto = document.frmPagamento.meio_pagamento[6].checked;
   if ((Visa) || (Mastercard) || (Diners) || (Aura) || (Hipercard) || (AmericanExpress) || (Boleto)) {
      document.frmPagamento.submit();
   } else {
	  alert("ATENÇÃO:\n\nSelecione a forma de Pagamento!");   
   }
}

function PreencherEndereco() {
    if (confirm("Deseja realmente preencher o formulário com os dados do seu cadastro?")) {
        document.frmPedido2.Nome.value = document.frmPedido.Nome.value;
        document.frmPedido2.Endereco.value = document.frmPedido.Endereco.value;
        document.frmPedido2.CEP.value = document.frmPedido.CEP.value;
        document.frmPedido2.Bairro.value = document.frmPedido.Bairro.value;
        document.frmPedido2.Cidade.value = document.frmPedido.Cidade.value;
        document.frmPedido2.Estado.value = document.frmPedido.Estado.value;
        document.frmPedido2.CEP.focus();
        document.frmPedido2.CEP.blur();
    }
}

function FecharPedidoGeral(Opcao) {
    if (Opcao == 1) {
        if (confirm("ATENÇÃO:\n\nDeseja realmente selecionar este endereço?")) {
            document.frmPedido.submit();
        }
    } else {
        if (document.frmPedido2.Nome.value.length == 0) {
            alert("Preencha o Nome Completo de Entrega!");
            document.frmPedido2.Nome.focus();
            return;
        }
        if (document.frmPedido2.Endereco.value.length == 0) {
            alert("Preencha o Endereço de Entrega!");
            document.frmPedido2.Endereco.focus();
            return;
        }
        if (document.frmPedido2.CEP.value.length == 0) {
            alert("Preencha o CEP de Entrega!");
            document.frmPedido2.CEP.focus();
            return;
        }
        if (document.frmPedido2.Bairro.value.length == 0) {
            alert("Preencha o Bairro de Entrega!");
            document.frmPedido2.Bairro.focus();
            return;
        }
        if (document.frmPedido2.Cidade.value.length == 0) {
            alert("Preencha a Cidade de Entrega!");
            document.frmPedido2.Cidade.focus();
            return;
        }
        if (document.frmPedido2.Estado.selectedIndex == 0) {
            alert("Preencha o Estado de Entrega!");
            document.frmPedido2.Estado.focus();
            return;
        }
        if (confirm("ATENÇÃO:\n\nDeseja realmente selecionar este endereço?")) {
            document.frmPedido2.submit();
        }
    }
}

function bloquearTeclas(e) {
    var key;
    var keychar;
    var reg;
    if (window.event) {
        key = e.keyCode;
    } else if (e.which) {
        key = e.which;
    } else {
        return true;
    }

    keychar = String.fromCharCode(key);
    reg = /\d/;
    return reg.test(keychar);
}

function VerificaComprar(idProduto) {
    SelecionadoComprar = 0;
    for (z = 0; z < document.frmTipo.Tipo.length; z++) {
        if (document.frmTipo.Tipo[z].checked) {
            SelecionadoComprar = document.frmTipo.Tipo[z].value;
            break;
        }
    }
    if (SelecionadoComprar > 0) {
        location.href = "shopping_carrinho.jsp?Opcao=Comprar&idProduto=" + idProduto + "&idTipo=" + SelecionadoComprar;
    } else {
        alert("ATENÇÃO:\n\nPara comprar este produto, você precisa escolher primeiro o Tipo!");
    }
}
