﻿	handleChange = function(event) {
		var path = event.path;
		if (path.substr(path.length - 1) != '/') {
			path += '/';
		}
		if( ($('.non_default').length > 0) && (path.replace(/\//gi, '') == '') ) {
			$('#conteudo_empreendimento').hide();
			$('.non_default').show();
			$.scrollTo('.non_default', 500);
		}
		if(path.replace(/\//gi, '') != 'abreFreedom')
			$('#bt_aba_' + path.replace(/\//gi, '')).trigger('click');
	}
	
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);

	$(document).ready(function(){
		
		clickLocalizacao = function(){
			$('#bt_aba_localizacao').trigger('click');
			$.scrollTo('#bt_aba_localizacao', 500);
		}
		
		clickPlantas = function (){
			$('#bt_aba_plantas').trigger('click');
			$.scrollTo('#bt_aba_plantas', 500);
		}
		
		clickGanhadores = function(){
			window.open('http://www.tha.com.br/blog/?p=1421');
		}

		var fraseAtual = 0;
		var tOut = null;
		var frases = new Array();
		
		$.get('/portal/html/empreendimentos/belvedere-joinville/_methods/listagem_mensagens_todas.php', function(data) {
			for(var i = 0; i < $(data).find('item').length; i++) {
				frases[i] = [$(data).find('item').eq(i).attr('mensagem'), $(data).find('item').eq(i).attr('nome')];
			}
			
			changeFrase(0);
		}, 'xml');
		
		$('#bt_frases_esq').bind('click', function() {
			changeFrase(-1);
		});
		$('#bt_frases_dir').bind('click', function() {
			changeFrase(+1);
		});
		
		changeFrase = function(quant) {
			clearTimeout(tOut);
			if(fraseAtual + quant < 0)
				fraseAtual = frases.length - 1;
			else if(fraseAtual + quant == frases.length)
				fraseAtual = 0;
			else
				fraseAtual = fraseAtual + quant;
			
			$('#div_frases').fadeOut('fast', function(){
				$('#div_frase').html(frases[fraseAtual][0]);
				$('#div_autor').html('Enviada por: ' + frases[fraseAtual][1]);
				$('#div_frases').fadeIn('fast');
				tOut = setTimeout("changeFrase(+1)", 8000);
			});
		}

		$('.btAbaOff:first').removeClass('btAbaOff').addClass('btAbaOn');
		$('#conteudo_abas').parent().css('height', $('#aba_empreendimento').height() + 'px');
		$('.btAbaOff').live('click', function(){
			var ths = $(this);
			var cont = $('#conteudo_abas');
			var target = $('#' + ths.attr('id').replace('bt_', ''));
			$.scrollTo('#' + ths.attr('id'), 500);
			cont.parent().animate({
				height: target.height() + 'px'
			});
			cont.animate({
				marginTop: (cont.offset().top - target.offset().top) + 'px'
			}, function(){
				switch(ths.attr('id').replace('bt_', '')) {
					case 'aba_localizacao': 
						$('#map_canvas').jmap('init', {'mapType':'hybrid', 'mapZoom':15, 'mapEnableSmoothZoom':true, 'mapEnableType':true, 'mapEnableScaleControl':true, 'mapControl':'large', 'mapCenter':eval('[' + coordenadas + ']')});
						$('#map_canvas').jmap('AddMarker', {'pointLatLng': eval('[' + coordenadas + ']')});
						break;
				}
			});
			$('.btAbaOn').removeClass('btAbaOn').addClass('btAbaOff');
			$(this).removeClass('btAbaOff').addClass('btAbaOn');
			SWFAddress.setValue('/' + target.attr('id').replace('aba_', '') + '/');
		});
		
		topUpdate = function(){
			var cont = $('#conteudo_abas');
			if ($('.btAbaOn').length > 0) {
				var target = $('#' + $('.btAbaOn').attr('id').replace('bt_', ''));
				if(target.offset().top != defTop)
					cont.css('margin-top', (cont.offset().top - target.offset().top) + 'px');
				
			}
		}
		var iVal = setInterval('topUpdate()', 500);
		var defTop = 0;
		if ($('#aba_empreendimento').length > 0) {
			defTop = $('#aba_empreendimento').offset().top;
		} 
		
		$('#bt_outrasplantas').bind('click', function(){
			$('#bt_aba_plantas').trigger('click');
			$.scrollTo('#bt_aba_plantas', 500);
		});
		
		$('#bt_ampliar_localizacao').bind('click', function(){
			$('#bt_aba_localizacao').trigger('click');
			$.scrollTo('#bt_aba_localizacao', 500);
		});
		
		$('#bt_vejamais_estagio').bind('click', function(){
			$('#bt_aba_estagiodaobra').trigger('click');
			$.scrollTo('#bt_aba_estagiodaobra', 500);
		});
		
		var thumbs_slidding = false;
		
		$('.thumbs_slider').each(function(){
			$(this).css('width', ($(this).find('img').length * 140) + 'px');
		});

		$('.bt_right_thumbs').bind('click', function(){
																	
			var obj = $('#' + $(this).attr('id').replace('bt_right_', ''));
			
			var wid = parseInt(obj.css('width'));
			var ml = parseInt(obj.css('margin-left'));
			
			if( (!thumbs_slidding) && (ml - 560 > (Math.ceil(wid / 560) * 560) * -1) ) {
				thumbs_slidding = true;
				obj.animate({
					marginLeft: (ml - 560) + 'px'
				}, function(){
					thumbs_slidding = false;
				});
			}
		});
		
		$('.bt_left_thumbs').bind('click', function(){
			var obj = $('#' + $(this).attr('id').replace('bt_left_', ''));
			
			var wid = parseInt(obj.css('width'));
			var ml = parseInt(obj.css('margin-left'));
			
			if( (!thumbs_slidding) && (ml + 560 <= 0) ) {
				thumbs_slidding = true;
				obj.animate({
					marginLeft: (ml + 560) + 'px'
				}, function(){
					thumbs_slidding = false;
				});
			}
		});
		
		$('.image_container').load(function(e){
			var ths = $(this);
			var hei = parseInt(ths.attr('height'));
			$(this).parent().animate({
				height: hei + 'px'
			}, {
				step: function() {
					$('#conteudo_abas').parent().css('height', $('#' + $('.btAbaOn').attr('id').replace('bt_', '')).height() + 'px');
				},
				complete: function() {
					$('#conteudo_abas').parent().css('height', $('#' + $('.btAbaOn').attr('id').replace('bt_', '')).height() + 'px');
					ths.animate({
						opacity: 1
					});
				}
			});
		});
		
		$('.thumbs_slider').find('img').css({
			cursor: 'pointer'
		});
		$('.thumbs_slider').find('img').bind('click', function(){
			var ths = $(this);
			var img_cont = $('#image_container_' + ths.parent().parent().attr('id').replace('thumbs_', ''));
			if(img_cont.attr('src') != ths.attr('src').replace('115/115', '600/600')) {
				$('#title_' + ths.parent().parent().attr('id')).html(ths.parent().find('div').html());
				$('#tamanho_' + ths.parent().parent().attr('id')).parent().html('');
//				$('#tamanho_' + ths.parent().parent().attr('id')).html(ths.attr('ref'));
				$('#download_' + ths.parent().parent().attr('id')).attr('href', ths.attr('src').replace('115/115', '0/0'));
				img_cont.attr('alt', ths.parent().find('div').html());
				img_cont.animate({
					opacity: 0
				}, function(){
					img_cont.attr('src', ths.attr('src').replace('115/115', '600/600'));
				});
			}
		});
		$('#thumbs_01').find('img:eq(0)').trigger('click');
		$('#thumbs_02').find('img:eq(0)').trigger('click');



	// Sidebar
		$('.slider_sidebar').each(function(){
			$(this).css('width', ($(this).find('img').length * 225) + 'px');
			$('#navigator_' + $(this).attr('id')).parent().css('width', ($(this).find('img').length * 13) + 'px');
		});

		$('#slider_01').find('img').css('cursor', 'pointer');
		$('#slider_01').find('img').bind('click', function(){
			var ths = $(this);
			$('#thumbs_02').find('img').each(function(i){
				if($(this).attr('src').replace('115/115', '175/110') == ths.attr('src'))
				{
					$('#bt_aba_plantas').trigger('click');
					$.scrollTo('#bt_aba_plantas', 500);
					$(this).trigger('click');
				}
			});
		});

		
		$('.navigator_slider').bind('click', function(e){
			var pos = Math.floor(Math.ceil(e.pageX - $(this).offset().left) / 13);
			if( (pos < $('#' + $(this).attr('id').replace('navigator_', '')).find('img').length) && (pos >= 0) ) {
				$(this).animate({
					backgroundPosition: (pos * 13) + 'px'
				});
				$('#' + $(this).attr('id').replace('navigator_', '')).animate({
					marginLeft: (0 - (pos * 225)) + 'px'
				});
			}
		});


	// Modais

		$('.bt_newsletter').bind('click', function(){
			$.blockUI({
				message: $('#modal_newsletter'),
				css: { 
					top: '50px', 
					left: ($(window).width() - 690) /2 + 'px',
					cursor: 'default',
					border: 'none'
				},
				overlayCSS:
				{
					cursor: 'default'
				} 
			});
			$('#modal_newsletter_fechar').bind('click', function(){
				$.unblockUI({
					onUnblock: function(){
						$('#div_form_newsletter').show();
						$('#bt_form_newsletter').show();
						$('#div_sucesso_newsletter').hide();
					}
				})
			});
		});

		$('#form_newsletter').submit(function(e) {
			e.preventDefault();
			if(checkFormNews())
			{
				$('#bt_form_newsletter').fadeOut('normal', function(){
					$('#msg_form_newsletter').html('Aguarde! Cadastrando e-mail.');
					$('#msg_form_newsletter').fadeIn('normal', function(){
						var str = $("#form_newsletter").serialize();
						$.post(_site_base + 'news', str, function(data){
							var msg_retorno = '';
							if(data.retorno == 'erro')
								msg_retorno = 'Ocorreu um erro. Tente novamente!';
							else if(data.retorno == 'enviado')
								msg_retorno = 'E-mail cadastrado com sucesso!';

							$('#msg_form_newsletter').fadeOut('normal', function(){
								$('#msg_form_newsletter').html(msg_retorno);
								$('#msg_form_newsletter').fadeIn('normal', function(){
									timerId = setTimeout(function(){
										clearTimeout(timerId);
										$('#msg_form_newsletter').fadeOut('normal', function() {
											$('#div_form_newsletter').slideUp('normal', function(){
												$('#div_sucesso_newsletter').slideDown('normal');
												$('#form_newsletter').each(function(){
													this.reset();
												});
											});
										});
									}, 2000);
								});
							});
						}, 'json');
					});
				});
			}
		});
		
		checkFormNews = function()
		{
			var erro = '';
			var foco;
			var frm = document.forms['form_newsletter'];
			
			if(frm.nome.value == '')
			{
				erro += '\n - Nome;';
				if(!foco)
					foco = frm.nome;
			}
			if( (frm.email.value == '') || (frm.email.value.indexOf('@') < 0) || (frm.email.value.indexOf('.') < 0) )
			{
				erro += '\n - E-mail;';
				if(!foco)
					foco = frm.email;
			}

			if(erro == '')
			{
				frm.cd_imovel.value = get_old_building_id();
				return true;
			}
			else
			{
				alert('Campos incorretos ou inválidos:\n' + erro);
				foco.focus();
				return false;
			}
		}

		$('#bt_liga').bind('click', function(){
			$.blockUI({
				message: $('#modal_liga'),
				css: { 
					top: '50px', 
					left: ($(window).width() - 690) /2 + 'px',
					cursor: 'default',
					border: 'none'
				},
				overlayCSS:
				{
					cursor: 'default'
				} 
			});
			$('#modal_liga_fechar').bind('click', function(){
				$.unblockUI({
					onUnblock: function(){
						$('#div_form_liga').show();
						$('#bt_form_liga').show();
						$('#div_sucesso_liga').hide();
					}
				})
			});
		});

		$('#form_liga').submit(function(e) {
			e.preventDefault();
			if(checkFormLiga())
			{
				$('#bt_form_liga').fadeOut('normal', function(){
					$('#msg_form_liga').html('Aguarde! Enviando e-mail.');
					$('#msg_form_liga').fadeIn('normal', function(){
						var str = $("#form_liga").serialize();
						$.post(_site_base + 'liga', str, function(data){
							var msg_retorno = '';
							if(data.retorno == 'erro')
								msg_retorno = 'Ocorreu um erro. Tente novamente!';
							else if(data.retorno == 'enviado')
								msg_retorno = 'E-mail enviado com sucesso!';

							$('#msg_form_liga').fadeOut('normal', function(){
								$('#msg_form_liga').html(msg_retorno);
								$('#msg_form_liga').fadeIn('normal', function(){
									timerId = setTimeout(function(){
										clearTimeout(timerId);
										$('#msg_form_liga').fadeOut('normal', function() {
											$('#div_form_liga').slideUp('normal', function(){
												$('#div_sucesso_liga').slideDown('normal');
												$('#form_liga').each(function(){
													this.reset();
												});
											});
										});
									}, 2000);
								});
							});
						}, 'json');
					});
				});
			}
		});
		
		checkFormLiga = function()
		{
			var erro = '';
			var foco;
			var frm = document.forms['form_liga'];
			
			if(frm.nome.value == '')
			{
				erro += '\n - Nome;';
				if(!foco)
					foco = frm.nome;
			}
			if(frm.ddd.value == '')
			{
				erro += '\n - DDD;';
				if(!foco)
					foco = frm.ddd;
			}
			if(frm.telefone.value == '')
			{
				erro += '\n - Telefone;';
				if(!foco)
					foco = frm.telefone;
			}

			if(erro == '')
			{
				return true;
			}
			else
			{
				alert('Campos incorretos ou inválidos:\n' + erro);
				foco.focus();
				return false;
			}
		}



		$('#bt_voltar_amigo').bind('click', function(){
			$('#div_sucesso_amigo').slideUp('normal', function(){
				$('#bt_form_amigo').show();
				$('#div_sucesso_amigo').hide();
				$('#div_form_amigo').slideDown('normal');
			});
		});
		$('.bt_amigo').bind('click', function(){
			$.blockUI({
				message: $('#modal_amigo'),
				css: { 
					top: '50px', 
					left: ($(window).width() - 690) /2 + 'px',
					cursor: 'default',
					border: 'none'
				},
				overlayCSS:
				{
					cursor: 'default'
				} 
			});
			$('#modal_amigo_fechar').bind('click', function(){
				$.unblockUI({
					onUnblock: function(){
						$('#div_form_amigo').show();
						$('#bt_form_amigo').show();
						$('#div_sucesso_amigo').hide();
					}
				})
			});
		});

		$('#form_amigo').submit(function(e) {
			e.preventDefault();
			if(checkFormAmigo())
			{
				$('#bt_form_amigo').fadeOut('normal', function(){
					$('#msg_form_amigo').html('Aguarde! Enviando e-mail.');
					$('#msg_form_amigo').fadeIn('normal', function(){
						var str = $("#form_amigo").serialize();
						$.post(_site_base + "indique", str, function(data){
							var msg_retorno = '';
							if(data.retorno == 'erro')
								msg_retorno = 'Ocorreu um erro. Tente novamente!';
							else if(data.retorno == 'enviado')
								msg_retorno = 'E-mail enviado com sucesso!';

							$('#msg_form_amigo').fadeOut('normal', function(){
								$('#msg_form_amigo').html(msg_retorno);
								$('#msg_form_amigo').fadeIn('normal', function(){
									timerId = setTimeout(function(){
										clearTimeout(timerId);
										$('#msg_form_amigo').fadeOut('normal', function() {
											$('#div_form_amigo').slideUp('normal', function(){
												$('#form_amigo').each(function(){
													this.reset();
												});
												$('#div_sucesso_amigo').slideDown('normal');
											});
										});
									}, 2000);
								});
							});
						}, 'json');
					});
				});
			}
		});
		
		checkFormAmigo = function()
		{
			var erro = '';
			var foco;
			var frm = document.forms['form_amigo'];
			
			if(frm.nome.value == '')
			{
				erro += '\n - Seu nome;';
				if(!foco)
					foco = frm.nome;
			}
			if( (frm.email.value == '') || (frm.email.value.indexOf('@') < 0) || (frm.email.value.indexOf('.') < 0) )
			{
				erro += '\n - Seu e-mail;';
				if(!foco)
					foco = frm.email;
			}
			if(frm.nome_amigo.value == '')
			{
				erro += '\n - Nome do amigo;';
				if(!foco)
					foco = frm.nome_amigo;
			}
			if( (frm.email_amigo.value == '') || (frm.email_amigo.value.indexOf('@') < 0) || (frm.email_amigo.value.indexOf('.') < 0) )
			{
				erro += '\n - E-mail do amigo;';
				if(!foco)
					foco = frm.email_amigo;
			}
			if(frm.mensagem.value == '')
			{
				erro += '\n - Mensagem;';
				if(!foco)
					foco = frm.mensagem;
			}

			if(erro == '')
			{
				return true;
			}
			else
			{
				alert('Campos incorretos ou inválidos:\n' + erro);
				foco.focus();
				return false;
			}
		}



		$('#bt_visita').bind('click', function(){
			$.blockUI({
				message: $('#modal_visita'),
				css: { 
					top: '10px', 
					left: ($(window).width() - 690) /2 + 'px',
					cursor: 'default',
					border: 'none'
				},
				overlayCSS:
				{
					cursor: 'default'
				} 
			});
			$('#modal_visita_fechar').bind('click', function(){
				$.unblockUI({
					onUnblock: function(){
						$('#div_form_visita').show();
						$('#bt_form_visita').show();
						$('#div_sucesso_visita').hide();
					}
				})
			});
		});

		$('#form_visita').submit(function(e) {
			e.preventDefault();
			if(checkFormVisita())
			{
				$('#bt_form_visita').fadeOut('normal', function(){
					$('#msg_form_visita').html('Aguarde! Enviando e-mail.');
					$('#msg_form_visita').fadeIn('normal', function(){
						var str = $("#form_visita").serialize();
						$.post(_site_base + 'agende', str, function(data){
							var msg_retorno = '';
							if(data.retorno == 'erro')
								msg_retorno = 'Ocorreu um erro. Tente novamente!';
							else if(data.retorno == 'enviado')
								msg_retorno = 'E-mail enviado com sucesso!';

							$('#msg_form_visita').fadeOut('normal', function(){
								$('#msg_form_visita').html(msg_retorno);
								$('#msg_form_visita').fadeIn('normal', function(){
									timerId = setTimeout(function(){
										clearTimeout(timerId);
										$('#msg_form_visita').fadeOut('normal', function() {
											$('#div_form_visita').slideUp('normal', function(){
												$('#form_visita').each(function(){
													this.reset();
												});
												$('#div_sucesso_visita').slideDown('normal');
											});
										});
									}, 2000);
								});
							});
						}, 'json');
					});
				});
			}
		});
		
		checkFormVisita = function()
		{
			var erro = '';
			var foco;
			var frm = document.forms['form_visita'];
			
			if(frm.nome.value == '')
			{
				erro += '\n - Nome;';
				if(!foco)
					foco = frm.nome;
			}
			if( ( (frm.forma[0].checked) || (frm.forma[2].checked) ) && ( (frm.ddd_telefone.value == '') || (frm.telefone.value == '') || (frm.ddd_celular.value == '') || (frm.celular.value == '') ) )
			{
				if( (frm.ddd_telefone.value != '') && (frm.telefone.value != '') ) {
				}
				else if ( (frm.ddd_celular.value != '') && (frm.celular.value != '') ) {
				}
				else {
					erro += '\n - Telefone ou Celular;';
					if(!foco)
						foco = frm.ddd_telefone;
				}
			}
			if( (frm.email.value == '') || (frm.email.value.indexOf('@') < 0) || (frm.email.value.indexOf('.') < 0) )
			{
				erro += '\n - E-mail;';
				if(!foco)
					foco = frm.email;
			}
			if(frm.mensagem.value == '')
			{
				erro += '\n - Mensagem;';
				if(!foco)
					foco = frm.mensagem;
			}

			if(erro == '')
			{
				frm.cd_imovel.value = get_old_building_id();
				return true;
			}
			else
			{
				alert('Campos incorretos ou inválidos:\n' + erro);
				foco.focus();
				return false;
			}
		}



		$('.bt_solicite').bind('click', function(){
			window.location.href= _site_base + 'grupo-tha/fale-conosco/' + get_building_by_url(window.location.href);
		});

		$('.bt_envie_email').bind('click', function(){
			window.location.href= _site_base + 'grupo-tha/fale-conosco/' + get_building_by_url(window.location.href);
		});

		$('#form_solicite').submit(function(e) {
			e.preventDefault();
			if(checkFormSolicite())
			{
				$('#bt_form_solicite').fadeOut('normal', function(){
					$('#msg_form_solicite').html('Aguarde! Enviando e-mail.');
					$('#msg_form_solicite').fadeIn('normal', function(){
						var str = $("#form_solicite").serialize();
						$.post("/homolog/pessuti/site/_methods/send_fale.php", str, function(data){
							var msg_retorno = '';
							if(data.retorno == 'erro')
								msg_retorno = 'Ocorreu um erro. Tente novamente!';
							else if(data.retorno == 'enviado')
								msg_retorno = 'E-mail enviado com sucesso!';

							$('#msg_form_solicite').fadeOut('normal', function(){
								$('#msg_form_solicite').html(msg_retorno);
								$('#msg_form_solicite').fadeIn('normal', function(){
									timerId = setTimeout(function(){
										clearTimeout(timerId);
										$('#msg_form_solicite').fadeOut('normal', function() {
											$('#div_form_solicite').slideUp('normal', function(){
												$('#form_solicite').each(function(){
													this.reset();
												});
												$('#div_sucesso_solicite').slideDown('normal');
											});
										});
									}, 2000);
								});
							});
						}, 'json');
					});
				});
			}
		});
		
		checkFormSolicite = function()
		{
			var erro = '';
			var foco;
			var frm = document.forms['form_solicite'];
			
			if(frm.nome.value == '')
			{
				erro += '\n - Nome;';
				if(!foco)
					foco = frm.nome;
			}
			if( ( (frm.forma[0].checked) || (frm.forma[2].checked) ) && ( (frm.ddd_telefone.value == '') || (frm.telefone.value == '') || (frm.ddd_celular.value == '') || (frm.celular.value == '') ) )
			{
				if( (frm.ddd_telefone.value != '') && (frm.telefone.value != '') ) {
				}
				else if ( (frm.ddd_celular.value != '') && (frm.celular.value != '') ) {
				}
				else {
					erro += '\n - Telefone ou Celular;';
					if(!foco)
						foco = frm.ddd_telefone;
				}
			}
			if( (frm.email.value == '') || (frm.email.value.indexOf('@') < 0) || (frm.email.value.indexOf('.') < 0) )
			{
				erro += '\n - E-mail;';
				if(!foco)
					foco = frm.email;
			}
			if(frm.assunto.value == '')
			{
				erro += '\n - Assunto;';
				if(!foco)
					foco = frm.assunto;
			}
			if(frm.mensagem.value == '')
			{
				erro += '\n - Mensagem;';
				if(!foco)
					foco = frm.mensagem;
			}

			if(erro == '')
			{
				return true;
			}
			else
			{
				alert('Campos incorretos ou inválidos:\n' + erro);
				foco.focus();
				return false;
			}
		}



		$('#bt_partic').bind('click', function(){
			$.blockUI({
				message: $('#modal_participe'),
				css: { 
					top: '50px', 
					left: ($(window).width() - 690) /2 + 'px',
					cursor: 'default',
					border: 'none'
				},
				overlayCSS:
				{
					cursor: 'default'
				} 
			});
			$('#modal_participe_fechar').bind('click', function(){
				$.unblockUI({
					onUnblock: function(){
						$('#div_form_participe').show();
						$('#bt_form_participe').show();
						$('#div_sucesso_participe').hide();
					}
				})
			});
		});

		$('#form_participe').submit(function(e) {
			e.preventDefault();
			if(checkFormParticipe())
			{
				$('#bt_form_participe').fadeOut('normal', function(){
					$('#msg_form_participe').html('Aguarde! Enviando mensagem.');
					$('#msg_form_participe').fadeIn('normal', function(){
						var str = $("#form_participe").serialize();
						$.post("/portal/html/empreendimentos/belvedere-joinville/_methods/cadastrar_mensagem.php", str, function(data){
							var msg_retorno = '';
							if(data.retorno == 'erro')
								msg_retorno = 'Ocorreu um erro. Tente novamente!';
							else if(data.retorno == 'enviado')
								msg_retorno = 'Mensagem enviada com sucesso!';

							$('#msg_form_participe').fadeOut('normal', function(){
								$('#msg_form_participe').html(msg_retorno);
								$('#msg_form_participe').fadeIn('normal', function(){
									timerId = setTimeout(function(){
										clearTimeout(timerId);
										$('#msg_form_participe').fadeOut('normal', function() {
											$('#div_form_participe').slideUp('normal', function(){
												$('#form_participe').each(function(){
													this.reset();
												});
												$('#div_sucesso_participe').slideDown('normal');
											});
										});
									}, 2000);
								});
							});
						}, 'json');
					});
				});
			}
		});
		
		checkFormParticipe = function()
		{
			var erro = '';
			var foco;
			var frm = document.forms['form_participe'];
			
			if(frm.nome.value == '')
			{
				erro += '\n - Nome completo;';
				if(!foco)
					foco = frm.nome;
			}
			if( (frm.email.value == '') || (frm.email.value.indexOf('@') < 0) || (frm.email.value.indexOf('.') < 0) )
			{
				erro += '\n - E-mail;';
				if(!foco)
					foco = frm.email;
			}
			if(frm.mensagem.value == '')
			{
				erro += '\n - Dica;';
				if(!foco)
					foco = frm.mensagem;
			}

			if(erro == '')
			{
				return true;
			}
			else
			{
				alert('Campos incorretos ou inválidos:\n' + erro);
				foco.focus();
				return false;
			}
		}

	});

	
	function get_building_by_url(url){
		total = _buildings_url.length;
		for(i=0;i<total;i++){
			if(url == _buildings_url[i]){
				return _buildings_id[i];
			}
		}
		return 0;
	}
	
	
	function get_old_building_by_url(url){
		total = _buildings_url.length;
		for(i=0;i<total;i++){
			if(url == _buildings_url[i]){
				return _buildings_old_id[i];
			}
		}
		return 0;
	}
	
	function get_old_building_id(){
		return get_old_building_by_url(window.location.href);
	}

function addFav(){

    var url      = "http://www.prodietnutricao.com.br/";

    var title    = "Suplementos nutricionais para dieta alimentar enteral e nutrição de pacientes";

    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if(window.opera && window.print){

        var mbm = document.createElement('a');

        mbm.setAttribute('rel','sidebar');

        mbm.setAttribute('href',url);

        mbm.setAttribute('title',title);

        mbm.click();

    }

    else if(document.all){window.external.AddFavorite(url, title);}

}

