function LimpaCampoBusca(local)
{
	var palavra;
		
	if (local == "Topo")
	{			
		palavra = document.getElementById("cabecalho_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("%", "");
		
		if (palavra != null && palavra == "Digite o que você procura...")
		{
			document.getElementById("cabecalho_txtBusca").value = "";
		}				
	}
	if (local == "Rodape")
	{
		palavra = document.getElementById("rodape_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("%", "");
				
		if (palavra != null && palavra == "Digite o que você procura...")
		{
			document.getElementById("rodape_txtBusca").value = "";
		}	
	}
}


function LimpaCampoBuscaHome(local)
{
	var palavra;	
	
	if (local == "Topo")
	{			
		palavra = document.getElementById("cabecalhoHome_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("%", "");
		
		if (palavra != null && palavra == "Digite o que você procura...")
		{
			document.getElementById("cabecalhoHome_txtBusca").value = "";
		}				
	}
	if (local == "Rodape")
	{
		palavra = document.getElementById("rodape_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("%", "");
				
		if (palavra != null && palavra == "Digite o que você procura...")
		{
			document.getElementById("rodape_txtBusca").value = "";
		}	
	}
}


/* CABEÇALHO HOME */
function ResumoCestaHome()
	{
		try
		{
			TrocaImagem("loading", "visible");
			cabecalhoHome.PublicaResumoCesta(callback_ResumoCestaHome);
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_ResumoCestaHome(res)
	{
		if (res.error)
		{
			alert(res.error.Message);
			TrocaImagem("loading", "hidden");
		}	
		
		if (res.value)
		{		
			TrocaImagem("loading", "hidden");
		}
	}
	
	function Topo_IdentificaHome()
	{
		try
		{				
			TrocaImagem("loading", "visible");
			cabecalhoHome.Identifica(callback_Topo_IdentificaHome);		
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_Topo_IdentificaHome(res)
	{
		if (res.error)
		{
			alert(res.error.Message);
			TrocaImagem("loading", "hidden");
		}	
		
		if (res.value)
		{
			if (document.getElementById("identificacao"))
			{
				document.getElementById("identificacao").innerHTML = res.value;
			}
			
			TrocaImagem("loading", "hidden");
		}
	}

	function Topo_DataCompletaHome()
	{
		try
		{
			TrocaImagem("loading", "visible");
			cabecalhoHome.RetornaDataCompleta(callback_Topo_DataCompletaHome);
		} 
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
	}

	function callback_Topo_DataCompletaHome(res)
	{
		if (res.error)
		{
			alert(res.error.Message);
			TrocaImagem("loading", "hidden");
		}	
		
		if (res.value)
		{
			if (document.getElementById("DataCompleta"))
			{
				document.getElementById("DataCompleta").innerHTML = res.value;
			}
			
			TrocaImagem("loading", "hidden");
		}
	}
	
	function ExcluiCookieLoginHome()
	{
		cabecalhoHome.ExcluiCookieLogin(ExcluiCookieLoginHome_callback)
	}
	
	function ExcluiCookieLoginHome_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);
		}
	}
	
	function Buscar(local)
	{
		TrocaImagem("loading", "visible");

		/*
		try
		{
		*/
			var mensagem = "";
			var fabricante = "";
			var palavra;
			var categoria;
			var aux_palavra;
			
			if (local == "Topo")
			{
				palavra = document.getElementById("cabecalho_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("%", "");
				categoria = document.getElementById("cabecalho_DropLojas").options[document.getElementById("cabecalho_DropLojas").selectedIndex].value;
				
				if (document.getElementById("cabecalhoHome_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("%", "");
				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;
				}
			}
			
			aux_palavra = palavra;

			if((palavra == "" || palavra == "Digite o que você procura...") && (categoria == "" || categoria == "0") && (fabricante == "" || fabricante == "0"))
			{
				mensagem+="Valor inválido (todos os campos vazio ou inválidos) !\n";
			}
			
			if (mensagem == "" && aux_palavra.replace(/-/g,"") == "")
			{
				mensagem+="Valor inválido (todos os campos vazios ou inválidos) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				cabecalho.ArmazenaDadosBusca(palavra.toString(), categoria.toString(), fabricante.toString(), Redirect_callback_ArmazenaDadosBusca);
			}
		/*
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
		*/
	}
	
	function BuscarHome(local)
	{
		TrocaImagem("loading", "visible");

		/*
		try
		{
		*/
			var mensagem = "";
			var fabricante = "";
			var palavra;
			var categoria;
			var aux_palavra;
			
			if (local == "Topo")
			{
				palavra = document.getElementById("cabecalhoHome_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("%", "");
				categoria = document.getElementById("cabecalhoHome_DropLojas").options[document.getElementById("cabecalhoHome_DropLojas").selectedIndex].value;
				
				if (document.getElementById("cabecalhoHome_DropFabricantes"))
				{
					fabricante = document.getElementById("cabecalhoHome_DropFabricantes").options[document.getElementById("cabecalhoHome_DropFabricantes").selectedIndex].value;
				}
				else
				{
					fabricante = 0;
				}
			}
			if (local == "Rodape")
			{
				palavra = document.getElementById("rodape_txtBusca").value.replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("&", "").replace("%", "");
				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;
				}
			}
			
			aux_palavra = palavra;

			if((palavra == "" || palavra == "Digite o que você procura...") && (categoria == "" || categoria == "0") && (fabricante == "" || fabricante == "0"))
			{
				mensagem+="Valor inválido (todos os campos vazio ou inválidos) !\n";
			}
			
			if (mensagem == "" && aux_palavra.replace(/-/g,"") == "")
			{
				mensagem+="Valor inválido (todos os campos vazios ou inválidos) !\n";
			}

			if(mensagem != "")
			{
				alert(mensagem);
				TrocaImagem("loading", "hidden");
			}
			else
			{
				cabecalhoHome.ArmazenaDadosBusca(palavra.toString(), categoria.toString(), fabricante.toString(), Redirect_callback_ArmazenaDadosBusca);
			}
		/*
		}
		catch(err)
		{
			alert(err.description);
			TrocaImagem("loading", "hidden");
		}
		*/
	}
	
	function Redirect_callback_ArmazenaDadosBusca(res)
	{
		if (res.error)
		{
			alert(res.error.Message);
			TrocaImagem("loading", "hidden");
		}

		if (res.value)
		{
			if (res.value == "1")
			{
				alert("Valor inválido (todos os campos vazios ou inválidos) !\n");
			}
			else
			{
				window.location.href = res.value;
			}
		}
	}
/* FIM - CABEÇALHO HOME*/