function Trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}
function ATrim(str){
	return str.replace(/\s+/g," ");
}

function maxSize(textarea, tamanho, info){
	if(textarea.onkeyup == null){
		textarea.onkeyup = textarea.onkeydown;
	}
	if(textarea.onfocus == null){
		textarea.onfocus = textarea.onkeydown;
	}
	if(textarea.onblur == null){
		textarea.onblur = textarea.onkeydown;
	}
	if (textarea.value.length >= tamanho)
		textarea.value = textarea.value.substr(0, tamanho);
	if(info!=undefined && info!=null)
		$('#'+info).html(tamanho-textarea.value.length);
}

function getAbsolutePosition(element) {
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) {
      var tmp = getAbsolutePosition(element.offsetParent);
      r.x += tmp.x;
      r.y += tmp.y;
    }
    return r;
}
var callBackLogin = null;
/*function logarVisitante(divResposta, email, senha)
{
	var alertas="";
	if (email=="")
		alertas+="- E-mail\n";
	if (senha=="")
		alertas+="- Senha\n";
	if (alertas!=""){
		alert("Os seguintes campos não foram preenchidos:\n"+alertas);
		return false;
	}
	
	var xmlhttp;
	if (window.XMLHttpRequest){	// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject){ // code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		return true;
	}
	
	// Carrega a função de execução do AJAX
	var valorAntigo="";
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 2){
			//Quando estiver "Carregando a página", exibe a mensagem
			valorAntigo = divResposta.innerHTML;
			divResposta.innerHTML ="<div id='loading_login'></div>";
		}else if(xmlhttp.readyState == 4){
			// Quando estiver completado o Carregamento
			if (eval(xmlhttp.responseText)){
				//LOGA OK
				if(callBackLogin!=null){
					callBackLogin();
					callBackLogin = null;
				}else{
					reloadPage();
				}
			}
			else
			{
				//ERRO
				alert("Erro ao Logar");
				divResposta.innerHTML = valorAntigo;
			}
		}

	};
	// Envia via método GET as informações
	xmlhttp.open("POST","/pages/visitante/loginResultado.php",true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1")
	xmlhttp.send("email="+email+"&senha="+senha);
	return false;
}*/

function reloadPage(){
	location.reload(true);
}

/* BALÕES */

var outBalao = true;
var idOpened = null;
function configBalao(){
	document.body.onmousedown = onPressBody;
}
function onPressBody(){
	if(idOpened != null){
		if(outBalao){
			closeDiv(idOpened);
		}
	}
}
function configOutOver(id, clear){
	if(clear==undefined)
		clear = false;
	var obj = document.getElementById(id);
	if(clear){
		obj.onmouseover=null;
		obj.onmouseout=null;
	}else{
		obj.onmouseover=function(){
			outBalao = false;
		}
		obj.onmouseout=function(){
			outBalao = true;	
		}
	}
}
function closeDiv(id){
	document.getElementById(id).style.display = 'none';
	
	if(id == idOpened){
		configOutOver(idOpened, true);
		idOpened = null;
	}
}
function openDiv(id){
	document.getElementById(id).style.display = 'block';
}
function openClose(id, idFoco){
	if(id == idOpened){
		closeDiv(idOpened);
	}else{
		if(idOpened != null && id != idOpened)
			closeDiv(idOpened);
		
		openDiv(id);
		idOpened = id;
		
		/*CONFIG CLOSE IN CLICK OUT DIV*/
		configOutOver(idOpened);
		
		if(idFoco!=undefined && idFoco!=null)
			document.getElementById(idFoco).focus();
	}
}
function trace(texto){
	var obj = document.getElementById('trace');
	obj.innerHTML = obj.innerHTML+'<br/>'+texto;
}
/*
function openCloseLogin(refer){
	var obj = document.getElementById('boxLogin');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y+35)+'px';
	obj.style.left =(pos.x-127)+'px';
	
	callBackLogin = null;
	
	closeDiv('div_esqueci_senha');
	closeDiv('info_usuario_deve_logar');
	openClose('boxLogin', 'login_campo');
}

function openCloseLoginVotar(refer, link){
	var obj = document.getElementById('boxLogin');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y)+'px';
	obj.style.left =(pos.x-210)+'px';
	
	if(idOpened != null)
		closeDiv(idOpened);
	closeDiv('div_esqueci_senha');
	openDiv('info_usuario_deve_logar');
	openClose('boxLogin', 'login_campo');
	
	callBackLogin = function(){
		onRelease(link);
	}
}
*/
function openLocalizacaoBox(refer){
	var obj = document.getElementById('boxLocalizacao');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y+25)+'px';
	obj.style.left =(pos.x-138)+'px';
	
	openClose('boxLocalizacao','select_estado_localizacao');
}
/*
function openCloseLoginComentarioTopico(refer, link){
	var obj = document.getElementById('boxLogin');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y)+'px';
	obj.style.left =(pos.x-208)+'px';
	
	callBackLogin = function(){
		onRelease(link);
	}
	
	if(idOpened != null)
		closeDiv(idOpened);
	closeDiv('div_esqueci_senha');
	openDiv('info_usuario_deve_logar');
	openClose('boxLogin', 'login_campo');
}
*/
var idPoliticoTwitter = null;
function openTwitterBox(refer, idPolitico){
	if(refer.name == undefined)
		refer = document.getElementById(refer);

	idPoliticoTwitter = idPolitico;
	var campoFocus = '';
	if(document.getElementById('twitter_tipo').value ==  'login'){
		document.getElementById('login_twitter_campo').value = '';
		document.getElementById('pass_twitter_campo').value = '';
		campoFocus = 'login_twitter_campo';
	}else{
		document.getElementById('twitter_mens').value = '';
		campoFocus = 'twitter_mens';
	}
	
	var obj = document.getElementById('boxTwitter');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y)+'px';
	obj.style.left =(pos.x-208)+'px';
	
	closeDiv('iconLoadingTwitter');
	openDiv('btnSubmitTwitter');
	openClose('boxTwitter',campoFocus);
}

function submitLogarTwitter(){
	var form = document.getElementById('formLogarTwitter');
	
	var login = form.login;
	var password = form.password;
	
	var erros = '';
	if(login.value == ''){
		erros += '- Preencher o campo login\n';
	}
	
	if(password.value==''){
		erros += '- Preencher o campo password\n';
	}
	
	if(erros!=''){
		alert('Foram encontrados os seguintes erros:\n\n'+erros);
		return false;
	}
	
	openDiv('iconLoadingTwitter');
	closeDiv('btnSubmitTwitter');
	return true;
}
function onResultLogarTwitter(status, info){
	if(status){
		reloadBoxTwitter();
	}else{
		closeDiv('iconLoadingTwitter');
		openDiv('btnSubmitTwitter');
		
		alert(info);
	}
}
function reloadBoxTwitter(){
	$.post('/services/twitter/printBoxTwitter.php', {idPolitico:idPoliticoTwitter}, 
		function(content){
			$('#boxTwitter').html(content);
		}
	);
}
function logoutTwitter(){
	$('#boxTwitter').html(
		'<div class="boxLogarTwitter">'+
			'<p class="info"><span class="textClear fl_twitter fl_twitter_ativo">Twitter</span>'+
			'<div id="iconLoadingTwitter" style="display:block;" class="item_mensagens_filho_loading"><span class="loading_icon"></span></div>'+
		  	'</p>'+
		'</div>');
	
	$.get('/services/twitter/logoutTwitter.php', null, 
		function(result){
			reloadBoxTwitter();
		}
	);
}

function submitTwitar(){
	var form = document.getElementById('formTwitar');
	
	var comentario = form.comentario;
	
	var erros = '';
	if(comentario.value==''){
		erros += '- Preencher o campo comentário\n';
	}
	
	if(erros!=''){
		alert('Foram encontrados os seguintes erros:\n\n'+erros);
		return false;
	}
	
	openDiv('iconLoadingTwitter');
	closeDiv('btnSubmitTwitter');
	return true;
}

function onResultTwitar(status, info, idPolitico){
	if(status){
		printLastTwitterByUserInPolitico(idPolitico, 
			function(){
				closeDiv('iconLoadingTwitter');
				openDiv('btnSubmitTwitter');
				closeDiv('boxTwitter');
			}
		);
	}else{
		alert(info);
	}
}
function printLastTwitterByUserInPolitico(idPolitico, callBack){
	if($('#twitters_tribuna_alvo').length < 1){
		if(callBack!=undefined && callBack != null) callBack();
		return;
	}
	
	$.post(
	    "/services/twitter/printLastTwitterUser.php", {idPolitico:idPolitico},
	    function(msg){
	    	$("#twitters_tribuna_alvo").prepend(msg);
	    	if(callBack!=undefined && callBack != null) callBack();
	    }
	);
}

function ativeBgEmotion(obj){
	$('#emotions_twitter > p > label').removeClass('ativo');
	$(obj).addClass('ativo');
}

function qualificaPolitico(politico, qualificacao){
	$.post(
	    "/pages/politico/qualificaAction.php",
	    {idPolitico:politico, newQualificacao:qualificacao},
	    function(msg){
			if(msg == 'sucesso'){
				alert('Qualificação adicionada com sucesso.');
			}else if(msg == 'erro'){
				alert('Não foi possivel adicionar sua qualificação.');				
			}else if(msg == 'jaqualificou'){
				alert('Você ja qualificou este politico.');				
			}
			reloadPage();
	    }
	);
}
function openNovoTopicoBox(refer, idPolitico){
	if(refer.name == undefined)
		refer = document.getElementById(refer);
	
	document.getElementById('tipo_comentario').value = 'topico';
	document.getElementById('id_comentario').value = '';
	document.getElementById('id_politico').value = idPolitico;
	document.getElementById('titulo_campo').value = '';
	
	var obj = document.getElementById('boxComentar');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y)+'px';
	obj.style.left =(pos.x-208)+'px';
	
	closeDiv('add_comentario');
	openDiv('add_topico');
	openDiv('titulo_field');
	closeDiv('iconLoadingComentar');
	openClose('boxComentar','nome_campo');
}
var dontOpenDiv=null;
//Isso para não abrir o box, quando clicar em comentar!
function dontOpenCloseTopico(div){
	dontOpenDiv = div;
}
//Abrindo o box topicos
function openCloseTopico(div){
	if(dontOpenDiv!=div){
		openCloseCaixa(div, null, 2);
	}
	dontOpenDiv = null;
}

function loadMensagens(div, idMensagemPai, pagina){
	var objData = new Object();
	objData.idMensagem = idMensagemPai;
	
	if(pagina != null && pagina != undefined)
		objData.pagina = pagina;
	
	$('#'+div).slideUp(200).html("<div class='item_mensagens_filho_loading'><span class='loading_icon'></span></div>")
		.load("/pages/tribuna/jListComentarios.php",
				objData
		).slideDown(300);
}

function openNovoComentarioBox(refer, idComent, idPolitico){
	if(refer.name == undefined)
		refer = document.getElementById(refer);
	
	document.getElementById('tipo_comentario').value = 'comentario';
	document.getElementById('id_comentario').value = idComent;
	document.getElementById('id_politico').value = idPolitico;
	document.getElementById('titulo_campo').value = 're:';
	
	var obj = document.getElementById('boxComentar');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y)+'px';
	obj.style.left =(pos.x-208)+'px';
	
	openDiv('add_comentario');
	closeDiv('add_topico');
	closeDiv('titulo_field');
	closeDiv('iconLoadingComentar');
	openClose('boxComentar','nome_campo');
}
/*
function openCloseLoginComentario(refer, link){
	var obj = document.getElementById('boxLogin');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y)+'px';
	obj.style.left =(pos.x-208)+'px';
	
	callBackLogin = function(){
		onRelease(link);
	}
	
	if(idOpened != null)
		closeDiv(idOpened);
	closeDiv('div_esqueci_senha');
	openDiv('info_usuario_deve_logar');
	openClose('boxLogin', 'login_campo');
}
*/
/* END BALÔES */

var cancelOnRelease = false;
function onRelease(link){
	if(!cancelOnRelease)
		window.location = link;
	else
		cancelOnRelease = false;
}
function cancelRelease(){
	cancelOnRelease = true;
}
/*
function onResultComentar(status, tipoOrErro, idMensagemPai, urlReload){
	closeDiv('boxComentar');
	
	closeDiv('iconLoadingComentar');
	openDiv('btnSubmitComentar');

	if(status){
		alert('Comentário adicionado com sucesso!');
		if(tipoOrErro=='comentario'){
			loadMensagens('item_mensagens_filho_'+idMensagemPai, idMensagemPai);
		}else if(tipoOrErro=='topico'){
			onRelease(urlReload);
		}
	}else{
		alert(tipoOrErro);
	}
}
function submitComentar(){
	var form = document.getElementById('formComentar');
	var comentario = form.comentario;
	var nome = form.nome;
	var email = form.email;
	var titulo = form.titulo;
	var tipo = form.tipo.value;
	
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	
	var erros = '';
	if(nome.value == ''){
		erros += '- Preencher o campo nome\n';
	}
	
	if (email.value == "") { erros +="- O e-mail está em branco.\n"; }
	else if (!er.test(email.value)) { erros +="- O e-mail está inválido.\n"; }
	
	if(tipo == 'topico'){
		if(titulo.value == ''){
			erros += '- Preencher o campo titulo\n';
		}
	}	
	if(comentario.value==''){
		erros += '- Preencher o campo comentário\n';
	}
	
	if(erros!=''){
		alert('Foram encontrados os seguintes erros:\n\n'+erros);
		return false;
	}
	
	openDiv('iconLoadingComentar');
	closeDiv('btnSubmitComentar');
	return true;
}

function submitLogin(){
	var div = document.getElementById('area_login');
	var form = document.getElementById('formLogin');
	return logarVisitante(div,form.login.value, form.senha.value);
}
*/
function submitLocalizacao(){
	var form = document.getElementById('formLocalizacao');
	if(form.estado.value==0){
		alert('Selecione um estado');
		form.estado.focus();
		return false;
	}
	return true;
}
/*
function submitRecuperarSenha(){
	var form = document.getElementById('formRecuperarSenha');
	if(form.email.value==""){
		alert('Preencha o campo com seu e-mail!');
		form.email.focus();
		return false;
	}
	return true;
}
*/
function cidadeLoad(idEstado, idSelect, idSetSelected) {
	if(idSetSelected==undefined)
		idSetSelected = null;
	$("#"+idSelect).empty()
		.append("Aguarde...")
			.load("/services/util/jqueryCidades.php",{'idEstado':idEstado, 'idSetSelected':idSetSelected});
}

function validateSetLocalizacao(){
	var objForm = document.getElementById('formLocation');
	
	if(eval(objForm.estado.value)==null){
		alert('Selecione o estado');
		return false;
	}
	return true;
}


/* VALIDA BUSCA */
function submitBusca(){
	var objForm = document.getElementById("form_busca_topo");
	
	if(validaBusca()){
		objForm.submit();
	}
}
function validaBusca(){
	var objForm = document.getElementById("form_busca_topo");
	var termo = ATrim(Trim(objForm.busca.value));
	if(termo.length < 3){
		alert('Para realizar a busca é necessario no mínimo 3 caracteres!');
		return false;
	}
	objForm.busca.value = termo;
	
		/* ISSO PARA USAR HTACCESS NA BUSCA * /
			termo = objForm.busca.value;//escape(objForm.busca.value);
			pg = objForm.pg.value;
			pg = pg=='home'?'clipping':pg;
			window.location = '/'+pg+'/busca/'+termo;
			
			return false;
		/* END */
			
	return true;
}

/* CADASTRO VISITANTE 
function onSubmitCadastroVisitante(){
	var objForm = document.getElementById('formularioCadastro');
	if(checaFormulario())
		objForm.submit();
}

function checaFormulario() {
	var objForm = document.getElementById('formularioCadastro');
	var erros = "";
	
	var edit = objForm.edit;
	
	if(edit==undefined) edit = false;
	else edit = true;
	
	var nome = objForm.nome.value;
	var email = objForm.email.value;
	var cidade = objForm.cidade.value;
	
	var senha1 = objForm.senha.value;
	var senha2 = objForm.senha2.value;
	
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	
	if (nome == "") { erros +="- O nome está em branco.\n"; }
	if (email == "") { erros +="- O e-mail está em branco.\n"; }
	else if (!er.test(email)) { erros +="- O e-mail está inválido.\n"; }
	if (cidade == "") { erros +="- Você precisa selecionar uma cidade.\n"; }
	
	if(!edit || (edit!=false && (senha1 != "" || senha2 != ""))){
		if (senha1 == "" || senha1 != senha2) { erros += "- As senhas não coincidem."; }
	}
	if (erros!=''){
		alert("Atenção:\n\n"+erros);
		return false;
	}
	
	return true;
}
*/
/* CADASTRO PORTAL */
function changeRadioFocoPortal(obj){
	var divEstado = document.getElementById('item_form_estado');
	//var divCidade = document.getElementById('item_form_cidade');
	var divInfo = document.getElementById('info_dont_checked');
	var divInfoPais = document.getElementById('info_pais_cheked');
		
	divInfo.style.display = 'none';
	
	if(obj.value=="brasil"){
		divEstado.style.display = 'none';
		//divCidade.style.display = 'none';
		divInfoPais.style.display = 'block';
	}else if(obj.value=="estado"){
		divEstado.style.display = 'block';
		//divCidade.style.display = 'none';
		divInfoPais.style.display = 'none';
		
		document.getElementById('select_estado').selectedIndex = 0;
	}else if(obj.value=="cidade"){
		divEstado.style.display = 'block';
		//divCidade.style.display = 'block';
		divInfoPais.style.display = 'none';
		
		document.getElementById('select_estado').selectedIndex = 0;
		//document.getElementById('select_cidade').selectedIndex = 0;
		//cidadeLoad(document.getElementById('select_estado').value,'select_cidade');
	}
}

function onSubmitCadastroPortal(){
	var objForm = document.getElementById('formularioCadastroPortal');
	if(checaFormularioPortal())
		objForm.submit();
}

function checaFormularioPortal(){
	var objForm = document.getElementById('formularioCadastroPortal');
	var erros = '';
	
	var estado = objForm.estado.value;
	//var cidade = objForm.cidade.value;
	
	var seu_nome = objForm.seu_nome.value;
	var seu_email = objForm.seu_email.value;
	var nome = objForm.nome.value;
	var url_site = objForm.url_site.value;
	var url_rss = objForm.url_rss.value;
	var logotipo_site = objForm.logotipo_site.value;
	//var email = objForm.email.value;
	//var cidade = objForm.cidade.value;
	
	//var senha1 = objForm.senha.value;
	//var senha2 = objForm.senha2.value;
	
	var edit = objForm.edit;
	
	if(edit==undefined) edit = false;
	else 				edit = true;
	
	if( !$('#radio_foco_portal_brasil').is(':checked') &&
		!$('#radio_foco_portal_estado').is(':checked')// &&
		//!$('#radio_foco_portal_cidade').is(':checked')
		){
		erros += '- É necessario selecionar o foco do portal.\n';
	}
	
	if( $('#radio_foco_portal_estado').is(':checked')){// || $('#radio_foco_portal_cidade').is(':checked') ){
		if(estado==""){
			erros += '- O campo estado é obrigatorio.\n';
		}
		/*if( $('#radio_foco_portal_cidade').is(':checked') && cidade=="" ){
			erros += '- O campo cidade é obrigatorio.\n';
		}*/
	}
	
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	
	if(seu_nome == ''){
		erros += '- O seu nome é obrigatorio.\n';
	}
	
	if (seu_email == "") { erros +="- O seu e-mail está em branco.\n"; }
	else if (!er.test(seu_email)) { erros +="- O seu e-mail está inválido.\n"; }
	
	if(nome == ''){
		erros += '- O nome do site é obrigatorio.\n';
	}
	if(url_site == ''){
		erros += '- A URL do site é obrigatorio.\n';
	}
	if(url_rss == ''){
		erros += '- O RSS do site é obrigatorio.\n';
	}
	var arLogo = new RegExp(/.*\.(gif|jpg|png)$/);

	if(logotipo_site == ''){
		erros += '- A logomarca do site é obrigatoria.\n';
	}else if(!arLogo.test(logotipo_site)){
		erros += '- Está logomarca não é valida .\n';
	}
	/*
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	
	if (email == "") { 			erros +="- O e-mail está em branco.\n"; }
	else if (!er.test(email)) { erros +="- O e-mail está inválido.\n"; }
	
	if(!edit || (edit!=false && (senha1 != "" || senha2 != ""))){
		if (senha1 == "" || senha1 != senha2) { erros += "- As senhas não coincidem."; }
	}
	*/
	if (erros!=''){
		alert("Atenção:\n\n"+erros);
		return false;
	}
	
	return true;
}

function changeColorBg(){
	document.body.style.backgroundColor = '#999999';
}


/* POLITICO */
function cidadeLoadPolitico(idEstado, idSelect, idSetSelected) {
	if(idSetSelected==undefined)
		idSetSelected = null;
	$("#"+idSelect).empty()
		.append("Aguarde...")
			.load("/services/util/jqueryCidades.php",{'order':'group','idEstado':idEstado, 'idSetSelected':idSetSelected, 'enconding':'base64'});
}

function changeEstadoPolitico(estadoObj, cargo, link) {
	var ar = estadoObj.value.split('|');
	if((cargo==1 || cargo==2) && ar[1]!=0){
		cidadeLoadPolitico(ar[1], 'selectCidade');
	}else{
		window.location = link+'&estado='+ar[0];
	}
}
function changeCidadePolitico(cidadeObj, link){
	var ar = cidadeObj.value.split('|');
	if(ar[0]=='NULL'){
		return;
	}else if(ar[0]=='ALL'){
		window.location = link+'&estado='+ar[1];
	}else{
		window.location = link+'&cidade='+ar[0];
	}
}

/* CAIXAS OPEN CLOSE EM JQUERY */

var arCaixaOpen = [];
function openCaixa(id, callBack) {
	if(callBack==undefined)
		$("#"+id).slideDown(300);
	else
		$("#"+id).slideDown(300, callBack);
}
function closeCaixa(id, callBack, nivel) {
	if(nivel==undefined) nivel = 1;
	
	if(callBack == undefined)
		$("#"+id).slideUp(300);
	else
		$("#"+id).slideUp(300, callBack);
	if (arCaixaOpen[nivel] == id)
		arCaixaOpen[nivel] = null;
}
function openCloseCaixa(id, idScroll, nivel){
	if(nivel==undefined) nivel = 1;
	if(idScroll==undefined) idScroll = null;
	
	if (arCaixaOpen[nivel] == id){
		closeCaixa(arCaixaOpen[nivel], null, nivel);
	} else {
		openCaixa(id, function(){
			if(arCaixaOpen[nivel] != null){
				if(idScroll!=null){
					closeCaixa(arCaixaOpen[nivel], function(){
						moveScrollTo(idScroll);
					}, nivel);
				}else{ 
					closeCaixa(arCaixaOpen[nivel], null, nivel);
				}
			}else if(idScroll!=null){
				moveScrollTo(idScroll);
			}
			arCaixaOpen[nivel] = id;
		});
	}
}
function moveScrollTo(idScroll){
	$.scrollTo("#"+idScroll, 200);
}

/* CONTROLS VER POLITICO */
var oldStyle = null;
var oldObj = null;
function onReleaseControls(id, idScroll, objMenu, newStyle){
	if(objMenu.name == undefined)
		objMenu = document.getElementById(objMenu);
	if(oldObj!=null){
		oldObj.className = oldStyle;
	}
	oldObj = objMenu;
	oldStyle = objMenu.className;
	
	objMenu.className = newStyle;
	openCloseCaixa(id, idScroll);
}


function openInfoNotComents(refer){
	var obj = document.getElementById('info_not_coments');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = (pos.y+10)+'px';
	obj.style.left =(pos.x+250)+'px';
	
	$("#info_not_coments").fadeIn(500,function(){
		window.setTimeout('clearInfoNotComents()', 1000);
	});
}
function clearInfoNotComents(){
	$("#info_not_coments").fadeOut(500);
}

function reportarErro(id, tipo) {
	$.post(
	    "/pages/util/ajax_reportar_erro.php",
	    {id:id, tipo:tipo},
	    function(msg){
			alert('Obrigado\nsua notificação de erro nos foi enviada!');
	    }
	);
}

/* TWITTER */
function postMaisTwitters(method, div){
	$('#clear_'+div).attr('class', 'load_mais_twitter');
	$('#'+div).slideUp(0);
	$('#'+div).load('/services/twitter/maisTwitter.php', {method:method}, 
		function(){
			$('#clear_'+div).slideUp(300).remove();
			$('#'+div).slideDown(300);
		}
	)
}

/* VER NOTICIA */
function openIndiqueBox(refer, idNews){
	if(refer.name == undefined)
		refer = document.getElementById(refer);
	
	var obj = document.getElementById('boxIndique');
	var pos = getAbsolutePosition(refer);
	
	obj.style.top = '5px';
	obj.style.left =(pos.x-300)+'px';
	
	openDiv('formIndique');
	closeDiv('loading_indique');
	openClose('boxIndique','nome_campo');
}

function submitIndique(){
	var form = document.getElementById('formIndique');
	var nome = form.nome;
	var email = form.email;
	var idNoticia = form.idNoticia;
	
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	
	var erros = '';
	if(nome.value == ''){
		erros += '- Preencher o campo nome\n';
	}
	
	if (email.value == "") { erros +="- O e-mail está em branco.\n"; }
	else if (!er.test(email.value)) { erros +="- O e-mail está inválido.\n"; }
	
	if(erros!=''){
		alert('Foram encontrados os seguintes erros:\n\n'+erros);
		return;
	}
	closeDiv('formIndique');
	openDiv('loading_indique');
	
	$.post(
	    "/services/noticia/IndiqueNoticia.php",
	    {nome:nome.value, email:email.value, idNoticia:idNoticia.value},
	    function(msg){
			if(msg == 'true'){
				alert('E-mail enviado com sucesso!');
			}else{
				alert('Ops! Não foi possível enviar este e-mail.');
			}
			openClose('boxIndique');
	    }
	);
}

function enviarOrkut(titulo, subtitulo, link, imgURL){
    var params = {};
    params[google.orkut.share.Field.TITLE] = titulo;
    params[google.orkut.share.Field.DESTINATION_URL] = link;
    
    imgs = [imgURL];
    
    params[google.orkut.share.Field.CONTENT] = subtitulo;
    params[google.orkut.share.Field.THUMBNAIL] = imgs;
    var connection = new google.orkut.share.Connection(params);
    connection.send('orkut.com', {}); 
}

var execFunc = null;
function onloadBody(dontChangeBg){
	if(!(dontChangeBg==true))
		changeColorBg();
	configBalao();
	
	if(execFunc != null)
		execFunc();
}
