var Util;
if (Util==null)
  Util={};
Util.closePopup = function() {
  var block = document.getElementById('popup-win');
  if (block!=null)
    block.style.top = '-1000px';

  var shade = document.getElementById('popup-shield');
  if (shade!=null)
    shade.style.display='none';
  return false;
}
Util.detailCache = {};

Util.docComplete = function(t, doc) {
  // Select the 'body' part of the data, insert into the target URL
  var res = (/\<body\>(.*)\<\/body\>/i).exec(doc);
  if (res!=null && res.length>1) {
    var bdy = document.getElementById('popup-body');
    if (res!=null && bdy!=null) {
      Util.detailCache[t.docID] = bdy.innerHTML = res[1];
    }
  }
}


Util.openMore = function(URL, docID, idx) {
  // Show data in-line if available
  var block = document.getElementById('popup-win');
  if (block==null)
    return true;

  // Need to find the advert that triggered the event
  var blk = document.getElementById('res_'+idx);
  if (blk==null)
    return true;

  var bdy = document.getElementById('popup-body');
  if (bdy!=null) {
    // Do we have the details for this document?
    if (docID in Util.detailCache)
      bdy.innerHTML = Util.detailCache[docID];
    else {
      // Start Async load for this documents details.
      bdy.innerHTML = '<div id="loading"><img src="/images/loading.gif" alt="Loading" title="loading document details"><br>Loading</div>';
      var r = HTTP.newRequest();
      r.docID = docID;
      r.get(URL, Util.docComplete, {});
    }
  }
  
	var posx = 0;
	var posy = 0;

	if (blk.pageX!=null || blk.pageY!=null) {
		posx = blk.pageX;
		posy = blk.pageY;
	}
	else if (blk.clientX || blk.clientY) {
		posx = blk.clientX + document.body.scrollLeft;
		posy = blk.clientY + document.body.scrollTop;
	}
	else if (blk.offsetTop!=null || blk.offsetLeft!=null) {
		posx = blk.offsetLeft;
		posy = blk.offsetTop;
	}

  posy += 25;
  posx += 20;

  block.style.top  = ''+posy+'px';
  block.style.left = ''+posx+'px';

//    shade.style.display='block';

  return false;
}

