    (function(){
      var a=window.alert;
      window.alert=function(q)
      {
	    if (q.toLowerCase() != "unknown" && q.toLowerCase() != "desconhecido")
	    {
		    a(q); 
	    }
      }
    })();

    
    function DecrementaQtde(id, maxVenda)
    {
        var oQtde = document.getElementById(id);
        if (oQtde.value=="1") return;
        ArmazenaValorAntigo(oQtde);
        oQtde.value = parseInt(oQtde.value)-1;
        AtualizaQtdeItem(oQtde,maxVenda);
    }
    
    function IncrementaQtde(id,  maxVenda)
    {
        var oQtde = document.getElementById(id);
        ArmazenaValorAntigo(oQtde);
        oQtde.value = parseInt(oQtde.value)+1;
        AtualizaQtdeItem(oQtde,maxVenda);
    }		
	
	function AlertaErroAjax(error) {   
	var message = "";

	if (typeof error.Message !== "undefined"){
		message = error.Message
	} else if (typeof error.message !== "undefined"){
		message = error.message
	} else {
		message = String(error);
	}

	if (message.toLowerCase() != "unknown" && message.toLowerCase() != "desconhecido") {
		alert(message);
	}
}

	
	function Redirect_callback(res)
	{
	    var erro = false;

		if (res.error)
		{
			AlertaErroAjax(res.error);
			TrocaImagem("loading", "hidden");
			
			erro = true;
		}

		if (res.value)
		{
		    if(res.value.indexOf('http') > -1)
		    {
    			window.location.href = res.value;
            }
            else
            {
		        alert(res.value);
		        erro = true;            
            }
		}
		
		if(erro)
		{
			if (document.getElementById("btComprarProduto") && document.getElementById("btAguarde"))
			{
				document.getElementById("btComprarProduto").style.display = 'block';
				document.getElementById("btAguarde").style.display = 'none';
			}		
		}
	}

	function ValidaEmail(email)
	{
		var retorno = true;

		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
		  
		if (!filter.test(email)) 
		{
			retorno = false;
		}
		
		return retorno;
	}
    
	// (1) faleconosco.aspx
	function VerificaEmailFaleConosco()
	{
		var spanMsgValidacao	= document.getElementById('spanMsgValidacaoEmail');
		var campo				= document.getElementById('txtEmail');
			
		if(Trim(campo.value) == '' || ValidaEmail(Trim(campo.value)))
		{
			spanMsgValidacao.innerHTML = '';	
		}
		else
		{
			spanMsgValidacao.innerHTML	= '« E-mail inválido';
		}
	}
	
	// (1) faleconosco.aspx
	function VerificaTelefoneFaleConosco()
	{
		var spanMsgValidacao		= document.getElementById('spanMsgValidacaoTelefone');
		var ddd						= document.getElementById('txtDDD');
		var telefone				= document.getElementById('txtTelefone');
		var retorno					= '';
		
		if(Trim(ddd.value) == '' || (Number(Trim(ddd.value)).toString() != 'NaN' && Trim(ddd.value).length == 2))
		{
			spanMsgValidacao.innerHTML = '';	
			
			if(Trim(telefone.value).replace('-','') == '' || Number(Trim(telefone.value).replace('-','')).toString() != 'NaN')
			{
				if(Trim(ddd.value) != '' || Trim(telefone.value) != '')
				{
					if(Trim(ddd.value) == '' || Trim(telefone.value) == '' || Trim(telefone.value).replace('-','').length < 7)
					{
						spanMsgValidacao.innerHTML	= '« Incompleto';
						retorno						= '« Incompleto';					
					}
				}				
			}
			else
			{
				spanMsgValidacao.innerHTML	= '« Telefone inválido';
				retorno						= '« Telefone inválido';
			}		
		}
		else
		{
			if(Number(Trim(ddd.value)).toString() == 'NaN')
			{
				spanMsgValidacao.innerHTML	= '« DDD inválido';
				retorno						= '« DDD inválido';
			}
			else
			{
				spanMsgValidacao.innerHTML	= '« DDD incompleto';
				retorno						= '« DDD incompleto';
			}
		}
		return retorno;
	}	
	
	// neutro / limar 
	function AtivaCampo(campo)
	{
		campo.style.backgroundColor = '#e4e7f7';
	}
	
	function DesativaCampo(campo)
	{
		campo.style.backgroundColor = '#ffffff';		
	}
	
	// (0)
	function NaoExisteMeioPgto(URL)
	{
		alert('Nenhuma forma de pagamento disponível para o valor desse pedido!');
		//window.location.href = URL;
	}
	    
    // (0)
	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>';
		}
	}
	
    // (1) comparar.aspx.cs
	function RetirarComparador(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");

			if (confirm('Você tem certeza que deseja retirar este produto do Comparador?'))
			{
				comparar.RetirarComparador(ProdutoCodigo, callback_RetirarComparador);
			}
			else
			{
				TrocaImagem("loading", "hidden");
			}
		} 
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_RetirarComparador(res)
	{
		if (res.error)
		{
			AlertaErroAjax(res.error);
		}
		else if (res.value)
		{
			window.location.href = res.value;
		}
	}
	
	function Gift(ItemCodigo, valor)
	{
		document.getElementById("GiftTmp" + ItemCodigo).value = valor;
	}
	
    
	function ValidaContaCorrenteRecuperado(campo)
	{
		if(campo.checked == false)
		{
			if(document.getElementById('ckCco')!= null)
			{
				document.getElementById('txtCcoValor').disabled = true;
				document.getElementById('ProsseguirContaCorrente').style.display = 'none';
				document.getElementById('txtCcoValor').value = '';
			}

			alteracaoFormaPagamento.ValidaContaCorrente(campo.checked, callback_ValidaContaCorrente)
		}
		else
		{
			if(document.getElementById('ckCco')!= null)
			{
				document.getElementById('txtCcoValor').disabled = false;
				document.getElementById('ProsseguirContaCorrente').style.display = '';
				document.getElementById('txtCcoValor').focus();
				document.getElementById('txtCcoValor').select();
			}
		}
	}
		
	
	// (1) alteracaoFormaPagamento.aspx
	function ArmazenaContaCorrenteRecuperado(campo)
	{
	    if(document.getElementById('ckCco'))
		{
	        if(document.getElementById('ckCco').checked)
	        {
		        alteracaoFormaPagamento.ArmazenaContaCorrente(Trim(campo.value), callback_ArmazenaContaCorrente);
            }
        }
	}
	
	
	// (1) alteracaoFormaPagamento.aspx
	function ValidaMeioPagamentoRecuperado(MeioCodigo)
	{
		TrocaImagem("loading", "visible");

		try
		{
			if (MeioCodigo.checked)
			{
				if (document.getElementById("OperadoraCodigo").value != MeioCodigo.value.substring(4))
				{
					//Se foi escolhido Cartão Amex, Hipercard ou Dinners tratar quantidade de dígitos do cartão
					//***********************************************************************************
					if (MeioCodigo.value.substring(4) == "1")
					{
						document.getElementById("CartaoNumero").maxLength = '15';
						document.getElementById("CartaoNumero").onkeyup = function()
						{
							if(this.value.length == 15) document.getElementById('CartaoCodigo').focus();
						};
						
						if(document.getElementById("CartaoNumero").value.length > 15)
						{
							document.getElementById("CartaoNumero").value = document.getElementById("CartaoNumero").value.substring(0,15);
						}						
					}
					else if (MeioCodigo.value.substring(4) == "7")
					{
						document.getElementById("CartaoNumero").maxLength = '19';
						document.getElementById("CartaoNumero").onkeyup = function()
						{
							if(this.value.length == 19) document.getElementById('CartaoCodigo').focus();
						};
					}
					else if (MeioCodigo.value.substring(4) == "6")
					{
						document.getElementById("CartaoNumero").maxLength = '14';
						document.getElementById("CartaoNumero").onkeyup = function()
						{
							if(this.value.length == 14) document.getElementById('CartaoCodigo').focus();
						};
						
						if(document.getElementById("CartaoNumero").value.length > 14)
						{
							document.getElementById("CartaoNumero").value = document.getElementById("CartaoNumero").value.substring(0,14);
						}						
					}					
					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);
    						}
                        }
					}
					//***************************************************************************************
			
					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)
							{
							    if(campo.id != 'formcadastro_rdnPJ' && campo.id != 'formcadastro_rdnPF')
								    campo.checked = false;
							}
						}
					}

					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")
					{
						alteracaoFormaPagamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_CCR);
					}
					else if (MeioCodigo.value.substring(0,3) == "BOL")
					{					
						document.getElementById("OperadoraTipo").value = "BOL";
						alteracaoFormaPagamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_BOL);
					}
					else if (MeioCodigo.value.substring(0,3) == "DEB")
					{
						alteracaoFormaPagamento.ValidaMeioPagamento(MeioCodigo.value.substring(4), callback_ValidaMeioPagamento_DEB);
					}
				}
				else
				{
					TrocaImagem("loading", "hidden");
				}
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

	    
    // (...) afiliados/relatorios/cadastro.aspx
    //     afiliados/relatorios/vendas.aspx 
    //     afiliados/relatorios/visitas.aspx
    //     basket/index.aspx
    //     consultaPrazoEntrega.aspx
    //     detalhes.aspx ...
	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)
		{
			AlertaErroAjax(err);
		}

		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
	 *
	 */
    
    // lima / tirar chamadas
	function TrocaImagem(name, visibilidade)
	{
		try
		{
			if(document.getElementById(name))
			{
				document.getElementById(name).style.visibility = visibilidade;
			}
		}
		catch(err)
		{
		}
	}

    // (2) detalhes.aspx
    //     listas/resultadoBusca.aspx.cs 
	function CarregaListas(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			detalhes.CarregaListas(ProdutoCodigo, callback_CarregaListas);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
	
	function callback_CarregaListas(res)
	{
    	if (res.error)
		{
			AlertaErroAjax(res.error);
		}

		if (res.value)
		{
			document.getElementById("FieldSetListas").innerHTML = res.value;
		}
		
		TrocaImagem("loading", "hidden");
	}
	 
    // duvida (4)
	function CarregaSKUBusca(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			busca.CarregaSKUBusca(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
    // duvida (1)
	function CarregaSKUCategoria(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			categoria.CarregaSKUCategoria(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
    // (1) comparar.aspx
    //     duvida
	function CarregaSKUComparador(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			comparar.CarregaSKUComparador(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
    // duvida
	function CarregaSKUFabricante(ProdutoCodigo)
	{
		try
		{
			TrocaImagem("loading", "visible");
			fabricante.CarregaSKUFabricante(ProdutoCodigo.toString(), callback_CarregaSKUBusca);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_CarregaSKUCross(res)
	{
		if (res.error)
		{
			//AlertaErroAjax(res.error);
			window.location.href = window.location;
		}

    	if (res.value)
		{
		    if(res.value[5])
		    {
		        window.location.href = res.value[5];
		    }
		    else
		    {
			    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_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;
					}
				}
			}

            if(res.value[2])
            {
                document.location.href = res.value[2];
            }
            
            // Trecho que seleciona a cor, caso exista apenas um valor
            if (res.value[3] && res.value[4] && res.value[5])
			{
		        if (res.value[3] != "" && res.value[4] != "" && res.value[5] != "")
		        {
		            ArmazenaOpcao(res.value[5].toString(), res.value[4].toString(), res.value[3].toString(), 'I');
		        }
			}
            jQuery(".indisp").fancybox({ height:96, width:500, type:'iframe' });
			TrocaImagem("loading", "hidden");
		}
	}
    
    // duvida
	function imageExists(url, fxRet)
    {
		var img = document.createElement("img");
		img.onload = function() { fxRet(true,this);}
		img.onerror = function() { fxRet(false,this);}
		img.src = url;
	}
    
    // duvida
	function Trim(STRING)
	{
		STRING = LTrim(STRING);
	    
		return RTrim(STRING);
	}   
    
    // duvida
	function RTrim(STRING)
	{
		while(STRING.charAt((STRING.length -1))==" ")
		{
			STRING = STRING.substring(0,STRING.length-1);
		}
	    
		return STRING;
	}

    // duvida
	function LTrim(STRING)
	{
		while(STRING.charAt(0)==" ")
		{
			STRING = STRING.replace(STRING.charAt(0),"");
		}
	    
		return STRING;
	}
    
    //duvida
	function reverse(inp)
	{
		var outp = "";

		for (i = 0; i <= inp.length; i++)
		{
			outp = inp.charAt (i) + outp ;
		}

		return outp;
	}
    
    // (3) detalhes.aspx.cs
    //     listadesejos/index.aspx.cs
    //     listas/acessoLive.aspx.cs
    function VerificaValePresente(ProdutoCodigo, CarValCod1, CarValCod2, CarValCod3, CarValCod4, CarValCod5, VitrineCodigo)
    {
        detalhes.VerificaValePresente(ProdutoCodigo.toString(), CarValCod1.toString(), CarValCod2.toString(), CarValCod3.toString(), CarValCod4.toString(), CarValCod5.toString(), VitrineCodigo.toString(), VerificaValePresente_callback)
    }

    function VerificaValePresente_callback(res)
    {
        if (res.value[0] == '1')
        {
            detalhes.AdicionarItemCesta(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), Redirect_callback)        
        }
	    else if(res.value[0] == '2')
	    {
	        document.location.href = res.value[1];
	    }
	    else if(res.value[0] == '3')
	    {
	        alert('Sua cesta de compras já possui itens.\nVale-presentes devem ser comprados separadamente.');
	        
			if (document.getElementById("btComprarProduto") && document.getElementById("btAguarde"))
			{
				document.getElementById("btComprarProduto").style.display = 'block';
				document.getElementById("btAguarde").style.display = 'none';
			}	        
	    }
	    else if(res.value[0] == '4')
	    {
	        if(confirm('Existe um ou mais vale-presentes na sua cesta de compras. Eles devem ser comprados separadamente.\nSe adicionar este novo item, o(s) vale-presente(s) da cesta serão excluídos.\nDeseja continuar?'))
	        {
	            detalhes.AdicionarItemCesta(res.value[1].toString(), res.value[2].toString(), res.value[3].toString(), res.value[4].toString(), res.value[5].toString(), res.value[6].toString(), res.value[7].toString(), Redirect_callback)        
	        }
	        else
	        {
			    if (document.getElementById("btComprarProduto") && document.getElementById("btAguarde"))
			    {
				    document.getElementById("btComprarProduto").style.display = 'block';
				    document.getElementById("btAguarde").style.display = 'none';
			    }	        	        
	        }
	    }
    }
    
    // (2) busca.aspx.cs
    //     includes/barra_paginacao.ascx.cs
	function MudaPaginaBusca(pagina)
	{
		try
		{
			TrocaImagem("loading", "visible");
			busca.MudaPaginaBusca(pagina.toString(), Redirect_callback);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
    // (2) categoria.aspx.cs
    //     includes/barra_paginacao.ascx.cs
	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)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
    // (1)  includes/barra_paginacao.ascx.cs
	function MudaPaginaVP(pagina)
	{
		try
		{
			TrocaImagem("loading", "visible");
			valePresente.MudaPaginaVP(pagina.toString(), Redirect_callback);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
	
	// (2) fabricante.aspx.cs
    //     includes/barra_paginacao.ascx.cs
	function MudaPaginaFabricante(pagina)
	{
		try
		{
			var Fabricante = document.getElementById("FabricanteCodigo").value;

			TrocaImagem("loading", "visible");
			fabricante.MudaPaginaFabricante(pagina.toString(), Fabricante.toString(), Redirect_callback);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

    // duvida
	function AlteraPedidoRecorrente(CestaCodigo){
	TrocaImagem("loading", "visible");

		try
		{
			index.AlteraPedidoRecorrente(CestaCodigo.toString(), callback_AlteraPedidoRecorrente);
		}
		catch(err)
		{
			AlertaErroAjax(err);
			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 replaceAll(string, token, newtoken) {
	    while (string.indexOf(token) != -1) {
 		    string = string.replace(token, newtoken);
	    }
	    return string;
    }	
	

	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();
			}
		}
	}
    
    // duvida
	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);
		}
	}
	
	// duvida
    function LimpaCpf()
    {
        if(Trim(document.getElementById('CartaoCNPJ').value) != '')
        {
            document.getElementById('CartaoCPF').value = '';
        }        
    }
    
    // duvida
    function LimpaCnpj()
    {
        if(Trim(document.getElementById('CartaoCPF').value) != '')
        {
            document.getElementById('CartaoCNPJ').value = '';
        }
    }    
    
    // duvida
	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);
		 }
	}
    
    // duvida
	function Mascara2(e, src, mask)
	{
		var key;

		if (window.event)
		{
			key = event.keyCode;
		}
		else
		{
			key = e.which;
		}

		if (key != 8)
		{
			Mascara(src, mask);
		}
	}
    
    // duvida
    function FormataValor(campo,tammax,teclapres) 
     {
	    var tecla = teclapres.keyCode;

	    vr = campo.value;
	    vr = vr.replace( "/", "" );
	    vr = vr.replace( "/", "" );
	    vr = vr.replace( ",", "" );
	    vr = vr.replace( ".", "" );
	    vr = vr.replace( ".", "" );
	    vr = vr.replace( ".", "" );
	    vr = vr.replace( ".", "" );

	    tam = vr.length;

	    if (tam < tammax && tecla != 8)
	    {
		    tam = vr.length + 1;
	    }

	    if (tecla == 8 )
	    {
		    tam = tam - 1; 
	    }

	    if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)
	    {
		    if (tam <= 2)
		    { 
			    campo.value = vr; 
		    }
		    else if ((tam > 2) && (tam <= 5))
		    {
			    campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam );
		    }
		    else if ((tam >= 6) && (tam <= 7))
		    {
			    campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
		    }
	    }
    }
    
    // duvida
	function Continuar(tipo)
	{
		TrocaImagem("loading", "visible");

		var mensagem = "";
		var username = "";
		var cep = "";

		try
		{
			if (tipo == "S" || tipo == "SA")
			{
				var username = document.getElementById("txtEmail").value;
			}
			else if (tipo == "P" || tipo == "PA")
			{
				var username = document.getElementById("txtEmail2").value;
			}

			var password = document.getElementById("txtSenha").value;

			if (document.getElementById("txtCep1"))
			{
				cep = document.getElementById("txtCep1").value;
			}


			if (Trim(username) == "")
			{
				mensagem+="E-mail Inválido (vazio) !\n";
			}

			if (tipo == "S" || tipo == "SA")
			{
				if (Trim(password) == "")
				{
					mensagem+="Senha inválida (vazia) !\n";
				}
			}
			else if (tipo == "P" || tipo == "PA")
			{
				if (Trim(cep) == "")
				{
					mensagem+="CEP inválido (vazio) !\n";
				}
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
			    if(tipo == "PA" || tipo == "SA")
			    {
			        loginAfiliado.Continuar(username, password, cep, tipo, Redirect_callback)
			    }
			    else
			    {
			        login.Continuar(username, password, cep, tipo, Redirect_callback)
			    }
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}
    
    // pedido
	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
				{
				    if(res.value[1])
				    {
					    alert(res.value[1]);
					}
				    if(res.value[2])
				    {
					    window.location = res.value[2];
					}					
				}
			}

			txtPedCodigo.value = '';
			TrocaImagem("loading", "hidden");
		}
		catch(err)
		{
			alert(err.message);
		}

		TrocaImagem("loading", "hidden");
	}
    
    // duvida
	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;
		}
	}
    
    // duvida (detalhes e catalogo)
	function SelecionaNota(nota)
	{
		var estrelas	= document.getElementById("spanAvaliacao");
		
		if(estrelas != null)
		{
			estrelas.style.width = (nota.value * 20).toString() + '%';
		}
	}
	
	// (1) alteracaoFormaPagamento
	function janelaHipercard(url,width,height,texto)
    {
	    
		if (!width || width == "")
		{
			width = window.screen.width;
		}

		if (!height || height == "")
		{
			height = window.screen.height;
		}

		var w = window.screen.width;
		var h = window.screen.height;
		var l = (w-width)/2;
		var t = (h-height)/2;

        window.showModalDialog(url,texto,"dialogWidth:" + width + "px;dialogHeight:" + height + "px;fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, top="+t+", left="+l);
    }

    // duvida
	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;
				}
			}
		}
	}
    
    // duvida / limar
	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);
		}
	}
    
    // duvida / limar
	function CamposPreenchidosFaleConosco()
	{
		retornoCamposPreenchidosFaleConosco = true;

		try
		{
			var CorErro                 			= '#FF0000';
			var CorOk                   			= '#E2E2E2';

			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');


			MudaCorBorda(txtNome, CorOk);
			MudaCorBorda(txtEmail, CorOk);
			MudaCorBorda(txtDDD, CorOk);
			MudaCorBorda(txtTelefone, CorOk);
			MudaCorBorda(txtMensagem, CorOk);
			MudaCorBorda(ddlAssunto, CorOk);

			if(Trim(txtNome.value) == '')		{MudaCorBorda(txtNome, CorErro);			retornoCamposPreenchidosFaleConosco = false;}
			if(Trim(txtEmail.value) == '')		{MudaCorBorda(txtEmail, CorErro);			retornoCamposPreenchidosFaleConosco = false;}
			if(Trim(txtDDD.value) == '')		{MudaCorBorda(txtDDD, CorErro);				retornoCamposPreenchidosFaleConosco = false;}
			if(Trim(txtTelefone.value) == '')	{MudaCorBorda(txtTelefone, CorErro);		retornoCamposPreenchidosFaleConosco = false;}
			if(Trim(txtMensagem.value) == '')	{MudaCorBorda(txtMensagem, CorErro);		retornoCamposPreenchidosFaleConosco = false;}
			if(Trim(ddlAssunto.value) == '')	{MudaCorBorda(ddlAssunto, CorErro);			retornoCamposPreenchidosFaleConosco = false;}
			
			if(Trim(txtEmail.value) != '' && !ValidaEmail(Trim(txtEmail.value)))
			{
				MudaCorBorda(txtEmail, CorErro);				
				retornoCamposPreenchidosFaleConosco = false;
				document.getElementById('spanMsgValidacaoEmail').innerHTML = '« E-mail inválido';
			}

			if(Trim(txtDDD.value) != '' && Trim(txtTelefone.value) != '' && VerificaTelefoneFaleConosco() != '')
			{
				MudaCorBorda(txtDDD, CorErro);				
				MudaCorBorda(txtTelefone, CorErro);
				retornoCamposPreenchidosFaleConosco = false;
			}


	        if(!retornoCamposPreenchidosFaleConosco)
			{
				alert('Preencha os campos corretamente!');
			}
		}
		catch(err)
		{
			document.write("<!--" + err.description + "-->");
		}

		return retornoCamposPreenchidosFaleConosco;
	}
    
    // duvida / limar
	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);
		}
	}

    // (1) institucionais/faleconosco.aspx.cs
	function EnviarMensagem(botao)
	{
		try
		{
			OmitirBotao(botao);
		
			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())
			{
				faleconosco.EnviarMensagem(txtNome.value,txtSobrenome.value,txtEmail.value,txtDDD.value,txtTelefone.value,ddlAssunto.options[ddlAssunto.selectedIndex].text,txtMensagem.value,EnviarMensagem_CallBack);
			}
			else
			{
				MostrarBotao(botao);
			}
		}
		catch(err)
		{
			alert(err.message);
			MostrarBotao(botao);
		}
	}

	function EnviarMensagem_CallBack(resp)
	{
		try
		{
			var lblMsgErro = document.getElementById('lblMsgErro');
			if(resp.value[0] == "1")
			{
				//lblMsgErro.innerHTML = resp.value[1];
				
				document.location.href = resp.value[2];
				
				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');
				
				ddlAssunto.value	= "";
				txtNome.value		= "";
				txtSobrenome.value	= "";
				txtEmail.value		= "";
				txtDDD.value		= "";
				txtTelefone.value	= "";
				txtMensagem.value	= "";
			}
			else
			{
       		    if (resp.value[1].indexOf("http://") > -1 || resp.value[1].indexOf("https://") > -1)
		        {
		            document.location.href = resp.value[1];
		        }
		        else
		        {
	    			lblMsgErro.innerHTML = resp.value[1];
	    	    }
			}
			
			MostrarBotao(document.getElementById('btnEnviar'));

		}
		catch(err)
		{
			lblMsgErro.value = err.message;
		}
	}

/* 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(Trim(password) == '')
			{
				mensagem = 'Senha inválida!';
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				login.ContinuarParceiro(password, Redirect_callback)
			}		
		} 
		catch(err)
		{
			AlertaErroAjax(err);
			TrocaImagem("loading", "hidden");
		}
	}

    function OmitirBotao(botao)
    {
	    try
	    {
	        if(document.getElementById('msg_' + botao.id))
	        {
		        document.getElementById('msg_' + botao.id).style.display = '';
            }
		    botao.style.display = 'none';	
	    }
	    catch(err)
	    {
		    AlertaErroAjax(err);
	    }
    }

    function MostrarBotao(botao)
    {
	    try
	    {
		    botao.style.display = '';	
    		
	        if(document.getElementById('msg_' + botao.id))
	        {		
		        document.getElementById('msg_' + botao.id).style.display = 'none';
            }
	    }
	    catch(err)
	    {
		    AlertaErroAjax(err);
	    }
    }
   
    
    function Avaliar(nota)
	{
		for (i=1; i<=5; i++)
		{
			document.getElementById("star" + i).src = (i <= nota ? document.getElementById("star" + i).src.replace("star_off", "star_ok").replace("star_on", "star_ok") : document.getElementById("star" + i).src);
		}
		
		document.getElementById("txtNota").value = nota;
		
		ResetPreview();
	}
    
	function Preview(nota)
	{
		for (i=1; i<=5; i++)
		{
			document.getElementById("star" + i).src = (i <= nota ? document.getElementById("star" + i).src.replace("star_off", "star_on").replace("star_ok", "star_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("star_off", "star_ok").replace("star_on", "star_ok") : document.getElementById("star" + i).src.replace("star_on", "star_off").replace("star_ok", "star_off"));
			}
		}
		else
		{
			for (i=1; i<=5; i++)
			{
				document.getElementById("star" + i).src = document.getElementById("star" + i).src.replace("star_on", "star_off").replace("star_ok", "star_off");
			}
		}
	}
	
	
	function GuardarAviso()
	{
		GuardarAviso(0);
	}
    

	function GuardarAviso(ProdutoCodigo, ProdutoValorCaracteristicaCodigo)
	{
		var Email = Trim(document.getElementById("txtEmailAviso_" + ProdutoCodigo + "_" + ProdutoValorCaracteristicaCodigo).value);
		var mensagem = "";

		TrocaImagem("loading", "visible");

		try
		{
			if(Trim(Email) == "")
			{
				mensagem+="Preencha o E-mail!\n";
				document.getElementById("txtEmailAviso_" + ProdutoCodigo + "_" + ProdutoValorCaracteristicaCodigo).focus();
				document.getElementById("txtEmailAviso_" + ProdutoCodigo + "_" + ProdutoValorCaracteristicaCodigo).select();
			}
			else if(!ValidaEmail(Trim(Email)))
			{
				mensagem+="E-mail inválido!\n";
				document.getElementById("txtEmailAviso_" + ProdutoCodigo + "_" + ProdutoValorCaracteristicaCodigo).focus();
				document.getElementById("txtEmailAviso_" + ProdutoCodigo + "_" + ProdutoValorCaracteristicaCodigo).select();
			}			

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				OmitirBotao(document.getElementById('aAvisar' + ProdutoCodigo.toString() + '_' + ProdutoValorCaracteristicaCodigo.toString()));
				detalhes.GuardarAviso(Email, ProdutoCodigo.toString(), ProdutoValorCaracteristicaCodigo.toString(), callback_GuardarAviso)
			}
		}
		catch(err)
		{
			AlertaErroAjax(err);
			MostrarBotao(document.getElementById('aAvisar' + ProdutoCodigo.toString() + '_' + ProdutoValorCaracteristicaCodigo.toString()));
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_GuardarAviso(res)
	{
		if (res.error)
		{
		    document.location.href = res.error.Message;
		}
        else
        {
		    if (res.value[0])
		    {
			    alert(res.value[0]);
			    document.getElementById(res.value[1]).value = "";
			    MostrarBotao(document.getElementById('aAvisar' + res.value[1].toString().substring(14, res.value[1].toString().length)));
			    TrocaImagem("loading", "hidden");
		    }
        }		    
	}
	
	
	function AlterarCampo(campo, tamanho)
	{
	    if(campo.value.length == tamanho)
	    {
	        if(document.getElementById('FormAfiliado_txtTelFaxDdd'))
	            document.getElementById('FormAfiliado_txtTelFaxDdd').focus();
	        if(document.getElementById('formcadastro_txtTelFaxDdd'))
	            document.getElementById('formcadastro_txtTelFaxDdd').focus();
	        if(document.getElementById('txtTelFaxDdd'))
	            document.getElementById('txtTelFaxDdd').focus();
	        else if(document.getElementById('txtMensagem'))
	            document.getElementById('txtMensagem').focus();
	    }
	}
	
	function RetiraNewsLetter()
    {
        txtEmail = document.getElementById('formcadastro_txtEmail');
        
        if(ValidaEmail(Trim(txtEmail.value)))
        {
            RemoveEmailNewsLetter.RemoveNewsLetter(txtEmail.value, RetiraNewsLetter_CallBack);
        }
        else
        {
            alert('Email Inválido.');
        }
    } 

    function RetiraNewsLetter_CallBack(res)
    {
        if (res.error)
		{
			AlertaErroAjax(res.error);
		}
		
		if(res.value)
		{
		    alert(res.value);
		    document.getElementById('formcadastro_txtEmail').value = '';
		}
    }

