//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

  var yScroll;

  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
  }

  arrayPageScroll = new Array('',yScroll)
  return arrayPageScroll;
}


function showAjaxLabel(timeout)
{
  var arrayPageScroll = getPageScroll();
  yScroll = arrayPageScroll[1] + 2;
  var objAjaxLabel = document.getElementById('ajaxLabel');
  if (objAjaxLabel)
  {
    objAjaxLabel.style.top = yScroll.toString() + 'px';
    objAjaxLabel.style.right = '2px';
    objAjaxLabel.style.display = 'block';
    window.setTimeout('hideAjaxLabel()', timeout);
  }
}

function hideAjaxLabel()
{
  var objAjaxLabel = document.getElementById('ajaxLabel');
  if (objAjaxLabel)
  {
    objAjaxLabel.style.display = 'none';
  }
}

function initAjaxLabel(bgImage)
{
  var objBody = document.getElementsByTagName("body").item(0);
  var objAjaxLabel = document.createElement("div");
  objAjaxLabel.setAttribute('id','ajaxLabel');
  objAjaxLabel.onclick = function () {hideAjaxLabel(); return false;}
  objAjaxLabel.style.backgroundImage = "url('images/loading.png')";
  objAjaxLabel.style.backgroundPosition = 'top left';
  objAjaxLabel.style.backgroundRepeat = 'no-repeat';
  objAjaxLabel.style.backgroundColor = '#009900';
  objAjaxLabel.style.position = 'absolute';
  objAjaxLabel.style.top = '0px';
  objAjaxLabel.style.right = '0px';
  objAjaxLabel.style.zIndex = '80';
  objAjaxLabel.style.width = '100px';
  objAjaxLabel.style.height = '15px';
  objAjaxLabel.style.fontSize = '1px';
  objAjaxLabel.style.display = 'none';
  objBody.insertBefore(objAjaxLabel, objBody.firstChild);
  var preload = new Image();
  preload.src = 'images/loading.png';
}

function loadAjaxCode(url, scriptID, timeout)
{
  var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
  req.onreadystatechange = function()
  {
    if (req.readyState == 4)
    {
      eval(req.responseText);
    }
  }

  url += ( (url.indexOf('?', 1) > 0) ? '&' : '?' ) + 'nocache=' + Math.random();

  if (!timeout)
  {
    timeout = 20000;
  }
  showAjaxLabel(timeout);
  req.open("GET", url, true);
  req.send(null);
}

var prevOnload = window.onload;
if (typeof window.onload != 'function')
{
    window.onload = initAjaxLabel;
}
else
{
  window.onload = function()
  {
    prevOnload();
    initAjaxLabel();
  }
}
