// ----------------------------------------------------------------------------------
// Filatelia em Portugal
// Ficheiro de funções
// JavaScript
// 
// ----------------------------------------------------------------------------------



// Cabecalho
function cab(tipo,titulo) {
	if (tipo == 1) {
	document.write('<IMG SRC="../imagens/margem.gif" WIDTH="95%" HEIGHT="20" ALT="" BORDER="0">')
	document.write('<TABLE ALIGN="center" WIDTH="600" CELLSPACING="4" CELLPADDING="4" BORDER="0">')
	document.write('<TR>')
	document.write('<TH ALIGN="right" VALIGN="top" CLASS="CABECALHO">')
	document.write(titulo)
	document.write('</TH>')
	document.write('</TR>')
	document.write('<TR>')
	document.write('<TD BGCOLOR="#ECFFF5">')
	}	
}

// Rodapé
function rod(tipo) {
	if (tipo == 1) {
	document.write('</TD>')
	document.write('</TR>')
	document.write('</TABLE>')
	document.write('<BR>')
	document.write('<div align="center" style="background-color: #FFFFDF;"><center>')
	document.write('<A HREF="http://www.caleida.pt/filatelia" NAME="Abertura de A Filatelia em Portugal" CLASS="MENOR">[ Página Filatelia Portuguesa ]</A>&nbsp;&nbsp;&nbsp;')
	document.write('<A HREF="mailto:pimenta@fep.up.pt?subject=Administracao Filatelia Portuguesa" CLASS="MENOR">[ E-mail to Webmaster ]</A>')
	document.write('</center></div>')
	}
}

function OpenImage(fich_imagem, w, h){
	var wi = new Number()
	var he = new Number()
	if (w+40 < 640) { wi = w+40 }
	else { wi = 640 }
	if (h+40 < 480) { he = h+40 }
	else { he = 480 }
	caract = 'toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + wi.toString() + ',height=' + he.toString()
	aPopUp = window.open('', 'Imagem', caract)
	ndoc = aPopUp.document
	astr = '<HTML><HEAD><TITLE>Visualização de imagens</TITLE>'
	astr += '</HEAD>'
	astr += '<BODY BGCOLOR="#000000">'
	astr += '<DIV ALIGN="center">'
	astr += '<IMG SRC="' + fich_imagem + '" WIDTH="' + w + '" HEIGHT="' + h +'" ALT="Ampliação" BORDER="0">'
	astr += '<BR></DIV>'
	astr += '</BODY></HTML>'
	ndoc.clear()
	ndoc.write(astr)
	ndoc.close()
}

// Substituir  ../../../ por ../
// Abrir janela de ajuda ------------------- Adaptar
// <A HREF="JavaScript:OpenNote('xxx')">Imagem</A>
function OpenNote(conteudo){
aPopUp = window.open('', 'Ajuda', 'toobar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=150')
ndoc = aPopUp.document
astr = '<HTML><HEAD><TITLE>FP: Ajuda</TITLE>'
astr += '</HEAD>'
astr += '<body bgcolor="#ECFFF5" text="#800000" link="#ff0000">'
astr += '<DIV ALIGN="center"><B>Filatelia em Portugal: Ajuda</B></DIV><BR>'
astr += conteudo + '<BR><BR>'
astr += '<DIV ALIGN="center"><A HREF="Javascript:self.close()">Fechar</A></DIV>'
astr += '</BODY></HTML>'
ndoc.clear()
ndoc.write(astr)
ndoc.close()
}

// Abrir janela de ajuda ------------------- Adaptar
// <A HREF="JavaScript:OpenNote('xxx')">Imagem</A>
function OpenJanela(titulo, conteudo){
aPopUp = window.open('', 'Ajuda', 'toobar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=350')
ndoc = aPopUp.document
astr = '<HTML><HEAD><TITLE>FP: Ajuda</TITLE>'
astr += '</HEAD>'
astr += '<body bgcolor="#ECFFF5" text="#800000" link="#ff0000">'
astr += '<DIV ALIGN="center"><B>Filatelia em Portugal:'
astr += titulo
astr += '</B></DIV><BR>'
astr += conteudo + '<BR><BR>'
astr += '<DIV ALIGN="center"><A HREF="Javascript:self.close()">Fechar</A></DIV>'
astr += '</BODY></HTML>'
ndoc.clear()
ndoc.write(astr)
ndoc.close()
}


// Gera um numero aleatório entre os que os limites colocados, inclusive
function getRandomNum(lbound, ubound) {
return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
// permite aleatoriamente ir buscar uma imagem
function imagemaleatoria(nome,tipo,w,h,a,alig) {
document.write('<img src=' + nome + getRandomNum(1,6) + '.' + tipo + ' width=' + w +' height=' + h + ' alt=' + a + ' border="1" align=' + alig+ '>');
}

// Garantia de correcção no preenchimento do formulário de anúncio
function checkAnuncio() {
	missinginfo = "";
	if (document.anunciar.texto.value == "") {
		missinginfo += "\n     -  Texto do anúncio por preencher";
	}
	if (document.anunciar.contacto.value == "") {
		missinginfo += "\n     -  O seu contacto por introduzir";
	}
	if (missinginfo != "") {
		missinginfo ="_______________________________________\n" +
		"Formulário não está correctamente preenchido:\n" +
		missinginfo + "\n_______________________________________" +
		"\nPor favor volte a escrever os campos em falha!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

// Garantia de correcção no preenchimento do formulário de inscricao livro visitas
function checkVisita() {
	missinginfo = "";
	if ((document.lvisita.mail.value == "") || 
		(document.lvisita.mail.value.indexOf('@') == -1) || 
		(document.lvisita.mail.value.indexOf('.') == -1)) {
		missinginfo += "\n     -  Endereço de Email inadequado";
	}
	if (missinginfo != "") {
		missinginfo ="_______________________________________\n" +
		"Formulário não está correctamente preenchido:\n" +
		missinginfo + "\n_______________________________________" +
		"\nPor favor volte a escrever os campos em falha!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

// Sobreposição de imagens
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.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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];}
}
