	function ApresentaVideo(video_id)
	{
	    if (document.getElementById("big_photo_container"))
	    {
	        document.getElementById("big_photo_container").style.display = "none";
	    }
	    
	    if (document.getElementById("big_video_container"))
	    {
	        document.getElementById("big_video_container").style.display = "block";
	        
	        var params = { allowScriptAccess: "always" };
            var atts = { id: "myytplayer" };
            swfobject.embedSWF("http://www.youtube.com/v/" + video_id + "?enablejsapi=1&playerapiid=ytplayer&rel=0", "big_video_yt", "370", "370", "8", null, null, params, atts);            
            
            if (document.getElementById("myytplayer"))
            {
                ytplayer = document.getElementById("myytplayer");
                //ytplayer.playVideo();
            }
        }
	}
	
	function AvisoEscolhaOpcao()
    {
        var mensagem = "";
    
		for (j=0; j<document.getElementsByTagName("input").length; j++)
		{
			campo = document.getElementsByTagName("input")[j];

			if (campo.type == "hidden")
			{
			    if (campo.id.indexOf("DRP_SKU_") > -1)
			    {
			        var campoLabel = document.getElementById(campo.id.replace('DRP_SKU_','SPAN_SKU_'));
			    
			        if (campoLabel && campo.value == 0)
			        {
			            if (mensagem == "")
			            {
			                mensagem = campoLabel.innerHTML.replace('Selecionar ', '').toUpperCase()
			            }
			            else
			            {
			                mensagem = mensagem + " e " + campoLabel.innerHTML.replace('Selecionar ', '').toUpperCase()
			            }
			        }
			    }			    
			}
		}
		
		
		if (mensagem != "")
		{
            alert("Escolha um(a) " + mensagem);
        }
    }
	
	function AlertaOpcaoUnica(nome, valor)
	{
		alert("opção única (" + nome + ": " + valor + ")");
	}
    
	function ArmazenaOpcao(drpOrdem, drpValor, ProdutoCodigo, process)
	{
	    if (document.getElementById('DRP_SKU_' + drpOrdem))
	    {
		    document.getElementById('DRP_SKU_' + drpOrdem).value = '0';
	    }
	
		if (process == "I")
		{
			if (document.getElementById('DRP_SKU_1'))
			{
				document.getElementById('DRP_SKU_1').value = '0';
			}

			if (document.getElementById('DRP_SKU_2'))
			{
				document.getElementById('DRP_SKU_2').value = '0';
			}

			if (document.getElementById('DRP_SKU_3'))
			{
				document.getElementById('DRP_SKU_3').value = '0';
			}

			if (document.getElementById('DRP_SKU_4'))
			{
				document.getElementById('DRP_SKU_4').value = '0';
			}

			if (document.getElementById('DRP_SKU_5'))
			{
				document.getElementById('DRP_SKU_5').value = '0';
			}
		}

		campo = document.getElementById('DRP_SKU_' + drpOrdem);

		if (campo.value != drpValor)
		{
			if (document.getElementById('DRP_SKU_' + drpOrdem))
			{
				campo.value = drpValor;
				DisponibilidadeSKU(campo, ProdutoCodigo, '', 'I', drpOrdem)
			}
		}
	}
	
	function carregaImgAux(oImg){
		var o_ImgDetalheAux = document.getElementById("ProdutoImagemAux");
		o_ImgDetalheAux.src = oImg.src;
	}
	
	function MostraImagemAmpliada()
	{
		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		try
		{
	        if (document.getElementById("big_video_container"))
	        {
	            document.getElementById("big_video_container").style.visibility = "hidden";
	            
	            if (document.getElementById("myytplayer"))
	            {
	                ytplayer = document.getElementById("myytplayer");
	                ytplayer.pauseVideo();
	            }
            }
            
	        if (document.getElementById("big_photo_container"))
	        {
	            document.getElementById("big_photo_container").style.visibility = "visible";
	        }
    	    
			if (document.getElementById("ImagemAmpliada"))
			{
				divs = document.getElementsByTagName("select");

				if (document.getElementById("ImagemAmpliada").style.visibility == "visible")
				{
					for (i=0;i<divs.length;i++)
					{
						if (divs[i].id.toLowerCase().indexOf("drp_sku_") >= 0)
						{
							divs[i].style.visibility = "visible";
						}
					}

					document.getElementById("ImagemAmpliada").style.visibility = "hidden";
				}
				else
				{
					for (i=0;i<divs.length;i++)
					{
						if (divs[i].id.toLowerCase().indexOf("drp_sku_") >= 0)
						{
							divs[i].style.visibility = "hidden";
						}
					}

					document.getElementById("ImagemAmpliada").style.visibility = "visible";
				}
			}
		}
		catch(err)
		{
		}
	}
	
	function ProdutosVisitados(CategoriaCodigo, ProdutoCodigo)
	{
		try
		{
			detalhes.ProdutosVisitados(CategoriaCodigo, ProdutoCodigo, callback_ProdutosVisitados)
		}
		catch(err)
		{
			AlertaErroAjax(err);
		}
	}
	
	function callback_ProdutosVisitados(res)
	{
	
 		if (res.error)
		{
			AlertaErroAjax(res.error);
		}
	}	
	
	// (1) detalhes.aspx
	function CarregaDadosUsuario()
	{
		try
		{
			TrocaImagem("loading", "visible");
			detalhes.CarregaDadosUsuario(callback_CarregaDadosUsuario)
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
	
	function callback_CarregaDadosUsuario(res)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
		}

		if (res.value[0])
		{
			document.getElementById("txtNome").value = res.value[0];
			document.getElementById("txtRemetente").value = res.value[0];
		}
		
		if (res.value[1])
		{
			document.getElementById("txtEmail").value = res.value[1];
			document.getElementById("txtEmailRemetente").value = res.value[1];
		}		
		
		TrocaImagem("loading", "hidden");
	}
	
	// (1) detalhes.aspx
	function CarregaPrazoEntrega(ProCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			detalhes.CarregaPrazoEntrega(ProCodigo, callback_CarregaPrazoEntrega)
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
	
	function callback_CarregaPrazoEntrega(res)
	{
 		if (res.error)
		{
			//AlertaErroAjax(res.error);
			window.location.href = window.location;
		}

		if (res.value)
		{
		    if(document.getElementById("pPrazoEntrega"))
		    {
			    document.getElementById("pPrazoEntrega").innerHTML = res.value;
            }
		}
		
		TrocaImagem("loading", "hidden");
	}

	function CarregaSKU(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			detalhes.CarregaSKU(ProdutoCodigo.toString(), callback_CarregaSKU)
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
	function CarregaSKUCross(ProdutoCodigo, ordem, GruSelCodigo, iGruSellItensAux)
	{
		try
		{
			TrocaImagem("loading", "visible");
			detalhes.CarregaSKUCross(ProdutoCodigo.toString(), ordem.toString(), GruSelCodigo.toString(), iGruSellItensAux.toString(), callback_CarregaSKUCross);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
	
	// (1) detalhes.aspx
	function DisponibilidadeSKU(campo, ProdutoCodigo, tipo, tipoEscolha, Ordem)
	{

		var mensagem = "";
		var aux = "";
		var aux2 = "";
		var aux3 = "";
		var extensao = "";
		var endereco = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		if (document.getElementById("btEscolhaOpcao"))
		{
			document.getElementById("btEscolhaOpcao").src = document.getElementById("btEscolhaOpcao").src.replace("bt_escolha_opcao", "bt_aguarde");
		}
		if (document.getElementById("btComprarProduto"))
		{
			document.getElementById("btComprarProduto").src = document.getElementById("btComprarProduto").src.replace("bt_comprar_produto", "bt_aguarde");
		}
		if (document.getElementById("btProdutoComprar"))
		{
			document.getElementById("btProdutoComprar").src = document.getElementById("btProdutoComprar").src.replace("bt_produto_indisp", "bt_aguarde");
		}

		try
		{
			if (tipoEscolha == "D")
			{
				CarValCod1 = (document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").options[document.getElementById("DRP_SKU_1").selectedIndex].value : 0);
				CarValCod2 = (document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").options[document.getElementById("DRP_SKU_2").selectedIndex].value : 0);
				CarValCod3 = (document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").options[document.getElementById("DRP_SKU_3").selectedIndex].value : 0);
				CarValCod4 = (document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").options[document.getElementById("DRP_SKU_4").selectedIndex].value : 0);
				CarValCod5 = (document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").options[document.getElementById("DRP_SKU_5").selectedIndex].value : 0);

				if(campo.options[campo.selectedIndex].value == "")
				{
					mensagem+="Opção inválida (vazio) !\n";
				}
			}
			else if (tipoEscolha == "I")
			{
				if (Ordem == "1") //Caso seja selecionado o primeiro SKU, limpa a seleção das SKUs seguintes
				{
				    CarValCod1 = (document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").value : 0);
				}
				else
				{
				    CarValCod1 = (document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").value : 0);
				    CarValCod2 = (document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").value : 0);
				    CarValCod3 = (document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").value : 0);
				    CarValCod4 = (document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").value : 0);
				    CarValCod5 = (document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").value : 0);
				}
				
				if(campo.value == "")
				{
					mensagem+="Opção inválida (vazio) !\n";
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				detalhes.DisponibilidadeSKU(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), callback_DisponibilidadeSKU)
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKU(res)
	{
 		if (res.error)
		{
//			AlertaErroAjax(res.error);
			window.location.href = window.location;
		}

		if (res.value)
		{
			if (res.value[0][0])
			{
				document.getElementById("spanDisponibilidade").innerHTML = res.value[0][0];
			}

			if (document.getElementById("spanPreco"))
			{
				if (res.value[0][1] != "")
				{
					document.getElementById("spanPreco").innerHTML = res.value[0][1];
					document.getElementById("spanPreco").style.visibility = "visible";
				}
				else
				{
					document.getElementById("spanPreco").innerHTML = res.value[0][1];
					document.getElementById("spanPreco").style.visibility = "hidden";
				}
			}

			if(document.getElementById("spanPrecoPor"))
			{
				document.getElementById("spanPrecoPor").innerHTML = res.value[0][2];
			}				

			if (document.getElementById("spanPrecoEconomize"))
			{
				if (res.value[0][3] != "")
				{
					document.getElementById("spanPrecoEconomize").innerHTML = res.value[0][3];
					//document.getElementById("spanPrecoEconomize").style.visibility = "visible";
				}
				else
				{
					document.getElementById("spanPrecoEconomize").innerHTML = "&nbsp;";
					//document.getElementById("spanPrecoEconomize").style.visibility = "hidden";
				}
			}

			if (document.getElementById("spanParcelamento1"))
			{
				document.getElementById("spanParcelamento1").innerHTML = res.value[0][4];
			}
	
			if (document.getElementById("spanParcelamento2"))
			{
				document.getElementById("spanParcelamento2").innerHTML = res.value[0][5];
			}
			
		    if(document.getElementById("spanOutroParc"))
		    {
			    document.getElementById("spanOutroParc").innerHTML = res.value[0][6];
            }
			
			/**********************************************************************/
			/*Seta imagens														  */
			/**********************************************************************/

			var imgs = document.getElementsByTagName("img");

			if (res.value[1][0])
			{
				for (i=0;i<imgs.length;i++)
				{
					if (imgs[i].name == "ProdutoImagem")
					{
						imgs[i].src = res.value[1][0]
						break;
					}
				}
			}
			
			///////
			
			if(document.getElementById('ImgDetalhe1'))
				{		
					//jQuery("#ImgDetalhe1").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes.jpg'));
					imageExists2(jQuery("#ImgDetalhe1").attr("src"), function() { jQuery("#liDetalhe1").show() },  function() { jQuery("#liDetalhe1").hide() }); 
					imageExists2(jQuery("#ImgDetalhe1").attr("src"), function() { jQuery("#ImgDetalhe1").show() },  function() { jQuery("#ImgDetalhe1").hide() }); 
				}
		
				if(document.getElementById('ImgDetalhe2'))
				{
					//jQuery("#ImgDetalhe2").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes1.jpg'));	
					imageExists2(jQuery("#ImgDetalhe2").attr("src"), function() { jQuery("#liDetalhe2").show() },  function() { jQuery("#liDetalhe2").hide() });
					imageExists2(jQuery("#ImgDetalhe2").attr("src"), function() { jQuery("#ImgDetalhe2").show() },  function() { jQuery("#ImgDetalhe2").hide() }); 			
				}
	
				if(document.getElementById('ImgDetalhe3'))
				{
					//jQuery("#ImgDetalhe3").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes2.jpg'));
					imageExists2(jQuery("#ImgDetalhe3").attr("src"), function() { jQuery("#liDetalhe3").show() },  function() { jQuery("#liDetalhe3").hide() }); 
					imageExists2(jQuery("#ImgDetalhe3").attr("src"), function() { jQuery("#ImgDetalhe3").show() },  function() { jQuery("#ImgDetalhe3").hide() });			
				}

				if(document.getElementById('ImgDetalhe4'))
				{
					//jQuery("#ImgDetalhe4").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes3.jpg'));
					imageExists2(jQuery("#ImgDetalhe4").attr("src"), function() { jQuery("#liDetalhe4").show() },  function() { jQuery("#liDetalhe4").hide() });
					imageExists2(jQuery("#ImgDetalhe4").attr("src"), function() { jQuery("#ImgDetalhe4").show() },  function() { jQuery("#ImgDetalhe4").hide() }); 			
	
				}
			
			
			/////////
			
			
			/*
			jQuery("[name=ProdutoImagem]").each(function()
			{
				this.src = jQuery(campo).attr("src");          
				MostraImagemDetalhe(this.src.replace('Thumb', 'Detalhe'));

				//Troca Imagem (Fancybox)
			//	jQuery('.cliqueParaAmpliar a').attr("href", this.src.replace('Thumb', 'Ampliada'));
			});
*/
			if (res.value[1][2] && document.getElementById(res.value[1][3]))
			{
				document.getElementById(res.value[1][3]).src = res.value[1][2];
			}	

			if (res.value[1][4])
			{
				document.getElementById(res.value[1][5]).src = res.value[1][4];
				document.getElementById(res.value[1][5]).style.display = '';					
			}
			else
			{
				document.getElementById(res.value[1][5]).style.display = 'none';
			}
			
			if (res.value[1][6])
			{
				document.getElementById(res.value[1][7]).src = res.value[1][6];
				document.getElementById(res.value[1][7]).style.display = '';	
			}
			else
			{
				document.getElementById(res.value[1][7]).style.display = 'none';
			}			
			
			if (res.value[1][8])
			{
				document.getElementById(res.value[1][9]).src = res.value[1][8];
				document.getElementById(res.value[1][9]).style.display = '';	
			}
			else
			{
				document.getElementById(res.value[1][9]).style.display = 'none';
			}			
			
			if (res.value[1][10])
			{
				document.getElementById(res.value[1][11]).src = res.value[1][10];
				document.getElementById(res.value[1][11]).style.display = '';	
			}						
			else
			{
				document.getElementById(res.value[1][11]).style.display = 'none';
			}
			
			if (res.value[1][12])
			{
				document.getElementById(res.value[1][12]).src = res.value[1][12];
				document.getElementById(res.value[1][12]).style.display = '';	
			}	
			else
			{
				//document.getElementById(res.value[1][12]).style.display = 'none';
			}											

			if (res.value[1][14])
			{
				if (document.getElementById(res.value[1][15]))
				{
					document.getElementById(res.value[1][15]).src = res.value[1][14];
				}
	
				if (document.getElementById('ImagemAmpliadaAux'))
				{
					document.getElementById('ImagemAmpliadaAux').value = res.value[1][14];
				}
			}	

			/**********************************************************************/
			/*Seta Selos														  */
			/**********************************************************************/

			if (res.value[2])
			{
				document.getElementById('spanSelos').innerHTML = res.value[2];
				document.getElementById('spanOutros').style.display = "block";
			}
			else
			{
				document.getElementById('spanSelos').innerHTML = "";
				document.getElementById('spanOutros').style.display = "none";
			}

			/**********************************************************************/
			/*Opções de SKU Disponíveis
			/**********************************************************************/

			if (res.value[3])
			{
				document.getElementById('spanSKU').innerHTML = res.value[3];
			}

			/*for (i=0;i<imgs.length;i++)
			{
				if (imgs[i].name == "ProdutoImagem")
				{
					TrocaImagemDetalhe(imgs[i]);
					break;
				}
			}*/
			
			
			jQuery("[name=ProdutoImagem]").each(function()
			{
				TrocaImagemDetalhe(this);
			});
			
			if (res.value[4])
			{
			    if (res.value[4][0] && document.getElementById('DRP_SKU_1'))
                {
                    document.getElementById('DRP_SKU_1').value = res.value[4][0];
                }
                
			    if (res.value[4][1] && document.getElementById('DRP_SKU_2'))
                {
                    document.getElementById('DRP_SKU_2').value = res.value[4][1];
                }
                
			    if (res.value[4][2] && document.getElementById('DRP_SKU_3'))
                {
                    document.getElementById('DRP_SKU_3').value = res.value[4][2];
                }
                
			    if (res.value[4][3] && document.getElementById('DRP_SKU_4'))
                {
                    document.getElementById('DRP_SKU_4').value = res.value[4][3];
                }
                
			    if (res.value[4][4] && document.getElementById('DRP_SKU_5'))
                {
                    document.getElementById('DRP_SKU_5').value = res.value[4][4];
                }
			}
			
			TrocaImagem("loading", "hidden");
		}
	}	
	
	function TrocaImagemDetalhe(campo)
	{		
		
		
		var baseSrc = "";
		var teste = "";

		try
		{
			if (document.getElementById("big_photo_container"))
			{
				document.getElementById("big_photo_container").style.display = "block";
			}
			
			if (document.getElementById("big_video_container"))
			{
				document.getElementById("big_video_container").style.display = "none";
	            
				if (document.getElementById("myytplayer"))
				{
					ytplayer = document.getElementById("myytplayer");
					
					//Verificar se o video está pausado
					try
                    {
                        ytplayer.pauseVideo();
                    }
                    catch(e)
                    {
                    }
				}
			}
	        
	        
	        
			jQuery("[name=ProdutoImagem]").each(function()
			{
				var srcAux = jQuery(campo).attr("src"); 				
				this.src = srcAux.replace("Thumb", "Detalhes");  

				
				var MontaURLIndisponivel = this.src.split('produtos');
				var MontaURL = MontaURLIndisponivel[0] + 'produtos/indisponivel.gif';  

				

				imageExists2(this.src,
				function()
				{
								this.src = srcAux.replace("Thumb", "Detalhes");
								
				}
				,
				function() { 
				
							var $produtoImagem = jQuery("[name=ProdutoImagem]");

								if($produtoImagem.length > 0)
								{
											   $produtoImagem.attr("src", MontaURL);
								}
				
				 }
				);

				

				MostraImagemDetalhe(this.src);				
				
				//Troca Imagem (Fancybox)				
			//	jQuery('.cliqueParaAmpliar a').attr("href", this.src.replace("Thumb", "Ampliada"));			
			});

		}
		catch(err)
		{
		}
	}
	   
	function MostraImagemDetalhe(src)
	{	
	
		try
		{
			var ImagemGif = src.substring(0,src.length - 4).replace('Detalhes', 'Ampliada').replace('Thumb', 'Ampliada') + '.gif';
			var ImagemJPG =	src.substring(0,src.length - 4).replace('Detalhes', 'Ampliada').replace('Thumb', 'Ampliada') + '.jpg';	
			
			if(document.getElementById('ImagemAmpliadaAux').value == '' && document.getElementById("ImagemAmpliadaFoto"))
			{
				document.getElementById('ImagemAmpliadaAux').value = document.getElementById("ImagemAmpliadaFoto").src;
			}

			imageExists(ImagemGif, 
				function fxRet(bRet, img)
				{
					if (bRet)
					{
						if (document.getElementById('Zoom1'))
						{
							document.getElementById('Zoom1').href = ImagemGif;
						}
						var divs = document.getElementsByTagName("img");

						for (i=0;i<divs.length;i++)
						{
							if (divs[i].src.toLowerCase().indexOf("_ampliada") >= 0)
							{
								divs[i].src = ImagemGif;
							}
						}
					}
					else
					{
						imageExists(ImagemJPG, 
							function fxRet(bRet, img)
							{
								if (bRet)
								{
									if (document.getElementById('Zoom1'))
									{
										document.getElementById('Zoom1').href = ImagemJPG;
									}
									var divs = document.getElementsByTagName("img");

									for (i=0;i<divs.length;i++)
									{
										if (divs[i].src.toLowerCase().indexOf("_ampliada") >= 0)
										{
											divs[i].src = ImagemJPG;
										}
									}
								}
								else
								{
									var divs = document.getElementsByTagName("img");

									for (i=0;i<divs.length;i++)
									{
										if (divs[i].src.toLowerCase().indexOf("_ampliada") >= 0)
										{
											divs[i].src = document.getElementById('ImagemAmpliadaAux').value;	
										}
									}
								}
							}
						);
					}
				}
			);	
		}
		catch(err)
		{
			alert(err);
		}	
	}
	
	// (1) detalhes.aspx.cs
    function VerificaValePresenteCross(ProdutoCodigoVenda, CarValCodVenda1, CarValCodVenda2, CarValCodVenda3, CarValCodVenda4, CarValCodVenda5, ProdutoCodigoCross, CarValCodCross1, CarValCodCross2, CarValCodCross3, CarValCodCross4, CarValCodCross5, VitrineCodigo)
    {
        detalhes.VerificaValePresenteCross(ProdutoCodigoVenda.toString(), CarValCodVenda1.toString(), CarValCodVenda2.toString(), CarValCodVenda3.toString(), CarValCodVenda4.toString(), CarValCodVenda5.toString(), ProdutoCodigoCross.toString(), CarValCodCross1.toString(), CarValCodCross2.toString(), CarValCodCross3.toString(), CarValCodCross4.toString(), CarValCodCross5.toString(), VitrineCodigo.toString(), VerificaValePresenteCross_callback)
    }

    function VerificaValePresenteCross_callback(res)
    {
        if (res.value[0] == '1')
        {
            detalhes.AdicionarItemCestaCross(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), res.value[8].toString(), res.value[9].toString(), res.value[10].toString(), res.value[11].toString(), res.value[12].toString(), res.value[13].toString(), Redirect_callback)        
        }
	    else if(res.value[0] == '2')
	    {
	        document.location.href = res.value[1];
	    }
	    else if(res.value[0] == '3')
	    {
	        if(confirm('Existe um ou mais vale-presentes na sua cesta de compras. Eles devem ser comprados separadamente.\nSe adicionar esta venda cruzada, o(s) vale-presente(s) da cesta serão excluídos.\nDeseja continuar?'))
	        {
                detalhes.AdicionarItemCestaCross(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), res.value[8].toString(), res.value[9].toString(), res.value[10].toString(), res.value[11].toString(), res.value[12].toString(), res.value[13].toString(), Redirect_callback)        
	        }
	    }
    }
    
    // (1) detalhes.aspx.cs
    function VerificaValePresenteGrupoCross(GruSelCodigo, Produtos, CarValCod1, CarValCod2, CarValCod3, CarValCod4, CarValCod5, VitrineCodigo)				
    {
        detalhes.VerificaValePresenteGrupoCross(GruSelCodigo.toString(), Produtos.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), VerificaValePresenteGrupoCross_callback)				
    }

    function VerificaValePresenteGrupoCross_callback(res)
    {
        if (res.value[0] == '1')
        {
            detalhes.AdicionarItemCestaGrupoCross(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), res.value[8].toString(), Redirect_callback)        
        }
	    else if(res.value[0] == '2')
	    {
	        document.location.href = res.value[1];
	    }
	    else if(res.value[0] == '3')
	    {
	        if(confirm('Existe um ou mais vale-presentes na sua cesta de compras. Eles devem ser comprados separadamente.\nSe adicionar esta venda cruzada, o(s) vale-presente(s) da cesta serão excluídos.\nDeseja continuar?'))
	        {
                detalhes.AdicionarItemCestaGrupoCross(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), res.value[8].toString(), Redirect_callback)        
	        }
	    }
    }
    
    // (1) detalhes.aspx.cs
    function VerificaValePresentePersonalizado(ProdutoCodigo, CarValCod1, CarValCod2, CarValCod3, CarValCod4, CarValCod5, VitrineCodigo, CodsProdutos, CarValCod1P, CarValCod2P, CarValCod3P, CarValCod4P, CarValCod5P, CampoPersonalizacaoExtra)
    {
        detalhes.VerificaValePresentePersonalizado(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), CodsProdutos.toString(), CarValCod1P.toString(), CarValCod2P.toString(), CarValCod3P.toString(), CarValCod4P.toString(), CarValCod5P.toString(), CampoPersonalizacaoExtra, VerificaValePresentePersonalizado_callback);
    }

    function VerificaValePresentePersonalizado_callback(res)
    {
        if (res.value[0] == '1')
        {
            detalhes.AdicionarItemCestaProdutoPersonalizado(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), res.value[8].toString(), res.value[9].toString(), res.value[10].toString(), res.value[11].toString(), res.value[12].toString(), res.value[13].toString(), res.value[14], Redirect_callback)        
        }
	    else if(res.value[0] == '2')
	    {
	        document.location.href = res.value[1];
	    }
	    else if(res.value[0] == '3')
	    {
	        if(confirm('Existe um ou mais vale-presentes na sua cesta de compras. Eles devem ser comprados separadamente.\nSe adicionar esta venda cruzada, o(s) vale-presente(s) da cesta serão excluídos.\nDeseja continuar?'))
	        {
                detalhes.AdicionarItemCestaProdutoPersonalizado(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), res.value[8].toString(), res.value[9].toString(), res.value[10].toString(), res.value[11].toString(), res.value[12].toString(), res.value[13].toString(), res.value[14], Redirect_callback)        
	        }
	    }
    }    
    
    // (1) detalhes.aspx
	function AdicionarItemCesta(ProdutoCodigo)
	{
		var enc = 0;
		var mensagem = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;
		var VitrineCodigo = 0;
		var CodsProdutos = "";

		for (var i=0; i<document.forms[0].elements.length; i++) 
		{
			var id_elemento = document.forms[0].elements[i].id;
		        
			if(document.forms[0].elements[i].id.indexOf('chkPersonalizacao_') > -1)
			{
				if (document.getElementById(id_elemento).checked)
				{
					CodsProdutos += document.getElementById(id_elemento).value + ",";
				}
			}
		}   

        var CompraPersonalizado = false;

        if (CodsProdutos != "")
        {
            if (confirm('Existem personalizações selecionadas para este produto!\nDeseja adiciona-las no carrinho junto ao produto escolhido?'))
            {
                CompraPersonalizado = true;
            }
        }
        
        if (CompraPersonalizado)
        {
            AdicionarItemCestaProdutoPersonalizado(ProdutoCodigo);
        }
        else
        {
            TrocaImagem("loading", "visible");
            
		    if (document.getElementById("btComprarProduto") && document.getElementById("btAguarde"))
		    {
			    document.getElementById("btComprarProduto").style.display = 'none';
			    document.getElementById("btAguarde").style.display = 'block';
		    }

		    try
		    {
			    CarValCod1 = (document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").value : 0);
			    CarValCod2 = (document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").value : 0);
			    CarValCod3 = (document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").value : 0);
			    CarValCod4 = (document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").value : 0);
			    CarValCod5 = (document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").value : 0);

			    VitrineCodigo = (document.getElementById("VitrineCodigo") ? document.getElementById("VitrineCodigo").value : 0);

			    for (j=0; j<document.forms[0].elements.length; j++)
			    {
				    campo = document.forms[0].elements[j];
    				
				    if (campo.name)
				    {
					    if (campo.name.indexOf("DRP_SKU") != -1 && campo.name.length == 9)
					    {
						    if (campo.value == "0")
						    {
							    mensagem+="Escolha um valor para todas as Opções de Compra! (2)\n";
							    break;
						    }
					    }
				    }
			    }
				
			    if(mensagem != "")
			    {
				    alert(mensagem);
    				
				    if (document.getElementById("btComprarProduto") && document.getElementById("btAguarde"))
				    {
					    document.getElementById("btComprarProduto").style.display = 'block';
					    document.getElementById("btAguarde").style.display = 'none';
				    }

				    TrocaImagem("loading", "hidden");
			    }
			    else
			    {
				    VerificaValePresente(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), Redirect_callback);
			    }
		    }
		    catch(err)
		    {
			    AlertaErroAjax(err);
    			
			    if (document.getElementById("btComprarProduto") && document.getElementById("btAguarde"))
			    {
				    document.getElementById("btComprarProduto").style.display = 'block';
				    document.getElementById("btAguarde").style.display = 'none';
			    }
    			
			    TrocaImagem("loading", "hidden");
		    }
		}
	}
    
    // (1) detalhes.aspx
	function AdicionarItemCestaCrossDuplo(ProdutoCodigoVenda, ProdutoCodigoCross, OrdemVenda, GrupoSellingCodigo, OrdemCross, iGruSellItensAux2)
	{
		var enc = 0;
		var mensagem = "";

		var Produto1_Op = true;
		var Produto2_Op = true;
		var Produto1_Di = true;
		var Produto2_Di = true;

		var CarValCodVenda1 = 0;
		var CarValCodVenda2 = 0;
		var CarValCodVenda3 = 0;
		var CarValCodVenda4 = 0;
		var CarValCodVenda5 = 0;

		var CarValCodCross1 = 0;
		var CarValCodCross2 = 0;
		var CarValCodCross3 = 0;
		var CarValCodCross4 = 0;
		var CarValCodCross5 = 0;

		var VitrineCodigo = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCodVenda1 = (document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2).value : (document.getElementById("DRP_SKUUnico_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2) ? document.getElementById("DRP_SKUUnico_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2).value : 0));
			CarValCodVenda2 = (document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_2_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_2_" + iGruSellItensAux2).value : 0);
			CarValCodVenda3 = (document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_3_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_3_" + iGruSellItensAux2).value : 0);
			CarValCodVenda4 = (document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_4_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_4_" + iGruSellItensAux2).value : 0);
			CarValCodVenda5 = (document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_5_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_5_" + iGruSellItensAux2).value : 0);

			CarValCodCross1 = (document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2).value : (document.getElementById("DRP_SKUUnico_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2) ? document.getElementById("DRP_SKUUnico_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2).value : 0));
			CarValCodCross2 = (document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_2_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_2_" + iGruSellItensAux2).value : 0);
			CarValCodCross3 = (document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_3_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_3_" + iGruSellItensAux2).value : 0);
			CarValCodCross4 = (document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_4_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_4_" + iGruSellItensAux2).value : 0);
			CarValCodCross5 = (document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_5_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_5_" + iGruSellItensAux2).value : 0);

			VitrineCodigo = (document.getElementById("VitrineCodigo") ? document.getElementById("VitrineCodigo").value : 0);

			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];

				if (campo.name)
				{
					if (Produto1_Op)
					{
						if (campo.name.indexOf("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo) != -1)
						{
							if (campo.value == "0")
							{
								mensagem+="Escolha um valor para todas as Opções de Compra! (3)\nProduto 1 da Venda Cruzada\n\n";
								Produto1_Op = false;
							}
						}
					}

					if (Produto2_Op)
					{
						if (campo.name.indexOf("DRP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo) != -1)
						{
							if (campo.value == "0")
							{
								mensagem+="Escolha um valor para todas as Opções de Compra! (4)\nProduto 2 da Venda Cruzada\n\n";
								Produto2_Op = false;
							}
						}
					}
				}
			}

			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];

				if (campo.name)
				{
					if (Produto1_Op)
					{
						if (Produto1_Di)
						{
							if (campo.name.indexOf("DRP_DISP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_" + iGruSellItensAux2) != -1)
							{
								if (campo.value == "I")
								{
									mensagem+="Combinação Indisponível!\nProduto 1 da Venda Cruzada\n\n";
									Produto1_Di = false;
								}
							}
						}
					}

					if (Produto2_Op)
					{
						if (Produto2_Di)
						{
							if (campo.name.indexOf("DRP_DISP_SKU_" + ProdutoCodigoCross + "_" + OrdemCross + "_" + GrupoSellingCodigo + "_" + iGruSellItensAux2) != -1)
							{
								if (campo.value == "I")
								{
									mensagem+="Combinação Indisponível!\nProduto 2 da Venda Cruzada\n\n";
									Produto2_Di = false;
								}
							}
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				VerificaValePresenteCross(ProdutoCodigoVenda.toString(), CarValCodVenda1.toString(), CarValCodVenda2.toString(), CarValCodVenda3.toString(), CarValCodVenda4.toString(), CarValCodVenda5.toString(), ProdutoCodigoCross.toString(), CarValCodCross1.toString(), CarValCodCross2.toString(), CarValCodCross3.toString(), CarValCodCross4.toString(), CarValCodCross5.toString(), VitrineCodigo.toString(), VerificaValePresenteCross_callback)
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
    // (1) detalhes.aspx
	function AdicionarItemCestaGrupoCross(GruSelCodigo, Produtos, iGruSellItensAux2)
	{
		var enc = 0;
		var mensagem = "";

		var Produto1_Op = true;
		var Produto1_Di = true;

		var CarValCod1 = '';
		var CarValCod2 = '';
		var CarValCod3 = '';
		var CarValCod4 = '';
		var CarValCod5 = '';

		var VitrineCodigo = 0;

		var CodsProdutos = Produtos.split(',');
		
		TrocaImagem("loading", "visible");

		for (var i = 0; i < CodsProdutos.length; i++)
		{
			try
			{
				if(!(Produto1_Op && Produto1_Di))
				{
					break;
				}

				for (j=0; j<document.forms[0].elements.length; j++)
				{
					campo = document.forms[0].elements[j];
					
					if (campo.name)
					{
						if (campo.name.indexOf("DRP_SKU_" + CodsProdutos[i] + "_" + (i + 1).toString() + "_" + GruSelCodigo) != -1)
						{
							if (campo.value == "0")
							{
								alert("Escolha um valor para todas as Opções de Compra! (5)\nProduto "+(i+1).toString()+" da Venda Cruzada\n\n");
								TrocaImagem("loading", "hidden");
								Produto1_Op = false;
								break;
							}
						}
					}
				}
				
				if (Produto1_Op)
				{
					for (j=0; j<document.forms[0].elements.length; j++)
					{
						campo = document.forms[0].elements[j];
						
						if (campo.name)
						{
							if (campo.name.indexOf("DRP_DISP_SKU_" + CodsProdutos[i] + "_" + (i + 1).toString() + "_" + GruSelCodigo  + "_" + iGruSellItensAux2) != -1)
							{
								if (campo.value == "I")
								{
									alert("Combinação Indisponível!\nProduto "+(i+1).toString()+" da Venda Cruzada\n\n");
									TrocaImagem("loading", "hidden");
									Produto1_Di = false;
									break;
								}
							}
						}
					}				
				}
				else
				{
					break;
				}
			}
			catch(err)
			{
				AlertaErroAjax(err);
				TrocaImagem("loading", "hidden");
			}
		}
			
		if (Produto1_Op && Produto1_Di)
		{	
			try
			{		
				for (var i = 0; i < CodsProdutos.length; i++)
				{
					CarValCod1 += (document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_1_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_1_" + iGruSellItensAux2).value : (document.getElementById("DRP_SKUUnico_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_1_" + iGruSellItensAux2) ? document.getElementById("DRP_SKUUnico_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_1_" + iGruSellItensAux2).value : 0))+",";
					CarValCod2 += (document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_2_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_2_" + iGruSellItensAux2).value : '0')+",";
					CarValCod3 += (document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_3_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_3_" + iGruSellItensAux2).value : '0')+",";
					CarValCod4 += (document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_4_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_4_" + iGruSellItensAux2).value : '0')+",";
					CarValCod5 += (document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_5_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + CodsProdutos[i] + "_" + (i+1).toString() + "_" + GruSelCodigo + "_5_" + iGruSellItensAux2).value : '0')+",";
				}
				
				VitrineCodigo = (document.getElementById("VitrineCodigo") ? document.getElementById("VitrineCodigo").value : 0);
				TrocaImagem("loading", "visible");

				VerificaValePresenteGrupoCross(GruSelCodigo.toString(), Produtos.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), VerificaValePresenteGrupoCross_callback)				
			}
			catch(err)
			{
				AlertaErroAjax(err);
				TrocaImagem("loading", "hidden");
			}			
		}
	}
	
	// (1) detalhes.aspx
	function DisponibilidadeSKUCross(campoSender, ProdutoCodigo, GrupoSelCodigo, tipo, ordem, GrupoSelCodigo, iGruSellItensAux)
	{
		var total = 0;
		var lastProd = 0;
			
		var mensagem = "";
		var aux = "";
		var extensao = "";
		var endereco = "";
		
		var ProdutosCrossCodigo = new Array();
		
		var CarValCod1 = new Array();
		var CarValCod2 = new Array();
		var CarValCod3 = new Array();
		var CarValCod4 = new Array();
		var CarValCod5 = new Array();

		try
		{
			var camposSender = campoSender.name.split("_");
			
			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];
				
				if (campo.type == "select-one" || campo.type == "hidden")
				{	
					if (campo.name)
					{
						if (campo.name.indexOf("_") >= 0)
						{
							var campos = campo.name.split("_");			
							
							if (campos[0] == "DRP" && campos.length == 7 && campos[4] == GrupoSelCodigo && campos[6] == camposSender[6] && campos[4] == camposSender[4])
							{
								if (lastProd == 0 || lastProd != campos[2])
								{
									ProdutosCrossCodigo[total] = campos[2];

									if (campo.type == "select-one")
									{
										CarValCod1[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_1_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_1_" + campos[6]).options[document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_1_" + campos[6]).selectedIndex].value : 0);
										CarValCod2[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_2_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_2_" + campos[6]).options[document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_2_" + campos[6]).selectedIndex].value : 0);
										CarValCod3[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_3_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_3_" + campos[6]).options[document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_3_" + campos[6]).selectedIndex].value : 0);
										CarValCod4[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_4_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_4_" + campos[6]).options[document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_4_" + campos[6]).selectedIndex].value : 0);
										CarValCod5[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_5_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_5_" + campos[6]).options[document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_5_" + campos[6]).selectedIndex].value : 0);
									}
									else if (campo.type == "hidden")
									{
										CarValCod1[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_1_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_1_" + campos[6]).value : (document.getElementById("DRP_SKUUnico_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_1_" + campos[6]) ? document.getElementById("DRP_SKUUnico_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_1_" + campos[6]).value : 0));
										CarValCod2[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_2_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_2_" + campos[6]).value : 0);
										CarValCod3[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_3_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_3_" + campos[6]).value : 0);
										CarValCod4[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_4_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_4_" + campos[6]).value : 0);
										CarValCod5[total] = (document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_5_" + campos[6]) ? document.getElementById("DRP_SKU_" + campos[2] + "_" + campos[3] + "_" + campos[4] + "_5_" + campos[6]).value : 0);
									}
								
									lastProd = campos[2];
									total++;
								}
							}
						}										
					}
				}
			}
			
			if (campoSender.type == "select-one")
			{
				if(campoSender.options[campoSender.selectedIndex].value == "")
				{
					mensagem+="Opção inválida (vazio) !\n";
				}
			}
			else if (campoSender.type == "hidden")
			{
				if(campoSender.value == "")
				{
					mensagem+="Opção inválida (vazio) !\n";
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				detalhes.DisponibilidadeSKUCross(ProdutoCodigo.toString(), GrupoSelCodigo.toString(), ProdutosCrossCodigo, CarValCod1, CarValCod2, CarValCod3, CarValCod4, CarValCod5, ordem.toString(), iGruSellItensAux, callback_DisponibilidadeSKUCross)
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUCross(res)
	{
		if (res.error)
		{
		    if(res.error.Message.indexOf("http") > -1)
		    {
			    window.location.href = res.error.Message;
            }
		}
        else
        {
		    if (res.value)
		    {
			    document.getElementById("DRP_DISP_SKU_" + res.value[0] + "_" + res.value[2] + "_" + res.value[5]).value = res.value[3];

				if (res.value[1])
				{
					if (res.value[1] != "")
					{
						if (document.getElementById("spanDisponibilidade_Cross_" + res.value[0] + "_" + res.value[2] + "_" + res.value[5] + "_" + res.value[11]))
						{
							if (document.getElementById("p_product_disp_" + res.value[0] + "_" + res.value[2] + "_" + res.value[5] + "_" + res.value[11]))
							{
								document.getElementById("p_product_disp_" + res.value[0] + "_" + res.value[2] + "_" + res.value[5] + "_" + res.value[11]).style.display = "";
							}
				            
							document.getElementById("spanDisponibilidade_Cross_" + res.value[0] + "_" + res.value[2] + "_" + res.value[5] + "_" + res.value[11]).innerHTML = res.value[1];
						}
					}
				}	
    			
			    if (res.value[4])
			    {
				    if (document.getElementById("ImgCross"+res.value[0]+"_"+res.value[2] + "_" + res.value[5] + "_" + res.value[11]))
				    {
					    document.getElementById("ImgCross"+res.value[0]+"_"+res.value[2] + "_" + res.value[5] + "_" + res.value[11]).src = res.value[4];
				    }
			    }
    		
			    if (res.value[5])
			    {
				    if (res.value[6])
				    {
				        if (document.getElementById("spanTotalCrossDe_" + res.value[11] + "_" + res.value[5]))
				        {
					        document.getElementById("spanTotalCrossDe_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[7];
					    }
					    
					    if (document.getElementById("spanTotalCrossPor_" + res.value[11] + "_" + res.value[5]))
					    {
					        document.getElementById("spanTotalCrossPor_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[8];
					    }
    					
    					if (document.getElementById("spanParcelamento1_" + res.value[11] + "_" + res.value[5]))
    					{
					        document.getElementById("spanParcelamento1_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[9];
					    }
					    
					    if (document.getElementById("spanParcelamento2_" + res.value[11] + "_" + res.value[5]))
					    {
					        document.getElementById("spanParcelamento2_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[10];
					    }
				    }				
			    }
			    
			    if (res.value[12])
			    {
			        if (res.value[13] != "")
			        {
			            if (document.getElementById("spanTotalCrossDescontoPor_" + res.value[11] + "_" + res.value[5]))
			            {
			                document.getElementById("spanTotalCrossDescontoPor_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[13];
			            }
			        }
			    }
            }
		
			TrocaImagem("loading", "hidden");
		}
	}
	
	/**************************************************************************************************************************/
	/*** Personalização *******************************************************************************************************/
	/**************************************************************************************************************************/
	
	// (1) detalhes.aspx
	function DisponibilidadeSKUProdutoPersonalizado(campoSender, ProdutoCodigo)
	{
		var total = 0;
		var lastProd = 0;
			
		var mensagem = "";
		var aux = "";
		var extensao = "";
		var endereco = "";
		
		var ProdutosPersonalizadosCodigo = new Array();
		
		var CarValCod1 = new Array();
		var CarValCod2 = new Array();
		var CarValCod3 = new Array();
		var CarValCod4 = new Array();
		var CarValCod5 = new Array();

		try
		{
			var camposSender = campoSender.name.split("_");
			
			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];
				
				if (campo.type == "select-one" || campo.type == "hidden")
				{	
					if (campo.name)
					{
						if (campo.name.indexOf("_") >= 0)
						{
							var campos = campo.name.split("_");			
							
							if (campos[0] == "DRP" && campos[1] == "PPE" && campos[2] == camposSender[2])
							{
								if (lastProd == 0 || lastProd != campos[2])
								{
									ProdutosPersonalizadosCodigo[total] = campos[2];

									if (campo.type == "select-one")
									{
										CarValCod1[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_1") ? document.getElementById("DRP_PPE_" + campos[2] + "_1").options[document.getElementById("DRP_PPE_" + campos[2] + "_1").selectedIndex].value : 0);
										CarValCod2[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_2") ? document.getElementById("DRP_PPE_" + campos[2] + "_2").options[document.getElementById("DRP_PPE_" + campos[2] + "_2").selectedIndex].value : 0);
										CarValCod3[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_3") ? document.getElementById("DRP_PPE_" + campos[2] + "_3").options[document.getElementById("DRP_PPE_" + campos[2] + "_3").selectedIndex].value : 0);
										CarValCod4[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_4") ? document.getElementById("DRP_PPE_" + campos[2] + "_4").options[document.getElementById("DRP_PPE_" + campos[2] + "_4").selectedIndex].value : 0);
										CarValCod5[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_5") ? document.getElementById("DRP_PPE_" + campos[2] + "_5").options[document.getElementById("DRP_PPE_" + campos[2] + "_5").selectedIndex].value : 0);
									}
									else if (campo.type == "hidden")
									{
										CarValCod1[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_1") ? document.getElementById("DRP_PPE_" + campos[2] + "_1").value : (document.getElementById("DRP_PPEUnico_" + campos[2] + "_1") ? document.getElementById("DRP_PPEUnico_" + campos[2] + "_1").value : 0));
										CarValCod2[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_2") ? document.getElementById("DRP_PPE_" + campos[2] + "_2").value : 0);
										CarValCod3[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_3") ? document.getElementById("DRP_PPE_" + campos[2] + "_3").value : 0);
										CarValCod4[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_4") ? document.getElementById("DRP_PPE_" + campos[2] + "_4").value : 0);
										CarValCod5[total] = (document.getElementById("DRP_PPE_" + campos[2] + "_5") ? document.getElementById("DRP_PPE_" + campos[2] + "_5").value : 0);
									}
								
									lastProd = campos[2];
									total++;
								}
							}
						}										
					}
				}
			}
			
			if (campoSender.type == "select-one")
			{
				if(campoSender.options[campoSender.selectedIndex].value == "")
				{
					mensagem+="Opção inválida (vazio) !\n";
				}
			}
			else if (campoSender.type == "hidden")
			{
				if(campoSender.value == "")
				{
					mensagem+="Opção inválida (vazio) !\n";
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				detalhes.DisponibilidadeSKUProdutoPersonalizado(ProdutoCodigo.toString(), ProdutosPersonalizadosCodigo, CarValCod1, CarValCod2, CarValCod3, CarValCod4, CarValCod5, callback_DisponibilidadeSKUProdutoPersonalizado)
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUProdutoPersonalizado(res)
	{
		if (res.error)
		{
		    if(res.error.Message.indexOf("http") > -1)
		    {
			    window.location.href = res.error.Message;
            }
		}
        else
        {
            //res.value[0] = ProdutoCodigo
            //res.value[1] = codigo
            //res.value[2] = sigla
            //res.value[3] = ImagemSku
            //res.value[4] = APartirDe
            //res.value[5] = strPrecoDeCross
            //res.value[6] = strPrecoPorCross
            
		    if (res.value)
		    {
			    document.getElementById("DRP_DISP_PPE_" + res.value[0]).value = res.value[2];

				if (res.value[1])
				{
					if (res.value[1] != "")
					{
						if (document.getElementById("spanDisponibilidade_PPE_" + res.value[0]))
						{
							if (document.getElementById("p_product_ppe_disp_" + res.value[0]))
							{
								document.getElementById("p_product_ppe_disp_" + res.value[0]).style.display = "";
							}
				            
							document.getElementById("spanDisponibilidade_PPE_" + res.value[0]).innerHTML = res.value[1];
						}
						
						if (res.value[2] != "")
					    {
						    if (res.value[2] == "I")
						    {
						        document.getElementById("p_ppe_price_" + res.value[0]).style.display = "none";
						        document.getElementById("p_personalizacao_" + res.value[0]).style.display = "none";
						    }
						    else if (res.value[2] == "D")
						    {
						        document.getElementById("p_ppe_price_" + res.value[0]).style.display = "block";
						        document.getElementById("p_personalizacao_" + res.value[0]).style.display = "block";
						    }
						}
					}
				}	
    			
			    if (res.value[3])
			    {
				    if (document.getElementById("ImgPPE" + res.value[0]))
				    {
					    document.getElementById("ImgPPE" + res.value[0]).src = res.value[3];
				    }
			    }
    		
			    if (res.value[4])
			    {
			        if (document.getElementById("spanTotalPPEDe_" + res.value[0]))
			        {
				        document.getElementById("spanTotalPPEDe_" + res.value[0]).innerHTML = res.value[5];
				    }
				    
				    if (document.getElementById("spanTotalPPEPor_" + res.value[0]))
				    {
				        document.getElementById("spanTotalPPEPor_" + res.value[0]).innerHTML = res.value[6];
				    }
			    }
            }
		
			TrocaImagem("loading", "hidden");
		}
	}
	
	// (1) detalhes.aspx
	function CarregaSKUPersonalizado(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			detalhes.CarregaSKUPersonalizado(ProdutoCodigo.toString(), callback_CarregaSKUPersonalizado);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
	
	function callback_CarregaSKUPersonalizado(res)
	{
		if (res.error)
		{
			window.location.href = window.location;
		}

    	if (res.value)
		{
		    //res.value[0] = ProdutoCodigo
            //res.value[1] = sbTexto.ToString()
            //res.value[2] = pagina
            
		    if(res.value[2])
		    {
		        window.location.href = res.value[2];
		    }
		    else
		    {
			    document.getElementById("spanSKU_PPE_" + res.value[0]).innerHTML = res.value[1];

			    for (j=0; j<document.forms[0].elements.length; j++)
			    {
				    campo = document.forms[0].elements[j];
    				
				    if (campo.name)
				    {
					    if (campo.name.indexOf("DRP_PPE_" + res.value[0] + "_") != -1)
					    {
						    campo.disabled = false;
					    }
				    }
			    }
			}

			TrocaImagem("loading", "hidden");
		}
	}
	
	// (1) detalhes.aspx
	function AdicionarItemCestaProdutoPersonalizado(ProdutoCodigo)
	{
		var Produto1_Op = true;
		var Produto1_Di = true;

		var CarValCod1 = '';
		var CarValCod2 = '';
		var CarValCod3 = '';
		var CarValCod4 = '';
		var CarValCod5 = '';
		
		var CarValCod1P = '';
		var CarValCod2P = '';
		var CarValCod3P = '';
		var CarValCod4P = '';
		var CarValCod5P = '';
		
		var CampoPersonalizacaoExtra = '';

		var VitrineCodigo = 0;
		var VitrineCodigoP = 0;
		
		var mensagem = '';

		var CodsProdutos = '';
		var NenhumProduto = false;
		var arrCodsProdutos = new Array();
		
		TrocaImagem("loading", "visible");
		
		for (var i=0; i<document.forms[0].elements.length; i++) 
		{
			var id_elemento = document.forms[0].elements[i].id;
		        
			if(document.forms[0].elements[i].id.indexOf('chkPersonalizacao_') > -1)
			{
				if (document.getElementById(id_elemento).checked)
				{
					CodsProdutos += document.getElementById(id_elemento).value + ",";
				}
			}
		}   
		
		if (CodsProdutos != "")
		{
			CodsProdutos = CodsProdutos.substring(0, CodsProdutos.length-1);
			arrCodsProdutos = CodsProdutos.split(',');
		}
		else
		{
		    NenhumProduto = true;
		}
        
		if (!NenhumProduto)
		{
		    /*--------------------------------------------------------------------------------------------------------------------------*/
			// Consistências de SKU de produto principal
			/*--------------------------------------------------------------------------------------------------------------------------*/
		    CarValCod1 = (document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").value : 0);

			VitrineCodigo = (document.getElementById("VitrineCodigo") ? document.getElementById("VitrineCodigo").value : 0);

			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];
				
				if (campo.name)
				{
					if (campo.name.indexOf("DRP_SKU") != -1 && campo.name.length == 9)
					{
						if (campo.value == "0")
						{
							mensagem += "Escolha um valor para todas as opções de compra do produto principal!\n";
							break;
						}
					}
				}
			}
			
			if (mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				/*--------------------------------------------------------------------------------------------------------------------------*/
			    // Consistências de SKU dos produtos personalizados
			    /*--------------------------------------------------------------------------------------------------------------------------*/		
		        for (var i = 0; i < arrCodsProdutos.length; i++)
		        {
			        if(!(Produto1_Op && Produto1_Di))
			        {
				        break;
			        }

			        for (j=0; j<document.forms[0].elements.length; j++)
			        {
				        campo = document.forms[0].elements[j];
        				
				        if (campo.name)
				        {
					        if (campo.name.indexOf("DRP_PPE_" + arrCodsProdutos[i]) != -1)
					        {
						        if (campo.value == "0")
						        {
							        alert("Escolha um valor para todas as opções de compra! (6)\nProduto " + (i+1).toString() + " da Personalização\n\n");
							        TrocaImagem("loading", "hidden");
							        Produto1_Op = false;
							        break;
						        }
					        }
				        }
			        }
        			
			        if (Produto1_Op)
			        {
				        for (j=0; j<document.forms[0].elements.length; j++)
				        {
					        campo = document.forms[0].elements[j];
        					
					        if (campo.name)
					        {
						        if (campo.name.indexOf("DRP_DISP_PPE_" + arrCodsProdutos[i]) != -1)
						        {
							        if (campo.value == "I")
							        {
								        alert("Combinação indisponível!\nProduto " + (i+1).toString() + " da personalização\n\n");
								        TrocaImagem("loading", "hidden");
								        Produto1_Di = false;
								        break;
							        }
						        }
					        }
				        }				
			        }
			        else
			        {
				        break;
			        }
		        }
        			
		        if (Produto1_Op && Produto1_Di)
		        {	
			        for (var i = 0; i < arrCodsProdutos.length; i++)
			        {
				        CarValCod1P += (document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_1") ? document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_1").value : (document.getElementById("DRP_PPEUnico_" + arrCodsProdutos[i] + "_1") ? document.getElementById("DRP_PPEUnico_" + arrCodsProdutos[i] + "_1").value : 0)) + ",";
				        CarValCod2P += (document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_2") ? document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_2").value : '0') + ",";
				        CarValCod3P += (document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_3") ? document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_3").value : '0') + ",";
				        CarValCod4P += (document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_4") ? document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_4").value : '0') + ",";
				        CarValCod5P += (document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_5") ? document.getElementById("DRP_PPE_" + arrCodsProdutos[i] + "_5").value : '0') + ",";
				        
				        CampoPersonalizacaoExtra += (document.getElementById("txtPersonalizacao_" + arrCodsProdutos[i]) ? document.getElementById("txtPersonalizacao_" + arrCodsProdutos[i]).value : '') + ",";
			        }
			        
			        if (CarValCod1P != "")
	                {
		                CarValCod1P = CarValCod1P.substring(0, CarValCod1P.length-1);
	                }
	                
	                if (CarValCod2P != "")
	                {
		                CarValCod2P = CarValCod2P.substring(0, CarValCod2P.length-1);
	                }
	                
	                if (CarValCod3P != "")
	                {
		                CarValCod3P = CarValCod3P.substring(0, CarValCod3P.length-1);
	                }
	                
	                if (CarValCod4P != "")
	                {
		                CarValCod4P = CarValCod4P.substring(0, CarValCod4P.length-1);
	                }
	                
	                if (CarValCod5P != "")
	                {
		                CarValCod5P = CarValCod5P.substring(0, CarValCod5P.length-1);
	                }
	                
	                if (CampoPersonalizacaoExtra != "")
	                {
		                CampoPersonalizacaoExtra = CampoPersonalizacaoExtra.substring(0, CampoPersonalizacaoExtra.length-1);
	                }
        			
			        TrocaImagem("loading", "visible");
        			
			        detalhes.VerificaValePresentePersonalizado(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), CodsProdutos.toString(), CarValCod1P.toString(), CarValCod2P.toString(), CarValCod3P.toString(), CarValCod4P.toString(), CarValCod5P.toString(), CampoPersonalizacaoExtra, VerificaValePresentePersonalizado_callback);
		        }
		    }
		}
		else
		{
		    alert("Nenhuma personalização selecionada!\n\n");
		}
	}
	
	/**************************************************************************************************************************/
	/*** Fim Personalização *******************************************************************************************************/
	/**************************************************************************************************************************/
	    
    // (1) detalhes.aspx
	var ProdutoCodigoGlobal;
	function SalvarTag(ProdutoCodigo)
	{
		TrocaImagem("loading", "visible");
		try
		{
			var TagNome = document.getElementById("txtTag").value;
			if(TagNome == "")
			{
				window.alert("Tag inválida (vazio).");
				TrocaImagem("loading", "hidden");
				return;
			}
			detalhes.SalvarTag(TagNome, ProdutoCodigo.toString(), callback_SalvarTag);
			ProdutoCodigoGlobal = ProdutoCodigo;
		}
		catch(exc)
		{
			AlertaErroAjax(exc);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_SalvarTag(res)
	{
		if(res.error)
		{
			if (res.error.Message.indexOf("http://") > -1 || res.error.Message.indexOf("https://") > -1)
			{
				window.location = res.error.Message;
			}
			else
			{
				AlertaErroAjax(res.error);
			}

			//window.AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
			return;
		}

		if(res.value)
		{
			window.alert(res.value);
			document.getElementById("txtTag").value = "";
			
			if(document.getElementById('TextoTag').innerHTML.indexOf('Seja o primeiro a incluir uma TAG') > -1)
			{
				document.getElementById('TextoTag').innerHTML = 'Deixe sua TAG para este produto';
			}
			
			detalhes.CarregaTags(ProdutoCodigoGlobal.toString(), callback_CarregaTags);
			
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_CarregaTags(res)
	{
		if(res.error)
		{
			window.AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
			return;
		}
		if(res.value)
		{
			document.getElementById("TagsProduto").innerHTML = res.value;
			TrocaImagem("loading", "hidden");
		}
	}
	
    // (1) detalhes.aspx
    function VerificaPreenchimentoNomeAvaliacao(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoNome');
    		
	    if(Trim(campo.value) != '')
	    {
		    spanMsgValidacao.innerHTML = '';	
		    MudaCorBorda(campo,'#036');
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha o Nome';
	        MudaCorBorda(campo,'red');   
	    }
    }
    
    // (1) detalhes.aspx
    function VerificaPreenchimentoEmailAvaliacao(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoEmail');
    		
	    if(Trim(campo.value) != '')
	    {
	        if(!(ValidaEmail(Trim(campo.value))))
			    document.getElementById("spanMsgValidacaoEmail").innerHTML = '« E-mail inválido';
		    else
		    {
		        spanMsgValidacao.innerHTML = '';	
		        MudaCorBorda(campo,'#036');
		    }
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha o E-mail';
	        MudaCorBorda(campo,'red');   
	    }
    }
    
    // (1) detalhes.aspx
    function VerificaPreenchimentoComentariosAvaliacao(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoComentarios');
    		
	    if(Trim(campo.value) != '')
	    {
		    spanMsgValidacao.innerHTML = '';	
		    MudaCorBorda(campo,'#036');
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha a Avaliação';
	        MudaCorBorda(campo,'red');   
	    }
    }
    
    // (1) detalhes.aspx
    function VerificaPreenchimentoNotaAvaliacao(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoAvaliacao');
    		
	    if(Trim(campo.value) != '')
	    {
		    spanMsgValidacao.innerHTML = '';	
		    MudaCorBorda(campo,'#036');
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha a Nota';
	        MudaCorBorda(campo,'red');
	    }
    }
    
    // (1) detalhes.aspx
	function SalvarOpiniao(ProdutoCodigo, botao)
	{
		var mensagem = "";
		var retorno = true

		var Nota = "";
		var Nome = "";
		var Email = "";
		var Comentario = "";
		var ExibeEmail = "";

		try
		{
			if(Trim(document.getElementById("txtNome").value) == "")
			{
				document.getElementById("spanMsgValidacaoNome").innerHTML = '« Preencha o Nome';
				retorno = false;
				MudaCorBorda(document.getElementById("txtNome"),'red');
			}
			
			if(Trim(document.getElementById("txtEmail").value) == "")
			{
				document.getElementById("spanMsgValidacaoEmail").innerHTML = '« Preencha o E-mail';
				retorno = false;
				MudaCorBorda(document.getElementById("txtEmail"),'red');
			}
			    
			if(!(ValidaEmail(Trim(document.getElementById("txtEmail").value))))
			{
				document.getElementById("spanMsgValidacaoEmail").innerHTML = '« E-mail inválido';
				retorno = false;
				MudaCorBorda(document.getElementById("txtEmail"),'red');
			}
			
			if(Trim(document.getElementById("txtDescricao").value) == "")
			{
				document.getElementById("spanMsgValidacaoComentarios").innerHTML = '« Preencha a Avaliação';
				retorno = false;
				MudaCorBorda(document.getElementById("txtDescricao"),'red');
			}
			
			if(Trim(document.getElementById("txtNota").value) == "")
			{
				document.getElementById("spanMsgValidacaoAvaliacao").innerHTML = '« Preencha a Nota';
				retorno = false;
				MudaCorBorda(document.getElementById("txtNota"),'red');
			}

			if(retorno)
			{
			    TrocaImagem("loading", "visible");
		        OmitirBotao(botao);
		        
				Nota = document.getElementById("txtNota").value;
				Nome = document.getElementById("txtNome").value;
				Email = document.getElementById("txtEmail").value;
				Comentario = document.getElementById("txtDescricao").value;
				ExibeEmail = document.getElementById("ckExibeEmail").checked;

				detalhes.SalvarOpiniao(ProdutoCodigo.toString(), Nome, Email, Comentario, Nota.toString(), ExibeEmail.toString(), callback_SalvarOpiniao)
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
			MostrarBotao(botao);
		}
	}

	function callback_SalvarOpiniao(res)
	{
		if (res.error)
		{
			document.location.href = res.error.Message;
		}

		if (res.value)
		{
			//Opinar('');
			alert(res.value);

			document.getElementById("txtNota").value = "";
			document.getElementById("txtNome").value = "";
			document.getElementById("txtEmail").value = "";
			document.getElementById("txtDescricao").value = "";
			document.getElementById("ckExibeEmail").checked = true;

			MostrarBotao(document.getElementById("btOpiniaoEnviar"));

			ResetPreview();

			TrocaImagem("loading", "hidden");
		}
	}
	
	// (1) detalhes.aspx
	function Tagar()
	{
		detalhes.ExisteSessao(callback_ExisteSessao);
	}

	function callback_ExisteSessao(res)
	{
		if(res.value != "")
		{
		    alert('Antes de deixar sua Tag você deve fazer o login');
			window.location = res.value;
			return;
		}

		try 
		{
			SalvarTag(document.getElementById('txtProdutoCodigo').value);
		} 
		catch (err) 
		{
		}
	}
    
    // (1) detalhes.aspx
	function Opinar(exibe) 
	{
		try 
		{
			if (document.getElementById("indique_container")) 
			{
				document.getElementById("indique_container").style.display = "none";
			}

			if (document.getElementById("opine_container")) 
			{
				document.getElementById("opine_container").style.display = "block";
			}

			window.location.href = "#O";
		} 
		catch (err) 
		{
		}
	}
    
    // (1) detalhes.aspx
	function Indicar()
	{
		try 
		{
			if (document.getElementById("opine_container")) 
			{
				document.getElementById("opine_container").style.display = "none";
			}

			if (document.getElementById("indique_container")) 
			{
				document.getElementById("indique_container").style.display = "block";
			}

			window.location.href = "#O";
		} 
		catch (err) 
		{
		}
	}

    // (1) detalhes.aspx
    function VerificaPreenchimentoNomeAmigoIndique(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoNomeAmigo');
    		
	    if(Trim(campo.value) != '')
	    {
		    spanMsgValidacao.innerHTML = '';	
		    MudaCorBorda(campo,'#036');
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha o Nome';
	        MudaCorBorda(campo,'red');   
	    }
    }

    // (1) detalhes.aspx
    function VerificaPreenchimentoNomeRemetenteIndique(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoNomeRemetente');
    		
	    if(Trim(campo.value) != '')
	    {
		    spanMsgValidacao.innerHTML = '';	
		    MudaCorBorda(campo,'#036');
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha o Nome';
	        MudaCorBorda(campo,'red');   
	    }
    }

    // (1) detalhes.aspx
    function VerificaPreenchimentoEmailAmigo(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoEmailAmigo');
    		
	    if(Trim(campo.value) != '')
	    {
	        if(!(ValidaEmail(Trim(document.getElementById("txtEmailAmigo").value))))
			    document.getElementById("spanMsgValidacaoEmailAmigo").innerHTML = '« E-mail inválido';
		    else
		    {
		        spanMsgValidacao.innerHTML = '';	
		        MudaCorBorda(campo,'#036');
		    }
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha o E-mail';
	        MudaCorBorda(campo,'red');   
	    }
    }

    // (1) detalhes.aspx
    function VerificaPreenchimentoEmailRemetente(campo)
    {
	    var spanMsgValidacao = document.getElementById('spanMsgValidacaoEmailRemetente');
    		
	    if(Trim(campo.value) != '')
	    {
	        if(!(ValidaEmail(Trim(campo.value))))
			    document.getElementById("spanMsgValidacaoEmailRemetente").innerHTML = '« E-mail inválido';
		    else
		    {
		        spanMsgValidacao.innerHTML = '';	
		        MudaCorBorda(campo,'#036');
		    }
	    }
	    else
	    {
	        spanMsgValidacao.innerHTML = '« Preencha o E-mail';
	        MudaCorBorda(campo,'red');   
	    }
    }

    // (1) detalhes.aspx
    function EnviaIndicacao(botao)
    {
	    var Mensagem = "";
	    var NomeAmigo = "";
	    var EmailAmigo = "";
	    var NomeRemetente = "";
	    var EmailRemetente = "";
	    var MsgIndicacao = "";
	    var retorno = true;

	    try
	    {
		    if(Trim(document.getElementById("txtNomeAmigo").value) == "")
	        {
		        document.getElementById("spanMsgValidacaoNomeAmigo").innerHTML = '« Preencha o Nome';
		        retorno = false;
		        MudaCorBorda(document.getElementById("txtNomeAmigo"),'red');
	        }
    	    
	        if(Trim(document.getElementById("txtEmailAmigo").value) == "")
		    {
			    document.getElementById("spanMsgValidacaoEmailAmigo").innerHTML = '« Preencha o E-mail';
			    retorno = false;
			    MudaCorBorda(document.getElementById("txtEmailAmigo"),'red');
		    }
    		    
		    if(!(ValidaEmail(Trim(document.getElementById("txtEmailAmigo").value))))
		    {
			    document.getElementById("spanMsgValidacaoEmailAmigo").innerHTML = '« E-mail inválido';
			    retorno = false;
			    MudaCorBorda(document.getElementById("txtEmailAmigo"),'red');
		    }
    		
		    if(Trim(document.getElementById("txtRemetente").value) == "")
	        {
		        document.getElementById("spanMsgValidacaoNomeRemetente").innerHTML = '« Preencha o Nome';
		        retorno = false;
		        MudaCorBorda(document.getElementById("txtRemetente"),'red');
	        }
    	    
	        if(Trim(document.getElementById("txtEmailRemetente").value) == "")
		    {
			    document.getElementById("spanMsgValidacaoEmailRemetente").innerHTML = '« Preencha o E-mail';
			    retorno = false;
			    MudaCorBorda(document.getElementById("txtEmailRemetente"),'red');
		    }
    		    
		    if(!(ValidaEmail(Trim(document.getElementById("txtEmailRemetente").value))))
		    {
			    document.getElementById("spanMsgValidacaoEmailRemetente").innerHTML = '« E-mail inválido';
			    retorno = false;
			    MudaCorBorda(document.getElementById("txtEmailRemetente"),'red');
		    }
    		
		    if (retorno)
		    {
		        TrocaImagem("loading", "visible");
	            OmitirBotao(botao);
    		
		        NomeAmigo = Trim(document.getElementById("txtNomeAmigo").value);
		        EmailAmigo = Trim(document.getElementById("txtEmailAmigo").value);
		        NomeRemetente = Trim(document.getElementById("txtRemetente").value);
		        EmailRemetente = Trim(document.getElementById("txtEmailRemetente").value);
		        MsgIndicacao = Trim(document.getElementById("txtMensagem").value);
    		    
		        detalhes.EnviaIndicacao(NomeAmigo, EmailAmigo, NomeRemetente, EmailRemetente, MsgIndicacao, callback_EnviaIndicacao)
		    }
	    } 
	    catch(err)
	    {
		    AlertaErroAjax(err);
		    TrocaImagem("loading", "hidden");
		    MostrarBotao(botao);
	    }
    }

    function callback_EnviaIndicacao(res)
    {
	    if (res.error)
	    {
		    //AlertaErroAjax(res.error);
		    TrocaImagem("loading", "hidden");
		    window.location.href = window.location;
	    }		

	    if (res.value[0])
	    {
		    document.getElementById("txtNomeAmigo").value = "";
		    document.getElementById("txtEmailAmigo").value = "";
		    document.getElementById("txtMensagem").value = "";
		    document.getElementById("txtRemetente").value = "";
		    document.getElementById("txtEmailRemetente").value = "";
    		
		    alert(res.value[0]);
    	
		    if (res.value[1])
		    {
			    window.location.href = res.value[1];
		    }
		    else
		    {
			    MostrarBotao(document.getElementById('btIndicacaoEnviar'));
		    }

		    TrocaImagem("loading", "hidden");
	    }
    }
    
    // (1) detalhes.aspx
	function janela(hp, width, height, texto)
	{
		if (!width || width == "")
		{
			width = window.screen.width;
		}

		if (!height || height == "")
		{
			height = window.screen.height;
		}

		var w = window.screen.width;
		var h = window.screen.height;
		var l = (w-width)/2;
		var t = (h-height)/2;

		wAbout = window.open(hp, texto, "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1, top="+t+", left="+l+", width=" + width + ",height=" + height + " ");
		
		if (!wAbout)
		{
			alert('ATENÇÃO!\n\nHouve um erro ao abrir a janela.\nVocê pode estar com algum bloqueador de PopUp ligado.');
		}
		else
		{
			wAbout.focus();
		}
	}
    
    // (1) detalhes.aspx
	function janelaConsultaFrete(hp, width, height, texto)
	{
		if (!width || width == "")
		{
			width = window.screen.width;
		}

		if (!height || height == "")
		{
			height = window.screen.height;
		}

		var w = window.screen.width;
		var h = window.screen.height;
		var l = (w-width)/2;
		var t = (h-height)/2;

		wAbout = window.open(hp, texto, "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, top="+t+", left="+l+", width=" + width + ",height=" + height + " ");

		if (!wAbout)
		{
			alert('ATENÇÃO!\n\nHouve um erro ao abrir a janela.\nVocê pode estar com algum bloqueador de PopUp ligado.');
		}
		else
		{
			wAbout.focus();
		}
	}
	
	// (1) detalhes.aspx.cs
	function AdicionarItemLista(ProdutoCodigo)
	{
		var enc = 0;
		var mensagem = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;
		var VitrineCodigo = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCod1 = (document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").value : 0);

			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];
				
				if (campo.name)
				{
					if (campo.name.indexOf("DRP_SKU") != -1 && campo.name.length == 9)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra! (7)\n";
							break;
						}
					}
				}
			}
				
			var ListaCodigo = '';
			
			for (k=0; k<document.getElementsByTagName("input").length; k++)
			{
				var campo = document.getElementsByTagName("input")[k];

				if (campo.type == "radio" && campo.id.indexOf('fld_Lista') != -1 && campo.checked)
				{
					ListaCodigo = campo.value;
					break;
				}
			}					

			if(ListaCodigo == '' && mensagem == '')
			{
				mensagem = 'Escolha uma lista!';
			}
			
			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				if(ListaCodigo.toString() == "ListaDesejo")
				{
					AdicionarListaDesejo();
				}
				else
				{
					detalhes.AdicionarItemLista(ListaCodigo.toString(), ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), document.location.href.toString(), AdicionarItemLista_callback)
				}
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

	function AdicionarItemLista_callback(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value[0])
		{
    	    if (document.getElementById("FieldSetListas"))
		    {
		        document.getElementById("FieldSetListas").style.display = "none";
		    }
				    
			alert(res.value[0]);						
		}
		if(res.value[1])
		{
		    window.location.href = res.value[1];
		}
	}
	
	// (1) detalhes.aspx
	function AdicionarListaDesejo()
	{
		var ProdutoCodigo	= 0;
		var CategoriaCodigo = 0;
		var CarValCod1		= 0;
		var CarValCod2		= 0;
		var CarValCod3		= 0;
		var CarValCod4		= 0;
		var CarValCod5		= 0;
		var mensagem		= '';

		try
		{

			ProdutoCodigo		= (document.getElementById("ProdutoCodigo") ? document.getElementById("ProdutoCodigo").value : 0);
			CategoriaCodigo		= (document.getElementById("CategoriaCodigo") ? document.getElementById("CategoriaCodigo").value : 0);

			CarValCod1 			= (document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").value : 0);
			CarValCod2 			= (document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").value : 0);
			CarValCod3 			= (document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").value : 0);
			CarValCod4 			= (document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").value : 0);
			CarValCod5 			= (document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").value : 0);
			
			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];
				
				if (campo.name)
				{
					if (campo.name.indexOf("DRP_SKU") != -1 && campo.name.length == 9)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra! (8)\n";
							break;
						}
					}
				}
			}

			if(Trim(mensagem) != '')
			{
				alert(mensagem);
			}
			else
			{
				detalhes.AdicionarListaDesejo(ProdutoCodigo.toString(), CategoriaCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), AdicionarListaDesejo_CallBack);
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);

		}
	}

	function AdicionarListaDesejo_CallBack(res)
	{
		try
		{
			if(res.value[0] == "0")
			{
				if(res.value[2] != "")
				{
				    if (document.getElementById("FieldSetListas"))
				    {
				        document.getElementById("FieldSetListas").style.display = "none";
				    }
				    
					alert(res.value[2]);
				}
				if(res.value[3] != "")
				{
					 window.location = res.value[3];
				}
			}
			else
			{
				if(res.value[2] != "")
				{
					alert(res.value[2]);
				}
				if(res.value[3] != "")
				{
					 window.location = res.value[3];
				}

			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
		}
	}
	
	function ExibeBlocoLista()
    {
	    document.getElementById('listaOpcoes_container').style.display = '';
    }
    
    function EscondeBlocoLista()
    {
	    document.getElementById('listaOpcoes_container').style.display = 'none';
    }	

    function LoginLista(ListaCodigo)
    {
	    detalhes.LoginLista(document.location.href.toString(), LoginLista_callback);
    }

    function LoginLista_callback(res)
    {
	    if(!res.error)
	    {
		    document.location.href = res.value;
	    }
	    else
	    {
		    AlertaErroAjax(res.error);
	    }
    }
    
     function SelecionaOpcao(var1)
	 {	
		
		var valoresArray = var1.split('|');

		
	
		
		document.getElementById('NomeProduto').innerHTML = valoresArray[0];
		document.getElementById('CodigoProduto').innerHTML = valoresArray[1];
		

		if(document.getElementById('spanPrecoPor'))
		{
			if(valoresArray[2] != "0")
			{
					document.getElementById('spanPrecoPor').innerHTML = 'R$ ' + valoresArray[2];
			}
			else
			{
				document.getElementById('spanPrecoPor').innerHTML = "";
			}
		}	
		
		if(document.getElementById('spanParcelamento1'))
		{
			if(valoresArray[3] != "vazio")
			{
				document.getElementById('spanParcelamento1').innerHTML = valoresArray[3];
			}
			else
			{
				document.getElementById('spanParcelamento1').innerHTML = "";
			}
		}
		if(document.getElementById('spanParcelamento2'))
		{
				if(valoresArray[4] != "vazio")
				{
					document.getElementById('spanParcelamento2').innerHTML = valoresArray[4];
				}
				else
				{
					document.getElementById('spanParcelamento2').innerHTML = "";
				}
		}
		if(document.getElementById('spanOutroParc'))
		{
				if(valoresArray[5] != "vazio")
				{
					document.getElementById('spanOutroParc').innerHTML = valoresArray[5];
				}
				else
				{
					document.getElementById('spanOutroParc').innerHTML = "";
				}
		}
		if(document.getElementById('spanPrecoEconomize'))
		{
				if(valoresArray[6] != "vazio")
				{
					document.getElementById('spanPrecoEconomize').innerHTML = valoresArray[6];
				}
				else
				{
					document.getElementById('spanPrecoEconomize').innerHTML = "";
				}
		}
		
		
		document.getElementById('idCaminho').innerHTML = valoresArray[0];		
		
		//document.getElementById('ImagemAmpliada').innerHTML = valoresArray[9];
		
		var chave = "#skuCustomizada" + valoresArray[7];
		
		detalhes.CarregaSKU(valoresArray[1].toString(), function(res) { callback_CarregaSKUCustomizado(res, chave);})		
	 }
	 
	 	 
	function imageExists2(url, successMethod, errorMethod) 
	{
		var img = document.createElement("img");	
		
		img.onload = function () {
			if(successMethod != null)
				successMethod();
		};
		img.onerror = function () {
			if(errorMethod != null)
				errorMethod();
		};		
		
		img.src = url;
	}

	function callback_CarregaSKUCustomizado(res, chave)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
			//window.location.href = window.location;
		}

		if (res.value)
		{
			if (res.value[0])
			{
				var chaveImg = jQuery(chave + " img").attr("id");
				document.getElementById("spanSKU").innerHTML = res.value[0];
				
				TrocaImagemDetalhe(document.getElementById(chaveImg));
				
				
				
				var srcAux = jQuery("[name=ProdutoImagem]").attr("src");		
				
				if(document.getElementById('ImgDetalhe1'))
				{		
					jQuery("#ImgDetalhe1").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes.jpg'));
					imageExists2(jQuery("#ImgDetalhe1").attr("src"), function() { jQuery("#liDetalhe1").show() },  function() { jQuery("#liDetalhe1").hide() }); 
					imageExists2(jQuery("#ImgDetalhe1").attr("src"), function() { jQuery("#ImgDetalhe1").show() },  function() { jQuery("#ImgDetalhe1").hide() }); 
				}
		
				if(document.getElementById('ImgDetalhe2'))
				{
					jQuery("#ImgDetalhe2").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes1.jpg'));	
					imageExists2(jQuery("#ImgDetalhe2").attr("src"), function() { jQuery("#liDetalhe2").show() },  function() { jQuery("#liDetalhe2").hide() });
					imageExists2(jQuery("#ImgDetalhe2").attr("src"), function() { jQuery("#ImgDetalhe2").show() },  function() { jQuery("#ImgDetalhe2").hide() }); 			
				}
	
				if(document.getElementById('ImgDetalhe3'))
				{
					jQuery("#ImgDetalhe3").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes2.jpg'));
					imageExists2(jQuery("#ImgDetalhe3").attr("src"), function() { jQuery("#liDetalhe3").show() },  function() { jQuery("#liDetalhe3").hide() }); 
					imageExists2(jQuery("#ImgDetalhe3").attr("src"), function() { jQuery("#ImgDetalhe3").show() },  function() { jQuery("#ImgDetalhe3").hide() });			
				}

				if(document.getElementById('ImgDetalhe4'))
				{
					jQuery("#ImgDetalhe4").attr("src", srcAux.replace('Detalhes.jpg', 'Detalhes3.jpg'));
					imageExists2(jQuery("#ImgDetalhe4").attr("src"), function() { jQuery("#liDetalhe4").show() },  function() { jQuery("#liDetalhe4").hide() });
					imageExists2(jQuery("#ImgDetalhe4").attr("src"), function() { jQuery("#ImgDetalhe4").show() },  function() { jQuery("#ImgDetalhe4").hide() }); 			
	
				}

								
			}

			if (res.value[1])
			{
				document.getElementById("spanSKUComprar").innerHTML = res.value[1];
			}

			for (j=0; j<document.forms[0].elements.length; j++)
			{
				campo = document.forms[0].elements[j];
				
				if (campo.name)
				{
					if (campo.name.indexOf("DRP_SKU") != -1)
					{
						campo.disabled = false;
					}
				}
			}

            if(res.value[2])
            {
                document.location.href = res.value[2];
            }
            
            // Trecho que seleciona a cor, caso exista apenas um valor
            if (res.value[3] && res.value[4] && res.value[5])
			{
		        if (res.value[3] != "" && res.value[4] != "" && res.value[5] != "")
		        {
		            ArmazenaOpcao(res.value[5].toString(), res.value[4].toString(), res.value[3].toString(), 'I');
		        }
			}
			
			//Customizacao
			jQuery(chave).attr("class", "thumb_off_Opacity");		
			
			TrocaImagem("loading", "hidden");
			
		}
	}
