var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function toggle_sound() {
	var frame = isInternetExplorer ? parent.hiddenFrame : parent.hiddenFrame.document;
	frame.playmovie();
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function buildPath(useParam){
	if (useParam){
		var thisFile = "recursos/"+self.location.href.substr(self.location.href.indexOf("?")+1);// "recursos/" é excclusivo do menu RECURSOS, se passar a existirem outrso sub-menus com a mesma estrutura este parâmentro terá que ser passado nos parametros.
	} else {
		var thisFile = self.location.href.substr(self.location.href.indexOf("/htmls/")+7);
		thisFile = thisFile.substr(0,thisFile.indexOf("."));
	}
	var i = tree.length-1;
	var visualPath = "";
	var lastLevel = 1000;
	var findPath = false;
	while (i >= 0) {
		if (findPath) {
			if (tree[i][2] < lastLevel && tree[i][2] != lastLevel) {
				var newPath = "";
				if (typeof(tree[i][0]) == "string") newPath = "<a href='/htmls/"+tree[i][0]+".shtml' class='palco_path'>";
				newPath += tree[i][1];
				if (typeof(tree[i][0]) == "string") newPath += "</a>";
				visualPath = newPath+" / "+visualPath;
				if (tree[i][2] == 1) i = 0;
				lastLevel = tree[i][2];
			}
		} else if (thisFile == tree[i][0]) {
			visualPath = tree[i][1];
			findPath = true;
			lastLevel = tree[i][2];
		}
		--i;
	}
	if (!useParam && !visualPath) {
		buildPath(true);
	} else {
		document.write("<a href='/htmls/home.shtml' class='palco_path'>Inicio</a> / "+visualPath);
	}
}

var mapClasses = ['menu1','menu2','menu3','menu4','menu5','menu5','menu5','menu5','menu5','menu5'];

function buildTree(startIn,maxDepth){
	var prevDepth = 0;
	var x = 0;
	if (startIn) {
		while (tree[x][0] != startIn){
			++x;
		}
	}
	var startDepth = (startIn) ? tree[x][2] : 0;
	while (x < tree.length) {
		if (tree[x][2] > prevDepth) {//acrescenta profundidade
			document.write('<ul class="menu_tree">');
		} else if (tree[x][2] < prevDepth) {//retira profundidade
			while (tree[x][2] < prevDepth) {
				document.write('</ul>');
				--prevDepth;
			}
		}
		var aTarget = "_self";
		var linkInfo = "";
		if (!tree[x][0]){
			var aLink = false;
		} else if (tree[x][0].toString().indexOf("http://") == 0){
			var aLink = tree[x][0];
			aTarget = "_blank";
		} else if (tree[x][0].toString().indexOf("/") == 0){
			var aLink = tree[x][0];
		} else if (typeof(tree[x][0])=="string"){
			var aLink = "/htmls/"+tree[x][0]+".shtml";
		} else {
			var y = x;
			var prevLevel = tree[y][2];
			var startLevel = tree[y][2];
			var subs = tree[y][0];
			while ((typeof(tree[y][0])!= "string") || (tree[y][2] >= startLevel)) {
				if (tree[y][2] < prevLevel){
					subs = ""+tree[y][0]+""+subs;
					prevLevel = tree[y][2];
				}
				--y;
			}
			prevSubs = tree[y][0];
			var aLink = "/htmls/"+prevSubs+".shtml#"+subs;
		}
		if ((!maxDepth) || (tree[x][2] <= startDepth+maxDepth)) {
			document.write('<li class="'+mapClasses[tree[x][2]-1]+'">');
			if ((!startDepth || tree[x][2] != startDepth) && aLink) document.write('<a href="'+aLink+'" target="'+aTarget+'">');
			document.write('<span class="'+mapClasses[tree[x][2]-1]+'">'+linkInfo+tree[x][1]+'</span>');
			if ((!startDepth || tree[x][2] != startDepth) && aLink) document.write('</a>');
			if (tree[x][3]) document.write('<br><span class="menu_info">'+tree[x][3]+'</span>');;
			document.write('</li>');
		}
		prevDepth = tree[x][2];
		++x;
		if (startDepth && tree[x][2] <= startDepth) x=9999;
	}

	while (prevDepth > 1) {
		document.write('</ul>');
		--prevDepth;
	}
}


//===========================================================
// ypChaser class definition
//===========================================================
function ypChaser(sLayerId, iTopOffset, iSlideTime, iCeiling, iFloor) {
this.chaserDiv = null
this.layerId = sLayerId
this.topOffset = iTopOffset
this.slideTime = iSlideTime
this.ceiling = iCeiling
this.floor = iFloor
ypChaser.registry[ypChaser.registry.length] = this
}
ypChaser.isIE = window.clientInformation ? true : false
ypChaser.isIEDTD = ((document.doctype && document.doctype.name.indexOf(".dtd")>-1) || document.compatMode == "CSS1Compat") ? true : false;
ypChaser.isN4 = document.layers ? true : false
ypChaser.isN6 = navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5
ypChaser.isO5 = navigator.userAgent.indexOf("Opera") != -1 && parseInt(navigator.appVersion) >= 4
ypChaser.registry = new Array( )
ypChaser.callRate = 10
window.setInterval("ypChaser.timer( )", ypChaser.callRate)
ypChaser.timer = function() {
for (var i = 0; chObj = this.registry[i]; i++) {
if (!chObj.chaserDiv) chObj.attemptLoad()
if (chObj.chaserDiv) chObj.main()
}
}
ypChaser.prototype.attemptLoad = function() {
var chDiv = null
if (ypChaser.isN6 || ypChaser.isO5) chDiv = document.getElementById(this.layerId)
else if (ypChaser.isIE) chDiv = document.all[this.layerId]
else if (ypChaser.isN4) chDiv = document.layers[this.layerId]
if (chDiv && chDiv != null) {
this.chaserDiv = chDiv
}
}
ypChaser.prototype.main = function( )
{
this.currentY = this.getCurrentY()
var scrollTop = ypChaser.getWindowScroll() 
var newTargetY = scrollTop + this.topOffset
var floor = ypChaser.getDocumentHeight() - this.floor
newTargetY = Math.max( newTargetY, this.ceiling)
if (!ypChaser.isO5) newTargetY = Math.min(newTargetY, floor)
if ( this.currentY != newTargetY ) {
if ( newTargetY != this.targetY ) {
this.targetY = newTargetY
this.slideInit( )
}
this.slide( )
}
}
ypChaser.prototype.slideInit = function( )
{
this.A = (this.targetY - this.currentY) / this.slideTime / this.slideTime
this.startT = (new Date()).getTime()
this.startP = this.getCurrentY()
this.D = this.targetY - this.startP
}

ypChaser.prototype.slide = function( )
{
var elapsed = (new Date()).getTime() - this.startT
if (elapsed < this.slideTime) {
this.moveTo(this.D - (Math.round(Math.pow(this.slideTime - elapsed, 2) * this.A)) + this.startP)
}
}
ypChaser.prototype.moveTo = function(ny) {
if (ypChaser.isN4) this.chaserDiv.top = ny
else this.chaserDiv.style.top = ny + "px"
}
ypChaser.prototype.getCurrentY = function() {
var n = ypChaser.isN4 ? this.chaserDiv.top : parseInt(this.chaserDiv.style.top)
return isNaN(n) ? 0 : n
}
ypChaser.getWindowScroll = function() {
if (ypChaser.isIEDTD) 
{
//window.status=document.documentElement.scrollTop;
return document.documentElement.scrollTop;
}
else if (ypChaser.isIE) return document.body.scrollTop;
else return window.pageYOffset
}
ypChaser.getDocumentHeight = function() {
if (ypChaser.isO5) return 0 // opera can't retreive this property.
else if (ypChaser.isIEDTD) return Math.max(document.documentElement.scrollHeight, document.documentElement.offsetHeight)
else if (ypChaser.isIE) return Math.max(document.body.scrollHeight, document.body.offsetHeight)
else return window.document.height
}
///////
function resumoDioc(tit,ref,num) {
	var output = '<hr><p class="menu2">Diocese d'+tit+'</p><ul>';
	output += '<li><a target="_blank" href="http://www.portal.ecclesia.pt/dioceses/'+ref+'.asp" class="menu3">Notícias</a></li>';
	output += '<li><a href="220.shtml#'+(num+1)+'" class="menu3">Contactos dos Secretariados Diocesanos</a></li>';
	output += '<li><a href="230.shtml#'+num+'" class="menu3">Estatísticas de Alunos</a></li>';
	output += '<li><a href="240.shtml#'+num+'" class="menu3">Limites da Diocese</a></li></ul>';
	MM_setTextOfLayer('legenda','',output);
}
var infoWindow;
function popinfo(file,w,h) {
	if (infoWindow){
		infoWindow.close();
	}
	if (!w) w=720;
	if (!h) h=550;
	infoWindow=window.open(file, "infoWindow", "height="+h+",width="+w+",resize=no,scrollbars=yes,status=yes");
}

var jukeWindow;
function popJukebox() {
	if (jukeWindow){
		jukeWindow.close();
	}
	jukeWindow=window.open("/jukebox.html", "jukeWindow", "height=100,width=250,resize=no,scrollbars=no,status=no");
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='• '+nm+': Tem que conter um endereço de e-mail válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='• '+nm+': O número não é valido.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='• '+nm+' Tem que ser um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '• '+nm+': É necessário.\n'; }
  }  if (errors) alert('Ocorreram os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function randHeader () {
	var rand_no = Math.ceil(4*Math.random());// 5 = # de CSS's (o 5º é do fórum)
	document.getElementById('headerimg').className="cx_cabecalho"+rand_no;
}
function randHeader2 () {
	var rand_no = Math.ceil(5*Math.random());// 5 = # de CSS's
	document.getElementById('headerimg').className="x_cabecalho"+rand_no;
}
//randHeader();