﻿<!--
//
// funções globais
// v.1
//

//-------------------------------------------------------------------
// RELÓGIO
//-------------------------------------------------------------------

var mMinutos;
var mSegundos;
var hora;
    
function PrintRelogio(){
    out = new Date();
    if (out.getMinutes() < 10){mMinutos = '0'} else mMinutos = '';
    if (out.getSeconds() < 10){mSegundos = '0'} else mSegundos = ''; hora="" + "<b>" + out.getHours() + ":"+mMinutos+out.getMinutes()+":"+mSegundos+out.getSeconds()+"</b>"; document.getElementById('relogio').innerHTML=hora; setTimeout('PrintRelogio()',1000)
}


//-------------------------------------------------------------------
// CROSSFADER
//-------------------------------------------------------------------

var useBSNns;

if (useBSNns) 
{
    if (typeof(bsn) == "undefined") bsn = {}
    var _bsn = bsn;
} 
else 
{
    var _bsn = this;
}


_bsn.Crossfader = function (divs, fadetime, delay ) 
{

    this.nAct = -1;
    this.aDivs = divs;

    for (var i=0;i<divs.length;i++) 
    {
        document.getElementById(divs[i]).style.opacity = 0;
        document.getElementById(divs[i]).style.position = "absolute"; 
        document.getElementById(divs[i]).style.filter = "alpha(opacity=0)"; 
        document.getElementById(divs[i]).style.visibility = "hidden"; 
    }

    this.nDur = fadetime;
    this.nDelay = delay;
    this._newfade();
}


_bsn.Crossfader.prototype._newfade = function() 
{  
    if (this.nID1) clearInterval(this.nID1);
    this.nOldAct = this.nAct;
    this.nAct++;

    if (!this.aDivs[this.nAct]) this.nAct = 0;
    if (this.nAct == this.nOldAct) return false;

    document.getElementById( this.aDivs[this.nAct] ).style.visibility = "visible"; 
    this.nInt = 50; 
    this.nTime = 0; 
    var p=this; 
    this.nID2 = setInterval(function() { p._fade() }, this.nInt); 
}


_bsn.Crossfader.prototype._fade = function() 
{
    this.nTime += this.nInt;
    var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 ); 
    var op = ieop / 100; 
    document.getElementById( this.aDivs[this.nAct] ).style.opacity = op; 
    document.getElementById( this.aDivs[this.nAct] ).style.filter = "alpha(opacity="+ieop+")";

    if (this.nOldAct > -1) 
    {
        document.getElementById( this.aDivs[this.nOldAct] ).style.opacity = 1 - op; 
        document.getElementById( this.aDivs[this.nOldAct] ).style.filter = "alpha(opacity="+(100 - ieop)+")"; 
    }

    if (this.nTime == this.nDur) 
    {
        clearInterval( this.nID2 );
        if (this.nOldAct > -1)
        document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden"; 
        var p=this; 
        this.nID1 = setInterval(function() { p._newfade() }, this.nDelay); 
    }
}


_bsn.Crossfader.prototype._easeInOut = function(t,b,c,d) 
{
  return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}


//-------------------------------------------------------------------
// LINKS
//-------------------------------------------------------------------
function nLink(url)
{
	if (url != "#") 
	{	
		if (url.toLowerCase().indexOf('/') != -1)
			location.href = url;
		else
			window.open(url,'_blank');
	}
}


//-------------------------------------------------------------------
// NÚMERO DE CONTRIBUINTE
//-------------------------------------------------------------------
function ValidaNIF(contrib)
{
   if(contrib.value != "")
   {
      var Field = contrib;
      var  s;
      var  c;
      var  checkDigit;

      s = contrib.value;

      if (s.length == 9)
      {
         c = s.charAt(0);
         if (c == '1' || c == '2' || c == '5' || c == '6' || c == '8' || c == '9')
         {
            checkDigit = (c - '0') * 9;
            for (i = 2 ; i <= 8 ; i ++ )
            {
               checkDigit += (s.charAt(i - 1) - '0') * (10 - i);
            }

            checkDigit = 11 - (checkDigit % 11);

            if (checkDigit >= 10)
            checkDigit = 0;

            if (checkDigit == (s.charAt(8) - '0'))
            return true;
         }

      }
      alert("O número de contribuinte que introduzio não é válido.");
      Field.select();
      Field.focus();
      return false;
   }
}

//-------------------------------------------------------------------
// VERIFICA IDADE 
//-------------------------------------------------------------------
function checkIdade(idade)
{
   if(idade.value != "")
   {
      var Field = idade;
      if (idade.value > 65)
      {
         alert("A idade deve ser inferior a 65 anos!");
         Field.value = "";
         Field.select();
         Field.focus();
         return false;
      }
      if (idade.value < 18)
      {
         alert("A idade deve ser superior a 18 anos!");
         Field.value = "";
         Field.select();
         Field.focus();
         return false;
      }
   }
}




-->