function openSugestaoEnquete() {
    var popup = new Popup(300, 400);
    popup.overflow = "hidden";
    popup.open(root+'site/inc/structure/formSugestaoEnquete.php');
}

function popUpDenuncia(pg, id) {
    var popup = new Popup(300, 300);
    popup.overflow = "hidden";
    popup.open(root+'site/inc/structure/formDenuncia.php?pg='+pg+'&id='+id);
}

function abre_popup() {
    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(root+'site/inc/structure/sendByMailNoticia.php?id='+tmp_id);
}
function printNoticia(tmp_id){
    window.open(root+'site/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(root+'site/inc/structure/sendByMailMateria.php?id='+tmp_id);
}
function printMateria(tmp_id){
    window.open(root+'site/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 urlflash(tmp_url, tmp_id) {
    somaClique(tmp_id);
    window.open(tmp_url);

}
function somaClique(tmp_id)
{
    var a = new Ajax();
    a.onLoad = function()
    {
    //		this.runJS(this.html);
    }
    a.get(root+'site/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(root+'site/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';
    }
    popup.open(root+'site/content/'+path+'/pop_up.php?id='+tmp_id);
}
function mudaImagem(idgaleria,idfoto,fonte,legenda,site) {
    
    document.getElementById('imgGrande').src = root+'_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 != '') {
	document.getElementById('div_fonteimagem').innerHTML = '<i>'+ fonte +'</i>';
    } else {
	document.getElementById('div_fonteimagem').innerHTML = '';
    }
    document.getElementById('div_legenda').innerHTML = legenda;
    fotoatual = idfoto;
    $('img_pequena'+fotoatual).className = 'image_selecionada';
	
    this.location = '#posiciona_pagina';
}
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').html(this.html);
    }
    a.get(root+'site/inc/routines/routines.php?action=paginacaoGaleria&idgaleria='+tmp_idgaleria+'&pagina='+paginaatual);
	
    if (paginaatual > 1) {
	$('.a_bt_anterior').show();
    } else {
	$('.a_bt_anterior').hide();
    }
    if (paginaatual < tmp_totalpagina) {
	$('.a_bt_proxima').css('display','block');
    } else {
	$('.a_bt_proxima').css('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(root+'site/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("...");
	    addOption(campo,arraux[1],arraux[0]);
	    if (arraux[0] == '') {
		campo.options[x+2].style.fontWeight = 'bold';
	    }
	}
    }
    a.get(root+'site/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 = document.getElementById('Categoria_CMB0').value;
    var idsubcategoria = document.getElementById('Seção_CMB0').value;
	
    if (document.getElementById('Palavra-chave_TXT0').value != document.getElementById('Palavra-chave_TXT0').defaultValue) {
	palavrachave = document.getElementById('Palavra-chave_TXT0').value;
    } 
	
    if ((palavrachave != '') || (idcategoria != '') || (idsubcategoria != '')) {
	var a = new Ajax();
	a.onLoad = function(){
	    document.getElementById('div_listaedicoes').innerHTML = this.html;
	};
	a.get(root+'site/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').html(this.html);
	};
	a.get(root+'site/content/formulario/formCadastraConteudo.php?frm='+tpForm);
    } else {
	alert("Selecione uma das opções.");
    }
}


