// JavaScript Document
function MostraFotoHidroalbum(id) {
	// Mostra fotos do hidro-album (abre numa janela)
	
	window.open('/snirh/divulgacao/hidroalbum/mostra.php?id='+id,'hidroalbum_fotos','width=580, height=570, toolbar=no,menubar=no,status=yes,resizable=no,scrollbars=yes');
}

//function MostraFilme3D(flv,legenda) {
function MostraFilme3D(item_rio,flv) {
	// Mostra filme dos Rios de Portugal
	
	//window.open('flash_rios/galeria.php?flv='+flv+'&legenda='+legenda,'hidroalbum_fotos','width=620, height=550, toolbar=no,menubar=no,status=yes,resizable=no,scrollbars=no');
	window.open('flash_rios/galeria.php?item_rio='+item_rio+'&flv='+flv,'videodorio','width=620, height=590, toolbar=no,menubar=no,status=yes,resizable=no,scrollbars=no');
	
}

function MostraCartaPDF(pdf) {
	// Mostra filme dos Rios de Portugal
	
	//window.open('flash_rios/galeria.php?flv='+flv+'&legenda='+legenda,'hidroalbum_fotos','width=620, height=550, toolbar=no,menubar=no,status=yes,resizable=no,scrollbars=no');
	window.open('_dados/rios_pdf/'+pdf,'cartadorio','width=620, height=590, toolbar=no,menubar=no,status=yes,resizable=yes,scrollbars=no');
	
}


function CicloAguaAbreGaleria(tipo,oque) {
	// Abre galeria do ciclo da água
	
	window.open('ciclo_agua/galeria.php?tipo=' + tipo + '&oque='+ oque,'hidroalbum_galeria','width=620, height=510, toolbar=no,menubar=no,status=yes,resizable=no,scrollbars=no');
}

function ShowIdeLayer(layer_on,layer_off,show_hide) {
	// Alterna as layers
	
	if(show_hide == 1) {
		document.getElementById(layer_on).style.visibility = "visible";
		document.getElementById(layer_off).style.visibility = "hidden";
	} else {
		document.getElementById(layer_on).style.visibility = "hidden";
		document.getElementById(layer_off).style.visibility = "visible";
	}
}

function ShowHideLayerDisplay(obj,accao) {
	if(accao == 1) {
		if (navigator.appName == "Microsoft Internet Explorer") {
			document.all[obj].style.display = "block";
		} else {
			document.getElementById(obj).style.display = "block";
		}
	} else {
		if (navigator.appName == "Microsoft Internet Explorer") {
			document.getElementById(obj).style.display = "none";
		} else {
			document.getElementById(obj).style.display = "none";
		}
	}
}

function MudaImagem(img_nome,img_src) {
	// Botões com RollOver
	
	if(document[img_nome]) {
		document[img_nome].src = img_src;
	}
}


function VerificaSeExisteTextoMail(texto) {
	// Activa o botão de ENVIAR
	if(texto != "") {
		document.getElementById("livrovisitas_submitbutton").disabled = false;
	}
}

function MostraImagemLivroVisitas (show_hide,id) {
	if(show_hide == 1) {
		document.getElementById("livrovisitas_foto_"+id).style.visibility = "visible";
		document.getElementById("flash_introduc").style.visibility = "hidden";
	} else {
		document.getElementById("livrovisitas_foto_"+id).style.visibility = "hidden";
		document.getElementById("flash_introduc").style.visibility = "visible";
	}

}

function AbreBD_AguasPerigosas() {
	// Mostra fotos do hidro-album (abre numa janela)
	
	window.open('banda_desenhada/bd_aguasperigosas.php','bd_aguasperigosas','width=510, height=730, toolbar=no,menubar=no,status=no,resizable=no,scrollbars=no');
}

function AbreGuiaoAvoH2O() {
	// Abre guião do filme Avó H2O

	window.open('trabalhos_escolas/popup_tescolas_champagnat_avoh2o_guiao.php','popup_tescolas_champagnat_avoh2o_guiao','width=555, height=655, toolbar=no,menubar=no,status=no,resizable=no,scrollbars=no');
}

function AbreSlidesImg(janelaurl,caminho,slides,formato,titulo) {
	window.open(janelaurl+'verslides.php?caminho='+caminho+'&slides='+slides+'&formato='+formato+'&titulo='+titulo,'SJ_CONCURSO','width=630,height=520,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0')
}
function AbreGaleriaFlash(janelaurl,caminho,galeria_xml,galeria_titulo) {
	window.open(janelaurl+'sj_fotos.php?caminho='+caminho+'&galeria_xml='+galeria_xml+'&galeria_titulo='+galeria_titulo,'SJ_CONCURSO','width=550,height=400,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0')
}

function AbreSlideShow(janelaurl,directory) {
	window.open(janelaurl+'phpslide/phpslideshow.php?directory='+directory,'SJ_SLIDESHOW','width=630,height=520,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0')
}

function EnviarLivroVisitas() {
	var f_nome_ = document.getElementById('f_nome').value;
	var f_texto_ = document.getElementById('f_texto').value;

	if(f_nome_ == "" || f_texto_ == "") {
		alert("Os campos NOME e MENSAGEM são obrigatórios.");
	} else {
		document.form_livro_visitas.submit();			
	}
}

function AbrirPosterJanela(titulo,poster) {
	window.open('concurso/poster.php?titulo='+titulo+'&poster='+poster,'SJ_CONCURSO','width=1,height=1,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0')
}

function AbreSlides(caminho,slides,formato) {
	window.open('concurso/slides.php?caminho='+caminho+'&slides='+slides+'&formato='+formato,'SJ_CONCURSO','width=630,height=500,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0')
}

function AbreSlidesA4(caminho,slides,formato) {
	window.open('concurso/slides.php?caminho='+caminho+'&slides='+slides+'&formato='+formato,'SJ_CONCURSO','width=650,height=550,toolbar=0,menubar=0,status=1,scrollbars=1,resizable=1')
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function SJ_OpcoesDiversao(id,accao) {
	//document.getElementById(id).style.overflow = 'visible';
	if(accao == 'LER') {
		document.getElementById(id).style.height = 'auto';
	} else if(accao == 'JALI') {
		//document.getElementById(id).style.display = 'none';
		document.getElementById(id).style.height = '5px';
	} else if(accao == 'SOLUCAO') {
		document.getElementById(id).style.height = 'auto';
		//document.getElementById(id+'solucao').style.display = 'block';
		document.getElementById(id+'solucao').style.visibility = 'visible';
	}
}

function AbreJanelaRiosGrafico(site,pars,cover) {
	window.open('flash_rios/grafico.php?site='+site+'&pars='+pars+'&cover='+cover,'dadosgrafico','width=637, height=550, toolbar=no,menubar=no,status=yes,resizable=no,scrollbars=yes');
}

function SJ_AbreJanela(url,w,h,resizable,scrollbars) {
	window.open(url,'sj_janela','width='+w+', height='+h+', toolbar=no,menubar=no,status=yes,resizable='+resizable+',scrollbars='+scrollbars);
}

function SJ_C2009_EnviarInscricao(formulario) {
	f_escola = document.getElementById('f_preinsc_escola').value;
	f_preinsc_localidade = document.getElementById('f_preinsc_localidade').value;
	f_responsavel = document.getElementById('f_preinsc_nome').value;
	f_email = document.getElementById('f_preinsc_email').value;
	f_telefone = document.getElementById('f_preinsc_telefone').value;
	f_alunos = document.getElementById('f_preinsc_alunos').value;
	f_ano = document.getElementById('f_preinsc_ano').value;

	f_email_valido = SNIRH_ValidarEnderecoEmail(f_email);
	
	if(!f_escola || !f_preinsc_localidade || !f_responsavel || !f_email || !f_telefone || !f_alunos || !f_ano) {
		alert("Preenche todos os campos marcados com *.");
		return false;
	}

	if(!f_email_valido) {
		alert("O e-mail indicado não é valido. Escreve só um endereço de e-mail.");
		return false;
	}

	formulario.submit();
}

function SJ_xAjax_NovaAdivinha() {
	
	document.getElementById('div_adivinha').innerHTML = ""
	
	//alert(colab_selected);
	var loader = dhtmlxAjax.getSync("xAjax/xa_getadivinha.php");

	if(loader.xmlDoc.responseText) {
		document.getElementById('div_adivinha').innerHTML = loader.xmlDoc.responseText
	} else {
		document.getElementById('div_adivinha').innerHTML = "<span>Tente novamente.</span>"
	}
}

function SJ_xAjax_SolucaoAdivinha(code) {
	
	//alert(colab_selected);
	var loader = dhtmlxAjax.getSync("xAjax/xa_getsolucaoadivinha.php?code="+code);

	if(loader.xmlDoc.responseText) {
		alert("A solução é: " + loader.xmlDoc.responseText);
	} else {
		alert("Tente novamente.");
	}
}

function SJ_xAjax_NovoDitadoPopular() {
	
	document.getElementById('div_ditadopular').innerHTML = ""
	
	//alert(colab_selected);
	var loader = dhtmlxAjax.getSync("xAjax/xa_getditadopopular.php");

	if(loader.xmlDoc.responseText) {
		document.getElementById('div_ditadopular').innerHTML = loader.xmlDoc.responseText
	} else {
		document.getElementById('div_ditadopular').innerHTML = "<span>Tente novamente.</span>"
	}
}

function SJ_xAjax_NovaQuadrasPoemas() {
	
	document.getElementById('div_quadraspoemas').innerHTML = ""
	
	//alert(colab_selected);
	var loader = dhtmlxAjax.getSync("xAjax/xa_getquadrasepoemas.php");

	if(loader.xmlDoc.responseText) {
		document.getElementById('div_quadraspoemas').innerHTML = loader.xmlDoc.responseText
	} else {
		document.getElementById('div_quadraspoemas').innerHTML = "<span>Tente novamente.</span>"
	}
}