
/*** Geral ***/

var addthis_config = {
	data_use_flash: false,
	ui_language: "pt"
}
addthis_hide_embed = true;
function printIt(getSlug) {
	var getTitle = $('h1').html();
	$.post("print.php", {
		title: getTitle,
		remover_classes: $('.txt *').removeClass(),
		remover_extranav: $('.txt #extraNav').remove(),
		content: $('.txt').html(),
		siteName: $('title').text(),
		siteURL: $('base').attr('href').substring(0, $('base').attr('href').length - 1),
		slug: getSlug
	}, function(html) {
		$('body *').css('display', 'none');
		$('body').css('background', 'transparent none');
		$('body').append('<div id="print"><!-- --></div>');
		$('#print').css('display', 'block');
		$('#print').html(html);
	});
}
var errorLog = "";
function hideEmbed() {
	$('embed, object').each(function() {
		$this = $(this);
		if ($this.is(':visible')) {
			$this.attr('c7hideembed', 'true').hide();
		}
	});
}
function showEmbed() {
	$('embed, object').each(function() {
		$this = $(this);
		if ($this.is(':hidden') && $this.attr('c7hideembed') == 'true') {
			$this.attr('c7hideembed', 'false').show();
		}
	});
}
function bookmarksite(object) {
	if (document.all) {
		window.external.AddFavorite(object.href, object.title);
		return false;
	}
	return true;
}
$(document).ready(function() {
	$('a[rel=external]').attr('target', '_blank');
	if (!jQuery.support.htmlSerialize)
		$('a[rel=sidebar]').click(function() { bookmarksite(this); });
	$('a[rel=popup]').click(function() { fScr(this.href); return false; });
	$('a[rel=suggest]').click(function() { $.showAkModal(this.href, this.title, 650, 450); return false; });
	$('a[rel=print]').click(function() { printIt(location.pathname); return false; });
	//alterna entre laranja e vermelho os itens do menu principal
	$('#cabecalho .bar_menu li').slice(0, 4).addClass('orange');
	$('#rodape .bar_menu li').slice(0, 4).addClass('orange');

	//esvazia input da área de login
	if ($('#cabecalho .box_login').size()) {
		$('#cabecalho .box_login .formLogin .paramUsername,#cabecalho .box_login .formLogin .paramPassword')
        .focus(function() {
        	$(this).css('background-color', '#979797');
        })
        .blur(function() {
        	if ($(this).val().length == 0)
        		$(this).css('background-color', 'transparent');
        });
	}
	$('.headerRonded,.headerRonded_red').each(function() {
		$element = $(this);
		$element.html($element.html().replace(/\u2022/g, '<span class="headerRonded_separador">\u2022</span>', 'g'));
	});
	$('#bar_tabs_lidas_votadas a').bind('click focus mouseover', function() {
		var $a = $(this);
		var $li = $a.parent();
		var $siblings = $li.siblings();
		var box_id = $a.get(0).href.replace($('base').attr('href'), '', 'gi');

		if (!$li.hasClass('selected')) {
			$li.addClass('selected');
			$siblings.removeClass('selected')
            .each(function() {
            	var box_id = $(this).children().get(0).href.replace($('base').attr('href'), '', 'gi');
            	$(box_id).hide('fast');
            });
			$(box_id).show('fast');
		}
		return false;
	});
	//para tirar esse evento do formulário, coloque a classe "edit" na tag form
	$('form').each(function() {
		var $form = $(this);

		if (!$form.hasClass('.edit')) {

			$form.find('input[type=text], textarea')
            .focus(function() {
            	var $entTxt = $(this);
            	if ($.trim($entTxt.val()) == this.defaultValue)
            		$entTxt.val('');
            })
            .blur(function() {
            	var $entTxt = $(this);
            	if ($.trim($entTxt.val()) == '')
            		$entTxt.val(this.defaultValue);
            });
		}
	});
	
	$('.itemRecado:nth-child(2n),.itemRecado_min:nth-child(2n)').css('background-color', '#DEDEDE');
	$('.boxVotoEstrela a').mouseover(function() {
		$this = $(this);
		$nota = $this.attr('title');
		$this.parent().removeClass('estrela1 estrela2 estrela3 estrela4 estrela5');
		$this.parent().addClass('estrela' + $nota);
	}).mouseout(function() {
		$this = $(this);
		$nota = $this.attr('title');
		$this.parent().removeClass('estrela1 estrela2 estrela3 estrela4 estrela5');
		if ($('#avaliacao_comentario').val()) {
			$this.parent().addClass('estrela' + $('#avaliacao_comentario').val());
		}
	}).click(function() {
		$this = $(this);
		$nota = $this.attr('title');
		$this.parent().removeClass('estrela1 estrela2 estrela3 estrela4 estrela5');
		$this.parent().addClass('estrela' + $nota);
		$('#avaliacao_comentario').val($nota);
	});

	//acrescenta na base uma view
//	if ($('#post_view_id').size()) {
//		var get_post_id = $('#post_view_id').attr('title');
//		$.post('http://expm.institucional.ws/proc/views.php', {
//			post_id: get_post_id
//		});
//	}
/*
	if ($('#post_view_id').size()) {
		$("#formNewsletter").validate({
			errorPlacement: function(error, element) {
				if ($(element).attr('temp'))
					fieldID = $(element).attr('temp');
				else
					var fieldID = Math.round(Math.random() * 100000 + 1);

				if (!$("span[temp=" + fieldID + "]").size())
					element.parent("div").after("<span class=\"msg\" temp=\"" + fieldID + "\"><\/span>");

				$("span[temp=" + fieldID + "]").html(error.attr('temp', fieldID));
				element.addClass("invalid").attr('temp', fieldID);
			},
			success: function(label) {
				$("* [temp='" + label.attr('temp') + "']").removeClass("invalid");
				label.parent().remove();
			},
			rules: {
				nl_email: { required: true, email: true },
				nl_nome: { required: true }
			},
			messages: {
				nl_email: { required: "Digite seu e-mail", email: "E-mail inválido" },
				nl_nome: { required: "Escreva o seu nome" }
			},
			submitHandler: function(form) {
				$.post('proc/newsletter.php', {
					nl_nome: $('#nl_nome').val(),
					nl_email: $('#nl_email').val()
				}, function(data) {
					alert(data);
				});
			}
		});
	}
*/
	if ($('#listAmigosEncontrados').size()) {
		$('.itemRecado_mensagem').click(function() {
			var $index = $('.itemRecado_mensagem').index(this);
			var $nome = $('.itemRecado:eq(' + $index + ') .itemRecado_title').text();
			if ($('.itemRecado:eq(' + $index + ')').hasClass('isauth')) {
				
			} else {
				alert("Você precisa ser um associado EXPM e estar logado para enviar uma mensagem a " + $nome);
			}
		});
	};
});

$(window).load(function() {
	if ((location.href).search("version=print") != -1)
		$('a[rel=print]').click();
});

function fScr(theURL) {
	params = 'width=' + screen.width;
	params += ', height=' + screen.height;
	params += ', top=0, left=0'
	params += ', fullscreen=yes';
	params += ', scrollbars=auto';

	window.open(theURL, '', params);
}

	function CadastrarNewsletter()
	{
		if (document.formNewsletter.nome.value == "")
		{
			alert("Preencha o campo Nome");
			document.formNewsletter.nome.focus();
			return false;
		}		
		if (document.formNewsletter.email.value == "")
		{
			alert("Preencha o campo Email");
			document.formNewsletter.email.focus();
			return false;
		}
	}
