  var timerIL, linkActivoIL = null, urlIL = null, urlSiteIL = '';

  function fInicializaIL() {
    //adicionar DIV à página
    var dvIL = document.createElement('DIV');
    dvIL.id = 'divInfoLink';
    dvIL.onmouseover = fAbrirInfoLink;
    dvIL.onmouseout = fFecharInfoLink;
    dvIL.className = 'dvIL';
    dvIL.style.display = 'none'; 
    dvIL.style.width = '146px'; 
    dvIL.style.height = '88px';
    dvIL.innerHTML = 
     '<table id="tableInfoLink" border=0 cellpadding=0 cellspacing=0>' +
     '<tr><td class="tdIL" id="tdAbrirIL" onclick="fAbrirLinkIL(this);" oncontextmenu="return false;" onmouseover="fSobreTDIL(this);" onmouseout="fSaiuTDIL(this);">Abrir</td></tr>' +
     '<tr><td class="tdIL" id="tdAbrirNovaIL" onclick="fAbrirLinkNovaJanelaIL(this);" oncontextmenu="return false;" onmouseover="fSobreTDIL(this);" onmouseout="fSaiuTDIL(this);">Abrir em nova janela</td></tr>' +
     '<tr><td class="tdIL" id="tdCopiarIL" onclick="fCopiarLinkIL(this);" oncontextmenu="return false;" onmouseover="fSobreTDIL(this);" onmouseout="fSaiuTDIL(this);">Copiar atalho</td></tr>';
    document.body.appendChild(dvIL);
    //adicionar Listener ao click do lado direito do rato
    document.oncontextmenu = fVerificaBotaoDireitoRato;
  }
  function fAbrirLinkIL(obj) {
    if (linkActivoIL != null && obj.className == 'tdIL') {
      if (linkActivoIL.click) {
        linkActivoIL.click();
      } else {
        if (linkActivoIL.href.indexOf('javascript:') > -1) {
          eval(linkActivoIL.href);
        } else {
          var target = linkActivoIL.target;
          if (target == '') { target = '_self'; }
          window.open(linkActivoIL.href, target);
        }
      }
    }
    fFecharInfoLink(0);    
  }
  function fAbrirLinkNovaJanelaIL(obj) {
    if (obj.className == 'tdIL') {
      fFecharInfoLink(0);
      //var x = window.open('about:blank', null);
      //x.location.href = 'http://master04/gcmov7/utilitarios/redirecciona.aspx?url=' + escape(urlIL.url);
      window.open(urlIL.url, '_blank');  
    }
  }
  function fCopiarLinkIL(obj) {
    if (obj.className == 'tdIL') {
      fFecharInfoLink(0);
      setTimeout("window.prompt('Copie o endereço:', '" + urlIL.url + "');", 25);
    }
  }
  function fParseLinkIL(href) {
    if (linkActivoIL.href.indexOf('javascript:') > -1) {
      var rg = /^javascript:(janExt|janMicroSite|linkWebSite|PerformNode|linkFicheiro|linkFicheiroListagem|linkExterno|mlkregisto|mlknoticia_\d+)\((.*)\)/gi;
      var res = rg.exec(href);
      if (res == null) {
        return {abrir: true, abrirNova: false, copiar: false, url: href};
      } else {
        var url = urlSiteIL, abrir = true, nova = true, copiar = true;
        var aux = unescape(res[2]).split(',');
        var args = new Array();
        //Preparar os argumentos
        for (var i = 0; i < aux.length; i++) {
          args[i] = aux[i].replace(/^[ ]*'?/, '').replace(/'?[ ]*$/, '');
        }
        //Verificar o link
        if (res[1].search(/janExt/i) > -1) { //Janela Externa
          url += '?cje=' + args[0];
          if (args.length > 1 && args[1] != '') { url += '&vars=' + escape('&' + fPreparaVariaveis(args[1])); }
          nova = false;
          
        } else if (res[1].search(/janMicroSite/i) > -1) { //Micro-Site
          url += '?cms=' + args[0];
          if (args.length > 1 && args[1] != '') { url += '&vars=' + escape('&' + fPreparaVariaveis(args[1])); }
          nova = false;
          
        } else if (res[1].search(/linkWebSite/i) > -1 || res[1].search(/PerformNode/i) > -1) { //Web Site
          url += '?cn=' + args[0];
          if (args.length > 2 && args[2] != '') { url += '&vars=' + escape('&' + fPreparaVariaveis(args[2])); }
        
        } else if (res[1].search(/linkFicheiroListagem/i) > -1) { //Ficheiro Listagem
          url += '?cfl=' + args[0];
          nova = false;
        
        } else if (res[1].search(/linkFicheiro/i) > -1) { //Ficheiro
          url += '?cr=' + args[0];
          if (args.length > 1 && args[1] != '') { url += '&vars=' + escape('&' + fPreparaVariaveis(args[1])); }          
          nova = false;
        
        } else if (res[1].search(/linkExterno/i) > -1) { //Link externo
          url = args[1];
          if (args.length > 2 && args[2] != '') { url += '?' + fPreparaVariaveis(args[2]); }
        
        } else if (res[1].search(/mlkregisto/i) > -1) { //Noticias
          url += '?cr=' + args[0];
        
        } else if (res[1].search(/mlknoticia_\d+/i) > -1) { //Noticias
          url += '?cr=' + args[0];

        } else {
          abrir = true;
          nova = false;
          copiar = false;
          url = href;
        }
        return {abrir: abrir, abrirNova: nova, copiar: copiar, url: url};
      }
    } else {
      return {abrir: true, abrirNova: false, copiar: false, url: href};
    }
  }
  function fAnulatimerIL() {
    try  { 
      clearTimeout(timerIL);
    } catch (e) { }
  }
  function fVerificaBotaoDireitoRato(evt) {
    var ie = (document.all ? true : false);
    if(!evt && window.event) { evt = window.event; }
    var tipo = evt.type; 
    if (tipo == 'contextmenu') {
      var elem = (ie == true ? window.event.srcElement : evt.target);
      if (elem.tagName == 'A' || (elem.tagName != 'A' && elem.parentNode && elem.parentNode.tagName == 'A' )) {
        fActivaInfoLink(elem, evt);
        if (ie) {
          window.event.returnValue = false;
        } else {
          return false;
        }
      }
    }
  }
  function fActivaInfoLink(elem, evt) {
    var divIL = document.getElementById('divInfoLink');
    var pos = fPosicionarInfoLink(elem, evt);
    linkActivoIL = (elem.tagName == 'A' ? elem : elem.parentNode);
    urlIL = fParseLinkIL(linkActivoIL.href);
    document.getElementById('tdAbrirIL').className = (urlIL.abrir == true ? 'tdIL' : 'tdILInactiva');
    document.getElementById('tdAbrirNovaIL').className = (urlIL.abrirNova == true ? 'tdIL' : 'tdILInactiva');
    document.getElementById('tdCopiarIL').className = (urlIL.copiar == true ? 'tdIL' : 'tdILInactiva');
    if (urlIL.abrir == true) {
    }
    //lança interface para copiar o link
    var tableIL = document.getElementById('tableInfoLink');
    for(var i = 0; i < tableIL.rows.length; i++) {
      tableIL.rows[i].cells[0].style.backgroundColor = '';
    }
    divIL.style.left = pos.left + 'px';
    divIL.style.top = pos.top + 'px';
    divIL.style.display = 'block';
  }
  function fAbrirInfoLink() {
    var divIL = document.getElementById('divInfoLink');
    fAnulatimerIL();
    divIL.style.display = 'block';
  }
  function fFecharInfoLink(tempo) {
    if (typeof(tempo) == 'undefined') { tempo = 500; }
    fAnulatimerIL();
    if (tempo == 0) {
      fFecharInfoLink_Executa();      
    } else {
      timerIL = setTimeout('fFecharInfoLink_Executa();', tempo);
    }
  }
  function fFecharInfoLink_Executa() {
    document.getElementById('divInfoLink').style.display = 'none';
    linkActivoIL = null;
  }
  function fPosicionarInfoLink(elem, evt) {
    var pos = fObtemCoordenadasRato(evt);
    var jan = fObtemDimensoesJanela();
    var scroll = fObtemPosicaoScroll();
    var divIL = document.getElementById('divInfoLink');
    var left, top, meio, larg, alt;
    //Calcular posicionamento horizontal
    meio = ((scroll.left + jan.width) / 2);
    larg = parseInt(divIL.style.width, 10);
    if (meio < pos.x && ((scroll.left + jan.width) < (pos.x + larg))) {
      //desenha para a esquerda
      left = pos.x - larg + 2;
    } else {
      //desenha para a direita
      left = pos.x - 2;
    }
    //Calcular posicionamento vertical
    meio = ((scroll.top + jan.height) / 2);
    alt = parseInt(divIL.style.height, 10);
    if ((meio < pos.y) && ((scroll.top + jan.height) < (pos.y + alt))) {
      //desenha para a cima
      top = pos.y - alt + 2;
    } else {
      //desenha para baixo
      top = pos.y - 2;
    }
    return {left: left, top: top};
  }
  function fObtemCoordenadasRato(evt) {
    var x = 0, y = 0;
    if( typeof( evt.pageX ) == 'number' ) {
      x = evt.pageX;
      y = evt.pageY;
    } else if(typeof( evt.clientX ) == 'number') {
      x = evt.clientX;
      y = evt.clientY;
      if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        x += document.body.scrollLeft;
        y += document.body.scrollTop;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        x += document.documentElement.scrollLeft;
        y += document.documentElement.scrollTop;
      }
    } else {
      return {x: x, y:y};
    }
    return {x: x, y:y};
  }
  
  function fObtemDimensoesJanela() {
    var w = 0, h = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
      w = window.innerWidth;
      h = window.innerHeight;
    } else {
      w = document.body.clientWidth;
      h = document.body.clientHeight;
    }
    return {width: w, height: h};
  }
  function fObtemPosicaoScroll() {
    var scrOfX = 0, scrOfY = 0, scrW = 0, scrH = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
      scrW = document.body.scrollWidth;
      scrH = document.body.scrollHeight;
    } else {
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
      scrW = document.body.scrollWidth;
      scrH = document.body.scrollHeight;
    }
    return {left: scrOfX, top: scrOfY, width: scrW, height: scrH};
  }  
  function fSobreTDIL(obj) {
    if (obj.className == 'tdIL') {
      obj.style.backgroundColor = '#F1F0F0';  
      obj.style.cursor = 'pointer';
    }
  }
  function fSaiuTDIL(obj) {
    obj.style.backgroundColor = '';
    obj.style.cursor = 'auto';
  }
