function abre_popup() {
	//alert("Oi");
	var popup = new Popup(561, 334);
	popup.overflow = "hidden";
	popup.open('pop_up.php');
}
function sendByMailNoticia(tmp_id) {
	var popup = new Popup(300, 350);
	popup.overflow = "hidden";
	popup.open('../../inc/structure/sendByMailNoticia.php?id='+tmp_id);
}
function printNoticia(tmp_id){
	window.open('../../inc/structure/printNoticia.php?id='+tmp_id,'_blank','width=1,height=1,top=-100,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0');
}
function sendByMailMateria(tmp_id) {
	var popup = new Popup(300, 290);
	popup.overflow = "hidden";
	popup.open('../../inc/structure/sendByMailMateria.php?id='+tmp_id);
}
function printMateria(tmp_id){
	window.open('../../inc/structure/printMateria.php?id='+tmp_id,'_blank','width=1,height=1,top=-100,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0');
}
function swapI(obj,focus){	
	if(focus){
		if(obj.value == obj.attributes["label"].value){
			obj.value = "";
		}
	} else {
		if(obj.value.trim() == ""){
			obj.value = obj.attributes["label"].value;
		}
	}
}
function somaClique(tmp_id) {
	var a = new Ajax();
	a.onLoad = function() { }
	a.get('../../inc/routines/routines.php?action=someClique&id='+tmp_id);
}
function openEnquete(tmp_quantidadeResposta){
	height = 220;
	if(tmp_quantidadeResposta){
		height = height + (tmp_quantidadeResposta * 40);
	}
	var popup = new Popup(561, height);
	popup.overflow = "hidden";
	popup.open('../../inc/structure/enquete.php');
}
function showMenu(tmp_idmenu,tmp_submenu) {
	if (tmp_submenu == '') {
		if ($('div_menu_'+tmp_idmenu).style.display == 'none') {
			$('div_menu_'+tmp_idmenu).style.display = '';
		} else {
			$('div_menu_'+tmp_idmenu).style.display = 'none';
		}
	} else {
		if ($('div_submenu_'+tmp_idmenu).style.display == 'none') {
			$('div_submenu_'+tmp_idmenu).style.display = '';
		} else {
			$('div_submenu_'+tmp_idmenu).style.display = 'none';
		}
	}
}
function loadResults(){
	var td;
	var total = 0;
	for(var x=0;x<arrResult.length;x++){
		td = document.getElementById("td_"+arrResult[x][0]);
		if(td){
			arrResult[x][1]++;
			arrResult[x][1]--;
			total = total + arrResult[x][1];
		}
	}
	for(var x=0;x<arrResult.length;x++){
		td = document.getElementById("td_"+arrResult[x][0]);
		if(td){
			arrResult[x][1]++;
			arrResult[x][1]--;
			if(arrResult[x][1] == 0){
				//percent = arrResult[x][1]*100/total;
				percent = '0.00';
			} else {
				percent = arrResult[x][1]*100/total;
				//percent = '0.00';
			}
			percent = percent+"";
			virgula = percent.indexOf(".");
			if(virgula != -1){
				percent = percent.substr(0,virgula+3).replace(".",",");
			}
			//percent = parseFloat(percent);
			/*if(percent == 'NaN'){
				percent = '0.00';
			} else {
				percent = '0.00';
			}*/
			td.innerHTML = "<b>"+percent+"%</b>";
		}
	}
	td = document.getElementById("td_total");
	if(td){
		td.innerHTML = " Total de votos: "+total+".";
	}
	td = document.getElementById("td_votar");
	if(td){
		td.innerHTML = "";
	}
}

function votar(){
	if(!votou){
		if(f.send('frm_enquete')){
			var td = document.getElementById("td_votar");
			if(td){
				td.innerHTML = "enviando voto...";
			}
		}
	}
}
function abre_popup2(tmp_id, path) {
	var popup = new Popup(480,652);
	popup.overflow = "hidden";
	popup.position = "fixed";
	if(path == '') { path = 'protegildo'; }
	//alert('../../content/'+path+'/pop_up.php?id='+tmp_id);
	popup.open('../../content/'+path+'/pop_up.php?id='+tmp_id);
}
function mudaImagem(idgaleria,idfoto,fonte,legenda,site) {
	$('imgGrande').src = '../../../_system/scripts/image.php?file=upload/'+site+'_galeria/'+idgaleria+'/'+idfoto+'.jpg&w=555&h=368&resize=4';
	if ($('img_pequena'+fotoatual)) {
		$('img_pequena'+fotoatual).className = 'image_no_select';
	}
	
	if (fonte != '') {
		$('div_fonteimagem').innerHTML = '<i>Fonte '+ fonte +'</i>';
	} else {
		$('div_fonteimagem').innerHTML = '';
	}
	
	$('div_legenda').innerHTML = legenda;
	
	fotoatual = idfoto;
	$('img_pequena'+fotoatual).className = 'image_selecionada';
}
function mudaClasse(tmp_idfoto,tmp_acao) {
	if (tmp_idfoto != fotoatual) {
		if (tmp_acao == 'out') {
			$('img_pequena'+tmp_idfoto).className = 'image_no_select';
		} else {
			$('img_pequena'+tmp_idfoto).className = 'image_selecionada';
		}
	}
}
function mudaPagina(tmp_idgaleria, acao, tmp_totalpagina) {
	if (acao == 'anterior') {
		paginaatual--;
	} else {
		paginaatual++;
	}

	var a = new Ajax();
	
	a.onLoad = function() {
		$('div_fotos').innerHTML = this.html;
	}
	
	a.get('../../inc/routines/routines.php?action=paginacaoGaleria&idgaleria='+tmp_idgaleria+'&pagina='+paginaatual);
	
	if (paginaatual > 1) {
		$('a_bt_anterior').style.display = '';
	} else {
		$('a_bt_anterior').style.display = 'none';
	}

	if (paginaatual < tmp_totalpagina) {
		$('a_bt_proxima').style.display = '';
	} else {
		$('a_bt_proxima').style.display = 'none';
	}
}
function somaVotoFoto() {
	var a = new Ajax();
	
	a.onLoad = function() {
		if(this.html == 'erro'){
			alert('Você já votou nesta foto!');
		} else {
			alert('Voto confirmado com sucesso.');
		}
	}
	
	a.get('../../inc/routines/routines.php?action=somaVoto&idfoto='+fotoatual);
}
function loadCampo(tmp_idSelecionando,tmp_idcampo,tmp_rotina){
	resetSelect(tmp_idcampo);
	var a = new Ajax();
	a.onLoad = function(){
		var str = this.html;
		var campo = document.getElementById(tmp_idcampo);
		var arr = str.split("###");//separa por registro
		var arraux = new Array();
		
		for(var x = 0; x < arr.length; x++){
			arraux = arr[x].split("...");
			//alert(arraux[1]+" - "+arraux[0]);
			addOption(campo,arraux[1],arraux[0]);
			if (arraux[0] == '') {
				campo.options[x+2].style.fontWeight = 'bold';
			}
		}
	}
	a.get('../../inc/routines/routines.php?action='+tmp_rotina+'&id_selecionado='+tmp_idSelecionando);
}
function resetSelect(tmp_idcmapo){
	var campo = document.getElementById(tmp_idcmapo);
	for(var x=campo.length-1;x>=2;x--){
		campo.remove(x);
	}
}
function addOption(obj_select,tmp_text,tmp_value){
	var option = document.createElement('option');
	option.value = tmp_value;
	option.text = tmp_text;
	
	try {//outros navegadores
		obj_select.add(option,null);
	} catch(ex) {//para IE
		obj_select.add(option);
	}
}
function buscarIndiceMateria() {
	var palavrachave = '';
	var idcategoria = $('Categoria_CMB0').value;
	var idsubcategoria = $('Seção_CMB0').value;
	
	if ($('Palavra-chave_TXT0').value != $('Palavra-chave_TXT0').defaultValue) {
		palavrachave = $('Palavra-chave_TXT0').value;
	} 
	
	if ((palavrachave != '') || (idcategoria != '') || (idsubcategoria != '')) {
		var a = new Ajax();
		a.onLoad = function(){
			$('div_listaedicoes').innerHTML = this.html;
		}
		a.get('../../inc/routines/routines.php?action=loadIndice&id_categoria='+idcategoria+'&id_subcategoria='+idsubcategoria+'&palavrachave='+palavrachave);
	} else {
		alert('Preencha um dos campos.');
	}
}

function formularioConteudo(tpForm) {
	if(tpForm != '') {
		var a = new Ajax();
		a.onLoad = function(){
			$('frmCadastraConbteudo').innerHTML = this.html;
		}
		a.get('../../content/formulario/formCadastraConteudo.php?frm='+tpForm);
	} else {
		alert("Selecione uma das opções.");
	}
}

