	function EnviarAlacarta()
	{
		try
		{
			TrocaImagem("loading", "visible");
			
			var nome		= document.getElementById("banner_lateral_Alacarta_txtNome").value;
			var sobrenome	= document.getElementById("banner_lateral_Alacarta_txtSobreNome").value;
			var email		= document.getElementById("banner_lateral_Alacarta_txtEmail").value;
			var regiao		= document.getElementById("banner_lateral_Alacarta_ddlRegiao").options[document.getElementById("banner_lateral_Alacarta_ddlRegiao").selectedIndex].value;
			
			
			if(nome.length > 0 && sobrenome.length > 0 && email.length > 0 && regiao != "")
			{
				alacarta.EnviarAlacarta(nome, sobrenome, email, regiao, EnviarAlacarta_CallBack)			
			}
			else
			{
				alert("É necessário preencher todos os campos antes de prosseguir!");
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	
	}
	
	
	
		
	function EnviarAlacarta_CallBack(resp)
	{
		try
		{
			if (resp.error)
			{
				alert(resp.error.Type + " : " + resp.error.Message);
			}
			else
			{
				if(resp.value[0] == "1")
				{
					alert(resp.value[1]);
					document.getElementById("banner_lateral_Alacarta_txtNome").value = "";
					document.getElementById("banner_lateral_Alacarta_txtSobreNome").value = "";
					document.getElementById("banner_lateral_Alacarta_txtEmail").value = "";	
					document.getElementById("banner_lateral_Alacarta_ddlRegiao").selectedIndex = 0;
								
					TrocaImagem("loading", "hidden");
				}
				else
				{
					alert(resp.value[1]);
					TrocaImagem("loading", "hidden");
				}
			}

		}
		catch(err)
		{
			alert(err.message);
		}
	}		
	
	
	function AlertaErroAjax(error)
	{
	    if (error.Message.toLowerCase() != "unknown")
	    {
	        alert(error.Message)	        
	    }
	}
	
	function ExcluirItem(ItemCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");

			if (confirm('Você tem certeza que deseja EXCLUIR este item da sua Cesta de Compras?'))
			{
				index.ExcluirItem(ItemCodigo, callback_ExcluirItem);
			}
			else
			{
				TrocaImagem("loading", "hidden");
			}
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_ExcluirItem(res)
	{
		if (res.error)
		{
			alert(res.error.Type + " : " + res.error.Message);
		}
		else if (res.value)
		{
			window.location.href = res.value;
		}
	}

	function PresenteItem(campo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			index.PresenteItem(campo.value, campo.checked, callback_PresenteItem);
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_PresenteItem(res)
	{
		if (res.error)
		{
			alert(res.error.Type + " : " + res.error.Message + "\n" + res.error.Stack + " : " + res.error.TargetSite);
		}	
		else if (res.value)
		{
			window.location.href = res.value;
		}
	}
	
	function NaoExisteMeioPgto(URL)
	{
		alert('Nenhum forma de pagamento disponível para o valor desse pedido!');
		window.location.href = URL;
	}
	
	function ResumoCesta()
	{
		try
		{
			TrocaImagem("loading", "visible");
			cabecalho.PublicaResumoCesta(callback_ResumoCesta);
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_ResumoCesta(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}	
		
		if (res.value)
		{
			/*
			if (res.value[0])
			{
				document.getElementById("QtdeItens").innerHTML = res.value[0];
			}
			if (res.value[1])
			{
				document.getElementById("ValorItens").innerHTML = res.value[1];
			}
			*/
			
			TrocaImagem("loading", "hidden");
		}
	}
	
	function Topo_Identifica()
	{
		try
		{
			TrocaImagem("loading", "visible");
			cabecalho.Identifica(callback_Topo_Identifica);
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_Topo_Identifica(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}	
		
		if (res.value)
		{
			document.getElementById("identificacao").innerHTML = res.value;
			TrocaImagem("loading", "hidden");
		}
	}

	function ExcluiCookieLogin()
	{
		cabecalho.ExcluiCookieLogin(ExcluiCookieLogin_callback)
	}
	
	function ExcluiCookieLogin_callback(retorno)
	{
		try
		{
			if(retorno.error == null)
			{
				if(retorno.value)
				{
					window.location.href = retorno.value;
				}
			}
			else
			{
				alert("erro : " + retorno.error.Message);
			}
		}
		catch(ex)
		{
			alert(ex.description);
		}
	}
	
	/*************************************************************************\
	CheckCardNumber(form)
	function called when users click the "check" button.
	\*************************************************************************/

	function validaCartao()
	{
		var retorno = true;

		var CCval = document.getElementById("CartaoNumero").value;
		

		if(CCval.substr(0,6) == "628076" && (parseInt(CCval) >= 6280760000000000 && parseInt(CCval) <= 6280769999999999))
		{
			return retorno;
		}				
		
		// check if credit card name has been entered
		if (arguments.IsValid)
		{
			if (CCval == "")
			{
				retorno = false;
			}
		}

		CCval = _strip_spaces(CCval);

		// check if credit card number is actually a number
		if (_isinteger(CCval) == false)
		{
			retorno = false;
		}
		if (retorno)
		{
			// check for 4242 4242 4242 4242
			if (CCval == "4242424242424242")
			{
				retorno = false;
			}
		}

		if (retorno)
		{
			//check that the credit card number is valid
			if (!CC_Validate(CCval))
			{
				retorno = false;
			}
		}

		return retorno;
	}

	function _strip_spaces(_ipstr)
	{
		var _opstr = '';
		var i;
		for (i = 1; i <= _ipstr.length; i++)
		{
			if(_ipstr.substring(i-1, i) != ' ')
			{
				_opstr = _opstr + _ipstr.substring(i-1, i);
			}
		}
		return _opstr;
	}


	function _isinteger(test_string)
	{
		var i;
		var non_nums = 0;

		for (i = 1; i < test_string.length; i++)
		{
			if ((test_string.substring(i-1,i) < '0') || (test_string.substring(i-1,i) > '9'))
			{
				non_nums++;
			}
		}

		if (non_nums == 0)
			return true;
		else
			return false;
	}


	function CC_Validate(ccnumber)
	{
		var checksum = 0;
		var i;
		var digit;
		var temp;

		var cclength=ccnumber.length;
		if (cclength % 2 != 0)
		{
			cclength += 1;
			ccnumber = "0" + ccnumber;
		}

		for (i = 0; i < cclength; i++)
		{
			digit = parseInt(ccnumber.charAt(i));
			if ((i % 2) == 0)
			{
				digit *= 2;
				if (digit > 9)
				{
					digit = parseInt(digit / 10) + parseInt(digit % 10);
				}
			}
			checksum += digit;
		}


		if (checksum % 10 == 0)
			return true;
		else
			return false;
	}

	function ExpandirTipo(j)
	{
		var Sinal		= document.getElementById('TipoSinal'+j);
		var linhas		= new Array();

		if(document.getElementById('Tipo'+j))
		{		
			while(document.getElementById('Tipo'+j) != null)
			{
				linhas.push(document.getElementById('Tipo'+j));
				document.getElementById('Tipo'+j).id = 'temporario';
			}
		}
		
		for(var i = 0; i < linhas.length; i++)
		{
			if(Sinal.innerHTML.toUpperCase() == '<B>+</B>')
			{
				linhas[i].style.display = '';
			}
			else
			{
				linhas[i].style.display = 'none';
			}
			linhas[i].id = 'Tipo'+j;
		}
		
		if(Sinal.innerHTML.toUpperCase() == '<B>+</B>')
		{
			Sinal.innerHTML = '<B>-</B>';
		}
		else
		{
			Sinal.innerHTML = '<B>+</B>';
		}
	}
	
	function RetirarComparador(col, qtd)
	{
		var colunas		= new Array();
		var ItensAtivos = 0;
		
		for(var j = 0; j < qtd; j++)
		{
			if(document.getElementById('ItemCompara'+j) != null){
				if(document.getElementById('ItemCompara'+j).style.display != 'none')
				{
					ItensAtivos++;
				}
			}
		}
		
		if(ItensAtivos > 2)
		{
			if(document.getElementById(col))
			{		
				while(document.getElementById(col) != null)
				{
					colunas.push(document.getElementById(col));
					document.getElementById(col).id = 'temporario';
				}
			}
		
			for(var i = 0; i < colunas.length; i++)
			{
				colunas[i].style.display = 'none';
				colunas[i].id = col;
			}
		}
		else
		{
		
			alert('Para fazer a comparação é necessário ter ao menos dois produtos!');
		}
	}
	
	function AtualizaItem(ItemCodigo)
	{
		var prossegue = false;

		var Presente = document.getElementById("GiftTmp" + ItemCodigo).value;
		var MsgPresente = document.getElementById("MsgGift" + ItemCodigo).value;

		TrocaImagem("loading", "visible");

		if (Presente.length < 1)
		{
			if (confirm("Você deseja prosseguir sem preencher o campo de Mensagem?"))
			{
				prossegue = true;
			}
		}
		else
		{
			prossegue = true;
		}

		if (prossegue)
		{
			presente.AtualizaItem(ItemCodigo.toString(), Presente, MsgPresente, callback_AtualizaItem)
		}
	}

	function callback_AtualizaItem(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			alert(res.value);
			TrocaImagem("loading", "hidden");
		}
	}

	function Gift(ItemCodigo, valor)
	{
		document.getElementById("GiftTmp" + ItemCodigo).value = valor;
	}


	function ArmazenaParcelamento(campo)
	{
		if (campo.type == "radio")
		{
			if (campo.checked)
			{
				document.getElementById("ParcelamentoSel").value = campo.id;
				document.getElementById("ParcelamentoSelCod").value = campo.value;
			}
		}
	}

	function ValidaContaCorrente(campo)
	{
		if(campo.checked == false)
		{
			if(document.getElementById('TipoCco1')!= null)
			{
				document.getElementById('TipoCco1').checked = false;
				document.getElementById('TipoCco1').disabled = true;
			}
			if(document.getElementById('TipoCco2')!= null)
			{
				document.getElementById('TipoCco2').checked = false;
				document.getElementById('TipoCco2').disabled = true;
			}
			if(document.getElementById('TipoCco3')!= null)
			{
				document.getElementById('TipoCco3').checked = false;
				document.getElementById('TipoCco3').disabled = true;
			}

			fechamento.ValidaContaCorrente(campo.checked, callback_ValidaContaCorrente)
		}
		else
		{
			if(document.getElementById('TipoCco1')!= null)
			{
				document.getElementById('TipoCco1').disabled = false;
			}
			if(document.getElementById('TipoCco2')!= null)
			{
				document.getElementById('TipoCco2').disabled = false;
			}
			if(document.getElementById('TipoCco3')!= null)
			{
				document.getElementById('TipoCco3').disabled = false;
			}
		}
	}
	
	function callback_ValidaContaCorrente(res)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
			window.location.href = window.location;
		}
		else
		{
			if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
			{
				document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
			{
				document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
			}
			
			if(document.getElementById("spanPagamentoEscolhidoCtC") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCtC").innerHTML = "";
			}
			
			for (j=0; j<document.getElementsByTagName("input").length; j++)
			{
				campo = document.getElementsByTagName("input")[j];

				if (campo.type == "radio")
				{
					campo.checked = false;
					if(campo.id.indexOf("TipoCco") == -1)
					{
						campo.disabled = false;
					}
				}
			}
			
			document.getElementById("OperadoraCodigo").value = "";
			document.getElementById("OperadoraTipo").value = "";
			document.getElementById("ParcelamentoSel").value = "";
			document.getElementById("ParcelamentoSelCod").value = "";

			IniciaFechamento();
		}
	}
		
	function ArmazenaContaCorrente(campo)
	{
		fechamento.ArmazenaContaCorrente(campo.value, callback_ArmazenaContaCorrente)
	}
	
	function callback_ArmazenaContaCorrente(res)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
			window.location.href = window.location;
		}

		if(res.value[0])
		{
			alert(res.value[0]);
		}
		else
		{
			document.getElementById("spanPagamentoEscolhidoCtC").innerHTML = res.value[2];

			for (j=0; j<document.getElementsByTagName("input").length; j++)
			{
				campo = document.getElementsByTagName("input")[j];

				if (campo.type == "radio" && campo.id != "TipoCco"+res.value[1])
				{
					campo.checked = false;

					if(res.value[3])
					{
						campo.disabled = true;
					}
				}
			}
		}

		if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
		{
			document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
		}

		if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
		{
			document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
		}

		if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
		{
			document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
		}
		
		document.getElementById("OperadoraCodigo").value = "";
		document.getElementById("OperadoraTipo").value = "";
		document.getElementById("ParcelamentoSel").value = "";
		document.getElementById("ParcelamentoSelCod").value = "";

		if(!res.value[3])
		{
			IniciaFechamento();
		}
				
		TrocaImagem("loading", "hidden");
	}
	
	function ValidaMeioPagamento(MeioCodigo)
	{
		TrocaImagem("loading", "visible");	
		
		var QtdeElementos = document.frm.elements.length;			
		var rdbEntregaId = "";
			
		for (var i=0; i < QtdeElementos; i++) 
		{				
			if(document.frm.elements[i].id.indexOf('rdbEntrega_') > -1 && document.frm.elements[i].checked)
				rdbEntregaId = document.frm.elements[i].id;
		}
			
		try
		{
			if (MeioCodigo.checked)
			{
				if (document.getElementById("OperadoraCodigo").value != MeioCodigo.value.substring(4))
				{
					//Se foi escolhido Cartão Amex ou AURA aumentar quantidade de dígitos do cartão
					//***********************************************************************************
					if (MeioCodigo.value.substring(4) == "1" || MeioCodigo.value.substring(4) == "2")
					{
						document.getElementById("CartaoNumero").maxLength = '19';
						document.getElementById("CartaoNumero").onkeyup = function()
						{
							if(this.value.length == 19) document.getElementById("CartaoCodigo").focus();
						};
					}
					else
					{
						if (document.getElementById("CartaoNumero") != null)
						{
							document.getElementById("CartaoNumero").maxLength = '16';
							document.getElementById("CartaoNumero").onkeyup = function()
							{
								if(this.value.length == 16) document.getElementById("CartaoCodigo").focus();
							};
							
							if(document.getElementById("CartaoNumero").value.length > 16)
							{
								document.getElementById("CartaoNumero").value = document.getElementById("CartaoNumero").value.substring(0,16);
							}
						}
					}
					//***************************************************************************************
					
					//Trata quantidade de digitos no codigo de seguranca
								//***********************************************************************************
					
			        if (MeioCodigo.value.substring(4) == "1")
					{
					    document.getElementById("CartaoCodigo").maxLength = '4';
						document.getElementById("CartaoCodigo").onkeyup = function()
						{
							if(this.value.length == 4) document.getElementById('CartaoNome').focus();
						};						
					}
					else
					{
						document.getElementById("CartaoCodigo").maxLength = '3';
						document.getElementById("CartaoCodigo").onkeyup = function()
						{
							if(this.value.length == 3) document.getElementById('CartaoNome').focus();
						};
						
					    if(document.getElementById("CartaoCodigo").value.length > 3)
					    {
						    document.getElementById("CartaoCodigo").value = document.getElementById("CartaoCodigo").value.substring(0,3);
						}										
					}			
			        //***************************************************************************************

					
					if (document.getElementById(MeioCodigo.value.substring(0,3)))
					{
						ValidaPagamento(document.getElementById(MeioCodigo.value.substring(0,3)));
					}

					for (j=0; j<document.getElementsByTagName("input").length; j++)
					{
						campo = document.getElementsByTagName("input")[j];

						if (campo.type == "radio")
						{
							if (campo.value == MeioCodigo.value.substring(0,3))
							{
								campo.checked = true;
							}
							if (campo.value.indexOf(MeioCodigo.value.substring(0,3)) < 0 && campo.id.indexOf('TipoCco') == -1)
							{
								campo.checked = false;
							}
						}
					}

					//window.location.href = "#p";
					
					document.getElementById("ParcelamentoSel").value = "";
					document.getElementById("ParcelamentoSelCod").value = "";
					document.getElementById("OperadoraCodigo").value = MeioCodigo.value.substring(4);
					document.getElementById("OperadoraTipo").value = MeioCodigo.value.substring(0,3);

					if (MeioCodigo.value.substring(0,3) == "CCR")
					{
						if (document.getElementById("pagtoDeb") != null)
						{
							document.getElementById("pagtoDeb").style.display = "none";    
						}

						/*
						if (MeioCodigo.value.substring(4) == "14")
						{
							document.getElementById("pCodSeguranca").style.visibility = "hidden";
						}
						else
						{
							document.getElementById("pCodSeguranca").style.visibility = "visible";
						}
						
						
						fechamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_CCR)
						*/
						
						if (MeioCodigo.value.substring(4) != "")
						{
							fechamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_CCR)
						}
						else
						{
							document.getElementById("OperadoraTipo").value = "CCR";
							document.getElementById("OperadoraCodigo").value = 11;
							document.getElementById("CCR_11").checked = true;
							fechamento.ValidaMeioPagamento("11", callback_ValidaMeioPagamento_CCR)
						}						
					}
					else if (MeioCodigo.value.substring(0,3) == "BOL")
					{	
						/*			
						document.getElementById("OperadoraTipo").value = "BOL";
						fechamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_BOL)
						*/
						if (document.getElementById("pagtoDeb") != null)
						{
							document.getElementById("pagtoDeb").style.display = "none";    
						}
						
						if (MeioCodigo.value.substring(4) != "")
						{
							fechamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_BOL)	
						}
						else
						{
							document.getElementById("OperadoraTipo").value = "BOL";
							document.getElementById("OperadoraCodigo").value = 9;
							document.getElementById("BOL_9").checked = true;
							fechamento.ValidaMeioPagamento("9", callback_ValidaMeioPagamento_BOL)
						}
					}
					else if (MeioCodigo.value.substring(0,3) == "DEB")
					{
						/*
						fechamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_DEB)
						*/
						if (document.getElementById("pagtoDeb") != null)
						{
							document.getElementById("pagtoDeb").style.display = "block";    
						}

						if (MeioCodigo.value.substring(4) != "")
						{
							fechamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_DEB)
						}
						else
						{
							document.getElementById("OperadoraTipo").value = "DEB";
							document.getElementById("OperadoraCodigo").value = 5;
							document.getElementById("DEB_5").checked = true;
							fechamento.ValidaMeioPagamento("5", callback_ValidaMeioPagamento_DEB)
						}						
					}
				}
				else
				{
					TrocaImagem("loading", "hidden");
				}
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
		
		if(rdbEntregaId != "")
			document.getElementById(rdbEntregaId).checked = true;
	}
	
	function callback_ValidaMeioPagamento_CCR(res)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
			window.location.href = window.location;
		}
		
		if (!IsValidBasket(res))
		{
			return;
		}

		if(res.value[2])
		{
			if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
			{
				document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
			{
				document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
			}
			document.getElementById("OperadoraCodigo").value = "";
			document.getElementById("OperadoraTipo").value = "";
			document.getElementById("ParcelamentoSel").value = "";
			document.getElementById("ParcelamentoSelCod").value = "";
			document.getElementById("CCR_"+res.value[3]).checked = false;
			
			alert(res.value[2]);

			//IniciaFechamento();
		}
		else
		{
			if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = res.value[0];
			}

			if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
			{
				document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
			{
				document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
			}

			if (res.value[1])
			{
				if (document.getElementById(res.value[1] + "_1"))
				{
					document.getElementById(res.value[1] + "_1").checked = true;
					ArmazenaParcelamento(document.getElementById(res.value[1] + "_1"));
				}
			}
		}
		TrocaImagem("loading", "hidden");
	}

	function callback_ValidaMeioPagamento_BOL(res)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
			window.location.href = window.location;
		}
		
		if (!IsValidBasket(res))
		{
			return;
		}

		if(res.value[2])
		{
			if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
			{
				document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
			{
				document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
			}
			document.getElementById("OperadoraCodigo").value = "";
			document.getElementById("OperadoraTipo").value = "";
			document.getElementById("ParcelamentoSel").value = "";
			document.getElementById("ParcelamentoSelCod").value = "";
			document.getElementById("BOL_"+res.value[3]).checked = false;
			
			alert(res.value[2]);

			IniciaFechamento();
		}
		else
		{
			if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
			{
				document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = res.value[0];
			}

			if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
			{
				document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
			}

			if (res.value[1])
			{
				if (document.getElementById(res.value[1] + "_1"))
				{
					document.getElementById(res.value[1] + "_1").checked = true;
					ArmazenaParcelamento(document.getElementById(res.value[1] + "_1"));
				}
			}
		}
		TrocaImagem("loading", "hidden");
	}

	function callback_ValidaMeioPagamento_DEB(res)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
			window.location.href = window.location;
		}
		
		if (!IsValidBasket(res))
		{
			return;
		}

		if(res.value[2])
		{
			if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
			{
				document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
			{
				document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
			}
			if(document.getElementById("pagtoDeb") != null)
			{
				document.getElementById("pagtoDeb").style.display = "block";
			}
			
			document.getElementById("OperadoraCodigo").value = "";
			document.getElementById("OperadoraTipo").value = "";
			document.getElementById("ParcelamentoSel").value = "";
			document.getElementById("ParcelamentoSelCod").value = "";			
			document.getElementById("DEB_"+res.value[3]).checked = false;
			
			alert(res.value[2]);

			IniciaFechamento();
		}
		else
		{
			if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
			{
				document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
			{
				document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
			}

			if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
			{
				document.getElementById("spanPagamentoEscolhidoDEB").innerHTML =  res.value[0];
			}

			if (res.value[1])
			{
				if (document.getElementById(res.value[1] + "_1"))
				{
					document.getElementById(res.value[1] + "_1").checked = true;
					ArmazenaParcelamento(document.getElementById(res.value[1] + "_1"));
				}
			}
			if(document.getElementById("pagtoDeb") != null)
			{
				document.getElementById("pagtoDeb").style.display = "block";
			}
		}

		TrocaImagem("loading", "hidden");
	}
	
	function IsValidBasket(res)
	{
		if (res.value[0] == 'CESTAVAZIA')
		{
			window.location.href = res.value[1];
			return false;
		}
		
		return true;
	}

	function ValidaPagamento(FormaCodigo)
	{
		if (FormaCodigo.checked)
		{
			var carrega = false;
			var MeioCodigo = 0;

			for (j=0; j<document.getElementsByTagName("input").length; j++)
			{
				campo = document.getElementsByTagName("input")[j];

				if (campo.type == "radio")
				{
					if (campo.value.indexOf(FormaCodigo.value) < 0 && campo.id.indexOf('TipoCco') == -1 && campo.id.indexOf('rdbEntrega') == -1)
					{	
						campo.checked = false;
					}
				}
			}

			if (FormaCodigo.value == "CCR")
			{
				if(document.getElementById("pagtoDeb"))
				{
					document.getElementById("pagtoDeb").style.display = "none";
				}
				
				if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
				{
					document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
				}
				if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
				{
					document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
				}
				
				if (document.getElementById("CCR_14") == null)
				{
					if (document.getElementById("CCR_11").checked == false && document.getElementById("CCR_10").checked == false && document.getElementById("CCR_1").checked == false)
					{
						document.getElementById("CCR_11").checked = true;
						document.getElementById("OperadoraTipo").value = "CCR";
						document.getElementById("OperadoraCodigo").value = "11";
						fechamento.ValidaMeioPagamento("11", callback_ValidaMeioPagamento_CCR)
					}
				}
				else
				{
					if (document.getElementById("CCR_11").checked == false && document.getElementById("CCR_14").checked == false)
					{
						document.getElementById("CCR_14").checked = true;
						document.getElementById("OperadoraTipo").value = "CCR";
						document.getElementById("OperadoraCodigo").value = "14";
						fechamento.ValidaMeioPagamento("14", callback_ValidaMeioPagamento_CCR)
					}
				}
			}
			else if (FormaCodigo.value == "BOL")
			{
				if(document.getElementById("pagtoDeb"))
				{
					document.getElementById("pagtoDeb").style.display = "none";
				}
				
				if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
				{
					document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
				}
				if(document.getElementById("spanPagamentoEscolhidoDEB") != null)
				{
					document.getElementById("spanPagamentoEscolhidoDEB").innerHTML = "";
				}
				
				document.getElementById("BOL_13").checked = true;
				document.getElementById("OperadoraTipo").value = "BOL";
				document.getElementById("OperadoraCodigo").value = "13";
				fechamento.ValidaMeioPagamento("13", callback_ValidaMeioPagamento_BOL)
			}
			else if (FormaCodigo.value == "DEB")
			{
				if(document.getElementById("spanPagamentoEscolhidoCCR") != null)
				{
					document.getElementById("spanPagamentoEscolhidoCCR").innerHTML = "";
				}
				if(document.getElementById("spanPagamentoEscolhidoBOL") != null)
				{
					document.getElementById("spanPagamentoEscolhidoBOL").innerHTML = "";
				}
				
				var OperadoraDeb = "5";
				
				
				if(document.getElementById("pagtoDeb").value)
				{
					document.getElementById("pagtoDeb").style.display = "block";
				}
				
				//* Comentado ao deixar somente uma forma de pagamento via débito
				//if (document.getElementById("DEB_3").checked)
				//{
				//	OperadoraDeb = "3";
				//}
				
				document.getElementById("DEB_" + OperadoraDeb).checked = true;
				document.getElementById("OperadoraTipo").value = "DEB";
				document.getElementById("OperadoraCodigo").value = OperadoraDeb;
				fechamento.ValidaMeioPagamento(OperadoraDeb, callback_ValidaMeioPagamento_DEB)
			}

			document.getElementById("ParcelamentoSel").value = "";
			document.getElementById("ParcelamentoSelCod").value = "";
			//document.getElementById("OperadoraTipo").value = FormaCodigo.value;
			//document.getElementById("OperadoraCodigo").value = "";

			TrocaImagem("loading", "hidden");

			//window.location.href = "#p";
		}
	}

	function positionit()
	{
		var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1;
		var loading_obj=ie? document.all.loading : document.getElementById? document.getElementById("loading_div") : document.loading;

		var Hoffset=82 //Enter logo's offset from right edge of window (edit only if you don't like the default offset)
		var Voffset=-4 //Enter logo's offset from top edge of window (edit only if you don't like the default offset)

		var dsocleft=ie? document.body.scrollLeft : pageXOffset;
		var dsoctop=ie? document.body.scrollTop : pageYOffset;
		var window_width=ie? document.body.clientWidth : window.innerWidth-25;

		if (ie || document.getElementById)
		{
			loading_obj.style.left=parseInt(dsocleft)+parseInt(window_width)-Hoffset;
			loading_obj.style.top=parseInt(dsoctop)+5+Voffset;
		}
		else if (document.layers)
		{
			loading_obj.left=dsocleft+window_width-Hoffset;
			loading_obj.top=dsoctop+window_height+5+Voffset;
		}
	}

	function positionitOpiniao()
	{
		var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1;
		var opiniao_obj=ie? document.all.opiniao : document.getElementById? document.getElementById("opiniao_div") : document.opiniao;

		var Voffset=196 //Enter logo's offset from top edge of window (edit only if you don't like the default offset)
		var Hoffset=9 //Enter logo's offset from top edge of window (edit only if you don't like the default offset)

		var dsocleft=ie? document.body.scrollLeft : pageXOffset;
		var dsoctop=ie? document.body.scrollTop : pageYOffset;
		var window_width=ie? document.body.clientWidth : window.innerWidth-20;

		if (ie||document.getElementById)
		{
			opiniao_obj.style.left=Hoffset;
			opiniao_obj.style.top=parseInt(dsoctop)+Voffset+2;
		}
		else if (document.layers)
		{
			opiniao_obj.left=Hoffset;
			opiniao_obj.top=dsoctop+Voffset;
		}
	}

	function beingloading()
	{
		loadinginterval = setInterval("positionit()",50);
	}

	function beingOpiniao()
	{
		Opiniaointerval = setInterval("positionitOpiniao()",50);
	}

	function ColocaFocus(NomeBtn, e)
	{
		try
		{
			var key;

			if(window.event)
			{
				key = window.event.keyCode;
			}
			else
			{
				key = e.which;
			}
			if(key == 13)
			{
				document.getElementById(NomeBtn).focus();

				if(window.event)
				{
					window.event.keyCode = 0;
				}
			}
		}
		catch(err)
		{
			alert(err.description);
		}

		return false;
	}

	/**
	 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
	 *
	 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
	 * http://www.opensource.org/licenses/mit-license.php
	 *
	 */

	function TrocaImagem(name, visibilidade)
	{
		try
		{
			document.getElementById(name).style.visibility = visibilidade;
		}
		catch(err)
		{
		}
	}

	function MostraImagemAmpliada()
	{
		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;
		
		try
		{
			/*if (document.getElementById("ImagemAmpliadaFoto").src.indexOf('indisponivel') == -1)
			{
				if (document.getElementById("ImagemAmpliada"))
				{
					if (document.getElementById("ImagemAmpliada").style.visibility == "visible")
					{
						document.getElementById("ImagemAmpliada").style.visibility = "hidden";

						(document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").style.visibility = "visible" : void(0));
						(document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").style.visibility = "visible" : void(0));
						(document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").style.visibility = "visible" : void(0));
						(document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").style.visibility = "visible" : void(0));
						(document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").style.visibility = "visible" : void(0));
					}
					else
					{
						document.getElementById("ImagemAmpliada").style.visibility = "visible";

						(document.getElementById("DRP_SKU_1") ? document.getElementById("DRP_SKU_1").style.visibility = "hidden" : void(0));
						(document.getElementById("DRP_SKU_2") ? document.getElementById("DRP_SKU_2").style.visibility = "hidden" : void(0));
						(document.getElementById("DRP_SKU_3") ? document.getElementById("DRP_SKU_3").style.visibility = "hidden" : void(0));
						(document.getElementById("DRP_SKU_4") ? document.getElementById("DRP_SKU_4").style.visibility = "hidden" : void(0));
						(document.getElementById("DRP_SKU_5") ? document.getElementById("DRP_SKU_5").style.visibility = "hidden" : void(0));
					}
				}
			}*/
		}
		catch(err)
		{
		}
	}
	
	function MostraBotaoAmpliada()
	{
		/*
		if (document.getElementById("ImagemAmpliadaFoto").src.indexOf('indisponivel') == -1)
			document.getElementById("imgAmpliar").style.visibility = "visible";
		else
		*/
			document.getElementById("imgAmpliar").style.visibility = "hidden";
		
	}

	function CarregaSKU(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			detalhes.CarregaSKU(ProdutoCodigo.toString(), callback_CarregaSKU)
		}
		catch(err)
		{
			alert(err.description);
			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)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function CarregaSKUBusca(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			busca.CarregaSKUBusca(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}
	
	
	function CarregaSKUVitrine(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			vitrine.CarregaSKUVitrine(ProdutoCodigo.toString(), callback_CarregaSKUVitrine);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function CarregaSKUCategoria(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			categoria.CarregaSKUCategoria(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function CarregaSKUComparador(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			comparar.CarregaSKUComparador(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function CarregaSKUFornecedor(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			fornecedor.CarregaSKUFornecedor(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_CarregaSKUCross(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
		}

		if (res.value)
		{
			document.getElementById("spanSKU_Cross_" + res.value[0] + "_" + res.value[2] + "_" + res.value[3] + "_" + res.value[4]).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_" + res.value[0] + "_") != -1)
					{
						campo.disabled = false;
					}
				}
			}

			TrocaImagem("loading", "hidden");
		}
	}

	function callback_CarregaSKUBusca(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value)
		{
			document.getElementById("spanSKU_" + 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_SKU_" + res.value[0] + "_") != -1)
					{
						campo.disabled = false;
					}
				}
			}

			TrocaImagem("loading", "hidden");
		}
	}
	
	function callback_CarregaSKUVitrine(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value)
		{
			document.getElementById("spanSKU_" + 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_SKU_" + res.value[0] + "_") != -1)
					{
						campo.disabled = false;
					}
				}
			}

			TrocaImagem("loading", "hidden");
		}
	}


	function callback_CarregaSKU(res)
	{
 		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value)
		{
			if (res.value[0])
			{
				document.getElementById("spanSKU").innerHTML = res.value[0];
			}

			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;
					}
				}
			}

			TrocaImagem("loading", "hidden");
		}
	}

	function DisponibilidadeSKU(campo, ProdutoCodigo, tipo)
	{

		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;

		TrocaImagem("loading", "visible");

		try
		{
			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";
			}

			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)
		{
			alert(err.description);
			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 (res.value[0][1])
			{
				document.getElementById("spanPreco").innerHTML = res.value[0][1];
			}

			if (res.value[0][2])
			{
				document.getElementById("spanPrecoPor").innerHTML = res.value[0][2];
			}

			if (res.value[0][3])
			{
				document.getElementById("spanPrecoEconomize").innerHTML = res.value[0][3];
			}

			if (res.value[0][4])
			{
				document.getElementById("spanParcelamento1").innerHTML = res.value[0][4];
			}

			if (res.value[0][5])
			{
				document.getElementById("spanParcelamento2").innerHTML = res.value[0][5];
			}

			if (res.value[0][6])
			{
				document.getElementById("spanAVista").innerHTML = res.value[0][6];
			}
			
			/**********************************************************************/
			/*Seta imagens														  */
			/**********************************************************************/
			if (res.value[1][0])
			{
				document.getElementById(res.value[1][1]).src = res.value[1][0];
			}
			
			if (res.value[1][2])
			{
				//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][13]).src = res.value[1][12];
				document.getElementById(res.value[1][13]).style.display = '';	
			}	
			else
			{
				document.getElementById(res.value[1][13]).style.display = 'none';
			}											

			if (res.value[1][14])
			{
				document.getElementById(res.value[1][15]).src = res.value[1][14];
				document.getElementById('ImagemAmpliadaAux').value = res.value[1][14];
			}	
			/**********************************************************************/
			
			TrocaImagem("loading", "hidden");
		}
	}

	function imageExists(url)
    {
		var tmp = new Image;
        tmp.src = url;
        if(tmp.height > 0 && tmp.height != 30)
		{
            return true;
        }
		else
		{
            return false;
		}
	}

	function TrocaImagemDetalhe(campo)
	{
		var base = document.getElementById('ProdutoImagem').src;
		document.getElementById('ProdutoImagem').src = campo.src;
		campo.src = base;

		MostraImagemDetalhe(document.getElementById('ProdutoImagem').src);
		MostraBotaoAmpliada();
	}

	function MostraImagemDetalhe(src)
	{	
		try
		{
			var ImagemGif = src.substring(0,src.length - 4).replace('Detalhes', 'Ampliada') + '.gif';
			var ImagemJPG =	src.substring(0,src.length - 4).replace('Detalhes', 'Ampliada') + '.jpg';

			if(document.getElementById('ImagemAmpliadaAux').value == '')
			{
				document.getElementById('ImagemAmpliadaAux').value = document.getElementById("ImagemAmpliadaFoto").src;
			}
			
			if (imageExists(ImagemGif))
			{
				document.getElementById("ImagemAmpliadaFoto").src = ImagemGif;	
			}
			else if(imageExists(ImagemJPG))
			{
				document.getElementById("ImagemAmpliadaFoto").src = ImagemJPG;	
			}
			else
			{
				document.getElementById("ImagemAmpliadaFoto").src = document.getElementById('ImagemAmpliadaAux').value;	
			}

			document.getElementById("ProdutoImagem").src = src;
		}
		catch(err)
		{
			alert(err);
		}	
	}

	function Trim(inp)
	{
		var outp = "";

		for (i = 0; i <= inp.length; i++)
		{
			if (inp.charAt (i) != " ")
			{
				outp = inp.charAt (i) + outp ;
			}
		}

		return outp;
	}

	function reverse(inp)
	{
		var outp = "";

		for (i = 0; i <= inp.length; i++)
		{
			outp = inp.charAt (i) + outp ;
		}

		return outp;
	}

	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;

		TrocaImagem("loading", "visible");		

		try
		{
			UrlReload = window.location.href;
			QtdeProduto = (document.getElementById('txtQtdeProduto') ? document.getElementById('txtQtdeProduto').value : 1 );
			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!\n";
							break;
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				detalhes.AdicionarItemCesta(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), QtdeProduto.toString(),UrlReload, Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	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 UrlReload = "";

		var VitrineCodigo = 0;

		TrocaImagem("loading", "visible");

		try
		{
			UrlReload = window.location.href;
			CarValCodVenda1 = (document.getElementById("DRP_SKU_" + ProdutoCodigoVenda + "_" + OrdemVenda + "_" + GrupoSellingCodigo + "_1_" + iGruSellItensAux2) ? document.getElementById("DRP_SKU_" + 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 : 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!\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!\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
			{
				detalhes.AdicionarItemCestaCross(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(), UrlReload.toString() , Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	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!\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)
			{
				alert('aqui = '+err.description);
				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 : '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");
				detalhes.AdicionarItemCestaGrupoCross(GruSelCodigo.toString(), Produtos.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), Redirect_callback)				
			}
			catch(err)
			{
				alert(err.description);
				TrocaImagem("loading", "hidden");
			}			
		}
	}
	
	function AdicionarItemCestaCross(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_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_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_" + ProdutoCodigo + "_") != -1)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra!\n";
							break;
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				detalhes.AdicionarItemCestaCross(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function AdicionarItemCestaBusca(ProdutoCodigo)
	{			
		var enc = 0;
		var mensagem = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{		
			UrlReload = window.location.href;
			QtdeProduto = (document.getElementById("txtQtdeProduto_" + ProdutoCodigo) ? document.getElementById("txtQtdeProduto_" + ProdutoCodigo).value : 1 );
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_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_" + ProdutoCodigo + "_") != -1)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra!\n";
							break;
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				busca.AdicionarItemCestaBusca(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(),QtdeProduto.toString(),UrlReload, Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}
	
	function AdicionarItemCestaVitrine(ProdutoCodigo)
	{			
		var enc = 0;
		var mensagem = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			UrlReload = window.location.href;
			QtdeProduto = (document.getElementById("txtQtdeProduto_" + ProdutoCodigo) ? document.getElementById("txtQtdeProduto_" + ProdutoCodigo).value : 1 );
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_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_" + ProdutoCodigo + "_") != -1)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra!\n";
							break;
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				vitrine.AdicionarItemCestaVitrine(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(),QtdeProduto.toString(),UrlReload.toString(), Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function AdicionarItemCestaFornecedor(ProdutoCodigo)
	{
		var enc = 0;
		var mensagem = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			var UrlReload = window.location.href;
			var QtdeProduto = (document.getElementById("txtQtdeProduto_" + ProdutoCodigo) ? document.getElementById("txtQtdeProduto_" + ProdutoCodigo).value : 1 );
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_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_" + ProdutoCodigo + "_") != -1)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra!\n";
							break;
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				fornecedor.AdicionarItemCestaFornecedor(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), QtdeProduto.toString(), UrlReload, Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function AdicionarItemCestaCategoria(ProdutoCodigo)
	{
		var enc = 0;
		var mensagem = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			var UrlReload = window.location.href;
			var QtdeProduto = (document.getElementById("txtQtdeProduto_" + ProdutoCodigo) ? document.getElementById("txtQtdeProduto_" + ProdutoCodigo).value : 1 );
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_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_" + ProdutoCodigo + "_") != -1)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra!\n";
							break;
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
			//alert(UrlReload.indexOf("#ancProd_"));
				if(UrlReload.indexOf("#ancProd_" ) == -1)
				{
					UrlReload = UrlReload + "#ancProd_" + ProdutoCodigo;
					//alert(ProdutoCodigo);
				}
				else
				{
						UrlReload = UrlReload.replace(/#.*/,"");
						UrlReload = UrlReload + "#ancProd_" + ProdutoCodigo;
						
				}
				categoria.AdicionarItemCestaCategoria(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), QtdeProduto.toString(), UrlReload, Callback_InsereProduto);
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}
	
	function Callback_InsereProduto(res)
	{	 		
	
	
		//alert(res.value[6]); checkProd_
		
		if(res.value[3] != "" && res.value[4]=="login")
		{
			//alert("Por favor efetue o login");
			window.location.href = res.value[3];
		}
		else
		{
			
			document.getElementById("pNomeProduto").innerHTML = res.value[0];
			document.getElementById("pQtdeProd").innerHTML = res.value[1];			
			document.getElementById("divCestaTotal").innerHTML = "R$ " + res.value[6];
			document.getElementById("checkProd_"+ res.value[8]).style.display = 'block';
			//document.getElementById("checkProd_"+ res.value[8]).title = 'Último produto adicionado';
			
			
			//jQuery(document).ready(function() {			
				//jQuery("#clickOculto").fancybox().trigger('click');				
			//});			
			//AlertCallback("Produto adicionado no carrinho. \n Para finalizar o pedido clique em \"Fechar compra\" "); 
						
		}
	}
	
	function AlertCallback(msg)
	{
		alert(msg);			
	}

	function AdicionarItemCestaComparador(ProdutoCodigo)
	{
		var enc = 0;
		var mensagem = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_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_" + ProdutoCodigo + "_") != -1)
					{
						if (campo.value == "0")
						{
							mensagem+="Escolha um valor para todas as Opções de Compra!\n";
							break;
						}
					}
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				comparar.AdicionarItemCestaComparador(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), Redirect_callback);
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function MudaPaginaBusca(pagina)
	{
		try
		{
			TrocaImagem("loading", "visible");
			busca.MudaPaginaBusca(pagina.toString(), Redirect_callback);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function MudaPaginaCategoria(pagina)
	{
		try
		{
			var Categoria = document.getElementById("CategoriaCodigo").value;
			var SubCategoria = document.getElementById("SubCategoriaCodigo").value;

			TrocaImagem("loading", "visible");
			categoria.MudaPaginaCategoria(pagina.toString(), Categoria.toString(), SubCategoria.toString(), Redirect_callback);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function MudaPaginaFornecedor(pagina)
	{
		try
		{
			var Fornecedor = document.getElementById("FornecedorCodigo").value;

			TrocaImagem("loading", "visible");
			fornecedor.MudaPaginaFornecedor(pagina.toString(), Fornecedor.toString(), Redirect_callback);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function Buscar(local)
	{
		TrocaImagem("loading", "visible");

		/*
		try
		{
		*/
			var mensagem = "";
			var fabricante = "";
			var palavra;
			var categoria;
			
			if (local == "Topo")
			{
				palavra = document.getElementById("cabecalho_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("#", "").replace("*", "").replace("?", "").replace("/", "").replace(":", "").replace(">", "").replace(".", "").replace("<", "").replace("%", "").trim();
				categoria = document.getElementById("cabecalho_DropLojas").options[document.getElementById("cabecalho_DropLojas").selectedIndex].value;
				
				if (document.getElementById("cabecalho_DropFabricantes"))
				{
					fabricante = document.getElementById("cabecalho_DropFabricantes").options[document.getElementById("cabecalho_DropFabricantes").selectedIndex].value;
				}
				else
				{
					fabricante = 0;
				}
			}
			if (local == "Rodape")
			{
				palavra = document.getElementById("rodape_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("#", "").replace("*", "").replace("?", "").replace("/", "").replace(":", "").replace(">", "").replace(".", "").replace("<", "").replace("%", "").trim();
				categoria = document.getElementById("rodape_DropLojas").options[document.getElementById("rodape_DropLojas").selectedIndex].value;
				
				if (document.getElementById("rodape_DropFabricantes"))
				{
					fabricante = document.getElementById("rodape_DropFabricantes").options[document.getElementById("rodape_DropFabricantes").selectedIndex].value;
				}
				else
				{
					fabricante = 0;
				}
			}

			if(palavra == "" && (categoria == "" || categoria == "0") && (fabricante == "" || fabricante == "0"))
			{
				mensagem+="Valor inválido (todos os campos vazio ou inválidos) !\n";
			}
			
			if(palavra == "" && categoria != "")
			{
				mensagem+="Valor inválido (todos os campos vazio ou inválidos) !\n";
			}
			
			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				cabecalho.ArmazenaDadosBusca(palavra.toString(), categoria.toString(), fabricante.toString(), Redirect_callback);
			}
		/*
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
		*/
	}

	function ArmazenaValorAntigo(campo)
	{
		document.getElementById("ValorAntigo").value = campo.value;
	}

	function AtualizaQtdeItem(campo, qtdemax)
	{

		var mensagem = "";

		TrocaImagem("loading", "visible");

		try
		{
			if(Trim(campo.value) == "")
			{
				mensagem+="Valor inválido (vazio) !\n";
			}

			if(isNaN(campo.value))
			{
				mensagem+="Valor inválido (não numérico : " + campo.value + ") !\n";
			}
			else
			{
				if (campo.value > qtdemax)
				{
					mensagem+="Valor inválido  - excede máximo permitido (" + qtdemax + ") !\n";
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				campo.value = document.getElementById("ValorAntigo").value;
				TrocaImagem("loading", "hidden");
			}
			else
			{
				if (Trim(campo.value) != Trim(document.getElementById("ValorAntigo").value))
				{
					index.AtualizaQtdeItem(campo.name, campo.value, Redirect_callback);
				}
				else
				{
					campo.value = Trim(document.getElementById("ValorAntigo").value);
					document.getElementById("ValorAntigo").value = "";
					TrocaImagem("loading", "hidden");
				}
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function LimparCesta()
	{
		TrocaImagem("loading", "visible");

		if (confirm('Você tem certeza que deseja LIMPAR sua Cesta de Compras?'))
		{
			index.LimparCesta(Redirect_callback);
		}
		else
		{
			TrocaImagem("loading", "hidden");
		}
	}


	function AlteraPedidoRecorrente(CestaCodigo){
	TrocaImagem("loading", "visible");

		try
		{
			index.AlteraPedidoRecorrente(CestaCodigo.toString(), callback_AlteraPedidoRecorrente);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	// Pedido Recorrente **************************
	function callback_AlteraPedidoRecorrente(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value)
		{
			window.location.href = res.value;
		}
	}
	// Fim do Bloco *******************************


	function FecharPedido(CestaCodigo)
	{
		TrocaImagem("loading", "visible");

		try
		{
			index.FecharPedido(CestaCodigo.toString(), callback_FecharPedido);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function FecharPedidoGift(CestaCodigo)
	{
		TrocaImagem("loading", "visible");

		try
		{
			presente.FecharPedido(CestaCodigo.toString(), callback_FecharPedido);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_FecharPedido(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value)
		{
			window.location.href = res.value;
		}
	}

	function FinalizarPedido()
	{
		var mensagem = "";
		var minSeg = 3;

		var OperadoraCodigo = "";
		var OperadoraTipo = "";
		var ParcelamentoSel = "";
		var ParcelamentoSelCod = "";
		var CartaoNumero = "";
		var CartaoSeguranca = "";
		var CartaoTitular = "";
		var CartaoValMes = "";
		var CartaoValAno = "";

		TrocaImagem("loading", "visible");
		
		try
		{
			OperadoraCodigo		= document.getElementById("OperadoraCodigo").value;
		
			var currentTime = new Date();
			
			/*
			//Recupera data de entrega
			var DiaEntrega = document.getElementById("DataEntrega_Day_ID").options[document.getElementById("DataEntrega_Day_ID").selectedIndex].text;
			var MesEntrega = document.getElementById("DataEntrega_Month_ID").selectedIndex+1//document.getElementById("DataEntrega_Month").selectedIndex + 1;
			var AnoEntrega = document.getElementById("DataEntrega_Year_ID").value;

			var DataAgora = new Date();	
			var DiaAgora	  = DataAgora.getDate();
			var MesAgora	  = DataAgora.getMonth() + 1; 
			var AnoAgora	  = DataAgora.getUTCFullYear();

			var DataEntrega = DiaEntrega +'/' +MesEntrega +'/'+ AnoEntrega;
			var DataAgora   = DiaAgora +'/' +MesAgora +'/'+ AnoAgora;				
			*/
			
			//Recupera periodo do dia
			var QtdeElementos = document.frm.elements.length;
			var rdbEntregaId = "";
			var EntregaEscolhida = "";
			var MsgEntregaEscolhida = "";
			
			for (var i=0; i < QtdeElementos; i++) 
			{
				if(document.frm.elements[i].id.indexOf('rdbEntrega_') > -1)
				{
					rdbEntregaId = document.frm.elements[i].id;
					
					if(document.frm.elements[i].checked)
					{
						EntregaEscolhida = document.frm.elements[i].value;
						MsgEntregaEscolhida = document.getElementById("lblEntrega_" + EntregaEscolhida.toString()).innerHTML;
					}
				}
			}			
			
			//alert(EntregaEscolhida + " - " + MsgEntregaEscolhida);
			//return;
			
			if(rdbEntregaId == "")
			{
				alert('Falha na configuração da loja. - [não existe Data de entrega]\nNão foi possível fechar o seu pedido.');
				return;
			}
			else if(EntregaEscolhida == "")
			{
				alert('Escolha uma opção de entrega.');
				window.location.href = '#dtaEntrega';
				return;
			}
			//Fim data de enrtega	
					

			if (document.getElementById("OperadoraTipo").value == "CCR")
			{
				if(document.getElementById("OperadoraCodigo").value == "")
				{
					mensagem+="Você precisa escolher uma Operadora de Cartão de Crédito !\n";
				}
				else
				{
					if (document.getElementById("OperadoraCodigo").value == "1")
					{
						minSeg = 4;
					}

					if(document.getElementById("CartaoNumero").value == "")
					{
						mensagem+="Número de cartão inválido (vazio) !\n";
					}
					else
					{
						if (!validaCartao() && document.getElementById("OperadoraCodigo").value != "7")
						{
							
							mensagem+="Número de cartão inválido (incorreto111) !\n";
						}
						else
						{
							CartaoNumero = document.getElementById("CartaoNumero").value;
						}
					}

					if  (OperadoraCodigo != "14")
					{
						if(document.getElementById("CartaoCodigo").value == "")
						{
							mensagem+="Código de segurança do cartão inválido (vazio) !\n";
						}
						else
						{
							if(document.getElementById("CartaoCodigo").value.length < minSeg)
							{
								mensagem+="Código de segurança do cartão inválido (incorreto) !\n";
							}
							else
							{
								if(!ValidaCodigoSeguranca(CartaoNumero.toString(), document.getElementById("CartaoCodigo").value, document.getElementById("OperadoraCodigo").value))
								{
									mensagem+="Código de segurança do cartão inválido (incorreto) !\n";
								}
								else
								{
									CartaoSeguranca = document.getElementById("CartaoCodigo").value;
								}
							}
						}
					}
					else
					{
						 CartaoSeguranca = "0";
					}

					if(document.getElementById("CartaoNome").value == "")
					{
						mensagem+="Nome no cartão inválido (vazio) !\n";
					}
					else
					{
						CartaoTitular = document.getElementById("CartaoNome").value;
					}

					if(document.getElementById("CartaoValMes").value == "")
					{
						mensagem+="Validade (mês) do cartão inválido (vazio) !\n";
					}
					else
					{
						if(document.getElementById("CartaoValMes").value.length < 2 || parseInt(document.getElementById("CartaoValMes").value) > 12)
						{
							mensagem+="Validade (mês) do cartão inválido (incorreto) !\n";
						}
						else
						{
							CartaoValMes = document.getElementById("CartaoValMes").value;
						}
					}

					if(document.getElementById("CartaoValAno").value == "")
					{
						mensagem+="Validade (ano) do cartão inválido (vazio) !\n";
					}
					else
					{
						if(document.getElementById("CartaoValAno").value.length < 2)
						{
							mensagem+="Validade (ano) do cartão inválido (incorreto) !\n";
						}
						else
						{
							if(Number("20" + document.getElementById("CartaoValAno").value) < currentTime.getFullYear())
							{
								mensagem+="Validade (ano) do cartão inválido (expirado) !\n";
							}
							else
							{
								CartaoValAno = document.getElementById("CartaoValAno").value;
							}
						}
					}

					if(document.getElementById("ParcelamentoSel").value == "" || document.getElementById("ParcelamentoSelCod").value == "")
					{
						mensagem+="Parcelamento inválido (vazio) !\n";
					}
				}
			}
			else if (document.getElementById("OperadoraTipo").value == "DEB")
			{
				if(document.getElementById("OperadoraCodigo").value == "")
				{
					mensagem+="Você precisa escolher um Banco de Cartão de Débito !\n";
				}

				if(document.getElementById("ParcelamentoSel").value == "" || document.getElementById("ParcelamentoSelCod").value == "")
				{
					mensagem+="Opção de Pagamento inválida (vazio) !\n";
				}
			}
			else if (document.getElementById("OperadoraTipo").value == "BOL")
			{
				if(document.getElementById("OperadoraCodigo").value == "")
				{
					mensagem+="Você precisa escolher um Banco para emissão do Boleto !\n";
				}

				if(document.getElementById("ParcelamentoSel").value == "" || document.getElementById("ParcelamentoSelCod").value == "")
				{
					mensagem+="Opção de Pagamento inválida (vazio) !\n";
				}
			}
			else
			{
				var Conta = false;

				if(document.getElementById('TipoCco1') != null && document.getElementById('TipoCco1').checked)
				{
					Conta = true;
				}
				else if(document.getElementById('TipoCco2') != null && document.getElementById('TipoCco2').checked)
				{
					Conta = true;
				}
				else if(document.getElementById('TipoCco3') != null && document.getElementById('TipoCco3').checked)
				{
					Conta = true;
				}
				if (!Conta)
				{
					mensagem += "Nenhuma conta corrente selecionada!\n";
				}
				
				document.getElementById("ParcelamentoSel").value = "Ctc_1";
			}
						
			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				MsgAguarda("FecharPedido", "FecharPedidoBase", "<b>Aguarde!</b><br>Pedido sendo processado!");
				
				OperadoraTipo		= document.getElementById("OperadoraTipo").value;
				ParcelamentoSel		= document.getElementById("ParcelamentoSel").value;
				ParcelamentoSelCod	= document.getElementById("ParcelamentoSelCod").value;

				setTimeout(FechamentoSimples, 15000);
				//Data de entrega não é mais utilizada pois o método de entrega foi modificado
				//fechamento.FinalizarPedido(OperadoraCodigo.toString(), OperadoraTipo.toString(), ParcelamentoSel.toString(), ParcelamentoSelCod.toString(), CartaoNumero.toString(), CartaoSeguranca.toString(), CartaoTitular.toString(), CartaoValMes.toString(), CartaoValAno.toString(), DataAgora.toString(), DataEntrega.toString(),EntregaEscolhida.toString() , callback_FinalizarPedido);
				fechamento.FinalizarPedido(OperadoraCodigo.toString(), OperadoraTipo.toString(), ParcelamentoSel.toString(), ParcelamentoSelCod.toString(), CartaoNumero.toString(), CartaoSeguranca.toString(), CartaoTitular.toString(), CartaoValMes.toString(), CartaoValAno.toString(), EntregaEscolhida.toString(), MsgEntregaEscolhida.toString() , callback_FinalizarPedido);
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
			RecuperaAguarda("FecharPedido", "FecharPedidoBase");
		}
	}

	function callback_FinalizarPedido(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			
			if (res.error.Message.indexOf("Périodo de entrega indísponivel devido ao horário da compra.") != -1)
				window.location.href = window.location;
			
			RecuperaAguarda("FecharPedido", "FecharPedidoBase");
		}

		if(res.value[0])
		{
			if(res.value[0] == "!CepInvalido")
			{
				alert('Não atendemos a região do cep escolhido.');
				window.location.href = URLSite.replace('http:', 'https:') + "/enderecos.aspx";
			}
			else if(res.value[0] == "!CartaoInvalido")
			{
				alert("Número de cartão inválido.");
				TrocaImagem("loading", "hidden");
				RecuperaAguarda("FecharPedido", "FecharPedidoBase");
			}
			else if(res.value[0] == "!Vazio")
			{
				alert("Os itens do seus pedido tiveram sua disponibilidade modificada durante a compra e foram removidos do pedido. \nSeu pedido está vazio e você será redirecionado para a home.");
				window.location.href = 'index.aspx';
			}
			else if (res.value[0] == "!Alterados")
			{
				var msg = "Um ou mais itens tiveram sua disponibilidade modificada durante a compra e foram removidos ou sua quantidade foi modificada no pedido, conforme a quantidade disponível em estoque. \nCaso queira continuar assim mesmo, clique em fechar pedido.\n\n";

				if (res.value[1] != "")
					msg += "Itens removidos:\n" + res.value[1];
					
				if (res.value[2] != "")
					msg += "\nItens alterados:\n" + res.value[2];
				
				alert(msg);
				
				window.location.href = 'basket/normaliza.aspx?action=fecharpedido';
			}
			else
			{
				window.location.href = res.value[0];
			}
		}
		
							

	}
	
	function FechamentoSimples()
	{
		window.location.href = URLSite + "/confirmacao.aspx";
	}

	function FiltrarFornecedor()
	{
		TrocaImagem("loading", "visible");

		try
		{
			var Ordem = document.getElementById("ordena_pesquisa_drpOrdem").value;
			var OrdemSentido = document.getElementById("ordena_pesquisa_drpOrdemSentido").value;
			var QtdePagina = document.getElementById("ordena_pesquisa_drpQtdePagina").value;
			var Fornecedor = document.getElementById("FornecedorCodigo").value;

			fornecedor.FiltrarFornecedor(Ordem.toString(), OrdemSentido.toString(), QtdePagina.toString(), Fornecedor.toString(), Redirect_callback);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function FiltrarCategoria()
	{
		TrocaImagem("loading", "visible");

		try
		{
			var Ordem = document.getElementById("ordena_pesquisa_drpOrdem").value;
			var OrdemSentido = document.getElementById("ordena_pesquisa_drpOrdemSentido").value;
			var QtdePagina = document.getElementById("ordena_pesquisa_drpQtdePagina").value;
			var Categoria = document.getElementById("CategoriaCodigo").value;
			var SubCategoria = document.getElementById("SubCategoriaCodigo").value;

			categoria.FiltrarCategoria(Ordem.toString(), OrdemSentido.toString(), QtdePagina.toString(), Categoria.toString(), SubCategoria.toString(), Redirect_callback);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function FiltrarBusca()
	{
		TrocaImagem("loading", "visible");

		try
		{
			var Ordem = document.getElementById("ordena_pesquisa_drpOrdem").value;
			var OrdemSentido = document.getElementById("ordena_pesquisa_drpOrdemSentido").value;
			var QtdePagina = document.getElementById("ordena_pesquisa_drpQtdePagina").value;

			busca.FiltrarBusca(Ordem.toString(), OrdemSentido.toString(), QtdePagina.toString(), Redirect_callback);
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	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();

		TrocaImagem("loading", "visible");

		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 : 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)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUCross(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value)
		{
			document.getElementById("DRP_DISP_SKU_" + res.value[0] + "_" + res.value[2] + "_" + res.value[5]).value = res.value[3];
			
			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])
				{
					document.getElementById("spanTotalCrossDe_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[7];
					document.getElementById("spanTotalCrossPor_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[8];
					
					document.getElementById("spanParcelamento1_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[9];
					document.getElementById("spanParcelamento2_" + res.value[11] + "_" + res.value[5]).innerHTML = res.value[10];
				}				
			}
		
			TrocaImagem("loading", "hidden");
		}
	}

	function DisponibilidadeSKUBusca(campo, ProdutoCodigo, tipo)
	{
		var mensagem = "";
		var aux = "";
		var extensao = "";
		var endereco = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").selectedIndex].value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").selectedIndex].value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").selectedIndex].value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").selectedIndex].value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").selectedIndex].value : 0);

			if(campo.options[campo.selectedIndex].value == "")
			{
				mensagem+="Opção inválida (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				busca.DisponibilidadeSKUBusca(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), callback_DisponibilidadeSKUBusca)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUBusca(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value[0][0])
		{
			if (res.value[0][1])
			{
				document.getElementById("spanDisponibilidade_" + res.value[0][0]).innerHTML = res.value[0][1];
			}

			if (res.value[0][2])
			{
				document.getElementById("spanPreco_" + res.value[0][0]).innerHTML = res.value[0][2];
			}

			if (res.value[0][3])
			{
				document.getElementById("spanPrecoPor_" + res.value[0][0]).innerHTML = res.value[0][3];
			}

			if (res.value[0][4])
			{
				document.getElementById("spanParcelamento_" + res.value[0][0]).innerHTML = res.value[0][4];
			}

			if (res.value[1][0])
			{
				document.getElementById("ImgBusca"+res.value[0][0]).src = res.value[1][0];
			}
			
			TrocaImagem("loading", "hidden");
		}
	}
	
	
	
	function DisponibilidadeSKUVitrine(campo, ProdutoCodigo, tipo)
	{
		var mensagem = "";
		var aux = "";
		var extensao = "";
		var endereco = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").selectedIndex].value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").selectedIndex].value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").selectedIndex].value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").selectedIndex].value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").selectedIndex].value : 0);

			if(campo.options[campo.selectedIndex].value == "")
			{
				mensagem+="Opção inválida (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				vitrine.DisponibilidadeSKUVitrine(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), callback_DisponibilidadeSKUVitrine)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUVitrine(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value[0][0])
		{
			if (res.value[0][1])
			{
				document.getElementById("spanDisponibilidade_" + res.value[0][0]).innerHTML = res.value[0][1];
			}

			if (res.value[0][2])
			{
				document.getElementById("spanPreco_" + res.value[0][0]).innerHTML = res.value[0][2];
			}

			if (res.value[0][3])
			{
				document.getElementById("spanPrecoPor_" + res.value[0][0]).innerHTML = res.value[0][3];
			}

			if (res.value[0][4])
			{
				document.getElementById("spanParcelamento_" + res.value[0][0]).innerHTML = res.value[0][4];
			}

			if (res.value[1][0])
			{
				document.getElementById("ImgBusca"+res.value[0][0]).src = res.value[1][0];
			}
			
			TrocaImagem("loading", "hidden");
		}
	}

	function DisponibilidadeSKUCategoria(campo, ProdutoCodigo, tipo)
	{
		var mensagem = "";
		var aux = "";
		var extensao = "";
		var endereco = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").selectedIndex].value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").selectedIndex].value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").selectedIndex].value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").selectedIndex].value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").selectedIndex].value : 0);

			if(campo.options[campo.selectedIndex].value == "")
			{
				mensagem+="Opção inválida (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				categoria.DisponibilidadeSKUCategoria(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), callback_DisponibilidadeSKUCategoria)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUCategoria(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value[0])
		{
			if (res.value[1])
			{
				document.getElementById("spanDisponibilidade_" + res.value[0]).innerHTML = res.value[1];
			}

			if (res.value[2])
			{
				document.getElementById("spanPreco_" + res.value[0]).innerHTML = res.value[2];
			}

			if (res.value[3])
			{
				document.getElementById("spanPrecoPor_" + res.value[0]).innerHTML = res.value[3];
			}

			if (res.value[4])
			{
				document.getElementById("spanParcelamento1_" + res.value[0]).innerHTML = res.value[4];
			}

			if (res.value[5])
			{
				document.getElementById("spanParcelamento2_" + res.value[0]).innerHTML = res.value[5];
			}
			
			if (res.value[6])
			{
				document.getElementById("ImgCategoria"+res.value[0]).src = res.value[6];
			}			

			TrocaImagem("loading", "hidden");
		}
	}

	function DisponibilidadeSKUComparador(campo, ProdutoCodigo, tipo)
	{
		var mensagem = "";
		var aux = "";
		var extensao = "";
		var endereco = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").selectedIndex].value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").selectedIndex].value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").selectedIndex].value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").selectedIndex].value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").selectedIndex].value : 0);

			if(campo.options[campo.selectedIndex].value == "")
			{
				mensagem+="Opção inválida (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				comparar.DisponibilidadeSKUComparador(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), callback_DisponibilidadeSKUComparador)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUComparador(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value[0])
		{
			if (res.value[1])
			{
				document.getElementById("spanDisponibilidade_" + res.value[0]).innerHTML = res.value[1];
			}

			if (res.value[2])
			{
				document.getElementById("spanPreco_" + res.value[0]).innerHTML = res.value[2];
			}

			if (res.value[3])
			{
				document.getElementById("spanPrecoPor_" + res.value[0]).innerHTML = res.value[3];
			}

			if (res.value[4])
			{
				document.getElementById("spanParcelamento1_" + res.value[0]).innerHTML = res.value[4];
			}

			if (res.value[5])
			{
				document.getElementById("spanParcelamento2_" + res.value[0]).innerHTML = res.value[5];
			}
			
			if (res.value[6])
			{
				document.getElementById("ImgCategoria"+res.value[0]).src = res.value[6];
			}			

			TrocaImagem("loading", "hidden");
		}
	}

	function DisponibilidadeSKUFornecedor(campo, ProdutoCodigo, tipo)
	{
		var mensagem = "";
		var aux = "";
		var extensao = "";
		var endereco = "";

		var CarValCod1 = 0;
		var CarValCod2 = 0;
		var CarValCod3 = 0;
		var CarValCod4 = 0;
		var CarValCod5 = 0;

		TrocaImagem("loading", "visible");

		try
		{
			CarValCod1 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_1").selectedIndex].value : 0);
			CarValCod2 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_2").selectedIndex].value : 0);
			CarValCod3 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_3").selectedIndex].value : 0);
			CarValCod4 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_4").selectedIndex].value : 0);
			CarValCod5 = (document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5") ? document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").options[document.getElementById("DRP_SKU_" + ProdutoCodigo + "_5").selectedIndex].value : 0);

			if(campo.options[campo.selectedIndex].value == "")
			{
				mensagem+="Opção inválida (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				fornecedor.DisponibilidadeSKUFornecedor(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), callback_DisponibilidadeSKUFornecedor)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_DisponibilidadeSKUFornecedor(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
//			window.location.href = window.location;
		}

		if (res.value[0][0])
		{
			if (res.value[0][1])
			{
				document.getElementById("spanDisponibilidade_" + res.value[0][0]).innerHTML = res.value[0][1];
			}

			if (res.value[0][2])
			{
				document.getElementById("spanPreco_" + res.value[0][0]).innerHTML = res.value[0][2];
			}

			if (res.value[0][3])
			{
				document.getElementById("spanPrecoPor_" + res.value[0][0]).innerHTML = res.value[0][3];
			}

			if (res.value[0][4])
			{
				document.getElementById("spanParcelamento_" + res.value[0][0]).innerHTML = res.value[0][4];
			}
			
			if (res.value[1][0])
			{
				document.getElementById("ImgForn"+res.value[0][0]).src = res.value[1][0];
			}	

			TrocaImagem("loading", "hidden");
		}
	}

	function MudaTab(tabNome, path_img)
	{
		// Descrição
		if (tabNome == "descricao")
		{
			if (document.getElementById("descricao"))
			{
				document.getElementById("descricao").style.visibility = "visible";
				document.getElementById("descricao").style.display = "block";
				document.getElementById("descricao").style.height = "100%";

				if (document.getElementById("lnk_descricao"))
				{
					document.getElementById("lnk_descricao").className = "selected";
				}								
			}
		}
		else
		{
			if (document.getElementById("descricao"))
			{
				document.getElementById("descricao").style.visibility = "hidden";
				document.getElementById("descricao").style.display = "none";
				document.getElementById("descricao").style.height = "0";

				if (document.getElementById("lnk_descricao"))
				{
					document.getElementById("lnk_descricao").className = "";
				}				
			}
		}
		// Tabela Nutricional
		if (tabNome == "tabelaNutricional")
		{
			if (document.getElementById("tabelaNutricional"))
			{
				document.getElementById("tabelaNutricional").style.visibility = "visible";
				document.getElementById("tabelaNutricional").style.display = "block";
				document.getElementById("tabelaNutricional").style.height = "100%";

				if (document.getElementById("lnk_tabelaNutricional"))
					document.getElementById("lnk_tabelaNutricional").className = "selected";
			}
		}
		else
		{
			if (document.getElementById("tabelaNutricional"))
			{
				document.getElementById("tabelaNutricional").style.visibility = "hidden";
				document.getElementById("tabelaNutricional").style.display = "none";
				document.getElementById("tabelaNutricional").style.height = "0";

				if (document.getElementById("lnk_tabelaNutricional"))
					document.getElementById("lnk_tabelaNutricional").className = "";
			}
		}
		
		//Características
		if (tabNome == "caracteristicas")
		{
			if (document.getElementById("caracteristicas"))
			{
				document.getElementById("caracteristicas").style.visibility = "visible";
				document.getElementById("caracteristicas").style.display = "block";
				document.getElementById("caracteristicas").style.height = "100%";

				if (document.getElementById("lnk_caracteristicas"))
				{
					document.getElementById("lnk_caracteristicas").className = "selected";
				}								
			}
		}
		else
		{
			if (document.getElementById("caracteristicas"))
			{
				document.getElementById("caracteristicas").style.visibility = "hidden";
				document.getElementById("caracteristicas").style.display = "none";
				document.getElementById("caracteristicas").style.height = "0";

				if (document.getElementById("lnk_caracteristicas"))
				{
					document.getElementById("lnk_caracteristicas").className = "";
				}								
			}
		}
		
		//Composição
		if (tabNome == "composicao")
		{
			if (document.getElementById("composicao"))
			{
				document.getElementById("composicao").style.visibility = "visible";
				document.getElementById("composicao").style.display = "block";
				document.getElementById("composicao").style.height = "100%";

				if (document.getElementById("lnk_composicao"))
				{
					document.getElementById("lnk_composicao").className = "selected";
				}								
			}
		}
		else
		{
			if (document.getElementById("composicao"))
			{
				document.getElementById("composicao").style.visibility = "hidden";
				document.getElementById("composicao").style.display = "none";
				document.getElementById("composicao").style.height = "0";

				if (document.getElementById("lnk_composicao"))
				{
					document.getElementById("lnk_composicao").className = "";
				}								
			}
		}

		//Opiniões
		if (tabNome == "opinioes")
		{
			if (document.getElementById("opinioes"))
			{
				document.getElementById("opinioes").style.visibility = "visible";
				document.getElementById("opinioes").style.display = "block";
				document.getElementById("opinioes").style.height = "100%";

				if (document.getElementById("lnk_opinioes"))
				{
					document.getElementById("lnk_opinioes").className = "selected";
				}
			}
		}
		else
		{
			if (document.getElementById("opinioes"))
			{
				document.getElementById("opinioes").style.visibility = "hidden";
				document.getElementById("opinioes").style.display = "none";
				document.getElementById("opinioes").style.height = "0";

				if (document.getElementById("lnk_opinioes"))
				{
					document.getElementById("lnk_opinioes").className = "";
				}
			}
		}

		//Atualiza Botao
		/*
		tabNome == "descricao"
		tabNome == "caracteristicas"
		tabNome == "opinioes"
		tabNome == "tabelaNuticional"
	
		var str_msg = "";
		str_msg += "::" + document.getElementById("img_descricao").src + "\n";
		str_msg += ":: " + document.getElementById("img_caracteristicas").src + "\n";
		str_msg += ":: " + document.getElementById("img_opinioes").src;

		alert(str_msg);
		alert(window.location.);
		*/
		
		
		if(document.getElementById("img_descricao"))
			document.getElementById("img_descricao").src = path_img + "/bt_descricao.gif";
		if(document.getElementById("img_tabelaNutricional"))		
			document.getElementById("img_tabelaNutricional").src = path_img + "/bt_tabelaNutricional.gif";
		if(document.getElementById("img_composicao"))		
			document.getElementById("img_composicao").src = path_img + "/bt_composicao.gif";
		if(document.getElementById("img_caracteristicas"))		
			document.getElementById("img_caracteristicas").src	= path_img + "/bt_caracteristicas.gif";
		if(document.getElementById("img_opinioes"))		
			document.getElementById("img_opinioes").src	= path_img + "/bt_opiniaoDoCliente.gif";
				
		switch(tabNome) {
		
			case 'descricao':
				if(document.getElementById("img_descricao"))
					document.getElementById("img_descricao").src = path_img + "/bt_descricaoOn.gif";
				break;

			case 'tabelaNutricional':
				if(document.getElementById("img_tabelaNutricional"))
					document.getElementById("img_tabelaNutricional").src = path_img + "/bt_tabelaNutricionalOn.gif";
				break;				
				
			case 'composicao':
				if(document.getElementById("img_composicao"))
					document.getElementById("img_composicao").src = path_img + "/bt_composicaoOn.gif";
				break;												
				
			case 'caracteristicas':
				if(document.getElementById("img_caracteristicas"))
					document.getElementById("img_caracteristicas").src = path_img + "/bt_caracteristicasOn.gif";
				break;
				
			case 'opinioes':
				if(document.getElementById("img_opinioes"))
					document.getElementById("img_opinioes").src	= path_img + "/bt_opiniaoDoClienteOn.gif";
				break;
				
			default:
				if(document.getElementById("img_descricao"))
					document.getElementById("img_descricao").src = path_img + "/bt_descricao.gif";

				if(document.getElementById("img_tabelaNutricional"))
					document.getElementById("img_tabelaNutricional").src = path_img + "/bt_tabelaNutricional.gif";
				
				if(document.getElementById("img_composicao"))
					document.getElementById("img_composicao").src = path_img + "/bt_composicao.gif";
												
				if(document.getElementById("img_caracteristicas"))
					document.getElementById("img_caracteristicas").src = path_img + "/bt_caracteristicas.gif";
							
				if(document.getElementById("img_opinioes"))
					document.getElementById("img_opinioes").src = path_img + "/bt_opiniaoDoCliente.gif";
							

		}
		//window.location.href = "#D";
	}

	function MudaCheck(tipo)
	{
		if (tipo == "S")
		{
			document.getElementById('rdnSenha').checked = true;
			document.getElementById('rdnPrimeiraCompra').checked = false;
			document.getElementById('txtCep1').value = '';
		}
		else
		{
			document.getElementById('rdnSenha').checked = false;
			document.getElementById('rdnPrimeiraCompra').checked = true;
			document.getElementById('txtSenha').value = '';
		}
	}

	function LoginAlternar()
	{
		if(document.getElementById('rdnSenha').checked)
		{
			document.getElementById('txtCep1').value = '';
			document.getElementById('txtCep1').disabled = true;

			document.getElementById('txtSenha').disabled = false;
		}
		else
		{
			document.getElementById('txtSenha').value = '';
			document.getElementById('txtSenha').disabled = true;

			document.getElementById('txtCep1').disabled = false;
		}
	}

	function SomenteNumero(e)
	{
		var key;

		if (window.event)
		{
			key = event.keyCode;
		}
		else
		{
			key = e.which;
		}

		if(key > 47 && key < 58 || key == 8 || key == 0)
		{
			return;
		}
		else
		{
			if(window.event)
			{
				window.event.returnValue = null;
			}
			else
			{
				e.preventDefault();
			}
		}
	}

	function SomenteNumero2(e, src, mask)
	{
		SomenteNumero(e);

		var key;

		if (window.event)
		{
			key = event.keyCode;
		}
		else
		{
			key = e.which;
		}


		if(	key != 8)
		{
			Mascara(src,mask);
		}
	}

	function Mascara(src, mask)
	{
		 var i = src.value.length;
		 var saida = mask.substring(0,1);
		 var texto = mask.substring(i)
		 if (texto.substring(0,1) != saida)
		 {
			  src.value += texto.substring (0,1);
		 }
	}

	function Mascara2(e, src, mask)
	{
		var key;

		if (window.event)
		{
			key = event.keyCode;
		}
		else
		{
			key = e.which;
		}

		if (key != 8)
		{
			Mascara(src, mask);
		}
	}

	function Continuar(tipo)
	{		
		TrocaImagem("loading", "visible");

		var mensagem = "";
		var username = "";
		var cep = "";

		try
		{
			if (tipo == "S")
			{
				username = document.getElementById("txtEmail").value;
			}
			else if (tipo == "P")
			{
				username = document.getElementById("txtEmail2").value;
			}

			var password = document.getElementById("txtSenha").value;

			if (document.getElementById("txtCep1"))
			{
				cep = document.getElementById("txtCep1").value;
			}


			if (Trim(username) == "")
			{
				mensagem+="Email inválido (vazio) !\n";
			}

			if (tipo == "S")
			{
				if (Trim(password) == "")
				{
					mensagem+="Senha inválida (vazia) !\n";
				}
			}
			else if (tipo == "P")
			{
				if (Trim(cep) == "")
				{
					mensagem+="CEP inválido (vazio) !\n";
				}
			}
			
			var ComperCard = document.getElementById("chkComperCard").checked;
		

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				login.Continuar(username, password, cep, tipo, ComperCard, Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}


	function ContinuarPedCodigo()
	{
		TrocaImagem("loading", "visible");

		try
		{
			var PedCodigo = document.getElementById("txtPedCodigo").value;

			if(PedCodigo != '')
			{
				loginpedido.ContinuarPedCodigo(PedCodigo.toString(), ContinuarPedCodigo_Callback)
			}
			else
			{
				alert('Preencha corretamente o Número do Pedido!');
				TrocaImagem("loading", "hidden");
			}
		}
		catch(err)
		{
			alert(err.message);
			TrocaImagem("loading", "hidden");
		}
	}


	function ContinuarPedCodigo_Callback(res)
	{
		try
		{
			var txtPedCodigo		= document.getElementById("txtPedCodigo");

			if(res.value[0] != null)
			{
				if(res.value[0] == "true")
				{
					if(res.value[0] != '')
					{
						window.location = res.value[2];
					}
					else
					{
						alert('Pedido inválido!');
					}
				}
				else
				{
					alert(res.value[1]);
				}
			}

			txtPedCodigo.value = '';
			TrocaImagem("loading", "hidden");
		}
		catch(err)
		{
			alert(err.message);
		}

		TrocaImagem("loading", "hidden");
	}

	function CarregaEnderecoEnderecos(cep)
	{
		TrocaImagem("loading", "visible");
		enderecos.CarregaEnderecoEnderecos(cep, callback_CarregaEnderecoEnderecos)
	}

	function callback_CarregaEnderecoEnderecos(res)
    {
        if (res.error)
        {
            AlertaErroAjax(res.error);
            TrocaImagem("loading", "hidden");
        }

        if (res.value)
        {
            if (res.value[0])
            {
                document.getElementById("txtEndereco").value = res.value[0];
                document.getElementById("txtEndereco").disabled = true;
			}
			else
			{
				document.getElementById("txtEndereco").disabled = false;
				document.getElementById("txtEndereco").value = "";
			}
            if (res.value[1])
            {
                document.getElementById("txtBairro").value = res.value[1];
                document.getElementById("txtBairro").disabled = true;
			}
			else
			{
				document.getElementById("txtBairro").disabled = false;
				document.getElementById("txtBairro").value = "";
			}
            if (res.value[2])
            {
                document.getElementById("txtCidade").value = res.value[2];
                document.getElementById("txtCidade").disabled = true;
			}
			else
			{
				document.getElementById("txtCidade").disabled = false;
				document.getElementById("txtCidade").value = "";
			}
            if (res.value[3])
            {
                document.getElementById("ddlEstado").value = res.value[3];
                document.getElementById("ddlEstado").disabled = true;
                document.getElementById("ddlPais").disabled = true;
			}
			else
			{
				document.getElementById("ddlEstado").disabled = false;
				document.getElementById("ddlEstado").value = "MS";
				document.getElementById("ddlPais").disabled = false;
			}
            
            if (res.value[6])
            {
                document.getElementById("ddlTipoLogradouro").value = res.value[6];
                document.getElementById("ddlTipoLogradouro").disabled = true;
			}
			else
			{
				document.getElementById("ddlTipoLogradouro").disabled = false;
				document.getElementById("ddlTipoLogradouro").value = "1";
			}
            //if (res.value[4])
            //{
            //    document.getElementById("ddlPais").value = res.value[4];
            //    document.getElementById("ddlPais").disabled = true;
			//}			
			//else
			//{
				//document.getElementById("ddlPais").disabled = false;
		//		document.getElementById("ddlPais").value = "31";
		//	}
				document.getElementById("txtComplemento").value = "";
				document.getElementById("txtRefEndereco").value = "";
				document.getElementById("txtNumero").value = "";


            TrocaImagem("loading", "hidden");
        }
        else
        {
			document.getElementById("txtEndereco").disabled = false;
			document.getElementById("txtBairro").disabled = false;
			document.getElementById("txtCidade").disabled = false;
			document.getElementById("ddlEstado").disabled = false;
			document.getElementById("ddlTipoLogradouro").disabled = false;
        }
    }
      
	function UsarEndereco(EnderecoCodigo)
	{
		TrocaImagem("loading", "visible");
		enderecos.UsarEndereco(EnderecoCodigo.toString(), Redirect_callback);
	}

	function EditarEndereco(EnderecoCodigo)
	{
		TrocaImagem("loading", "visible");
		enderecos.EditarEndereco(EnderecoCodigo.toString(), callback_EditarEndereco);
	}

	function callback_EditarEndereco(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			document.getElementById("txtEndereco").disabled = true;
			document.getElementById("txtBairro").disabled = true;
			document.getElementById("txtCidade").disabled = true;
			document.getElementById("ddlEstado").disabled = true;
			document.getElementById("ddlTipoLogradouro").disabled = true;
			
			if (res.value[0])
			{
				document.getElementById("txtCep").value = res.value[0];
			}
			if (res.value[1])
			{
				document.getElementById("ddlEndereco").value = res.value[1];
			}
			if (res.value[2])
			{
				document.getElementById("txtEndereco").value = res.value[2];
			}
			if (res.value[3])
			{
				document.getElementById("txtNumero").value = res.value[3];
			}
			if (res.value[4])
			{
				document.getElementById("txtComplemento").value = res.value[4];
			}
			if (res.value[5])
			{
				document.getElementById("txtBairro").value = res.value[5];
			}
			if (res.value[6])
			{
				document.getElementById("txtCidade").value = res.value[6];
			}
			if (res.value[7])
			{
				document.getElementById("ddlEstado").value = res.value[7];
			}
			if (res.value[8])
			{
				document.getElementById("ddlPais").value = res.value[8];
			}
			if (res.value[9])
			{
				document.getElementById("txtTel1Ddd").value = res.value[9];
			}
			if (res.value[10])
			{
				document.getElementById("txtTel1").value = res.value[10];
			}
			if (res.value[11])
			{
				document.getElementById("txtRamal1").value = res.value[11];
			}
			if (res.value[12])
			{
				document.getElementById("txtTel2Ddd").value = res.value[12];
			}
			if (res.value[13])
			{
				document.getElementById("txtTel2").value = res.value[13];
			}
			if (res.value[14])
			{
				document.getElementById("txtRamal2").value = res.value[14];
			}
			if (res.value[15])
			{
				document.getElementById("txtTel3Ddd").value = res.value[15];
			}
			if (res.value[16])
			{
				document.getElementById("txtTel3").value = res.value[16];
			}
			if (res.value[17])
			{
				document.getElementById("txtRamal3").value = res.value[17];
			}
			if (res.value[18])
			{
				document.getElementById("txtTelCelDdd").value = res.value[18];
			}
			if (res.value[19])
			{
				document.getElementById("txtTelCel").value = res.value[19];
			}
			if (res.value[20])
			{
				document.getElementById("txtTelFaxDdd").value = res.value[20];
			}
			if (res.value[21])
			{
				document.getElementById("txtTelFax").value = res.value[21];
			}
			if (res.value[22])
			{
				document.getElementById("txtRefEndereco").value = res.value[22];
			}
			if (res.value[23])
			{
				document.getElementById("ddlTipoLogradouro").value = res.value[23];
			}
			if (res.value[24])
			{
				document.getElementById("txtNomeEndereco").value = res.value[24];
			}

			TrocaImagem("loading", "hidden");
			window.location.href = "#e";
		}
	}

	function CancelarEndereco()
	{
		TrocaImagem("loading", "visible");
		enderecos.CancelarEndereco(callback_CancelarEndereco);
	}

	function callback_CancelarEndereco(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			document.getElementById("txtEndereco").disabled = false;
			document.getElementById("txtBairro").disabled = false;
			document.getElementById("txtCidade").disabled = false;
			document.getElementById("ddlEstado").disabled = false;
			document.getElementById("ddlTipoLogradouro").disabled = false;
			
			document.getElementById("txtCep").value = "";
			document.getElementById("ddlEndereco").selectedIndex = 0;
			document.getElementById("txtEndereco").value = "";
			document.getElementById("txtNumero").value = "";
			document.getElementById("txtComplemento").value = "";
			document.getElementById("txtBairro").value = "";
			document.getElementById("txtCidade").value = "";
			document.getElementById("ddlEstado").value = "SP";
			document.getElementById("ddlPais").value = "31";
			document.getElementById("txtTel1Ddd").value = "";
			document.getElementById("txtTel1").value = "";
			document.getElementById("txtRamal1").value = "";
			document.getElementById("txtTel2Ddd").value = "";
			document.getElementById("txtTel2").value = "";
			document.getElementById("txtRamal2").value = "";
			document.getElementById("txtTel3Ddd").value = "";
			document.getElementById("txtTel3").value = "";
			document.getElementById("txtRamal3").value = "";
			document.getElementById("txtTelCelDdd").value = "";
			document.getElementById("txtTelCel").value = "";
			document.getElementById("txtTelFaxDdd").value = "";
			document.getElementById("txtTelFax").value = "";
			document.getElementById("txtRefEndereco").value = "";
			document.getElementById("ddlTipoLogradouro").selectedIndex = 0;
			document.getElementById("txtNomeEndereco").value = "";

			TrocaImagem("loading", "hidden");
		}
	}

	function ExcluirEndereco(EnderecoCodigo)
	{
		TrocaImagem("loading", "visible");

		if (confirm("Tem certeza que deseja excluir o endereço escolhido?"))
		{
			enderecos.ExcluirEndereco(EnderecoCodigo.toString(), Redirect_callback);
		}
		else
		{
			TrocaImagem("loading", "hidden");
		}
	}

	function SalvarEndereco()
	{
		var mensagem = "";

		TrocaImagem("loading", "visible");

		try
		{					
			document.getElementById("txtEndereco").disabled = false;
			document.getElementById("txtBairro").disabled = false;
			document.getElementById("txtCidade").disabled = false;
			document.getElementById("ddlEstado").disabled = false;
			document.getElementById("ddlTipoLogradouro").disabled = false;
			
			if (Trim(document.getElementById("txtCep").value) == "")
			{
				mensagem+="CEP inválido (vazio) !\n";
			}
			else
			{
				if (Trim(document.getElementById("txtCep").value).length < 9)
				{
					mensagem+="CEP inválido (incompleto) !\n";
				}
			}
			if(document.getElementById("ddlEndereco").value == "")
			{
				mensagem+="Tipo inválido (vazio) !\n";
			}			
			if (Trim(document.getElementById("txtNomeEndereco").value) == "")
			{
				mensagem+="Nome inválido (vazio) !\n";
			}
			if (Trim(document.getElementById("txtEndereco").value) == "" || document.getElementById("ddlTipoLogradouro").value == "")
			{
				mensagem+="Endereço inválido (vazio) !\n";
			}
			if (Trim(document.getElementById("txtNumero").value) == "")
			{
				mensagem+="Número inválido (vazio) !\n";
			}
			if (Trim(document.getElementById("txtBairro").value) == "")
			{
				mensagem+="Bairro inválido (vazio) !\n";
			}
			if (Trim(document.getElementById("txtCidade").value) == "")
			{
				mensagem+="Cidade inválida (vazia) !\n";
			}
			if (document.getElementById("ddlEstado").value == "")
			{
				mensagem+="Estado inválido (vazio) !\n";
			}
			if (document.getElementById("ddlPais").value == "")
			{
				mensagem+="País inválido (vazio) !\n";
			}
			if (Trim(document.getElementById("txtTel1Ddd").value) == "" || Trim(document.getElementById("txtTel1").value) == "")
			{
				mensagem+="Telefone inválido (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				enderecos.SalvarEndereco(document.getElementById("txtCep").value, document.getElementById("ddlEndereco").value, document.getElementById("txtEndereco").value, document.getElementById("txtNumero").value, document.getElementById("txtComplemento").value, document.getElementById("txtBairro").value, document.getElementById("txtCidade").value, document.getElementById("ddlEstado").value, document.getElementById("ddlPais").value, document.getElementById("txtTel1Ddd").value, document.getElementById("txtTel1").value, document.getElementById("txtRamal1").value, document.getElementById("txtTel2Ddd").value, document.getElementById("txtTel2").value, document.getElementById("txtRamal2").value, document.getElementById("txtTel3Ddd").value, document.getElementById("txtTel3").value, document.getElementById("txtRamal3").value, document.getElementById("txtTelCelDdd").value, document.getElementById("txtTelCel").value, document.getElementById("txtTelFaxDdd").value, document.getElementById("txtTelFax").value, document.getElementById("txtRefEndereco").value, document.getElementById("ddlTipoLogradouro").value, document.getElementById("txtNomeEndereco").value, Redirect_callback)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function Redirect_callback(res)
	{
		
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			if(res.value == "NaoLogado")
			{
				//alert("É necessário estar logado para efetuar esta operação.");
				window.location.href = URLSite + "/login.aspx";
			}
			else if(res.value == "reload")
			{
				window.location.reload();
			}
			else if(res.value == "!EmailExistente")
			{
				alert("O e-mail informado já existe na base.");
			}
			else
			{
			//alert(res.value.toString());
				window.location.href = res.value;
			}
		}
	}

	function CancelarCupom()
	{
		index.CancelarCupom(callback_CancelarCupom);
	}

	function callback_CancelarCupom(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
		}

		if (res.value)
		{
			window.location.href = res.value;
		}
	}

	function CalcularFrete()
	{
		try
		{
			var mensagem = "";

			TrocaImagem("loading", "visible");

			if (document.getElementById("CEP"))
			{
				if (document.getElementById("CEP").value.length < 1)
				{
					mensagem+="CEP inválido (vazio) !\n";
				}
				else
				{
					if (document.getElementById("CEP").value.length < 9)
					{
						mensagem+="CEP inválido (incompleto) !\n";
					}
				}

				if(mensagem != "")
				{
					alert(mensagem);
					TrocaImagem("loading", "hidden");
				}
				else
				{
					index.CalcularFrete(document.getElementById("CEP").value.replace("-", ""), callback_CalcularFrete)
				}
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_CalcularFrete(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			document.getElementById("Cupom").value = "";
		}

		if (res.value)
		{
			window.location.href = res.value;
		}
	}

	function CalcularCupom()
	{
		try
		{
			var mensagem = "";

			TrocaImagem("loading", "visible");

			if (document.getElementById("Cupom"))
			{
				if (document.getElementById("Cupom").value.length < 1)
				{
					mensagem+="Cupom inválido (vazio) !\n";
				}
				else
				{
					if (document.getElementById("Cupom").value.length < 36)
					{
						mensagem+="Cupom inválido (incompleto) !\n";
					}
				}

				if(mensagem != "")
				{
					alert(mensagem);
					TrocaImagem("loading", "hidden");
				}
				else
				{
					index.CalcularCupom(document.getElementById("Cupom").value.toString(), callback_CalcularCupom)
				}
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_CalcularCupom(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
			document.getElementById("Cupom").value = "";
		}

		if (res.value)
		{
			if(res.value.indexOf('login.aspx') != -1)
			{
				alert('Para validar um vale-presente é preciso estar logado!');
			}
			window.location.href = res.value;
		}
	}

	function Contagem(qtde, campotxt, campoqtde)
	{
		field = document.getElementById(campotxt.name);
		if (field)
		{
			if(field.value.length >= Number(qtde))
			{
				field.value = field.value.substring(0, qtde);
			}
		}
		txt_field = document.getElementById(campoqtde);
		if (txt_field)
		{
			txt_field.innerHTML = campotxt.value.length;
		}
	}

	function Avaliar(nota)
	{
		for (i=1; i<=5; i++)
		{
			document.getElementById("star" + i).src = (i <= nota ? document.getElementById("star" + i).src.replace("off", "ok").replace("on", "ok") : document.getElementById("star" + i).src);
		}
		document.getElementById("txtNota").value = nota;
	}

	function Preview(nota)
	{
		for (i=1; i<=5; i++)
		{
			document.getElementById("star" + i).src = (i <= nota ? document.getElementById("star" + i).src.replace("off2", "on").replace("ok", "on") : document.getElementById("star" + i).src);
		}
	}

	function ResetPreview()
	{
		var nota = 0;

		if (document.getElementById("txtNota").value.length > 0)
		{
			nota = Number(document.getElementById("txtNota").value)

			for (i=1; i<=5; i++)
			{
				document.getElementById("star" + i).src = (i <= nota ? document.getElementById("star" + i).src.replace("off2", "ok").replace("on", "ok") : document.getElementById("star" + i).src.replace("on", "off2").replace("ok", "off2"));
			}
		}
		else
		{
			for (i=1; i<=5; i++)
			{
				document.getElementById("star" + i).src = document.getElementById("star" + i).src.replace("on", "off2").replace("ok", "off2");
			}
		}
	}

	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)
		{
			window.alert(exc.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_SalvarTag(res)
	{
		if(res.error)
		{
			if (res.error.Message.indexOf("http://") > -1)
			{
				window.location = res.error.Message;
			}
			else
			{
				AlertaErroAjax(res.error);
			}

			//window.AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
			return;
		}

		if(res.value)
		{
			Tagar();
			window.alert(res.value);
			document.getElementById("txtTag").value = "";
			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");
		}
	}

	function SalvarOpiniao(ProdutoCodigo)
	{
		var mensagem = "";
		TrocaImagem("loading", "visible");

		var Nota = "";
		var Nome = "";
		var Email = "";
		var Comentario = "";

		try
		{
			if(document.getElementById("txtNome").value == "")
			{
				mensagem+="Nome inválido (vazio) !\n";
			}

			if(document.getElementById("txtEmail").value == "")
			{
				mensagem+="Email inválido (vazio) !\n";
			}

			if(document.getElementById("txtDescricao").value == "")
			{
				mensagem+="Comentário inválido (vazio) !\n";
			}

			if(document.getElementById("txtNota").value == "")
			{
				mensagem+="Nota inválida (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				Nota = document.getElementById("txtNota").value;
				Nome = document.getElementById("txtNome").value;
				Email = document.getElementById("txtEmail").value;
				Comentario = document.getElementById("txtDescricao").value;

				detalhes.SalvarOpiniao(ProdutoCodigo.toString(), Nome, Email, Comentario, Nota.toString(), callback_SalvarOpiniao)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_SalvarOpiniao(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			Opinar();
			alert(res.value);

			document.getElementById("txtNota").value = "";
			document.getElementById("txtNome").value = "";
			document.getElementById("txtEmail").value = "";
			document.getElementById("txtDescricao").value = "";

//			ResetPreview();

			TrocaImagem("loading", "hidden");
		}
	}

	function PublicaSelo(PromocaoGCodigo, PromocaoPCodigo, ProdutoCodigo, Path, PromoNome)
	{
		if (document.getElementById("Selo" + ProdutoCodigo))
		{
			if (PromocaoGCodigo > 0 || PromocaoPCodigo > 0)
			{
				if (imageExists(Path + "/promocao/" + (PromocaoGCodigo > 0 ? "G"+PromocaoGCodigo : "P"+PromocaoPCodigo) + ".gif"))
				{
					document.getElementById("Selo" + ProdutoCodigo).innerHTML = "<img src='" + Path + "/promocao/" + (PromocaoGCodigo > 0 ? "G"+PromocaoGCodigo : "P"+PromocaoPCodigo) + ".gif' alt='" + PromoNome + "' title='" + PromoNome + "'><br>";
				}
				else if (imageExists(Path + "/promocao/" + (PromocaoGCodigo > 0 ? "G"+PromocaoGCodigo : "P"+PromocaoPCodigo) + ".jpg"))
				{
					document.getElementById("Selo" + ProdutoCodigo).innerHTML = "<img src='" + Path + "/promocao/" + (PromocaoGCodigo > 0 ? "G"+PromocaoGCodigo : "P"+PromocaoPCodigo) + ".jpg' alt='" + PromoNome + "' title='" + PromoNome + "'><br>";
				}
				else
				{
					document.getElementById("Selo" + ProdutoCodigo).innerHTML = "<img src='" + Path + "/casper.gif' width='1' height='1' border='0'><br>";
				}
			}
		}
	}

	function Tagar()
	{
		detalhes.ExisteSessao(callback_ExisteSessao);
	}

	function callback_ExisteSessao(res)
	{
		if(res.value != "")
		{
			window.location = res.value;
			return;
		}
		try
		{
		try 
		{
			if (document.getElementById("indique_container")) 
			{
				document.getElementById("indique_container").style.display = "none";
			}

			if (document.getElementById("opine_container")) 
			{
				document.getElementById("opine_container").style.display = "none";
			}

			if (document.getElementById("Tag_container")) 
			{
				if (document.getElementById("Tag_container").style.display == "none" || document.getElementById("Tag_container").style.display == "") 
				{
					document.getElementById("Tag_container").style.display = "inline";
				} 
				else 
				{
					document.getElementById("Tag_container").style.display = "none";
				}
			}

			if (document.getElementById("Tag_container").style.display == "inline")
			{
				//window.location.href = "#O";
			}
		} 
		catch (err) 
		{
		}
		}
		catch(err)
		{
		}
	}

	function Opinar() 
	{
		try 
		{
			if (document.getElementById("indique_container")) 
			{
				document.getElementById("indique_container").style.display = "none";
			}

			if (document.getElementById("Tag_container")) 
			{
				document.getElementById("Tag_container").style.display = "none";
			}

			if (document.getElementById("opine_container")) 
			{
				if (document.getElementById("opine_container").style.display == "none" || document.getElementById("opine_container").style.display == "") 
				{
					document.getElementById("opine_container").style.display = "inline";
				} 
				else 
				{
					document.getElementById("opine_container").style.display = "none";
				}
			}

			if (document.getElementById("opine_container").style.display == "inline")
			{
				//window.location.href = "#O";
			}
		} 
		catch (err) 
		{
		}
	}

	function Indicar()
	{
		try 
		{
			if (document.getElementById("opine_container")) 
			{
				document.getElementById("opine_container").style.display = "none";
			}

			if (document.getElementById("Tag_container")) 
			{
				document.getElementById("Tag_container").style.display = "none";
			}

			if (document.getElementById("indique_container")) 
			{
				if (document.getElementById("indique_container").style.display == "none" || document.getElementById("indique_container").style.display == "") 
				{
					document.getElementById("indique_container").style.display = "inline";
				} 
				else 
				{
					document.getElementById("indique_container").style.display = "none";
				}
			}

			if (document.getElementById("indique_container").style.display == "inline")
			{
				//window.location.href = "#O";
			}
		} 
		catch (err) 
		{
		}
	}

function EnviaIndicacao()
{
	var Mensagem = "";
	var NomeAmigo = "";
	var EmailAmigo = "";
	var NomeRemetente = "";
	var EmailRemetente = "";
	var MsgIndicacao = "";

	TrocaImagem("loading", "visible");

	try
	{
		NomeAmigo = document.getElementById("txtNomeAmigo").value;
		EmailAmigo = document.getElementById("txtEmailAmigo").value;
		NomeRemetente = document.getElementById("txtRemetente").value;
		EmailRemetente = document.getElementById("txtEmailRemetente").value;
		MsgIndicacao = document.getElementById("txtMensagem").value;
		
		if(NomeAmigo == "")
		{
			Mensagem += "Nome do amigo inválido (vazio) !\n";
		}
		
		if(EmailAmigo == "")
		{
			Mensagem += "Email do amigo inválido (vazio) !\n";
		}
		
		if(NomeRemetente == "")
		{
			Mensagem += "Nome do remetente inválido (vazio) !\n";
		}
		
		if(EmailRemetente == "")
		{
			Mensagem += "Email do remetente inválido (vazio) !\n";
		}

		if(Mensagem != "")
		{
			alert(Mensagem);
			TrocaImagem("loading", "hidden");
		}
		else
		{
			detalhes.EnviaIndicacao(NomeAmigo, EmailAmigo, NomeRemetente, EmailRemetente, MsgIndicacao, callback_EnviaIndicacao)
		}		
	} 
	catch(err)
	{
		alert(err.description);
		TrocaImagem("loading", "hidden");
	}
}

function callback_EnviaIndicacao(res)
{
	if (res.error)
	{
		AlertaErroAjax(res.error);
		TrocaImagem("loading", "hidden");
	}		

	if (res.value)
	{
		alert(res.value);
		
		if (res.value == "Login não efetuado!")
		{
			window.location.href = "login.aspx";
		}
		
		document.getElementById("txtNomeAmigo").value = "";
		document.getElementById("txtEmailAmigo").value = "";
		document.getElementById("txtRemetente").value = "";
		document.getElementById("txtEmailRemetente").value = "";
		document.getElementById("txtMensagem").value = "";

		TrocaImagem("loading", "hidden");
	}
}

	function GuardarAviso()
	{
		GuardarAviso(0);
	}

	function GuardarAviso(ProdutoValorCaracteristicaCodigo)
	{
		var Email = "";
		var mensagem = "";

		TrocaImagem("loading", "visible");

		try
		{
			if(document.getElementById("txtEmailAviso").value == "")
			{
				mensagem+="Email inválido (vazio) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				Email = document.getElementById("txtEmailAviso").value;
				detalhes.GuardarAviso(Email, ProdutoValorCaracteristicaCodigo.toString(), callback_GuardarAviso)
			}
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_GuardarAviso(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			alert(res.value);
			document.getElementById("txtEmailAviso").value = "";
			TrocaImagem("loading", "hidden");
		}
	}

	function janela(hp, width, height, texto)
	{
		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");

		wAbout.blur();
		window.focus();
		wAbout.resizeTo(width,height);
		wAbout.moveTo(l, t);
		wAbout.focus();
	}

	//FALE CONOSCO(AJAX)


	function Mostra(quem, tammax)
	{
		VerifiqueTAB=true;

		if (quem.value.length == tammax && VerifiqueTAB)
		{
			var i=0,j=0, indice=-1;

			for (i=0; i<document.forms.length; i++)
			{
				for (j=0; j<document.forms[i].elements.length; j++)
				{
					if (document.forms[i].elements[j].name == quem.name)
					{
						indice=i;
						break;
					}
				}
				if (indice != -1)
				{
					break;
				}
			}
			for (i=0; i<=document.forms[indice].elements.length; i++)
			{
				if (document.forms[indice].elements[i].name == quem.name)
				{
					try
					{
						while ((document.forms[indice].elements[(i+1)].type == "hidden") && (i < document.forms[indice].elements.length))
						{
							i++;
						}
						document.forms[indice].elements[(i+1)].focus();
					}
					catch(err)
					{
					}

					VerifiqueTAB=false;
					break;
				}
			}
		}
	}

	function ColocaFocoEm(NomeBtn, e)
	{
		try
		{
			var key;

			if (window.event)
			{
				key = event.keyCode;
			}
			else
			{
				key = e.which;
			}

			if (key == 13)
			{
				document.getElementById(NomeBtn).focus();
				key = 13;
			}
		}
		catch(err)
		{
			alert(err);
		}
	}

	function CamposPreenchidosFaleConosco()
	{
		retornoCamposPreenchidosFaleConosco = true;

		try
		{
			var CorErro                 			= '#FF0000';
			var CorOk                   			= '#6C79A6';

			var ddlDestino		= document.getElementById('ddlDestino');
			var ddlAssunto		= document.getElementById('ddlAssunto');
			var txtNome			= document.getElementById('txtNome');
			var txtEmail		= document.getElementById('txtEmail');
			var txtDDD			= document.getElementById('txtDDD');
			var txtTelefone		= document.getElementById('txtTelefone');
			var txtMensagem		= document.getElementById('txtMensagem');

			if(Trim(ddlDestino.value) == '')	{MudaCorBorda(ddlDestino, CorErro);			retornoCamposPreenchidosFaleConosco = false;} else MudaCorBorda(ddlDestino, CorOk);
			if(Trim(txtNome.value) == '')		{MudaCorBorda(txtNome, CorErro);			retornoCamposPreenchidosFaleConosco = false;} else MudaCorBorda(txtNome, CorOk);
			if(Trim(txtEmail.value) == '')		{MudaCorBorda(txtEmail, CorErro);			retornoCamposPreenchidosFaleConosco = false;} else MudaCorBorda(txtEmail, CorOk);
			if(Trim(txtDDD.value) == '')		{MudaCorBorda(txtDDD, CorErro);				retornoCamposPreenchidosFaleConosco = false;} else MudaCorBorda(txtDDD, CorOk);
			if(Trim(txtTelefone.value) == '')	{MudaCorBorda(txtTelefone, CorErro);		retornoCamposPreenchidosFaleConosco = false;} else MudaCorBorda(txtTelefone, CorOk);
			if(Trim(txtMensagem.value) == '')	{MudaCorBorda(txtMensagem, CorErro);		retornoCamposPreenchidosFaleConosco = false;} else MudaCorBorda(txtMensagem, CorOk);
			if(Trim(ddlAssunto.value) == '')	{MudaCorBorda(ddlAssunto, CorErro);			retornoCamposPreenchidosFaleConosco = false;} else MudaCorBorda(ddlAssunto, CorOk);

	        if(!retornoCamposPreenchidosFaleConosco)
			{
				alert('Preencha os campos corretamente!');
			}
		}
		catch(err)
		{
			document.write("<!--" + err.description + "-->");
		}

		return retornoCamposPreenchidosFaleConosco;
	}

	function MudaCorBorda(obj, cor)
	{
		try
		{
			var Borda               = '1px';
			var BordaEstilo         = 'solid';

			obj.style.border        = Borda;
			obj.style.borderStyle   = BordaEstilo;
			obj.style.borderColor   = cor;
		}
		catch(err)
		{
			document.write(err.description);
		}
	}


	function EnviarMensagem()
	{
		try
		{
			var ddlDestino		= document.getElementById('ddlDestino');
			var ddlAssunto		= document.getElementById('ddlAssunto');
			var txtNome			= document.getElementById('txtNome');
			var txtSobrenome	= document.getElementById('txtSobrenome');
			var txtEmail		= document.getElementById('txtEmail');
			var txtDDD			= document.getElementById('txtDDD');
			var txtTelefone		= document.getElementById('txtTelefone');
			var txtMensagem		= document.getElementById('txtMensagem');

			if(CamposPreenchidosFaleConosco())
			{
				document.getElementById("btnEnviar").disabled="true";
				faleconosco.EnviarMensagem(ddlDestino.options[ddlDestino.selectedIndex].value, txtNome.value,txtSobrenome.value,txtEmail.value,txtDDD.value,txtTelefone.value,ddlAssunto.options[ddlAssunto.selectedIndex].text,txtMensagem.value,EnviarMensagem_CallBack);
			}

		}
		catch(err)
		{
			alert(err.message);
		}
	}

	function EnviarMensagem_CallBack(resp)
	{
		try
		{
			var lblMsgErro = document.getElementById('lblMsgErro');
			if(resp.value[0] == "1")
			{
				document.getElementById("btnEnviar").disabled="false";
				lblMsgErro.innerHTML = resp.value[1];
				document.getElementById('ddlDestino').selectedIndex = 0;
				document.getElementById('ddlAssunto').selectedIndex = 0;
				document.getElementById('txtNome').value = "";
				document.getElementById('txtSobrenome').value = "";
				document.getElementById('txtEmail').value = "";
				document.getElementById('txtDDD').value = "";
				document.getElementById('txtTelefone').value = "";
				document.getElementById('txtMensagem').value = "";
			}
			else			
			{
				lblMsgErro.innerHTML = resp.value[1];
				document.getElementById('ddlDestino').selectedIndex = 0;
				document.getElementById('ddlAssunto').selectedIndex = 0;
				document.getElementById('txtNome').value = "";
				document.getElementById('txtSobrenome').value = "";
				document.getElementById('txtEmail').value = "";
				document.getElementById('txtDDD').value = "";
				document.getElementById('txtTelefone').value = "";
				document.getElementById('txtMensagem').value = "";			
			}
		}
		catch(err)
		{
			lblMsgErro.value = err.message;
				document.getElementById('ddlDestino').selectedIndex = 0;
				document.getElementById('ddlAssunto').selectedIndex = 0;
				document.getElementById('txtNome').value = "";
				document.getElementById('txtSobrenome').value = "";
				document.getElementById('txtEmail').value = "";
				document.getElementById('txtDDD').value = "";
				document.getElementById('txtTelefone').value = "";
				document.getElementById('txtMensagem').value = "";
		}
	}

	function AdicionarListaDesejo()
	{
		var ProdutoCodigo	= 0;
		var CategoriaCodigo = 0;
		var CarValCod1		= 0;
		var CarValCod2		= 0;
		var CarValCod3		= 0;
		var CarValCod4		= 0;
		var CarValCod5		= 0;

		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").tagName.toLowerCase() == "select")?(document.getElementById("DRP_SKU_1").options[document.getElementById("DRP_SKU_1").selectedIndex].value):(0)): 0);
			CarValCod2			= (document.getElementById("DRP_SKU_2") ? ((document.getElementById("DRP_SKU_2").tagName.toLowerCase() == "select")?(document.getElementById("DRP_SKU_2").options[document.getElementById("DRP_SKU_2").selectedIndex].value):(0)): 0);
			CarValCod3			= (document.getElementById("DRP_SKU_3") ? ((document.getElementById("DRP_SKU_3").tagName.toLowerCase() == "select")?(document.getElementById("DRP_SKU_3").options[document.getElementById("DRP_SKU_3").selectedIndex].value):(0)): 0);
			CarValCod4			= (document.getElementById("DRP_SKU_4") ? ((document.getElementById("DRP_SKU_4").tagName.toLowerCase() == "select")?(document.getElementById("DRP_SKU_4").options[document.getElementById("DRP_SKU_4").selectedIndex].value):(0)): 0);
			CarValCod5			= (document.getElementById("DRP_SKU_5") ? ((document.getElementById("DRP_SKU_5").tagName.toLowerCase() == "select")?(document.getElementById("DRP_SKU_5").options[document.getElementById("DRP_SKU_5").selectedIndex].value):(0)): 0);

			detalhes.AdicionarListaDesejo(ProdutoCodigo.toString(), CategoriaCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), AdicionarListaDesejo_CallBack);
		}
		catch(err)
		{
			alert(err.description);

		}
	}

	function AdicionarListaDesejo_CallBack(res)
	{
		try
		{

			if(res.value[0] == "0")
			{
				if(res.value[2] != "")
				{
					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)
		{
			alert(err.description);
		}
	}


	function CompararTodos(campo)
	{
		divs=document.getElementsByTagName("input");
		for (i=0;i<divs.length;i++)
		{
			if (divs[i].type == "checkbox")
			{
				if (divs[i].name.indexOf("CompProd_") >= 0)
				{
					divs[i].checked = campo.checked;
				}
			}
		}
	}

	function CompararProdutos(origem)
	{
		var totalItens = 0;
		var ItensCod = "";

		divs=document.getElementsByTagName("input");

		for (i=0;i<divs.length;i++)
		{
			if (divs[i].type == "checkbox")
			{
				if (divs[i].name.indexOf("CompProd_") >= 0)
				{
					if(divs[i].checked)
					{
						if (ItensCod == "")
						{
							ItensCod = divs[i].value;
						}
						else
						{
							ItensCod += "|" + divs[i].value;
						}

						totalItens++;
					}
				}
			}
		}

		if (totalItens > 1)
		{
			if (totalItens < 5)
			{
				if (origem == "C")
				{
					categoria.CompararProdutos(ItensCod.toString(), callback_CompararProdutos);
				}
				else if (origem == "B")
				{
					busca.CompararProdutos(ItensCod.toString(), callback_CompararProdutos);
				}
			}
			else
			{
				alert("Você pode selecionar no méximo 4 produtos para comparação!");
			}
		}
		else
		{
			alert("Você precisa selecionar mais de 1 produto pra poder fazer a comparação de produtos!");
		}
	}

	function callback_CompararProdutos(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			window.location.href = res.value;
		}
	}

function BuscaItensTrilha(PaginaAtual)
{
	var mensagem = "";

	TrocaImagem("loading", "visible");

	if(document.getElementById("txtBuscaTrilha").value == "")
	{
		mensagem+="Busca inválida (vazia) !\n";
	}
	else
	{
		if (document.getElementById("txtBuscaTrilha").value.replace(" ", "").length < 3)
		{
			mensagem+="Busca inválida (menos de 3 letras) !\n";
		}
	}

	if(mensagem != "")
	{
		alert(mensagem);
		TrocaImagem("loading", "hidden");
	}
	else
	{
		index.BuscaItens(document.getElementById("txtBuscaTrilha").value, PaginaAtual, document.getElementById("ddlCampoBusca").selectedIndex, document.getElementById("ddlCampoBusca").value, callback_BuscaItensTrilha);
	}
}

function callback_BuscaItensTrilha(res)
{
	if (res.error)
	{
		AlertaErroAjax(res.error);
	}

	if (res.value)
	{
		if(res.value.indexOf("Redirect:") > -1)
		{
			window.location = res.value.replace("Redirect:", "");
			return;
		}
		document.getElementById("spanResultado").innerHTML = res.value;
	}
	TrocaImagem("loading", "hidden");
}
var arrItensDescricao = new Array();
function SalvarDescricaoTrilhaArray()
{
	var Panel_Selecionados = document.getElementById("Panel_Selecionados");
	if(!Panel_Selecionados)
	{
		return;
	}
	var arrInputCommentProd = Panel_Selecionados.getElementsByTagName("textarea");
	for(var arrI = 0; arrI < arrInputCommentProd.length; arrI++)
	{
		arrItensDescricao[arrInputCommentProd[arrI].id] = arrInputCommentProd[arrI].value;
	}
}

function CarregarDescricaoTrilhaArray()
{
	var Panel_Selecionados = document.getElementById("Panel_Selecionados");
	if(!Panel_Selecionados)
	{
		return;
	}
	var arrInputCommentProd = Panel_Selecionados.getElementsByTagName("textarea");
	for(var arrI = 0; arrI < arrInputCommentProd.length; arrI++)
	{
		if(arrItensDescricao[arrInputCommentProd[arrI].id])
		{
			arrInputCommentProd[arrI].value = arrItensDescricao[arrInputCommentProd[arrI].id];
		}
	}
}

function AdicionarProdTrilha(ProCodigo)
{
	var mensagem = "";

	TrocaImagem("loading", "visible");
	SalvarDescricaoTrilhaArray();
	index.SalvaItens(ProCodigo.toString(), 'A', callback_SalvaItens);
}

function ExcluirProdTrilha(ProCodigo)
{
	var mensagem = "";

	TrocaImagem("loading", "visible");
	SalvarDescricaoTrilhaArray();
	index.SalvaItens(ProCodigo.toString(), 'E', callback_SalvaItens);
}

function ValidaTrilha()
{
	var mensagem = "";

	if(document.getElementById("txtNomeTrilha").value == "")
	{
		mensagem+="Nome inválido (vazio) !\n";
	}

	if(document.getElementById("txtDescriTrilha").value == "")
	{
		mensagem+="Descrição inválida (vazia) !\n";
	}

	if (document.getElementById("spanEscolhidos").innerHTML == "" || document.getElementById("spanEscolhidos").innerHTML.indexOf("Nenhum produto selecionado!") != -1)
	{
		mensagem+="Nenhum produto selecionado para sua Trilha!\n";
	}

	if(mensagem != "")
	{
		alert(mensagem);
	}
	else
	{
		var Panel_Selecionados = document.getElementById("Panel_Selecionados");
		var arrInputCommentProd = Panel_Selecionados.getElementsByTagName("textarea");
		var arrProdutoCodigo = new Array();
		var arrProdutoComentario = new Array();

		for(var arrI = 0; arrI < arrInputCommentProd.length; arrI++)
		{
			arrProdutoCodigo[arrI] = arrInputCommentProd[arrI].id;
			arrProdutoComentario[arrI] = arrInputCommentProd[arrI].value;
		}
		
		index.SalvaTrilha(document.getElementById("txtNomeTrilha").value, document.getElementById("txtDescriTrilha").value, arrProdutoCodigo, arrProdutoComentario, callback_SalvaTrilha);
	}
}

function CancelarTrilha()
{
	TrocaImagem("loading", "visible");
	index.CancelarTrilha(callback_SalvaTrilha);
}

function callback_SalvaTrilha(res)
{
	if (res.error)
	{
		AlertaErroAjax(res.error);
		TrocaImagem("loading", "hidden");
		return;
	}

	if (res.value)
	{
		if(res.value.indexOf("Redirect:") > -1)
		{
			window.location = res.value.replace("Redirect:", "");
			return;
		}
		if(res.value.indexOf("ERRO: ") > -1)
		{
			window.alert(res.value);
			return;
		}

		document.getElementById("spanEscolhidos").innerHTML = "";
		document.getElementById("spanResultado").innerHTML = "";
		document.getElementById("txtDescriTrilha").value = "";
		document.getElementById("txtDescriTrilha").disabled = false;
		document.getElementById("txtBuscaTrilha").value = "";
		document.getElementById("txtBuscaTrilha").disabled = false;
		document.getElementById("txtNomeTrilha").value = "";
		document.getElementById("txtNomeTrilha").disabled = false;
		document.getElementById("criadaEm").innerHTML = "";
		document.getElementById("dataCriacao").innerHTML = "";
		document.getElementById("ultimaAtual").innerHTML = "";
		document.getElementById("dataAtualizacao").innerHTML = "";

		alert(res.value);
		TrocaImagem("loading", "hidden");
		//window.location = "./index.aspx";
	}
}

function callback_SalvaItens(res)
{
	if (res.error)
	{
		AlertaErroAjax(res.error);
		TrocaImagem("loading", "hidden");
	}

	if (res.value)
	{
		document.getElementById("txtDescriTrilha").disabled = false;
		document.getElementById("txtBuscaTrilha").disabled = false;
		document.getElementById("txtNomeTrilha").disabled = false;

		document.getElementById("spanEscolhidos").innerHTML = res.value;
		CarregarDescricaoTrilhaArray();
		TrocaImagem("loading", "hidden");
	}
}

function EditarTrilha(TrilhaCodigo)
{
	TrocaImagem("loading", "visible");

	if (TrilhaCodigo != "0" && TrilhaCodigo != "")
	{
		index.EditarTrilha(TrilhaCodigo.toString(), callback_EditarTrilha)
	}
	else
	{
		TrocaImagem("loading", "hidden");
	}
}

function callback_EditarTrilha(res)
{
	if (res.error)
	{
		AlertaErroAjax(res.error);
	}

	if(res.value[0].toString().indexOf("Redirect:") > -1)
	{
		window.location = res.value[0].toString().replace("Redirect:", "");
		return;
	}
	try
	{
		document.getElementById("txtNomeTrilha").value = res.value[0];
		document.getElementById("txtDescriTrilha").value = res.value[1];
		document.getElementById("criadaEm").innerHTML = "Trilha criada em:";
		document.getElementById("dataCriacao").innerHTML = res.value[2];
		document.getElementById("ultimaAtual").innerHTML = "Última atualização:";
		document.getElementById("dataAtualizacao").innerHTML = res.value[3];

		ExcluirProdTrilha(0);
	}
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}

	TrocaImagem("loading", "hidden");
}
/*
function callback_SalvarComentario(res)
{
	TrocaImagem("loading", "hidden");
	if (res.error)
	{
		AlertaErroAjax(res.error);
	}
	if (res.value)
	{
		i
		f(res.value.indexOf("Exception") > -1 || res.value.indexOf("::") > -1)
		{
			alert(res.value);
		}
	}
}
*/
/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

	function ContinuarParceiro()
	{
		TrocaImagem("loading", "visible");

		var mensagem = "";

		try
		{
			var password = document.getElementById("txtSenha").value;

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				login.ContinuarParceiro(password, Redirect_callback)
			}		
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}	
	
	
	
	
//BANNERS
function ContabilizarCliqueBannerFullSuperiorHome(strCodigoBanner)
{
	try
	{
		BannerSuperiorHome.ContabilizarCliqueBannerFullSuperior(strCodigoBanner,ContabilizarCliqueBannerFullSuperior_CallBack);
	} 
	catch(err)
	{
		//alert(res.value[0]);
		//alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}

function ContabilizarCliqueBannerFullSuperior(strCodigoBanner)
{
	try
	{
		BannerSuperior.ContabilizarCliqueBannerFullSuperior(strCodigoBanner,ContabilizarCliqueBannerFullSuperior_CallBack);
	} 
	catch(err)
	{
		//alert(res.value[0]);
	//	alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerFullSuperior_CallBack(res)
{
	try
	{
		if(res.value[0] != null && res.value[0] != "" && res.value[0] == 1)
		{
			if(res.value[1] != null && res.value[1] != "")
			{
				alert(res.value[1]);
			}
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		else if(res.value[0] != null && res.value[0] != "" && res.value[0] == 0)
		{
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}

function ContabilizarCliqueBannerFullInferior(strCodigoBanner)
{
	try
	{
		BannerInferior.ContabilizarCliqueBannerFullInferior(strCodigoBanner,ContabilizarCliqueBannerFullInferior_CallBack);
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerFullInferior_CallBack(res)
{
	try
	{
		if(res.value[0] != null && res.value[0] != "" && res.value[0] == 1)
		{
			if(res.value[1] != null && res.value[1] != "")
			{
				alert(res.value[1]);
			}
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		else if(res.value[0] != null && res.value[0] != "" && res.value[0] == 0)
		{
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerLateralEsquerda(strCodigoBanner)
{
	try
	{
		BannerLateralEsquerda.ContabilizarCliqueBannerLateralEsquerda(strCodigoBanner,ContabilizarCliqueBannerLateralEsquerda_CallBack);
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerLateralEsquerda_CallBack(res)
{
	try
	{
		if(res.value[0] != null && res.value[0] != "" && res.value[0] == 1)
		{
			if(res.value[1] != null && res.value[1] != "")
			{
				alert(res.value[1]);
			}
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		else if(res.value[0] != null && res.value[0] != "" && res.value[0] == 0)
		{
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerLateralDireita(strCodigoBanner)
{
	try
	{
		BannerLateralDireita.ContabilizarCliqueBannerLateralDireita(strCodigoBanner,ContabilizarCliqueBannerLateralDireita_CallBack);
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerLateralDireita_CallBack(res)
{
	try
	{
		if(res.value[0] != null && res.value[0] != "" && res.value[0] == 1)
		{
			if(res.value[1] != null && res.value[1] != "")
			{
				alert(res.value[1]);
			}
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		else if(res.value[0] != null && res.value[0] != "" && res.value[0] == 0)
		{
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerLandingPage(strCodigoBanner)
{
	try
	{
		BannerLandingPage.ContabilizarCliqueBannerLandingPage(strCodigoBanner,ContabilizarCliqueBannerLandingPage_CallBack);
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function ContabilizarCliqueBannerLandingPage_CallBack(res)
{
	try
	{
		if(res.value[0] != null && res.value[0] != "" && res.value[0] == 1)
		{
			if(res.value[1] != null && res.value[1] != "")
			{
				alert(res.value[1]);
			}
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		else if(res.value[0] != null && res.value[0] != "" && res.value[0] == 0)
		{
			if(res.value[2] != null && res.value[2] != "")
			{
				window.location.href	=	res.value[2];
			}
		}
		
	} 
	catch(err)
	{
		alert("Erro: " + err.message + "\nErro Ajax : " + res.error.Message);
	}
}	

function Ops()
{
	alert("Ops! Nâo implementado...:D");
}

function DataAtual()
{
	var DataHoje = new Date(); 
	var Hora = DataHoje.getHours(); 
	var Minutos = DataHoje.getMinutes(); 
	var HoraFormato = "" + ((Hora >12) ? Hora -12 :Hora) 
	HoraFormato += ((Minutos < 10) ? ":0" : ":") + Minutos
	HoraFormato += (Hora >= 12) ? " PM" : " AM" 
	timerRunning = true; 

	DataExibir = new Date(); 
	DiaExibir = DataExibir.getDay(); 
	MesExibir = DataExibir.getMonth() + 1; 
	DiaSemanaExibir= DataExibir.getDate(); 
	weekday= DiaSemanaExibir; 
		
	myyear= DataExibir.getUTCFullYear(); 
	year = myyear	

	if(DiaExibir == 0) 
	day = " Domingo, ";

	else if(DiaExibir == 1) 
	day = " Segunda, ";

	else if(DiaExibir == 2) 
	day = " Terça, ";

	else if(DiaExibir == 3) 
	day = " Quarta, "; 

	else if(DiaExibir == 4) 
	day = " Quinta, ";

	else if(DiaExibir == 5) 
	day = " Sexta, ";

	else if(DiaExibir == 6) 
	day = " Sábado, "; 

	if(MesExibir == 0) 
	month = " de Janeiro de ";

	else if(MesExibir ==1) 
	month = " de Fevereiro de ";

	else if(MesExibir ==2) 
	month = " de Março de ";

	else if(MesExibir ==3) 
	month = " de April de ";

	else if(MesExibir ==4) 
	month = " de Maio de ";

	else if(MesExibir ==5) 
	month = " de Junho de "; 

	else if(MesExibir ==6) 
	month = " de Julho de ";

	else if(MesExibir ==7) 
	month = " de Agosto de "; 

	else if(MesExibir == 8)
	month = " de Setembro de ";

	else if(MesExibir ==9) 
	month = " de Outubro de "; 

	else if(MesExibir ==10) 
	month = " de Novembro de ";

	else if(MesExibir ==11) 
	month = " de Dezembro de "; 
	
	
	//alert(day + DiaSemanaExibir + month + year + " - " + HoraFormato); 
	return day + PadDigitoZero(DiaSemanaExibir,2) + "/" + PadDigitoZero(MesExibir,2) + "/" + year;

}

function PadDigitoZero(valor, quantidade) 
{ 
	valor = valor.toString(); 
	var pd = ''; 
	if (quantidade > valor.length) 
	{ 
		for (i=0; i < (quantidade-valor.length); i++) 
		{ 
			pd += '0'; 
		} 
	} 
	return pd + valor.toString(); 
} 




function IncrementaQtde(IdTextBox)
{
	if(document.getElementById(IdTextBox))
	{
		var Qtde = document.getElementById(IdTextBox);
		Qtde.value = (Number(Qtde.value) + 1);
	}	
}

function DecrementaQtde(IdTextBox)
{
	if(document.getElementById(IdTextBox))
	{
		var Qtde = document.getElementById(IdTextBox);
		
		if(Qtde.value <= 1 )
				Qtde.value = 1
		else
				Qtde.value = (Number(Qtde.value) - 1);
	}	
}
function RecuperaAguarda(name, base)
{
	try
	{
		if (document.getElementById(base))
		{
			if (document.getElementById(base).innerHTML != "")
			{
				document.getElementById(name).innerHTML = document.getElementById(base).innerHTML;
				document.getElementById(base).innerHTML = "";
			}
		}
	}
	catch(err)
	{
		alert(err.description);
	}
}	

function MsgAguarda(name, base, msg)
{
	try
	{
		if (document.getElementById(base))
		{
			document.getElementById(base).innerHTML = document.getElementById(name).innerHTML;
		}
	
		document.getElementById(name).innerHTML = (msg != "" ? msg : "Aguarde!");
	}
	catch(err)
	{
		if (document.getElementById(base))
		{
			if (document.getElementById(base).innerHTML != "")
			{
				document.getElementById(name).innerHTML = document.getElementById(base).innerHTML;
			}
		}
		
		alert(err.description);
	}
}	

function RedirectTabloide()
{	
	var idReg = document.getElementById("banner_lateral_RegiaoTabloide1_ddlRegioes").options[document.getElementById("banner_lateral_RegiaoTabloide1_ddlRegioes").selectedIndex].value;	
	window.location.href = URLSite + '/tabloide.aspx?regCod='+idReg;
}

function CarregaResumoCarrinho(Url) 
{
	try
	{
		TrocaImagem("loading", "visible");
		resumo_carrinho.CarregaResumoCarrinho(Url, callback_CarregaResumoCarrinho);
	} 
	catch(err)
	{
		alert(err.description);
		TrocaImagem("loading", "hidden");
	}
}

function callback_CarregaResumoCarrinho(res)
{
	if (res.error)
	{
		AlertaErroAjax(res.error);
		TrocaImagem("loading", "hidden");
	}	
	
	if (res.value)
	{
		document.getElementById("divMeuCarrinho").style.display = "block";
		//document.getElementById("link_Cadastre").style.display = res.value[0];
		document.getElementById("h3Topo").className = res.value[1];
		document.getElementById("divContentBg").className = res.value[2];
		document.getElementById("divContent").className = res.value[3];
		document.getElementById("divRodape").className = res.value[4];
		document.getElementById("pNomeProduto").innerHTML = res.value[5];
		document.getElementById("pQtdeProd").innerHTML = res.value[6];
		document.getElementById("divCestaTotal").innerHTML = res.value[7];
		document.getElementById("ddCompCard").style.display = res.value[8];
		
		//Pequeno hack para ajustar o título na tela de categorias e fabricantes, não consegui ajustar via css de jeito nenhum.
		if (res.value[8] == "block")
		{
			if (document.getElementById("divTituloTopo") != null)
			{
				document.getElementById("divTituloTopo").style.height = "26px";
			}
		}
		
		TrocaImagem("loading", "hidden");
	}
}		

function RefazerPedido(PedidoCodigo)
{
	TrocaImagem("loading", "visible");		

	try
	{
		alert('Alguns produtos podem não estar disponíveis ou não ter a quantidade desejada em estoque.\nCaso isso aconteça não serão adicionados na cesta ou terão sua quantidade modificada.\n\nObs: Sua cesta atual será perdida.');
	
		//window.location.href = "../basket/normaliza.aspx?action=refazer&pedidorefazer=" + PedidoCodigo.toString();
		
		detalhes.RefazerPedido(PedidoCodigo.toString(), Redirect_callback)
	}
	catch(err)
	{
		alert(err.description);
		TrocaImagem("loading", "hidden");
	}
}

function CheckContent(evt, local)
{
	var texto = "";
	
	if (local == "Topo")
	{
		texto = document.getElementById("cabecalho_txtBusca").value;
	}
	if (local == "Rodape")
	{
		texto = document.getElementById("rodape_txtBusca").value;
	}
	
	if(texto == "")
	{
		var charCode = (evt.which) ? evt.which : event.keyCode;
		return (charCode>=48 && charCode<=57 || charCode<20 || charCode>=65 && charCode<=90 || charCode>=97 && charCode<=122 || charCode>=127);
	}
	else
	{
		var charCode = (evt.which) ? evt.which : event.keyCode;
		return (charCode>=48 && charCode<=57 || charCode<20 || charCode==32 || charCode==45 || charCode>=65 && charCode<=90 || charCode>=97 && charCode<=122 || charCode>=127);
	}
}




//function ocultarMaster()
//{
//document.getElementById("lbl_CCR_10").style.display = 'none';
//document.getElementById("CCR_10").style.display = 'none';
//}



function ValidaCodigoSeguranca(NumeroCartao, CodSeguranca, OperadoraCodigo) 
    {
        var final1 = NumeroCartao.substr(NumeroCartao.length - 4, 3);//Pega os 3 últimos números do último quarteto do número do cartão
        var final2 = NumeroCartao.substr(NumeroCartao.length - 3, 3);//Pega os 3 primeiros números do último quarteto do número do cartão
  
        if(OperadoraCodigo != '1')
        {
            if (final1 == CodSeguranca || final2 == CodSeguranca)
             return false;
            else
             return true;                            
        }
        else
        {
              final1 = NumeroCartao.substr(NumeroCartao.length - 4, 4);//Pega os números do último quarteto do número do cartão
            
            if (final1 == CodSeguranca)
             return false;
            else
             return true;                
        }

    }
function GravarOpiniaoDHTML()
	{
		var txt = document.getElementById('txtOpiniao').value;
		var pedido = document.getElementById('hddPedido').value;
		var conta = document.getElementById('hddConta').value;
		if(txt != null)
		{
			confirmacao.GravarOpiniaoDHTML(txt, pedido, conta,  callback_GravarOpiniaoDHTML);
		}
		else
		{
			alert('Por favor preencha a Opinião');
		}
	}
	
	function callback_GravarOpiniaoDHTML(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
		}
		else if (res.value)
		{			
			alert(res.value);
			TrocaImagem('dhtmlOpiniao','hidden');
		}
	} 
	
	function SoTexto(par_tecla)
	{
		/* Tratamento para IE e FireFox */
		var var_tecla = par_tecla.keyCode ? par_tecla.keyCode : par_tecla.which;
		/* Tecla Backspace */
		if (var_tecla == 8)
				{return true;}
		/* Tecla Space */
		if (var_tecla == 32)
				{return true;}
		/* Teclas a-z e A-Z */
		if ((var_tecla > 64 && var_tecla < 91) || (var_tecla > 96 && var_tecla < 123))
				{return true;}
		/* Teclas acentuadas e cidilha */
		if ((var_tecla > 191 && var_tecla < 221) || (var_tecla > 223 && var_tecla < 253))
				{return true;}

		return false;
	}

