	 function Retirar_Embalagem(id_prod) {
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
  	  if(ajax){  
            //alert("Teste");
            ajax.onreadystatechange = function() 
										{ 
											if (ajax.readyState == 4) { 
												if (ajax.status ==200) { 
													cont_emb=document.getElementById("img_embalagem"+id_prod).innerHTML = ajax.responseText; 
												} else { 
													alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
												} 
											} 
										}    ; 
		    //alert("chegou até aqui !!!");
			ajax.open("GET", "carrinho/retirar_embalagem.php?id_prod="+id_prod,true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      ajax.send(null);
      Calculo_embalagem(); 
	  }   
	  
   }

	 function Adicionar_Embalagem(id_prod, id_produto) {
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
  	  if(ajax){  
            
            ajax.onreadystatechange = function() 
										{ 
											if (ajax.readyState == 4) { 
												if (ajax.status ==200) { 
													cont_emb=document.getElementById("img_embalagem"+id_prod).innerHTML = ajax.responseText; 
												} else { 
													alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
												} 
											} 
										}    ;
            //alert(id_prd);                                         
			ajax.open("GET", "embalagem_add2.php?id_prod="+id_prod+"&id_produto=" + id_produto,true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.send(null);
            Calculo_embalagem(); 
	  }   
	  
   }
   function Calculo_embalagem()
   {

	  try {
         ajax1 = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax1 = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax1 = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax1 = null;
            }
         }
      }
  	  if(ajax1){  
            //alert("Teste");
            ajax1.onreadystatechange = function() 
										{ 
											if (ajax1.readyState == 4) { 
												if (ajax1.status ==200) { 
												//alert(document.getElementById("div_valor_embalagem"));
			                     document.getElementById("div_valor_embalagem").innerHTML = ajax1.responseText; 
												} else { 
													alert("Houve um problema ao obter os dados:\n" + ajax1.statusText); 
												} 
											} 
										}    ; 
			//alert("chegou ate aqui !!!");
			ajax1.open("GET", "carrinho/calculo_embalagem.php",true);
			ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax1.send(null);  
      } 
   }



	 function Recalcular_cep(cep) {
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
  	  if(ajax){  
			var conteudo=document.getElementById("id_cep");
			conteudo.innerHTML='<strong>Carregando valor do frete...</strong>';
            ajax.onreadystatechange = processCepChange; 
			ajax.open("GET", "carrinho/frete.php?id_cep="+cep,true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.send(null); 
	  }   
   }


function Recalcular_vale(vale) {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	if(ajax){  
		var conteudo=document.getElementById("id_vale");
		conteudo.innerHTML='<strong>Carregando...</strong>';
		ajax.onreadystatechange = processValeChange; 
		ajax.open("GET", "carrinho/recalcular_vale.php?vale="+vale,true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null); 

		Desconto_Compra();
		Saldo_Vale_Presente(vale);
		Total_Compra();
	}   
}

   function Saldo_Vale_Presente(vale)
   {
	  try {
         ajax_saldo = new ActiveXObject("Microsoft.XMLHTTP");

      } 
      catch(e) {
         try {
            ajax_saldo = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax_saldo = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax_saldo = null;
            }
         }
      }
  	  if(ajax_saldo){  
	  		var conteudo = document.getElementById("id_vale_saldo");
			conteudo.innerHTML='<strong>Carregando...</strong>';
            ajax_saldo.onreadystatechange = function()
											{
												if (ajax_saldo.readyState == 4) { 
													if (ajax_saldo.status ==200) { 
														conteudo.innerHTML = ajax_saldo.responseText; 
													} else { 
														alert("Houve um problema ao obter os dados:\n" + ajax_saldo.statusText); 
													} 
												} 
											
											}
 
			ajax_saldo.open("GET", "carrinho/calcular_saldo_vale.php?vale="+vale,true);
			ajax_saldo.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax_saldo.send(null); 
	  }   
   }
   function Recalcular_vale2(valor)
   {
		window.location.href="carrinho/recalcular_vale2.php?vale="+valor;
   }

   function Atualizar_Valores(linhas) {
			 try {
				 ajax = new ActiveXObject("Microsoft.XMLHTTP");
			  } 
			  catch(e) {
				 try {
					ajax = new ActiveXObject("Msxml2.XMLHTTP");
				 }
				 catch(ex) {
					try {
					   ajax = new XMLHttpRequest();
					}
					catch(exc) {
					   alert("Esse browser não tem recursos para uso do Ajax");
					   ajax = null;
					}
				 }
			  }
			  if(ajax){  
					if (linhas > "0")
					{
						for (i=1;i <= linhas; i++) 
						{
							if (i == 1)
							   texto = eval('document.getElementById("cmp_qtd'+i+'").value');
							else
							   texto = texto + ',' + eval('document.getElementById("cmp_qtd'+i+'").value');
						}

			        }else
			        texto="";
					var conteudo=document.getElementById("lista");
					//conteudo.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
					ajax.onreadystatechange = processReqChange;
					ajax.open("GET", "carrinho/atualizar_valores.php?texto="+texto+"&linhas="+linhas,true);
					//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					//alert(ajax.readyState);
					ajax.send(null); 
					Calculo_embalagem();
					Desconto_Compra();
					Total_Compra();
 		  }   
   }
   


	 function Total_Compra() {
	  try {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               xmlhttp = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               xmlhttp = null;
            }
         }
      }
  	  if(xmlhttp){  
  		    var cont_preco = document.getElementById("preco_total");
			var cod_vale = document.frm_vale.cmp_vale.value;
			var id_frete = document.getElementById("opEntrega").value;
            
            if (id_frete > "0") 
 			   var vr_frete = eval('document.getElementById("total_frete'+id_frete+'").value');
			else
			   var vr_frete = "0";

			cont_preco.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
            xmlhttp.onreadystatechange = processTotalChange; 
			xmlhttp.open("GET", "carrinho/total_compra.php?vale="+cod_vale+"&vr_frete="+vr_frete,true);
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlhttp.send(null);   
			
	  }   
   }


 function Desconto_Compra() {
	  try {
         deschttp = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            deschttp = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               deschttp = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               deschttp = null;
            }
         }
      }
  	  if(deschttp){  
  		    var cont_desc = document.getElementById("id_desconto");
			cont_desc.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
            deschttp.onreadystatechange = processDescChange; 
			deschttp.open("GET", "carrinho/desconto_compra.php",true);
			deschttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            deschttp.send(null); 
	  }   
   }



    function Limpar_Carrinho() {
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
  	  if(ajax){  
  		    var conteudo=document.getElementById("lista");
			conteudo.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
			document.getElementById("id_Atualizar").innerHTML = '<a href="#" onClick="javascript:Atualizar_Valores(0);"><img src="imagens/bt_atualizar_valores.gif" border="0" width="74" height="14">';
            ajax.onreadystatechange = processReqChange; 
			ajax.open("POST", "carrinho/limpar_carrinho.php",true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.send(null); 
            Atualizar_Valores(0);
	  }   
   }


function Remover_Item(valor) {
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
  	  if(ajax){  
            var total = document.getElementById("hd_total").value;
			total = total -1;
  		    var conteudo=document.getElementById("lista");
			conteudo.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
			document.getElementById("id_Atualizar").innerHTML = '<a href="#" onClick="javascript:Atualizar_Valores('+total+');"><img src="imagens/bt_atualizar_valores.gif" border="0" width="74" height="14">';
            ajax.onreadystatechange = processReqChange2; 
			ajax.open("GET", "carrinho/remover_item.php?n="+valor,true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.send(null);
            
            
	  }   
}
   
function processReqChange() 
{ 
    if (ajax.readyState == 4) {
        if (ajax.status ==200) { 
			conteudo=document.getElementById("lista").innerHTML = ajax.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    }
}    

function processReqChange2() 
{ 
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			conteudo=document.getElementById("lista").innerHTML = ajax.responseText;
			Atualizar_Valores(document.getElementById("hd_total").value);
			
			valorTotal = document.getElementById("hd_total").value;
			
			if (valorTotal > 100 && valorTotal < 150){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 100,00 você ganha um vibrador Blue Heaven</b>";
			}
			if (valorTotal > 150 && valorTotal < 200){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 150,00 você ganha um vibrador Magic G Spot</b>";
			}
			if (valorTotal > 200 && valorTotal < 300){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 200,00 você ganha um estimulador Rocket Lover</b>";
			}
			if (valorTotal > 300){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 300,00 você ganha um vibrador Heart Pink</b>";
			}
			if (valorTotal < 100){
				document.getElementById("promocao_mensagem").innerHTML = "";
			}
			
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    } 
}    

function processTotalChange() 
{ 
    if (xmlhttp.readyState == 4) { 
        if (xmlhttp.status ==200) { 
			cont_preco=document.getElementById("preco_total").innerHTML = xmlhttp.responseText; 
			valorTotal = cont_preco.replace(".","");
			valorTotal = valorTotal.replace(",",".");
			valorTotal = parseFloat(valorTotal);
			
			if (valorTotal > 100 && valorTotal < 150){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 100,00 você ganha um vibrador Blue Heaven</b>";
			}
			if (valorTotal > 150 && valorTotal < 200){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 150,00 você ganha um vibrador Magic G Spot</b>";
			}
			if (valorTotal > 200 && valorTotal < 300){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 200,00 você ganha um estimulador Rocket Lover</b>";
			}
			if (valorTotal > 300){
				document.getElementById("promocao_mensagem").innerHTML = "<b>Compras acima de R$ 300,00 você ganha um vibrador Heart Pink</b>";
			}
			if (valorTotal < 100){
				document.getElementById("promocao_mensagem").innerHTML = "";
			}
			/*
			if (valorTotal > 150.00){
				document.getElementById('promocao1').style.display = 'block';
				document.getElementById('promocao2').style.display = 'block';
			}else{
				document.getElementById('promocao1').style.display = 'none';
				document.getElementById('promocao2').style.display = 'none';
			}
			*/
        } else { 
            alert("Houve um problema ao obter os dados:\n" + xmlhttp.statusText); 
        } 
    } 
}    



function processSaldoVale()
{
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			conteudo=document.getElementById("id_vale_saldo").innerHTML = ajax_saldo.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax_saldo.statusText); 
        } 
    } 

}
function processValeChange() 
{ 
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			conteudo=document.getElementById("id_vale").innerHTML = ajax.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    } 
}    

function processCepChange() 
{ 
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			//alert(ajax.responseText);
			document.getElementById("id_cep").innerHTML = ajax.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    } 
}    

function processDescChange() 
{ 
    if (deschttp.readyState == 4) { 
        if (deschttp.status ==200) { 
			if (deschttp.responseText != 'R$0,00')
			{
				if (document.all)
				{
					document.getElementById("trDesconto").style.display = "block";
					document.getElementById("trDesconto2").style.display = "block";
				} else {
					document.getElementById("trDesconto").style.display = "table-row";
					document.getElementById("trDesconto2").style.display = "table-row";
				}
				cont_desc=document.getElementById("id_desconto").innerHTML = deschttp.responseText; 
			} else {
				document.getElementById("trDesconto").style.display = "none";
				document.getElementById("trDesconto2").style.display = "none";
			}
        } else { 
            alert("Houve um problema ao obter os dados:\n" + deschttp.statusText); 
        } 
    } 
}    
/*
function processImgChange() 
{ 
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			cont_emb=document.getElementById("img_embalagem").innerHTML = ajax.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    } 
}    
*/

function format(obj, format_type)
{
    var formatted_value;

    switch (format_type)
    {
        case 'number':
            formatted_value = obj.value.replace(/[^0-9]/g, '');
        break;

        case 'percent':
            formatted_value = obj.value.replace(/[^0-9,]/g, '');
        break;

        case 'currency':
            formatted_value = obj.value.replace(/[^0-9\.,]/g, '');
        break;

        case 'date':
            formatted_value = obj.value.replace(/\-/g, '/');
            formatted_value = formatted_value.replace(/[^0-9\/]/g, '');
        break;

        case 'letter':
            formatted_value = obj.value.replace(/[^\w ]/g, '');
        break;

        case 'phone':
            formatted_value = obj.value.replace(/[^0-9\- ]/g, '');
        break;

        case 'code':
            formatted_value = obj.value.replace(/[<>'"]/g, '');
        break;

        case 'email':
            formatted_value = obj.value.replace(/[^\@\a-zA-Z0-9\.\-\_]/g, '');
        break;
        
        case 'alpha':
            formatted_value = obj.value.replace(/[^A-Za-z0-9 ]/g, '');
        break;
        
        case 'space':
            formatted_value = obj.value.replace(/[ ]/g, '');
        break;
    }

 	if (formatted_value == 0) {
      obj.value = 1;	
	} else {
      obj.value = formatted_value;
	}
}