function FloatingPopup (forceWindow)
	{
	this.ie = false;
	this.ud = false;
	if (forceWindow)
    this.up = true;
  else
    {
  	this.up = false;
    if (window.createPopup)
      this.ie = true;
    else
      this.ud = true;
    }
	this.txt = null;
	this.title = "";
	this.emptyUrl = null;

	this.createDiv = function ()
		{
		div = document.createElement("div");
		div.setAttribute ("style", "position:absolute;visibility:hidden");
		document.body.appendChild (div);
		return div;
		};	

	if (this.ie)
		this.oPopup = window.createPopup();
	else if (this.up)
		this.oPopup = null;
	else
		this.div = this.createDiv();

	this.setContent = function (txt)
		{
		if (this.ie)
		  this.oPopup.document.body.innerHTML = txt;
		else if (this.up)
		  this.txt = txt;
		else
		  this.div.innerHTML = txt;
		};

	this.setTitle = function (txt)
		{
    this.title = txt;
		};

  this.setEmptyUrl = function (url)
    {
    this.emptyUrl = url;
    }

	this.show = function (x, y, width, height)
		{
		if (this.ie)
			this.oPopup.show (x, y, width, height, document.body);
		else if (this.up)
			{
			var options = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,titlebar=no,dependent,width=" + width + ",height=" + height + ",left=" + x + ",top=" + y;
			var myUrl = "about:blank";
			if (this.emptyUrl)
			  myUrl = this.emptyUrl;
			this.oPopup = window.open(myUrl, "floatingPopup", options);
      if (this.title)
  			this.oPopup.document.write("<html><head><title>" + this.title + "</title></head><body>");
			this.oPopup.document.bgColor = window.document.bgColor;
      this.oPopup.that = this;
			this.oPopup.document.body.innerHTML = this.txt;
			}
		else
			{
			this.div.style.left = x + "px";
			this.div.style.width = width + "px";
			//this.div.style.height = height + "px";
			if (y + this.div.scrollHeight > document.body.clientHeight)
				y = document.body.clientHeight - this.div.scrollHeight;
			y += document.body.scrollTop;
      if (y < 0)
        y = 0;
			this.div.style.top = y + "px";
			this.div.style.visibility = "visible";
			}	
		};
		
	this.getScrollWidth = function()
		{
		if (this.ie || this.up)
			return this.oPopup.document.body.scrollWidth;
		return this.div.scrollWidth;
		};
		
	this.getScrollHeight = function()
		{
		if (this.ie || this.up)
			return this.oPopup.document.body.scrollHeight;
		return this.div.scrollHeight;
		};
		

	this.hide = function(doClose)
		{
		if (this.ie)
			this.oPopup.hide();
		else if (this.up)
			this.oPopup.close();
		else
			{
			this.div.style.visibility = "hidden";
			if (doClose)
			  this.div.innerHTML = "";
			}

		};
	}



var _popupwidth = -1;

var _popupposx;
var _popupposy;
var _popuptimer = null;
var _popupstr;
var _popupwho = null;
var _popupdiv = null;
var _popuptextdiv = null;


function _getWindowHeight() 
  {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
    {
    //Non-IE
    myHeight = window.innerHeight;
    } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
    } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
    }
  return myHeight;
  }


function _getDivHeight(divobj)
  {
  var h = divobj.offsetHeight;
  var obj = divobj.firstChild;
  
  while (obj != null) 
    {
    if (obj.nodeName == "DIV")
      h += obj.offsetHeight;
    obj = obj.nextSibling;
    }
  return h;
  }

function _getDivWidth(divobj)
  {
  var w = divobj.offsetWidth;
  var obj = divobj.firstChild;
  
  while (obj != null) 
    {
    if (obj.nodeName == "DIV" && w < obj.offsetWidth)
      w = obj.offsetWidth;
    obj = obj.nextSibling;
    }
  return w;
  }

function _setDivWidth()
  {
  if (_popupwidth == -1)
    return;
  _popupdiv.style.width = _popupwidth + "px";
  var obj = _popupdiv.firstChild;
  
  while (obj != null) 
    {
    if (obj.nodeName == "DIV")
      obj.style.width = _popupwidth + "px";
    obj = obj.nextSibling;
    }
  }

function _getPopupScreenPos()
  {
  var oleft = _popupposx + 5;
  var otop = _popupposy + 5;
 
  var height = _getWindowHeight();
  
  var divheight = _getDivHeight(_popupdiv);
  var divwidth = _getDivWidth(_popupdiv);
  if (_popupwho)
    {
    otop = 0;

    obj = _popupwho;
    do
      {
       if (obj.scrollTop)
         otop -= obj.scrollTop;
       }
       while (obj = obj.parentNode);

    obj = _popupwho;
    do
      {
      otop = otop + obj.offsetTop;
      }
      while (obj = obj.offsetParent);

    otop += _popupwho.offsetHeight;

    if ((otop + divheight) > height)
      otop = otop - divheight - _popupwho.offsetHeight;
    }
  else
    if ((otop + divheight) > height)
      otop = _popupposy - divheight;
  if ((oleft + divwidth) > document.body.clientWidth)
     oleft = document.body.clientWidth - divwidth - 1;
     
  oleft += document.documentElement.scrollLeft;
  if (oleft < 0)
    oleft = 0;
  otop += document.documentElement.scrollTop;
  if (otop < 0)
    otop = 0;
  return [oleft, otop];
  }

function _showPopup()
  {
  _popuptextdiv.innerHTML = _popupstr;

  _popupdiv.style.visibility = "visible";
  _popupdiv.style.display = "block";
  _popupdiv.style.position = "absolute";
  _setDivWidth ();

  var pos = _getPopupScreenPos ();

  _popupdiv.style.top = pos[1] + "px";
  _popupdiv.style.left = pos[0] + "px";
  _setDivWidth ();
  }

function showPopup(event, str, popDiv, textDiv, minWidth)
  {
  if (minWidth)
    _popupwidth = minWidth;  
    
  if (popDiv)
    {
    _popupdiv = popDiv;
    if (textDiv)
      _popuptextdiv = textDiv;
    else
      _popuptextdiv = popDiv;
    }
  else
    {
    _popupdiv = document.createElement ("div");
    _popupdiv.style.visibility = "hidden";
    _popupdiv.style.display = "none";
    _popupdiv.style.padding = "1px";
    _popupdiv.style.fontFamily = "verdana";
    _popupdiv.style.fontSize = "8pt";
    _popupdiv.style.border = "1px solid black";
    document.body.appendChild (_popupdiv);
    _popuptextdiv = _popupdiv
    }

  if (!event)
    event = window.event;
  _popupposx = event.clientX;
  _popupposy = event.clientY;
  _popupstr = str;
  _popupwho = (typeof event.target != 'undefined') ? event.target : event.srcElement;

  _showPopup();
  }


function closeFloatPopup()
  {
  if (_popupdiv == null)
    return;
  _popupdiv.style.visibility = "hidden";
  _popupdiv.style.display = "none";
  }



