// Title: Tigra Hints
// URL: http://www.softcomplex.com/products/tigra_hints/
// Version: 1.3
// Date: 09/03/2003 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.

//Amended by VRS Aug 04 to remove bug which caused hints to be off screen when IE6 reads strict DTD document.
// Amended by JRC Mar 30 to remove bug which caused hints to be off screen when in FIREFOX.
// Amended by JRC Mar 29, 2006 to remove bug which caused hints to be off screen when in FIREFOX and image is near bottom page.
// Version: 1.1.10
// Amended by JRC Apr 25, 2006 remove nowrap
// Version: 1.1.11

// 2007/05/26
// Esta era la versión que estaba trabajando hasta abril pasado
// pero en IE6 al pasar el HINT sobre un combobox, no hubo forma de que lo tapara
// SIN EMBARGO ESA PARTE FUNCIONA OK en FIREFOX y parece que en IE7
// aunque en IE7 no se posiciona correctamente porque parece no estar definido
// mi el ancho ni el alto de la ventana HINT
//
// queda como versión: 1.1.11

// 2007/07/13
// Versión: 1.1.12
//
// Aplicable a Firefox e Internet Explorer 7
// soluciona el problema de mal posicionamiento de la ventana emergente
// en Internet Explorer 7


// 2008/11/17
// Versión: 1.1.13
// s_tag no usa más una tabla, ahora sólo usa DIV


// 2008/11/26
// Versión: 1.1.14
// Adecuado para trabajar con DIVs de posicionamiento absoluto


// 2008/12/10
// Versión: 1.1.15
//    Solucionado problema en IE7 mal control posicionamiento
//    horizonatl si excede límites pantalla.
//    Al definir en s_tag no se debe usar width: 1px, dejarlo en blanco
//    como en Firefox. Elemental!


var THintsS = [];
function THints (o_cfg, items) {
  this.n_id = THintsS.length;
  THintsS[this.n_id] = this;
  this.top = o_cfg.top ? o_cfg.top : 0;
  this.left = o_cfg.left ? o_cfg.left : 0;
  this.n_dl_show = o_cfg.show_delay;
  this.n_dl_hide = o_cfg.hide_delay;
  this.b_wise = o_cfg.wise;
  this.b_follow = o_cfg.follow;
  this.x = 0;
  this.y = 0;
  this.divs = [];
  this.show  = TTipShow;
  this.showD = TTipShowD;
  this.hide = TTipHide;
  this.move = TTipMove;

  // v. 1.1.14
  this.offsettop  =  0;
  this.offsetleft =  0;
  this.SetOffsetTop = TTipSetTop;
  this.SetOffsetLeft = TTipSetLeft;

  // register the object in global collection
  this.n_id = THintsS.length;
  THintsS[this.n_id] = this;
  // filter Netscape 4.x out
  if (document.layers) return;
  var b_FF = navigator.userAgent.indexOf('Firefox') > -1;
  var b_IE7 = ((navigator.userAgent.indexOf('MSIE')) > -1 && (typeof document.body.style.maxHeight != "undefined"));

  var b_IE = navigator.userAgent.indexOf('MSIE') > -1,

  //  s_tag = ['<div id="TTip%name%" style="visibility:hidden;position:absolute;top:0px;left:0px;',   b_IE ? 'width:1px;height:1px;' : '', o_cfg['z-index'] != null ? 'z-index:' + o_cfg['z-index'] : '', '"><div class="', o_cfg.css, '">%text%</div></div>'].join('');
  // 1.1.15
  s_tag = ['<div id="TTip%name%" style="display: block; visibility:hidden;position:absolute;top:0px;left:0px;',   (b_IE && ! b_IE7) ? 'width:1px;height:1px;' : '', o_cfg['z-index'] != null ? 'z-index:' + o_cfg['z-index'] : '', '"><div class="', o_cfg.css, '">%text%</div></div>'].join('');

  this.getElem =
    function (id) { return document.all ? document.all[id] : document.getElementById(id); };
  this.showElem =
    function (id, hide) {this.divs[id].o_css.visibility = hide ? 'hidden' : 'visible'; };

  if (window.innerHeight != null && !b_FF)// not IE browser
    {
    this.getWinSz = function (b_hight) {return b_hight ? innerHeight : innerWidth;};
    this.getWinSc = function (b_hight) {return b_hight ? pageYOffset : pageXOffset;};
    }
  else if ( !b_FF && document.documentElement &&
          ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) //Strict IE6
    {
    this.getWinSz = function (b_hight) {return document.documentElement[b_hight ? 'clientHeight' : 'clientWidth'];};
    this.getWinSc = function (b_hight) {return document.documentElement[b_hight ? 'scrollTop' : 'scrollLeft'];};
    }
  else if ( b_FF ) // FireFox 2006-03-29
    {
    this.getWinSz = function (b_hight) {return document.documentElement[b_hight ? 'clientHeight' : 'clientWidth'];};
    this.getWinSc = function (b_hight) {return document.documentElement[b_hight ? 'scrollTop' : 'scrollLeft'];};
    }
  else
    {
    this.getWinSz = function (b_hight) {return document.body[b_hight ? 'clientHeight' : 'clientWidth'];};
    this.getWinSc = function (b_hight) {return document.body[b_hight ? 'scrollTop' : 'scrollLeft'];};
    }

  if (window.opera) {
    this.getSize = function (id, b_hight) {
      return this.divs[id].o_css[b_hight ? 'pixelHeight' : 'pixelWidth']
    };
    document.onmousemove = function () {
      for (var n_i in THintsS) {
        THintsS[n_i].x = event.clientX;
        THintsS[n_i].y = event.clientY;
        if (THintsS[n_i].b_follow && THintsS[n_i].visible)
          THintsS[n_i].move(THintsS[n_i].visible);
      }
      return true;
    };
  }
  else
  {
    if (b_IE7)
    {
      this.getSize = function (id, b_hight)
      {
        return this.divs[id].o_obj[b_hight ? 'scrollHeight' : 'scrollWidth']
      };
    } else
    {
      this.getSize = function (id, b_hight)
      {
        return this.divs[id].o_obj[b_hight ? 'offsetHeight' : 'offsetWidth']
      };
    }
    document.onmousemove = b_IE
    ? function () {
      for (var n_i in THintsS) {
        if( document.documentElement &&
          ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
          {
          //IE is set to fully compliant mode
          x_offset = document.documentElement.scrollLeft;
          y_offset = document.documentElement.scrollTop;
          }
        else
          {
          //IE is not fully compliant
          x_offset = document.body.scrollLeft;
          y_offset = document.body.scrollTop;
          }
        THintsS[n_i].x = event.clientX + x_offset;
        THintsS[n_i].y = event.clientY + y_offset;
        if (THintsS[n_i].b_follow && THintsS[n_i].visible)
          THintsS[n_i].move(THintsS[n_i].visible);
      }
      return true;
    }
    : function (e) {
      for (var n_i in THintsS) {
        THintsS[n_i].x = e.pageX;
        THintsS[n_i].y = e.pageY;
        if (THintsS[n_i].b_follow && THintsS[n_i].visible)
          THintsS[n_i].move(THintsS[n_i].visible)
      }
      return true;
    };
  }
  for (i in items) {
    document.write (s_tag.replace(/%text%/, items[i]).replace(/%name%/, i));
    this.divs[i] = { 'o_obj' : this.getElem('TTip' + i) };
    this.divs[i].o_css = this.divs[i].o_obj.style;
  }
}

function TTipShow (id) {
  if (document.layers) return;
  this.hide();
  if (this.divs[id]) {
    if (this.n_dl_show) this.divs[id].timer = setTimeout("THintsS[" + this.n_id + "].showD(" + id + ")", this.n_dl_show);
    else this.showD(id);
    this.visible = id;
  }
}

function TTipShowD (id) {
  this.move(id);
  this.showElem(id);
  if (this.n_dl_hide) this.timer = setTimeout("THintsS[" + this.n_id + "].hide()", this.n_dl_hide);
}

function TTipMove (id) {
  var n_x = this.x + this.left, n_y = this.y + this.top;
  if (this.b_wise) {
    var n_w = this.getSize(id), n_h = this.getSize(id, true),
    n_win_w = this.getWinSz(), n_win_h = this.getWinSz(true),
    n_win_l = this.getWinSc(), n_win_t = this.getWinSc(true);

    if (n_x + n_w > n_win_w + n_win_l) n_x = n_win_w + n_win_l - n_w;
    if (n_x < n_win_l) n_x = n_win_l;
    if (n_y + n_h > n_win_h + n_win_t) n_y = n_win_h + n_win_t - n_h;
    if (n_y < n_win_t) n_y = n_win_t;
  }

  // v. 1.1.14
  //  this.divs[id].o_css.left = n_x+'px';
  //  this.divs[id].o_css.top = n_y+'px';
  this.divs[id].o_css.left = (n_x -this.offsetleft)+'px';
  this.divs[id].o_css.top = (n_y -this.offsettop)+'px';
}

function TTipHide ()
{
  if (this.timer) clearTimeout(this.timer);
  if (this.visible != null) {
    if (this.divs[this.visible].timer) clearTimeout(this.divs[this.visible].timer);
    setTimeout("THintsS[" + this.n_id + "].showElem(" + this.visible + ", true)", 10);
    this.visible = null;
  }
}

//v. 1.1.14
function TTipSetTop (ltop)
{
  this.offsettop = ltop;
}
function TTipSetLeft (lleft)
{
  this.offsetleft = lleft;
}
