(function($)
{
	$(document).ready(function(event)
	{
		var imagem, caminho_imagens_cadastro = webPath + "Content/images/cadastro/";
		for (imagem in ["check.jpg", "check-on.jpg", "radio.jpg", "radio-on.jpg"])
		{
			$(document).append($("<img />").attr("src", caminho_imagens_cadastro + imagem).bind("load", function(event)
			{
				var $this = $(this);
				$this.remove();
			}));
		}

		if ($("div.imageslider").length > 0)
		{

			var increment = parseInt($("div.imageslider div.slider div.viewport ul.list li:first").css("marginRight")) + parseInt($("div.imageslider div.slider div.viewport ul.list li:first").css("width"));
			$("div.imageslider div.slider div.left").hide();
			$("div.imageslider div.slider div.right").live("mouseup", function()
			{
				var total = $("div.imageslider div.slider div.viewport ul.list").find("li").length * increment - (increment * 3);
				var margin = parseInt($("div.imageslider div.slider div.viewport ul.list").css("marginLeft"));
				$("div.imageslider div.slider div.viewport ul.list").animate({ marginLeft: margin - increment }, 500);
				if ((margin - increment) == (total * (-1)))
					$("div.imageslider div.slider div.right").hide();
				$("div.imageslider div.slider div.left").show();
			});

			$("div.imageslider div.slider div.left").live("mouseup", function()
			{
				var total = $("div.imageslider div.slider div.viewport ul.list").find("li").length * increment - (increment * 3);
				var margin = parseInt($("div.imageslider div.slider div.viewport ul.list").css("marginLeft"));
				$("div.imageslider div.slider div.viewport ul.list").animate({ marginLeft: margin + increment }, 500);
				if ((margin + increment) == 0)
					$("div.imageslider div.slider div.left").hide();
				$("div.imageslider div.slider div.right").show();
			});

			$("div.nutra-side-content ul.list li").hide();
			$("div.nutra-side-content ul.list li:first").show();
			$("div.nutra-side-content ul.list li:first ul li").show();
			$("div.imageslider div.slider div.viewport ul.list li").each(function()
			{
				$(this).bind("mouseup", function()
				{
					var classe = $(this).attr("class");
					$("div.nutra-side-content ul.list li").hide();
					$("div.nutra-side-content ul.list").find("li." + classe).show();
					$("div.nutra-side-content ul.list li." + classe + " ul li").show();
				});
			});

		}

		if ($("#divHomePilares").length > 0)
		{
			$(".pilares-sessoes-content").find(".pilares-sessoes-box").each(function(e)
			{
				$(this).find('.pilares-sessoes-box-pag a').each(function(e)
				{
					if ($(this).hasClass('anterior'))
					{
						$(this).bind("click", function(e)
						{
							$a = $(this);
							var i = $a.parent().find(".contador").val();
							i--;
							$a.parent().find(".contador").val(i);
							var total = $a.parent().find(".total").val();
							total--;

							$.ajax({
								url: webPath + "Util/PilaresCarregaContedudo",
								cache: false,
								type: "POST",
								data: {
									coluna: $a.parent().find(".coluna").val(),
									item: i
								},
								success: function(data)
								{
									$box = $a.parent().parent().find(".pilares-sessoes-box-main");

									var $box_side = $a.parent().parent().find(".pilares-sessoes-box-side");
									var $box_pag = $a.parent().parent().find(".pilares-sessoes-box-pag");

									$box_side.find("h4").html(data.Titulo);
									$box_side.find("p").html(data.Chamada);
									$box_pag.find("a.continue-lendo").attr("href", $a.parent().find(".url").val() + data.Url);

									if ($box.parent().filter("#div-use-bem").size() === 0)
									{
										$box.find("img").attr("src", webPath + "Content/images/pilares/" + data.AutorImagem);
										$box.find("img").attr("alt", "por " + data.Autor);
										$box.find("img").attr("title", "por " + data.Autor);
										$box.find("h5").html("por " + data.Autor);
									}
								},
								error: function(a, status, c)
								{
									alert("erro");
								}
							});


							if (i == 0)
								$a.hide();
							//                            if (total > 5)
							//                                total = 5;
							if (i < total)
								$a.parent().find("a.proximo").show();


						});
						$(this).hide();
					}
					else if ($(this).hasClass('proximo'))
					{

						$(this).bind("click", function(e)
						{
							$a = $(this);
							var i = $a.parent().find(".contador").val();
							i++;
							$a.parent().find(".contador").val(i);
							var total = $a.parent().find(".total").val();
							total--;

							$.ajax({
								url: webPath + "Util/PilaresCarregaContedudo",
								cache: false,
								type: "POST",
								data: {
									coluna: $a.parent().find(".coluna").val(),
									item: i
								},
								success: function(data)
								{
									$box = $a.parent().parent().find(".pilares-sessoes-box-main");

									var $box_side = $a.parent().parent().find(".pilares-sessoes-box-side");
									var $box_pag = $a.parent().parent().find(".pilares-sessoes-box-pag");

									$box_side.find("h4").html(data.Titulo);
									$box_side.find("p").html(data.Chamada);
									$box_pag.find("a.continue-lendo").attr("href", $a.parent().find(".url").val() + data.Url);

									if ($box.parent().filter("#div-use-bem").size() === 0)
									{
										$box.find("img").attr("src", webPath + "Content/images/pilares/" + data.AutorImagem);
										$box.find("img").attr("alt", "por " + data.Autor);
										$box.find("img").attr("title", "por " + data.Autor);
										$box.find("h5").html("por " + data.Autor);
									}
								},
								error: function(a, status, c)
								{
									alert("erro");
								}
							});

							//                            if (total > 5)
							//                                total = 5;

							if (i == total)
								$a.hide();
							if (i > 0)
								$a.parent().find("a.anterior").show();
						});
					}
				});
			});
		}

		if ($("#divCadastroPassos").length > 0 || $("#cadastro-cadastro").length > 0)
		{
			$("#DataNacime,#DtNascimento,#DataNascimento,#DataNacimento").mask("99/99/9999");
			$("#CEP").mask("99999-999");
			$("#Telefone").mask("99 9999-9999");
		}

		if ($("#lb-ckbNews").length > 0)
		{
			$("#lb-ckbNews").bind("click", function(e)
			{
				if ($("#lb-hdNews").val() == 0)
					$("#lb-hdNews").val(1);
				else
					$("#lb-hdNews").val(0);
			});
		}

		if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
		{
			$("#footer").css("width", "auto");
		}

		if ($(".sliderShow").length > 0)
			$(".sliderShow").sliderHorizontal({ slideDuration: 200 });

		if ($(".box-ferramenta ul.break-tabs").length > 0)
		{
			$(".box-ferramenta ul.break-tabs").find('a').each(function(e)
			{
				$(this).bind("click", function(e)
				{
					$(".box-ferramenta ul.break-tabs").find('.active').removeClass('active');
					$(this).addClass("active");
					$(".tabs").hide();
					$("." + $(this).attr("id")).show();
				});
			});
		}

		if ($("div.minha-escolha-left").length > 0)
		{
			$("div.tabs").find('a.tab').bind("click", function(e)
			{
				$("div.tabs").find('a.tab').removeClass("active");
				$(this).addClass("active");
			});
		}

		if ($("#Compare-login").length > 0)
		{
			$("#Compare-login, #Busca, #Busca1").bind("mouseup", function(e)
			{
				$(".bg-branco:not(.convite-preview)").show();

				$("#compare-info-login").show();
				$("#compare-info-login").animate({ top: $(document).scrollTop() + (($(window).height() / 2) - 80) }, 200);
			});
		}



		$(".bt-mensagem-ok").bind("mouseup", function(e)
		{
			$("#Mensagem-lightbox").find(".texto").html("");
			$("#Mensagem-lightbox").hide();
			$(".bg-branco:not(.convite-preview)").hide();
		});

		$("#dtInicial, #dtFinal").datepicker();

		if ($(".profissionais").length > 0)
		{
			$(".sliderMask").find(".toSlide").each(function(e)
			{
				var leiaMaisHeight = $(this).find("h4").height() + $(this).find('p:first').height() + 55;
				if ($(this).find("h4").height() < 291)
					leiaMaisHeight += 291;
				$(this).height(leiaMaisHeight);

				$(this).find(".leia-mais").bind("mouseup", function(e)
				{
					hgt = $(this).parent().find("h4").height() + 55;
					$(this).parent().find("p").each(function(e) { hgt += $(this).height() + 20; });
					hgt = hgt - $(this).parent().find('p:first').height();
					$(this).parent().animate({ height: hgt }, 200);
					$(this).hide();
					$(this).parent().find(".leia-mais-fechar").show();
				});
				$(this).find(".leia-mais-fechar").bind("mouseup", function(e)
				{
					$(this).parent().animate({ height: leiaMaisHeight }, 200);
					$(this).hide();
					$(this).parent().find(".leia-mais").show();
				});
			});
		}

		if ($("#flashcontent").length > 0)
		{
			// version 9.0.115 or greater is required for launching AIR apps.
			var so = new SWFObject("http://www.nutraeviva.com.br/Trendi/Content/AIRInstallBadge.swf", "Badge", "215", "160", "9.0.115", "#FFFFFF");
			so.useExpressInstall('http://www.nutraeviva.com.br/Trendi/Content/expressinstall.swf');

			// these parameters are required for badge install:
			so.addVariable("airversion", "1.0"); // version of AIR runtime required
			so.addVariable("appname", "Break Alert"); // application name to display to the user
			so.addVariable("appurl", "http://www.nutraeviva.com.br/Trendi/Content/BreakAlert.air"); // absolute URL (beginning with http or https) of the application ".air" file

			// these parameters are required to support launching apps from the badge (but optional for install):
			so.addVariable("appid", "br.com.nutraeviva.BreakAlert"); // the qualified application ID (ex. com.gskinner.air.MyApplication)
			so.addVariable("pubid", ""); // publisher id

			// this parameter is required in addition to the above to support upgrading from the badge:
			so.addVariable("appversion", "1.0.2"); // AIR application version

			// these parameters are optional:
			so.addVariable("image", "http://www.nutraeviva.com.br/Trendi/Content/images/Breakalert.jpg"); // URL for an image (JPG, PNG, GIF) or SWF to display in the badge (205px wide, 170px high)
			so.addVariable("appinstallarg", "installed from web"); // passed to the application when it is installed from the badge
			so.addVariable("applauncharg", "launched from web"); // passed to the application when it is launched from the badge
			so.addVariable("helpurl", "help.html"); // optional url to a page containing additional help, displayed in the badge's help screen
			so.addVariable("hidehelp", "true"); // hides the help icon if "true"
			so.addVariable("skiptransition", "true"); // skips the initial transition if "true"
			so.addVariable("titlecolor", "#D6903B"); // changes the color of titles
			so.addVariable("buttonlabelcolor", "#D6903B"); // changes the color of the button label
			so.addVariable("appnamecolor", "#D6903B"); // changes the color of the application name if the image is not specified or loaded

			// these parameters allow you to override the default text in the badge:
			// supported strings: str_error, str_err_params, str_err_airunavailable, str_err_airswf, str_loading, str_install, str_launch, str_upgrade, str_close, str_launching, str_launchingtext, str_installing, str_installingtext, str_tryagain, str_beta3, str_beta3text, str_help, str_helptext
			so.addVariable("str_err_airswf", "<u>Running locally?</u><br/><br/>The AIR proxy swf won't load properly when this demo is run from the local file system."); // overrides the error text when the AIR proxy swf fails to load
			so.addVariable("str_loading", "Carregando...");
			so.addVariable("str_install", "Instalar Agora");
			so.addVariable("str_launch", "Executar Break Alert");
			so.addVariable("str_upgrade", "Atualizar Agora");
			so.addVariable("str_close", "Fechar");
			so.addVariable("str_launching", "Executando...");
			so.addVariable("str_launchingtext", "Aguarde enquanto executa.");
			so.addVariable("str_installing", "Instalando...");
			so.addVariable("str_installingtext", "Aguarde enquanto instala.");
			so.addVariable("str_tryagain", "Tentar Novamente");
			so.addVariable("str_help", "Ajuda");

			so.write("flashcontent");
		}

		if ($("#pilares").length > 0)
		{
			if ($("#dicas div.texto-corpo").find("p").length > 1)
			{
				$("#dicas div.texto-corpo").find("p:first").after("<div class='leia-mais'><a href='javascript:void(0);' id='bt_readMore'>Leia Mais</a></div>");
				$("#dicas div.texto-corpo").height($("#dicas div.texto-corpo").find("p:first").height() + 30);
			}

			$("#bt_readMore").live("mouseup", function(e)
			{
				hgt = 0;
				$("#dicas div.texto-corpo").find("p").each(function(e) { hgt += $(this).height() + 10; });
				$(this).parent().remove();
				$("#dicas div.texto-corpo").animate({ height: hgt + 25 }, 200);
				$("#dicas div.texto-corpo").find("p:last").after("<div class='leia-mais'><a href='javascript:void(0);' id='bt_closeReadMore'>Fechar</a></div>");
			});

			$("#bt_closeReadMore").live("mouseup", function(e)
			{
				$(this).parent().remove();
				$("#dicas div.texto-corpo").animate({ height: $("#dicas div.texto-corpo").find("p:first").height() + 30 }, 200);
				$("#dicas div.texto-corpo").find("p:first").after("<div class='leia-mais'><a href='javascript:void(0);' id='bt_readMore'>Leia Mais</a></div>");
			});
		}

		if ($(".midia-main").length > 0)
		{
			var counter = 0;
			var total = $("#TOTAL_ANTERIORES").val();

			$(".seta-down").bind('mouseup', function(e)
			{

				if (counter < (total - 3))
				{
					counter++;
					var tmp = counter * (-60);
					$("#content-lista").animate({ top: tmp }, { duration: 290, easing: "easeOutExpo", complete: function(p) { } })
				}
				if (counter == 1)
					$("#setaUp").removeClass('u-disabled');
				if (counter == (total - 3))
					$("#setaDown").addClass('d-disabled');
			});

			$(".seta-up").bind('mouseup', function(e)
			{
				if (counter > 0)
				{
					counter--;
					var tmp = counter * (-60);
					$("#content-lista").animate({ top: tmp }, { duration: 350, easing: "easeOutExpo", complete: function(p) { } })
				}
				if (counter == 0)
					$("#setaUp").addClass('u-disabled');
				if (counter <= (total - 3))
					$("#setaDown").removeClass('d-disabled');
			});

			$(".ano").bind("mouseup", function(e)
			{
				$(".ano").removeClass("active");
				if ($(this).attr("title") == "Todos")
				{
					$(".box").show();
					total = $("#TOTAL_ANTERIORES").val();
				}
				else
				{
					$(".box").hide();
					$("." + $(this).attr("title")).show();
					total = $("TOTAL_ANTERIORES_" + $(this).attr("title")).val();
				}
				$(this).addClass("active");
				$("#setaUp").addClass('u-disabled');
				if (total > 3)
					$("#setaDown").removeClass('d-disabled');
				else
					$("#setaDown").addClass('d-disabled');

				$("#content-lista").animate({ top: 0 }, { duration: 10, easing: "easeOutExpo", complete: function(p) { } })
				counter = 0;
			});
		}

		if ($("#pilares").length > 0)
		{
			var counter = 0;
			var total = 18;

			$(".seta-down").bind('mouseup', function(e)
			{

				if (counter < (total - 3))
				{
					counter++;
					var tmp = counter * (-90);
					$("#content-lista").animate({ top: tmp }, { duration: 290, easing: "easeOutExpo", complete: function(p) { } })
				}
				if (counter == 1)
					$("#setaUp").removeClass('u-disabled');
				if (counter == (total - 3))
					$("#setaDown").addClass('d-disabled');
			});

			$(".seta-up").bind('mouseup', function(e)
			{
				if (counter > 0)
				{
					counter--;
					var tmp = counter * (-90);
					$("#content-lista").animate({ top: tmp }, { duration: 350, easing: "easeOutExpo", complete: function(p) { } })
				}
				if (counter == 0)
					$("#setaUp").addClass('u-disabled');
				if (counter == (total - 7))
					$("#setaDown").removeClass('d-disabled');
			});

			$(".ano").bind("mouseup", function(e)
			{
				$(".ano").removeClass("active");
				if ($(this).attr("title") == "Todos")
				{
					$(".box").show();
					total = 18;
				}
				else
				{
					$(".box").hide();
					$("." + $(this).attr("title")).show();
					total = 6;
				}
				$(this).addClass("active");
				$("#setaDown").removeClass('d-disabled');
				$("#setaUp").addClass('u-disabled');
				$("#content-lista").animate({ top: 0 }, { duration: 10, easing: "easeOutExpo", complete: function(p) { } })
				counter = 0;
			});
		}

		$("input[type=text].compare-busca").selfcompleter({
			comboheight: "auto",
			requestcallback: function(request, string)
			{
				request.url = webPath + 'Util/SelfCompleter';
				request.data = { "Busca": string };
				request.type = "POST";
				request.dataType = "json";
				request.error = function(xhr, status, error)
				{
					alert("erro ");
				};
				return request;
			}
		});
		/* FORM CUSTOMIZADO */

		$("select, .cadastro input:checkbox, .cadastro input:radio, input:file").uniform();


		/*** CADASTRO - SENHA / Data / Telefone / CEP***/
		if ($('.cadastro').length > 0)
		{
			$('#Login').bind('click', function(e)
			{
				$("#cadastro-cadastro").hide();
				$("#cadastro-login").show();
				//$('#Login').blur();
			});
			$('#Cadastro').bind('click', function(e)
			{
				$("#cadastro-login").hide();
				$("#cadastro-cadastro").show();
				//$('#Cadastro').blur();
			});
			/*
			$('#Masc').bind('click', function(e) { $('#Masc').blur(); });
			$('#Fem').bind('click', function(e) { $('#Fem').blur(); });

			$('#Leve').bind('click', function(e) { $('#Leve').blur(); });
			$('#Moderado').bind('click', function(e) { $('#Moderado').blur(); });
			$('#Intenso').bind('click', function(e) { $('#Intenso').blur(); });

			$('#OptIn').bind('click', function(e) { $('#OptIn').blur(); });
			*/

			$('#LoginPassword').bind('focus', function()
			{
				$(this).hide();
				$('#LoginPassword1').show();
				height = $('#LoginPassword1').height();
				$('#LoginPassword1').css("border", "solid 2px #EAB665").height(height - 2);
				window.setTimeout(function()
				{
					$('#LoginPassword1').focus();
				}, 300);
			});
			$('#LoginPassword1').bind('blur', function()
			{
				if ($(this).val() == "")
				{
					height = $('#LoginPassword1').height();
					$('#LoginPassword1').css("border", "solid 1px #EAB665").height(height + 2);
					$(this).hide();
					$('#LoginPassword').show();
				}
			});


			$('#CadSenha').bind('focus', function()
			{
				$(this).hide();
				$('#Senha').show();
				height = $('#Senha').height();
				$('#Senha').css("border", "solid 2px #EAB665").height(height - 2);
				window.setTimeout(function()
				{
					$('#Senha').focus();
				}, 300);
			});
			$('#SenhaConfCad').bind('focus', function()
			{
				$(this).hide();
				$('#SenhaConfirmacao').show();
				height = $('#SenhaConfirmacao').height();
				$('#SenhaConfirmacao').css("border", "solid 2px #EAB665").height(height - 2);
				window.setTimeout(function()
				{
					$('#SenhaConfirmacao').focus();
				}, 300);
			});

			$('#Senha').bind('blur', function()
			{
				if ($(this).val() == "")
				{
					height = $('#Senha').height();
					$('#Senha').css("border", "solid 1px #EAB665").height(height + 2);
					$(this).hide();
					$('#CadSenha').show();
				}
			});
			$('#SenhaConfirmacao').bind('blur', function()
			{
				if ($(this).val() == "")
				{
					height = $('#SenhaConfirmacao').height();
					$('#SenhaConfirmacao').css("border", "solid 1px #EAB665").height(height + 2);
					$(this).hide();
					$('#SenhaConfCad').show();
				}
			});
			$("#DataNascimento").bind("focus", function()
			{
				$("#DataNascimento").val("");
				$("#DataNascimento").mask("99/99/9999");
			});
			$("#DataNascimento").bind("blur", function()
			{
				window.setTimeout(function()
				{
					if ($("#DataNascimento").val().length == 0)
					{
						$("#DataNascimento").unmask();
						window.setTimeout(function() { $("#DataNascimento").val("Data de Nascimento"); }, 50);
					}
				}, 50);
			});

		}

		/*** LOGIN BREAK ALERT ***/
		$('#passwordBreak').bind('focus', function()
		{
			$(this).hide();
			$('#senhaBreak').show();
			window.setTimeout(function()
			{
				$('#senhaBreak').focus();
			}, 300);
		});
		$('#passwordBreak').bind('focus', function()
		{
			$(this).hide();
			$('#senhaBreak').show();
			window.setTimeout(function()
			{
				$('#senhaBreak').focus();
			}, 300);
		});
		$('#senhaBreak').bind('blur', function()
		{
			if ($(this).val() == "")
			{
				$(this).hide();
				$('#passwordBreak').show();
			}
		});

		if ($(this).find(".scrollbar1:eq(0)").length > 0)
			$(this).find(".scrollbar1:eq(0)").tinyscrollbar();

		$("div.box-tempo").horizontalAccordion();

		$('#footer .footer-content h5 a').bind("mouseup", function(e)
		{
			if ($(this).parent().parent().hasClass('active'))
				$(this).parent().parent().removeClass('active');
			else
				$(this).parent().parent().addClass('active');
		});

		$("#MENU_FOOTER").find("li a").each(function(e)
		{
			$(this).bind("click", function(e)
			{
				if ($(this).parent().hasClass("active"))
				{
					$(this).parent().children('div:eq(0)').hide();
					$(this).parent().removeClass("active");
				}
				else
				{
					$(".box-info-1").hide();
					$(this).parent().parent().find('li').each(function(e)
					{
						$(this).removeClass("active");
					});
					$(this).parent().children('div:eq(0)').show();
					$(this).parent().addClass("active");
					var limite = $(this).parent().find("ul li").size();
					$(this).parent().find("ul li").eq(Math.floor(Math.random() * limite)).children("a").trigger("click");
				}
			});
		});

		$("#PILARES_FOOTER").find("li a").each(function(e)
		{
			$(this).bind("mouseup", function(e)
			{
				if ($(this).parent().hasClass("active"))
				{
					$("#box-" + $(this).parent().attr("id")).hide();
					//$(this).parent().children('div:eq(0)').hide();
					$(this).parent().removeClass("active");
				}
				else
				{
					$(".box-info-2").hide();
					$(this).parent().parent().parent().removeClass();
					$(this).parent().parent().parent().addClass("footer-side").addClass($(this).parent().attr("id"));
					$(this).parent().parent().find('li').each(function(e)
					{
						$(this).removeClass("active");
					});
					$("#box-" + $(this).parent().attr("id")).show();
					//$(this).parent().children('div:eq(0)').show();
					$(this).parent().addClass("active");
				}
			});
		});

		//obj = AC_FL_RunContent('type', 'application/x-shockwave-flash', 'data', webPath + "Content/player.swf?autostart=false", 'width', $(document).width(), 'height', ($(window).height() - 20), 'movie', webPath + 'Content/player?autostart=false', 'allowfullscreen', 'true', 'autoplay', 'false', 'allowscriptaccess', 'always', 'flashvars', 'file=' + webPath + "Content/video.flv"); //end AC code


		$("div#ferramenta").delegate("[name=top_anchor]", "click", function(event)
		{
			if ($(this).filter("#gerar-tabela").length > 0 && $("#filtros").find("#set-filtros").length > 0 && $("#filtros").find("#set-filtros").find("input:checked").length < 2)
			{
				return false;
			}
			else
			{
				$(document).scrollTop($("div#ferramenta").offset().top);
			}
		});

		$("#home-video").find(".lightbox-close").click(function()
		{
			$("#obj-video").html("");
		});

		$("a#video-home-1.lightbox-open").click(function()
		{
			obj = AC_FL_RunContent('type', 'application/x-shockwave-flash', 'data', webPath + "Content/player.swf?autostart=true", 'width', '500px', 'height', '350px', 'movie', webPath + 'Content/player?autostart=true', 'allowfullscreen', 'true', 'autoplay', 'false', 'allowscriptaccess', 'always', 'flashvars', 'file=' + webPath + "Content/video.flv"); //end AC code
			$obj = $("" + obj);
			$("#obj-video").append($obj);
			$("#home-video").css("left", ($(window).width() / 2) - 250);
			$("#home-video").animate({ top: $(document).scrollTop() + (($(window).height() / 2) - 175) }, 200);
		});

		$("a#video-home-1.lightbox-open").lightBox({
			modal: true,
			swf: true
		});

		/*** LEIA MAIS ***/
		/*
		if ($("#pilares").length > 0) {
		var leiaMaisHeight = 0;
		var count = 0;
		$(".texto-mask").find('p').each(function(e) {
		if (count < 2)
		leiaMaisHeight += $(this).height();
		count++;
		});
		if (leiaMaisHeight > 0)
		$(".texto-mask").height(leiaMaisHeight + 12);

			$("#pilares").find("#leia-mais-abrir").bind("mouseup", function(e) {
		hgt = $(this).parent().find(".texto-corpo").height();
		$(this).parent().find(".texto-mask").animate({ height: hgt + 10 }, 200);
		$(this).hide();
		$("#leia-mais-fechar").show();
		});
		//FUCK = $("#pilares").find(".leia-mais").parent().find(".texto-corpo").height();
		//if (FUCK <= 100) $("#pilares").find(".leia-mais").hide();
		$("#pilares").find("#leia-mais-fechar").bind("mouseup", function(e) {

				$(this).parent().find(".texto-mask").animate({ height: leiaMaisHeight + 12 }, 200);
		$(".leia-mais").show();
		$("#leia-mais-fechar").hide();
		//$(".texto-mask").height(leiaMaisHeight + 12);
		});
		}*/

		$("body").bind("click", function(event)
		{
			var $target = $(event.target),
                $box_login = $("#box-login");

			if (
                $box_login.css("display") === "block" &&
                ((
                    $target.filter("#login").size() === 0 &&
                    $target.parents("#login").size() === 0
                ) && (
                    $target.parents("#box-login").size() === 0 &&
                    $target.filter("#box-login").size() === 0
                ) && (
                    $target.parents("#Mensagem-lightbox").size() === 0 &&
                    $target.filter("#Mensagem-lightbox").size() === 0
                ) && (
                    $target.parents("#nav-slider").size() === 0 &&
                    $target.filter("#nav-slider").size() === 0
                ) && (
                    $target.parents("#btn-login").size() === 0 &&
                    $target.filter("#btn-login").size() === 0
                ))
            )
			{
				$box_login.hide();
			}
		});

		/*** LIGHTBOX ***/
		$("#btn-perfilAlimentar").bind("click", function()
		{
			$("#perfil-alimentar-lightbox").show();
			$(".bg-branco:not(.convite-preview)").show();
		});

		$("#btn-ferramentas").bind("mouseup", function()
		{
			$("#ferramentas-lightbox").show();
			$(".bg-branco:not(.convite-preview)").show();
		});

		/*** FECHA o LIGHTBOX ***/
		$(".bg-branco").bind("mouseup", function()
		{
			$("#ferramentas-lightbox").hide();
			$("#Mensagem-lightbox").hide();
			$("#materia-lightbox").hide();
			$("#compare-info-login").hide();
			$("#perfil-alimentar-lightbox").hide();
			$("#divLBCadastro").hide();
			$(this).hide();
		});

		/*** LIGHTBOX ***/
		$("#btn-ampliar").bind("mouseup", function()
		{
			$("#materia-lightbox").show();
			var left = (($(window).width() - $("#materia-lightbox").width()) / 2) - 177;
			$("#materia-lightbox").animate({ left: left }, 50);
			$(".bg-branco").show();
		});

		/*** FECHA o LIGHTBOX ***/
		/*$(".bg-branco").bind("mouseup", function() {
		$("#materia-lightbox").hide();
		$(this).hide();
		});*/

		$("#fechar").bind("mouseup", function()
		{
			$("#materia-lightbox").hide();
			$(".bg-branco").hide();
		});

		/*** LOGIN ***/
		$("#btn-login").bind("click", function(e)
		{
			$("#box-login").toggle();
			$("#box-newsletter").hide();
		});

		$("#btn-newsletter").find('a').bind("click", function(e)
		{
			$("#box-newsletter").toggle();
			$("#box-login").hide();
		});

		/*** MENU***/
		$(".hover-submenu").mouseover(function()
		{
			$(this).find(".submenu").width($(this).width());
			return false;
		});

		$(".btn-submenu").mouseover(function()
		{
			$(this).addClass('btn-submenu-over');
			return false;
		});

		$(".btn-submenu").mouseout(function()
		{
			$(this).removeClass('btn-submenu-over');
			return false;
		});

		$(".submenu").mouseover(function()
		{//d2dccc
			$(this).parent().find(".btn-submenu").addClass('btn-submenu-over');
			return false;
		});

		$(".submenu").mouseout(function()
		{
			$(this).parent().find(".btn-submenu").removeClass('btn-submenu-over');
			return false;
		});

		/*** ABAS ***/
		if ($('.online').length > 0)
		{
			$(".tabs").tabs({
				startTab: 1
			});
		}
		else
		{
			$(".tabs").tabs({
				startTab: 0
			});
		}

		/*** SLIDER : HOME  ***/
		$('#nav-slider').find('li').each(function(n)
		{
			$('#link' + (n + 1)).click(function(event)
			{
				window.clearInterval(intervaloBannerHome);

				SliderHome(n);
			});

		});

		/*** SLIDER : NUTRABEM  ***/
		$('#nav-slider-interna').find('li').each(function(n)
		{
			$('#link' + (n + 1)).click(function()
			{
				if ($('#hd').val() != '#slide-banner-nutrabem-' + (n + 1))
				{
					$('#slide-banner-nutrabem-' + (n + 1)).css('left', '940px');
					$($('#hd').val()).animate({
						left: '-938px'
					});
					$('#slide-banner-nutrabem-' + (n + 1)).animate({
						left: 0
					});
					$('#hd').val('#slide-banner-nutrabem-' + (n + 1));
					$('#nav-slider-interna li a').removeClass('active');
					$(this).addClass("active");
				}
			});

		});

		$("input[type=text].campo.pesquisa").selfcompleter({
			requestcallback: function(request, string)
			{
				request.url = webPath + 'Util/SelfCompleter';
				request.data = { "Busca": string };
				request.type = "POST";
				request.dataType = "json";
				request.error = function(xhr, status, error)
				{
					alert("erro");
				};
				return request;
			}
		});

		/*********** COMPARE **********/
		if ($("#compare-escolha").length > 0)
		{

			$("ul#complete-result li").live("click", function(event)
			{
				event.preventDefault();
				var $this = $(this);
				var $inputText = $("#ferramenta #Busca1");
				classe = $this.attr("class").split("_");
				grupoID = classe[0];
				grupoNOME = classe[1];
				if (window.groupid === undefined)
				{
					loadGrupo($this.children("a").attr("href"), grupoID, grupoNOME);
				}
				else
				{
					ordenar($("div#filtros div#set-filtros>form#filtros-form>ul>li"), $inputText.val(), /^(.*)\s\(.*\)/.exec($(this).text())[1])
				}
				$("#resultado").fadeOut(300);
				$("#filtros").fadeIn(400);
				$("#box-busca").css("backgroundImage", "url(" + window["imagens compare e escolha"].adicione + ")");
				return false;
			});





			$("gerar_pdf").bind("click", function(event)
			{
				SubmitForPDF();

				return false;
			});
			function SubmitForPDF()
			{
				var $form = $("#filtros").find("#filtros-form");
				$form.attr({
					"action": webPath + "Util/CompareEscolha_GerarPDF",
					"method": "POST",
					"target": "pdf_frame"
				});
				$form.submit();
			}

			$("ul.rack").find("a").click(function(event)
			{
				event.preventDefault();
				$img = $(this).find("img");
				loadGrupo($(this).attr('href'), $img.attr('class'), $img.attr('alt'));
			});

			/*** fitlros ***/
			$("#filtros").delegate(".check-all", "change", function()
			{
				$(this).parents("#container_grupo_alimentar").find("input[type=checkbox]").attr("checked", $(this).is(":checked"));
			});

			$("#filtros").find(".voltar").mouseup(function()
			{
				var text = "Digite o alimento que quer comparar";
				$("#filtros").fadeOut(300);
				$("#escolha").fadeIn(400);
				//$("#Busca").attr("palceholder", text);
				$("#Busca").val('');
				$("#Busca1").hide();
				$("#Busca").show();


				if (window.groupid !== undefined) window.groupid = undefined;
				$("#box-busca").css("backgroundImage", "url(" + window["imagens compare e escolha"].selecione + ")");
			});

			var gerartabela = function()
			{
				var $this = $(this);
				$inputs = $("#filtros").find("#set-filtros").find("input:checked");
				if ($inputs.length >= 2)
				{
					$this.unbind("mouseup");
					formData = $("#filtros").find("#filtros-form").serialize();
					exibirLoading();
					$.ajax({
						url: webPath + "Util/Resultado",
						cache: false,
						type: "POST",
						data: formData,
						success: function(data, status, xhr)
						{
							$("#resultado").find('table').children().remove();
							$("#resultado").find('table').html(data);
							preparaTabela('resultado');
							$("#filtros").fadeOut(300);
							$("#resultado").fadeIn(400);
							$("#box-busca").css("backgroundImage", "url(" + window["imagens compare e escolha"].confira + ")");
						},
						error: function(a, status, c)
						{
							alert("erro");
						},
						complete: function(xhrk, status)
						{
							removerLoading();
							$this.bind("mouseup", gerartabela);
						}
					});
				} else
				{
					alert("Selecione pelo menos dois produtos para continuar.");
					return false;
				}
			};

			$("#filtros").find("#gerar-tabela").bind("mouseup", gerartabela);

			/*** resultados ***/
			$("#resultado").find(".voltar").mouseup(function()
			{
				$("#resultado").fadeOut(300);
				$("#filtros").fadeIn(400);
				$("#box-busca").css("backgroundImage", "url(" + window["imagens compare e escolha"].adicione + ")");
			});

			$("#resultado").find(".nova-consulta").mouseup(function()
			{
				var text = "Digite o alimento que quer comparar";
				$("#resultado").fadeOut(300);
				$("#escolha").fadeIn(400);
				if (window.groupid !== undefined) window.groupid = undefined;
				//placeholders[$("#Busca").val(text).index()] = text;
				$("#box-busca").css("backgroundImage", "url(" + window["imagens compare e escolha"].selecione + ")");
			});

		}
	});
})(jQuery);

function preparaTabela(id) {
    $trs = $("#" + id).find('tr');


    $trs.each(function(k) {
        $tds = $(this).find("td");
        i = $trs.index($(this));

        if (i % 2 == 0) {
            $(this).addClass("even");
        }
        else {
            $(this).addClass("odd");
        }

        $tds.each(function(j) {
            t = $tds.index($(this));

            if (t == 0) { $(this).addClass("first"); }

            if (t % 2 == 0 && t > 0) {
                $(this).addClass("even");
            }
            else {
                $(this).addClass("odd");
            }
            if (!trim($(this).parent("tr").parent("tbody").siblings("thead").children("tr").children("th").eq(t).text()).match(/.+/)) {
                $(this).removeClass("even").removeClass("odd");
            }
        });


    });
}

/** acordion **/
(function($) {
    $.fn.horizontalAccordion = function(settings) {
        var options = $.extend({}, $.fn.horizontalAccordion.defaults, settings);
        $(this).each(function(index, element) {
            var $super, $div, $ul, $li, $header, $content;
            if ($(this).children("ul").length > 0) {
                $div = $(this).filter("div");
            }
            else if ($(this).children("div").length > 0) {
                $super = $(this).filter("div");
                $div = $super.children("div");

                $super.addClass("super").addClass("accordion");
                $super.width(options.width);
            }
            else {
                return this;
            }
            $ul = $div.children("ul");
            $li = $ul.children("li");
            $header = $li.children("h3");
            $content = $li.children("div");

            $div.addClass("accordion");
            $ul.addClass("accordion");
            $li.addClass("accordion");
            $header.addClass("accordion");
            $content.addClass("accordion");

            $div.width(options.width);

            $li.bind("mouseup", function(event) {
                var $this = $(this);
                var $function = arguments.callee;
                if ($this.attr("class").indexOf("open") != -1) return false;
                $li.unbind("mouseup");
                $li.filter("li.open").children("div").hide(0);
                $this.children("div").show(options.duration);
                $li.filter("li.open").removeClass("open");
                $this.addClass("open");
                window.setTimeout(function() {
                    $this.find(".scrollbar1").tinyscrollbar();
                }, 400);
                $li.bind("mouseup", $function)
            });
        });
        return this;
    }

    $.fn.horizontalAccordion.defaults = {
        duration: 700,
        width: 960
    };

})(jQuery);

/* SCROLLER */

(function($) {
    $.fn.tinyscrollbar = function(options) {
        var defaults = {
            axis: 'y',
            wheel: 40,
            scroll: true,
            size: 'auto',
            sizethumb: '12'
        };
        var options = $.extend(defaults, options);
        var oWrapper = $(this); var oViewport = {
            obj: $('.viewport', this)
        };
        var oContent = {
            obj: $('.overview', this)
        };
        var oScrollbar = {
            obj: $('.scrollbar', this)
        };
        var oTrack = {
            obj: $('.track', oScrollbar.obj)
        }; var oThumb = {
            obj: $('.thumb', oScrollbar.obj)
        };
        var sAxis = options.axis == 'x', sDirection = sAxis ? 'left' : 'top', sSize = sAxis ? 'Width' : 'Height';
        var iScroll, iPosition = {
            start: 0, now: 0
        }, iMouse = {};
        if (this.length > 1) {
            this.each(function() {
                $(this).tinyscrollbar(options)
            });
            return this;
        }
        this.initialize = function() {
            this.update();
            setEvents();
        };
        this.update = function() {
            iScroll = 0;
            oViewport[options.axis] = oViewport.obj[0]['offset' + sSize];
            oContent[options.axis] = oContent.obj[0]['scroll' + sSize];
            oContent.ratio = oViewport[options.axis] / oContent[options.axis];
            oScrollbar.obj.toggleClass('disable', oContent.ratio >= 1);
            oTrack[options.axis] = options.size == 'auto' ? oViewport[options.axis] : options.size;
            oThumb[options.axis] = Math.min(oTrack[options.axis], Math.max(0, (options.sizethumb == 'auto' ? (oTrack[options.axis] * oContent.ratio) : options.sizethumb)));
            oScrollbar.ratio = options.sizethumb == 'auto' ? (oContent[options.axis] / oTrack[options.axis]) : (oContent[options.axis] - oViewport[options.axis]) / (oTrack[options.axis] - oThumb[options.axis]);
            setSize();
        }; function setSize() {
            oContent.obj.removeAttr('style');
            oThumb.obj.removeAttr('style');
            iMouse['start'] = oThumb.obj.offset()[sDirection];
            var sCssSize = sSize.toLowerCase();
            oScrollbar.obj.css(sCssSize, oTrack[options.axis]);
            oTrack.obj.css(sCssSize, oTrack[options.axis]);
            oThumb.obj.css(sCssSize, oThumb[options.axis]);
        };
        function setEvents() {
            oThumb.obj.bind('mousedown', start);
            oTrack.obj.bind('mouseup', drag);
            if (options.scroll && this.addEventListener) {
                oWrapper[0].addEventListener('DOMMouseScroll', wheel, false);
                oWrapper[0].addEventListener('mousewheel', wheel, false);
            }
            else if (options.scroll) {
                oWrapper[0].onmousewheel = wheel;
            }
        };
        function start(oEvent) {
            iMouse.start = sAxis ? oEvent.pageX : oEvent.pageY;
            iPosition.start = parseInt(oThumb.obj.css(sDirection));
            oTrack.obj.bind('mousemove', drag);
            $(document).bind('mouseup', end);
            oThumb.obj.bind('mouseup', end);
            return false;
        }; function wheel(oEvent) {
            if (!(oContent.ratio >= 1)) {
                oEvent = $.event.fix(oEvent || window.event);
                var iDelta = oEvent.wheelDelta ? oEvent.wheelDelta / 120 : -oEvent.detail / 3;
                iScroll -= iDelta * options.wheel;
                iScroll = Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll));
                oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio);
                oContent.obj.css(sDirection, -iScroll); oEvent.preventDefault();
            };
        };
        function end(oEvent) {
            oTrack.obj.unbind('mousemove', drag);
            $(document).unbind('mouseup', end);
            oThumb.obj.unbind('mouseup', end);
            return false;
        };
        function drag(oEvent) {
            if (!(oContent.ratio >= 1)) {
                iPosition.now = Math.min((oTrack[options.axis] - oThumb[options.axis]), Math.max(0, (iPosition.start + ((sAxis ? oEvent.pageX : oEvent.pageY) - iMouse.start)))); iScroll = iPosition.now * oScrollbar.ratio; oContent.obj.css(sDirection, -iScroll);
                oThumb.obj.css(sDirection, iPosition.now);
                ;
            }
            return false;
        };
        return this.initialize();
    };
   })(jQuery);


/*** SLIDER : HOME  ***/
function SliderHome(n)
{
	if ($('#hd').val() != '#slide-banner-home-' + (n + 1))
	{
		$('#slide-banner-home-' + (n + 1)).css('left', '938px');
		$($('#hd').val()).animate({
			left: '-938px'
		});
		$('#slide-banner-home-' + (n + 1)).animate({
			left: 0
		});
		$('#hd').val('#slide-banner-home-' + (n + 1));
		$('#nav-slider li a').removeClass("active");
		$('#link' + (n + 1)).addClass("active");
	}
}



function ValidaCadastroPasso1(nome, email, confirmacaoEmail, senha, confirmacaoSenha, news) {
    var valid = true;
    nome.removeClass("erro");
    email.removeClass("erro");
    confirmacaoEmail.removeClass("erro");
    senha.removeClass("erro");
    confirmacaoSenha.removeClass("erro");

    if (nome.val() == '') {
        nome.addClass('erro');
        valid = false;
    }
    if (email.val() == '') {
        email.addClass('erro');
        valid = false;
    }
    if (confirmacaoEmail.val() == '') {
        confirmacaoEmail.addClass('erro');
        valid = false;
    }
    if (senha.val() == '') {
        senha.addClass('erro');
        valid = false;
    }
    if (confirmacaoSenha.val() == '') {
        confirmacaoSenha.addClass('erro');
        valid = false;
    }

    if (!validacao.EmailValido(email.val())) {
        valid = false;
        email.addClass('erro');
        email.parents("fieldset").append("<span class='field-validation-error'>O e-mail digitado n&atilde;o &eacute; v&aacute;lido!</span>");
    }

    if (email.val() != confirmacaoEmail.val()) {
        confirmacaoEmail.addClass('erro');
        email.addClass('erro');
        confirmacaoEmail.parents("fieldset").append("<span class='field-validation-error'>O e-mail e a confirma&ccedil;&atilde;o de e-mail n&atilde;o conferem!</span>");
        valid = false;
    }
    if (senha.val() != confirmacaoSenha.val()) {
        confirmacaoSenha.addClass('erro');
        senha.addClass('erro');
        confirmacaoSenha.parents("fieldset").append("<span class='field-validation-error'>A senha e a confirma&ccedil;&atilde;o de senha n&atilde;o conferem!</span>");
        valid = false;
    }

    return valid;
}
function ValidaCadastroPasso2() {
    var valid = true,
	    mensagem_de_erro = "";

    $(".sexo").removeClass("erro");
    $("#DataNacimento").removeClass("erro");
    $("#Peso").removeClass("erro");
    $("#Altura").removeClass("erro");
    $(".atividade").removeClass("erro");
    $(".temperatura").removeClass("erro");

    if ($("#Sexo").val() == '') {
        $(".sexo").addClass('erro');
        mensagem_de_erro += "Preencha o Sexo.\n";
        valid = false;
    }
    if ($("#DataNacimento").val() == '') {
        $("#DataNacimento").addClass('erro');
        valid = false;
    }
    else if (!ValidaData($("#DataNacimento").val())) {
        $("#DataNacimento").addClass('erro');
        valid = false;
    }

    if ($("#Peso").val() == '') {
        $("#Peso").addClass('erro');
        valid = false;
    }
    else if (!ValidaDecimal($("#Peso").val())) {
        $("#Peso").addClass('erro');
        valid = false;
    }

    if ($("#Altura").val() == '') {
        $("#Altura").addClass('erro');
        valid = false;
    }
    else if (!ValidaDecimal($("#Altura").val())) {
        $("#Altura").addClass('erro');
        valid = false;
    }

    if ($("#NivelAtividade").val() == '') {
        $(".atividade").addClass('erro');
        mensagem_de_erro += "Preencha o Nível de Atividade.\n";
        valid = false;
    }

    if ($("#Temperatura").val() == '') {
        $(".temperatura").addClass('erro');
        mensagem_de_erro += "Preencha a Temperatura Média Ambiente.";
        valid = false;
    }

    if (mensagem_de_erro.length > 0) {
        alert(mensagem_de_erro);
    }

    return valid;
}
function ValidaCadastroPasso3() {
    var valid = true,
	    mensagem_de_erro = "";

    $("#AreaAtuacao").removeClass("erro");
    $("#Telefone").removeClass("erro");
    $("#Endereco").removeClass("erro");
    $("#Numero").removeClass("erro");
    $("#Bairro").removeClass("erro");
    $("#Cidade").removeClass("erro");
    $("#Estado").removeClass("erro");
    $("#CEP").removeClass("erro");

    if ($("#AreaAtuacao").val() == '') {
        $("#AreaAtuacao").addClass('erro');
        mensagem_de_erro += "Escolha a sua Área de Atuação.\n";
        valid = false;
    }
    if ($("#Telefone").val() == '') {
        $("#Telefone").addClass('erro');
        valid = false;
    }

    if ($("#Endereco").val() == '') {
        $("#Endereco").addClass('erro');
        valid = false;
    }

    if ($("#Numero").val() == '') {
        $("#Numero").addClass('erro');
        valid = false;
    }

    if ($("#Bairro").val() == '') {
        $("#Bairro").addClass('erro');
        valid = false;
    }

    if ($("#Cidade").val() == '') {
        $("#Cidade").addClass('erro');
        valid = false;
    }

    if ($("#Estado").val() == '') {
        $("#Estado").addClass('erro');
        mensagem_de_erro += "Escolha o Estado que você mora.\n";
        valid = false;
    }

    if ($("#CEP").val() == '') {
        $("#CEP").addClass('erro');
        valid = false;
    }

    if (mensagem_de_erro.length > 0) {
        MostraMensagem(mensagem_de_erro);
    }

    return valid;
}
function Cadastro1(continua) {
    if (ValidaCadastroPasso1($('#cp1-Nome'), $('#cp1-Email'), $('#cp1-ConfirmacaoEmail'), $('#cp1-Senha'), $('#cp1-ConfirmacaoSenha'), $("#cp1-hdNews"))) {
        $.ajax({
            type: "POST",
            url: webPath + 'Util/CadastroLB',
            global: false,
            data: {
                nome: $('#cp1-Nome').val(),
                email: $('#cp1-Email').val(),
                senha: $('#cp1-Senha').val(),
                news: $("#cp1-hdNews").val() == 1,
                continua: continua
            },
            dataType: "html",
            success: function(content) {
                if (content == 'Erro-email') {
                    $('#cp1-Email').addClass('erro');
                    $('#cp1-Email').parents("fieldset").prepend("<span class='field-validation-error'>O e-mail digitado j&aacute; est&aacute; cadastrado em nossa base.</span>");
                }
                else if (content == "sucesso") {
                    if (continua) {
                        window.location.replace(webPath + "util/Cadastro/?passo=2");
                    }
                    else {
                        window.location.replace((typeof $("#url_ferramenta").val() === "string" && $("#url_ferramenta").val().length > 0) ? $("#url_ferramenta").val() : webPath);
                    }
                }
            }
        });
    }
}
function CadastroLB(continua) {
    if (ValidaCadastroPasso1($('#lb-Nome'), $('#lb-Email'), $('#lb-ConfirmacaoEmail'), $('#lb-Senha'), $('#lb-ConfirmacaoSenha'), $("#lb-hdNews"))) {
        $.ajax({
            type: "POST",
            url: webPath + 'Util/CadastroLB',
            global: false,
            data: {
                nome: $('#lb-Nome').val(),
                email: $('#lb-Email').val(),
                senha: $('#lb-Senha').val(),
                news: $("#lb-hdNews").val() == 1
            },
            dataType: "html",
            success: function(content) {
                if (content == 'Erro-email') {
                    $('#lb-Email').addClass('erro');
                    $('#lb-Email').parent().append("<span class='field-validation-error'>O e-mail digitado j&aacute; est&aacute; cadastrado em nossa base.</span>");
                }
                else if (content == "sucesso") {
                    if (continua) {
                        window.location.replace(webPath + "util/Cadastro/?passo=2");
                    }
                    else {
                        window.location.replace($("#hdUrl").val());
                    }
                }
            },
            error: function(xhr, status, error) {
                console.log(xhr);
            }
        });
    }
    return false;
}
function Cadastro2(continua) {
    if (ValidaCadastroPasso2()) {
        $.ajax({
            type: "POST",
            url: webPath + 'Util/Cadastro2',
            global: false,
            data: {
                Sexo: $('#Sexo').val(),
                DataNacimento: $('#DataNacimento').val(),
                Peso: $('#Peso').val(),
                Altura: $("#Altura").val(),
                NivelAtividade: $("#NivelAtividade").val(),
                Temperatura: $("#Temperatura").val()
            },
            dataType: "html",
            success: function(content) {
                if (content == "sucesso") {
                    if (continua) {
                        window.location.replace(webPath + "util/Cadastro/?passo=3");
                    } else {
                        window.location.replace((typeof $("#url_ferramenta").val() === "string" && $("#url_ferramenta").val().length > 0) ? $("#url_ferramenta").val() : webPath);
                    }
                }
                else {
                    MostraMensagem(content);
                }
            }
        });
    }

    return false;
}
function Cadastro3() {
    if (ValidaCadastroPasso3()) {
        $.ajax({
            type: "POST",
            url: webPath + 'Util/Cadastro3',
            global: false,
            data: {
                AreaAtuacao: $('#AreaAtuacao').val(),
                Telefone: $('#Telefone').val(),
                Endereco: $('#Endereco').val(),
                Numero: $("#Numero").val(),
                Complemento: $("#Complemento").val(),
                Bairro: $("#Bairro").val(),
                Cidade: $("#Cidade").val(),
                Estado: $("#Estado").val(),
                CEP: $("#CEP").val(),
                CodigoPromocional: $("#CodigoPromocional").val()
            },
            dataType: "html",
            success: function(content) {
                if (content == "Erro-codigo") {
                    $("#CodigoPromocional").addClass('erro');
                    MostraMensagem("O C&oacute;digo Promocional digitado n&atilde;o &eacute; v&aacute;lido!");
                }
                else if (content == "sucesso") {

                    if ((typeof $("#url_ferramenta").val() === "string") && ($("#url_ferramenta").val().length > 0)) {
                        window.location.replace = $("#url_ferramenta").val();
                    } else {
                        window.location.replace = webPath;
                    }
                } else if (content == "nutrabem") {
                    LogarNutrabem2();
                } else {
                    MostraMensagem(content);
                }
            }
        });
    }

    return false;
}
function Logar() {
    $.ajax({
        type: "POST",
        url: webPath + 'Util/Logar',
        global: false,
        data: $('#FORM_LOGIN').serialize(),
        dataType: "html",
        success: function(content) {
            if (content == 'RENOVACAO')
                LogarNutrabem(nutraWebPath + 'servico/Renovacao.aspx');
            else if (content == 'DICAS')
                LogarNutrabem(nutraWebPath + 'servico/servico_dicas.aspx');
            else if (content == 'OK')
                LogarNutrabem(nutraWebPath + 'servico/servico_home.aspx');
            else
                window.location.replace(content);
        }
    });
}
function Logar2() {
    $.ajax({
        type: "POST",
        url: webPath + 'Util/Logar',
        global: false,
        data: $('#FORM_LOGIN_2').serialize(),
        dataType: "html",
        success: function(content) {
            if (content == 'RENOVACAO')
                LogarNutrabem(nutraWebPath + 'servico/Renovacao.aspx');
            else if (content == 'DICAS')
                LogarNutrabem(nutraWebPath + 'servico/servico_dicas.aspx');
            else if (content == 'OK')
                LogarNutrabem(nutraWebPath + 'servico/servico_home.aspx');
            else
                window.location.replace(content);
        }
    });
}

function LogarNutrabem(url) {
    var iframe_src = nutraWebPath + 'site/index.aspx';
    var usuario = $('#FORM_LOGIN').find("#usuario").val();
    var senha = $('#FORM_LOGIN').find("#senha").val();
    $("iframe#login_frame").attr("src", iframe_src);
    $("iframe#login_frame").bind("load", function(event) {
        var $this = $(this);
        var doc = this.contentWindow ? this.contentWindow.document : this.contentDocument ? this.contentDocument : this.document;
        if (!doc || (window.opera !== undefined && (doc.body == null || doc.body.innerHTML == ''))) {
            return;
        }
        $this.unbind("load");
        var content = doc.body ? doc.body.innerHTML : doc.documentElement ? doc.documentElement.innerHTML : null;

        doc.getElementById("txtEmail").value = usuario;
        doc.getElementById("txtSenha").value = senha;
        doc.getElementById("btnLogin").click();

        $this.bind("load", function(e) {
            parent.change_parent_url(url);
        });
    });
}
function LogarNutrabem2() {
    var iframe_src = nutraWebPath + 'site/index.aspx';
    var usuario = "";
    var senha = "";
    var url = "";
    $.ajax({
        type: "POST",
        url: webPath + 'Util/UsuarioCredencial',
        global: false,
        data: null,
        dataType: "html",
        success: function(content) {
            if (content == "ERRO") {
                MostraMensagem("Ocorreu um erro, tente novamente.");
            }
            else {
                var array = content.split('|');
                usuario = array[0];
                senha = array[1];
                url = array[2];
                $("iframe#login_frame").attr("src", iframe_src);

                $("iframe#login_frame").bind("load", function(event) {
                    var $this = $(this);
                    var doc = this.contentWindow ? this.contentWindow.document : this.contentDocument ? this.contentDocument : this.document;
                    if (!doc || (window.opera !== undefined && (doc.body == null || doc.body.innerHTML == ''))) {
                        return;
                    }
                    $this.unbind("load");
                    var content = doc.body ? doc.body.innerHTML : doc.documentElement ? doc.documentElement.innerHTML : null;

                    doc.getElementById("txtEmail").value = usuario;
                    doc.getElementById("txtSenha").value = senha;
                    doc.getElementById("btnLogin").click();

                    $this.bind("load", function(e) {
                        parent.change_parent_url(url);
                    });
                });
            }
        }
    });
}
function change_parent_url(url) {
    window.location.replace(url);
}
function LogarBreak() {

    $.ajax({
        type: "POST",
        url: webPath + 'Util/LogarBreak',
        global: false,
        data: $('#FORM_LOGIN_BREAK').serialize(),
        dataType: "html",
        success: function(content) {
            if (content.substring(0, 4) == "http") {
                window.location.replace(content);
            }
            else if (content.substring(0, 4) == "erro") {
                MostraMensagem(content.substring(4));
            }
            else {
                if (content == 'RENOVACAO')
                    LogarNutrabem(nutraWebPath + 'servico/Renovacao.aspx');
                else if (content == 'DICAS')
                    LogarNutrabem(nutraWebPath + 'servico/servico_dicas.aspx');
                else if (content == 'OK')
                    LogarNutrabem(nutraWebPath + 'servico/servico_home.aspx');
                else
                    window.location.replace(content);
            }
        }
    });
}
function CarregarEquivalencias() {
    $.ajax({
        type: "POST",
        url: webPath + "Util/TabelaEquivalencias",
        global: false,
        dataType: "html",
        success: function(data, status, xhr) {
            $("div.box-resultados").html(data);
        },
        error: function(xhr, status, error) {

        }
    });
}
function NewsLetter() {
    $.ajax({
        type: "POST",
        url: webPath + 'Util/CadastroNewsLetter',
        global: false,
        data: $('#FORM_NEWS').serialize(),
        dataType: "html",
        success: function(content) {
            window.location.replace(content);
        }
    });
}
function EsqueciMinhaSenha(login) {
    if (login == '' || login == 'E-mail')
        MostraMensagem('Digite o seu e-mail.');
    else {
        $.ajax({
            type: "POST",
            url: webPath + 'Util/EsqueciMinhaSenha/' + login,
            global: false,
            data: null,
            dataType: "html",
            success: function(content) {
                MostraMensagem(content);
            }
        });
    }
}
function AbrePopCadastro() {
    $(".bg-branco:not(.convite-preview)").show();

    $('#lb-Nome').removeClass('erro');
    $('#lb-Email').removeClass('erro');
    $('#lb-ConfirmacaoEmail').removeClass('erro');
    $('#lb-Senha').removeClass('erro');
    $('#lb-ConfirmacaoSenha').removeClass('erro');
    $(".field-validation-error").remove();
    $('#lb-Nome').val('');
    $('#lb-Email').val('');
    $('#lb-ConfirmacaoEmail').val('');
    $('#lb-Senha').val('');
    $('#lb-ConfirmacaoSenha').val('');
    $('#lb-Nome').blur();
    $('#lb-Email').blur();
    $('#lb-ConfirmacaoEmail').blur();
    $('#lb-Senha').blur();
    $('#lb-ConfirmacaoSenha').blur();


    $("#divLBCadastro").show();
    $("#divLBCadastro").animate({ top: 80 }, 200);
}
function FechaPopCadastro() {
    $("#divLBCadastro").hide();
    $(".bg-branco:not(.convite-preview)").hide();
}
function MostraMensagem(mensagem) {
    $(".bg-branco:not(.convite-preview)").show();

    $("#Mensagem-lightbox").show();
    $("#Mensagem-lightbox").animate({ top: $(document).scrollTop() + (($(window).height() / 2) - 80) }, 200);
    $("#Mensagem-lightbox").find(".texto").html(mensagem);
}
function FechaLightboxPerfilAlimentar() {
    $("#perfil-alimentar-lightbox").hide();
    $(".bg-branco:not(.convite-preview)").hide();
}

/* Brazilian initialisation for the jQuery UI date picker plugin. */
/* Written by Leonildo Costa Silva (leocsilva@gmail.com). */
jQuery(function($) {
    $.datepicker.regional['pt-BR'] = {
        closeText: 'Fechar',
        prevText: '&#x3c;Anterior',
        nextText: 'Pr&oacute;ximo&#x3e;',
        currentText: 'Hoje',
        monthNames: ['Janeiro', 'Fevereiro', 'Mar&ccedil;o', 'Abril', 'Maio', 'Junho',
		'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
        monthNamesShort: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun',
		'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
        dayNames: ['Domingo', 'Segunda-feira', 'Ter&ccedil;a-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sabado'],
        dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'],
        dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        firstDay: 0,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['pt-BR']);
});

function ValidaData(data) {
    var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
    if ((data.match(expReg)) && (data != '')) {
        var dia = data.substring(0, 2);
        var mes = data.substring(3, 5);
        var ano = data.substring(6, 10);
        if ((mes == 4 || mes == 6 || mes == 9 || mes == 11) && dia > 30) {
            return false;
        } else {
            if (ano % 4 != 0 && mes == 2 && dia > 28) {     
                return false;
            } else {
                if (ano % 4 == 0 && mes == 2 && dia > 29) {
                    return false;
                }
                if (ano < 1900 || ano > new Date().getFullYear())
                    return false;
                return true;
            }
        }
    }
    return false;
}

function ValidaDecimal(valor) {
    var expReg = /^[+-]?((\d+|\d{1,3}(\.\d{3})+)(\,\d*)?|\,\d+)$/;
    if (valor.match(expReg) && valor != '') {
        return true;
    }
    return false;
}
function email_valido(email) { return email.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/); }

$(document).ready(function() {
    $("#video_nutrabem_online a").bind("click", function(event) {
        var video_nutrabem_online = AC_FL_RunContent('type', 'application/x-shockwave-flash', 'data', webPath + "Content/player.swf?", 'width', '500px', 'height', '350px', 'movie', webPath + 'Content/player', 'allowfullscreen', 'true', 'allowscriptaccess', 'always', 'flashvars', 'file=' + webPath + "Content/NutrabemOnline.mp4"), //end AC code
			$video_nutrabem_online = $("" + video_nutrabem_online);

        $("#video_nutrabem_online").children().remove();
        $("#video_nutrabem_online").append($video_nutrabem_online);

        return false
    });
});
