var isFF=window.Event?1:0;

function setFocus()
{
  var obj = document.getElementById('Focused');
  if (obj != null && typeof(obj) != 'undefined')
  {
    obj.focus();
  }
  if (self.register_isearch) register_isearch();
}

function getXMLHttpRequest()
{
  var obj = null;
  if (window.XMLHttpRequest) obj = new XMLHttpRequest();
  else if (window.ActiveXObject) obj = new ActiveXObject("Microsoft.XMLHTTP");
  return obj;
}

function show_msg(p, msg)
{
  if (!p) return;
  p.innerHTML = msg;
  if (!document.body) document.body = document.getElementsByTagName("body")[0];
  if (!document.body) return;
  var b = document.body;
  var wx = (isFF?innerWidth:b.clientWidth);
  var wy = (isFF?innerHeight:b.clientHeight);
  var sx = (isFF?pageXOffset:b.scrollLeft);
  var sy = (isFF?pageYOffset:b.scrollTop);
  //alert('wx=' + wx + ',sx=' + sx + ',w=' + p.offsetWidth + ',left=' + p.style.left);
  p.style.left = (wx-p.offsetWidth)/2 + sx + 'px'; 
  p.style.top = (wy-p.offsetHeight)/2 + sy + 'px'; 
  p.style.visibility = '';
  //alert('wx=' + wx + ',sx=' + sx + ',left=' + p.style.left);
}

function pdf(url)
{
  if (!document.body) document.body = document.getElementsByTagName("body")[0];
  if (!document.body) return;
  var b = document.body;
  b.style.cursor = 'wait';

  var p = document.getElementById('popuploading');
  if (!p) {
    p =  document.createElement('div');
    p.id = 'popuploading';
    p.name = 'popuploading';
    p.className = 'popup';
    p.onclick = close_popup;
    b.appendChild(p);
  }
  show_msg(p, L('PDFLoading'));

  var d = document.getElementById('hiddenframe');
  if (!d)
  {
    d = document.createElement("iframe");
    d.id = 'hiddenframe';
    d.name = 'hiddenframe';
    d.style.visibility = 'hidden';
    document.body.appendChild(d);
  }

  var doc = new Image();
  doc.onerror = function() {
    var p = document.getElementById('popuploading');
    var d = document.getElementById('hiddenframe');
    if (p && d) {
      show_msg(p, L('PDFLoaded'));
      p.url = url;
      p.closing_popup_timer = setTimeout(closing_popup, 2000);
      p.style.cursor = 'pointer';
      document.body.style.cursor = '';
      d.src = url;
    }
  }
  doc.src = url;
}

function closing_popup()
{
  var p = document.getElementById('popuploading');
  if (p)
  {
    if (typeof(p.time_remaining) == 'undefined' || p.time_remaining == 0) p.time_remaining = 10;
    else p.time_remaining -= 1;
    if (p.time_remaining <= 0) {
      close_popup();
    } else {
      show_msg(p, L('PDFLoaded').replace('#URL#', p.url) + L('PopupClosing').replace('#SEC#', p.time_remaining));
      p.closing_popup_timer = setTimeout(closing_popup, 1000);
    }
  }
}

function close_popup()
{
  var p = document.getElementById('popuploading');
  if (p)
  {
    p.style.visibility = 'hidden';
    clearTimeout(p.closing_popup_timer);
  }
}

$(document).ready(function() {
  $('[@title]').cluetip({
    splitTitle: '|',
    showTitle: false,
    hoverIntent: {
        sensitivity: 1,
        interval: 500,
        timeout: 250
    },
    cluetipClass: 'jtip',
    arrows: true
  });
});
