//
// Copyright (c) 2006 BroadVision, Inc. All rights reserved.
//
// This software is copyrighted.  Under the copyright laws, this software
// may not be copied, in whole or in part, without prior written consent
// of BroadVision, Inc. or its assignees. This software is provided under
// the terms of a license between BroadVision and the recipient, and its
// use is subject to the terms of that license.
//
// This software may be protected by one or more U.S. and International
// patents. Certain applications of BroadVision One-To-One software are
// covered by U.S. patent 5,710,887.
//
// TRADEMARKS: BroadVision and the BroadVision logo are registered
// trademarks, and BroadVision One-To-One is a trademark of BroadVision,
// Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,
// MD5, and RC2 are trademarks of RSA Data Security, Inc. All other
// trademarks, service marks, and trade names belong to their respective
// owners. BroadVision, Inc. disclaims any proprietary interest in the
// marks and names of others.
//


//
// Popup - Represent a popup.
//
function Popup(name, anchor) {

  var id = g_popups.length;
  g_popups[id] = this;
  g_popups[name] = this;

  // internal UID
  this._id = id;

  this.name = name;
  this.autoHide = true;
  this.contents = "";

  this.offsetX = 0;
  this.offsetY = 25;

  // Define the "methods"
  this.moveTo = _popup__moveTo;
  this.show = _popup__show;
  this.setAutoHide = _popup__setAutoHide;
  this.isAutoHide = _popup__isAutoHide;
  this.refresh = _popup__refresh;
  this.setContents = _popup__setContents;


  // DIV elements that make up a block

  this.container = new Div(name);

  if (anchor != null) {
    var pt = getAnchorPoint(anchor);
    this.moveTo(pt.x, pt.y);
  }

  this.obj = "g_PopupObject" + id;

  eval(this.obj + " = this");

  return this;
}

//
// Popup::moveTo - move the popup to a (x, y)
//
// Parameters:
//
//   x -
//   y -
//
function _popup__moveTo(x, y) {
  this.container.moveTo(x + this.offsetX, y + this.offsetY);
}

//
// Popup::show - show/hide the popup
//
// Parameters:
//
//   bVisible - Visibility flag (boolean)
//                true -
//                false -
//
function _popup__show(bVisible) {
  this.container.show(bVisible);
}

//
//
//
function _popup__setAutoHide(autoHide) {
  this.autoHide = autoHide;
}

//
//
//
function _popup__isAutoHide() {
  return this.autoHide;
}

//
//
//
function _popup__refresh() {
////  this.container.refresh(this.contents);


////////*** function:  _div__refresh
  if (browser.dom) {
    this.container.element.innerHTML = this.contents;
  }
  else if (browser.ie4) { 
    this.container.element.innerHTML = this.contents;
  }
  else if (browser.ns4) { 
    this.container.element.document.open();
    this.container.element.document.writeln(this.contents);
    this.container.element.document.close();
  }

  var x = this.container.x;
  var y = this.container.y;
  var clientHeight = browserEx.getClientHeight();
  var height = this.container.element.offsetHeight;
  if (y + height - g_scrollTop > clientHeight) {
    y = clientHeight - height + g_scrollTop;
  }
  this.container.moveTo(x, y);

}

//
//
//
function _popup__setContents(contents) {
  this.contents = contents;
}

//
//
//
function popup_onmouseover(event) {
  if (c_disable) return;

  var element = (event.target) ? event.target : event.srcElement;
  var id = element.id;

  clearTimeout(g_cleanupPopupTimer);
  g_isPopupTimerRunning = false;

  event.cancelBubble = true;
}

//
//
//
function popup_cleanup() {
  if ("" != g_lastPopup) {
    g_popups[g_lastPopup].show(false);
    g_lastPopup = "";
  }

  g_isPopupTimerRunning = false;
  g_popupVisible = false;
}

//
//
//
function popup_mouseover_listener() {
  if (("" != g_lastPopup) && (!g_isPopupTimerRunning)) {
    g_cleanupPopupTimer = setTimeout("popup_cleanup()", c_cleanupPopupTimeout);
    g_isPopupTimerRunning = true;
  }
}

//
// Globals
//

  var g_popups = new Array;

  var g_lastPopup = "";
  var g_popupVisible = false;
  var g_cleanupPopupTimer = 0;
  var g_isPopupTimerRunning = false;

  var c_cleanupPopupTimeout = 500;
