//
// echo "王 ";
//
// Event:
//   IE: event
//   NS > 4.0: window.event
//   NS 3: no event
//
var brOK=false;
var isIE=false;
var isNS=false;
var isOPERA=false;
var ieOK=false;
var nsOK=false;

var appVer = parseInt(navigator.appVersion.substring(0,1));
var appName = navigator.appName;
var userAgent = navigator.userAgent;

if(appName.indexOf("Internet Explorer") != -1)
{
  isIE=true;
  if(appVer >= 4)
  {
    brOK = navigator.javaEnabled();
    ieOK=true;
  }
}

if(userAgent.indexOf("Opera") != -1)
{
  isOPERA=true;
  if(appVer >= 4)
  {
    brOK = navigator.javaEnabled();
    ieOK=true;
  }
}

if(appName.indexOf("Netscape") !=-1 )
{
  isNS=true;
  if(appVer >= 4)
  {
    brOK = navigator.javaEnabled();
    nsOK=true;
  }
}

if(brOK)
{
  if(isNS)
  {
    event = window.event;
  }
}
//NS3 when using event as argument to handler.
else
{
  event = null;
}

var winPop = null, winInfo = null;
/*
 * locationType: 0: top left corner at the mouse.
 * 3: right botton corner at the mouse.
 */
function popupInfoLocation(evt, url, timeout, locationType)
{
  var x, y, width, height;
  width = 220;
  height = 300;

  if(brOK)
  {
    if(isIE)
    {
      if(evt == null)
      {
        evt = window.event;
      }
    }
    if(evt)
    {
      x = evt.screenX;
      y = evt.screenY;
      if(locationType == 3)
      {
        x -= width;
        y -= height;
      }
    }
    else
    {
      x = screen.width - width - 10;
      y = 1;
    }
    x = "left=" + x + ",top=" + y + ",";
  }
  else
  {
    x = "";
  }
  x += "width=" + width + ",height=" + height;
  x += ",scrollbars=yes";
  winInfo = window.open(url, "winPopInfo", x);
  if(timeout != null)
  {
    setTimeout("winInfoClose()", timeout);
  }
  return true;
}

function popupInfo(evt, url, timeout)
{
  return popupInfoLocation(evt, url, timeout, 0);
}

function popupInfoRightBottom(evt, url, timeout)
{
  return popupInfoLocation(evt, url, timeout, 3);
}

function winInfoClose()
{
  if(winInfo != null)
  {
    if(! winInfo.closed)
    {
      winInfo.close();
      winInfo = null;
    }
  }
  return;
}

function popdownInfo()
{
  return winInfoClose();
}

function popupSlideUrl(evt, url)
{
  var x, y, width, height;
  width = 150;
  height = 180;
  if(brOK)
  {
    if(isIE)
    {
      if(evt == null)
      {
        evt = window.event;
      }
    }
    if(evt)
    {
      x = evt.screenX;
      y = evt.screenY;
    }
    else
    {
      x = screen.width - width - 50;
      y = 1;
    }
    x = "left=" + x + ",top=" + y + ",";
  }
  else
  {
    x = "";
  }
  x += "width=" + width + ",height=" + height;
  winPop = window.open(url, "winPopSlide", x);
  return true;
}
function popdownSlide()
{
  if(winPop != null)
  {
    if(! winPop.closed)
    {
      winPop.close();
    }
  }
  return 1;
}
function popupSlide(evt, url)
{
  return popupSlideUrl(evt, url);
}
function popupSlideCn(evt)
{
  return popupSlideUrl(evt, "popslcn.htm");
}
function popupSlideEn(evt)
{
  return popupSlideUrl(evt, "popslen.htm");
}
function popupSlideFr(evt)
{
  return popupSlideUrl(evt, "popslfr.htm");
}

// iPos: 0=mouse, 1=top-left, 2=top-right, 3=bottom-right, 4=bottom-left.
function msgBox(evt, strMsg, strTitle, strClose, iPos, width0, height0)
{
  var x, y, width, height;
  var w, d, winnam;
//
  if(width0 == null)
  {
    width = 250;
  }
  else
  {
    width = width0;
  }
//
  if(height0 == null)
  {
    height = 350;
  }
  else
  {
    height = height0;
  }
// 1=top-left:
  if(iPos == 1)
  {
    ;
  }
// 2=top-right:
  else if(iPos == 2)
  {
    x = screen.width - width - 10;
    x = "left=" + x + ",";
  }
//  3=bottom-right:
  else if(iPos == 3)
  {
    x = screen.width - width - 10;
    y = screen.height - height - 10;
    x = "left=" + x + ",top=" + y + ",";
  }
//  4=bottom-left:
  else if(iPos == 4)
  {
    y = screen.height - height - 10;
    x = "top=" + y + ",";
  }
// mouse:
  else
  {
    if(brOK)
    {
      // NS:
      if(isNS)
      {
      }
      // IE:
      else
      {
        evt = window.event;
      }
      //
      if(evt == null)
      {
        x = screen.width - width - 10;
        y = 0;
      }
      else
      {
        x = evt.screenX;
        y = evt.screenY;
      }
      //
      if(x + width > screen.width)
      {
        x = screen.width - width - 10;
      }
      //
      y -= height;
      y = y < 0 ? 0 : y;
      //
      x = "left=" + x + ",top=" + y + ",";
    }
    else
    {
      x = "";
    }
  }
//
  x += "width=" + width + ",height=" + height;
  x += ",scrollbars=yes";
  winnam = "msgBox";
  w = window.open("", winnam, x);
//
  if(strTitle == null)
  {
    strTitle = "Message Box";
  }
//
//w.resizeTo(800, 600);
//
// this does not work under Opera,
// as it does not returns the document object:
//
// d = w.document.open("text/html");
//
  w.document.open("text/html");
//
// so use this:
//
  d = w.document;
//
  if(strClose == null)
  {
    strClose = "Close";
  }
//
  d.write("<html>\n\
<head>\n\
<title>" + strTitle + "</title>\n\
<style type=\"text/css\">\n\
<!--\n\
body {background-color: #ffff00; font-size: 10pt}\n\
form {text-align: center}\n\
h1 {color: red; text-align: center}\n\
input {font-size: 8pt}\n\
.button {\n\
  border-right: #ffff99 1px solid;\n\
  border-top: #ffff99 1px solid;\n\
  border-left: #ff66dd 1px solid;\n\
  border-bottom: #ff66dd 1px solid;\n\
  background-color: #ff00cc;\n\
  color: #ffff00;\n\
  font-weight: bold;\n\
  font-size: 8pt;\n\
  cursor: hand;\n\
}\n\
-->\n\
</style>\n\
</head>\n\
<body>\n\
<h1>" + strTitle + "</h1>\n\
" + strMsg + "\n\
<form name=\"frmNavigate\">\n\
<input type=\"button\" name=\"cmdClose\" class=\"button\" value=\"" + strClose + "\" onclick=\"window.close()\" onmouseover=\"this.style.backgroundColor='#ff0000'\" onmouseout=\"this.style.backgroundColor=''\" />\n\
</form>\n\
</body>\n\
</html>\n\
");
//
  d.close();
//
  w.focus();
//
  if(d.frmNavigate.cmdClose)
  {
    d.frmNavigate.cmdClose.focus();
  }
//
  return w;
}

function msgBoxTopRight(evt, strMsg, strTitle, strClose)
{
  return msgBox(evt, strMsg, strTitle, strClose, 2);
}

 function msgBoxBgcolor(strMsg, strFore)
{
  var w, d, winnam, strBgcolor;
//
  strBgcolor = strMsg;
  winnam = "msgBox";
//alert("Window name: " + winnam);
  w = window.open("", winnam, "width=600,height=500");
//  w.resizeTo(600, 500);
  w.document.open("text/html");
  d = w.document;
  d.write("<html>\n\
<head>\n\
<title>Message Box</title>\n\
<style type=\"text/css\">\n\
<!--\n\
H1 {color: red; text-align: center}\n\
input {font-size: 8pt}\n\
.button {\n\
  border-right: #ffff99 1px solid;\n\
  border-top: #ffff99 1px solid;\n\
  border-left: #ff66dd 1px solid;\n\
  border-bottom: #ff66dd 1px solid;\n\
  background-color: #ff00cc;\n\
  color: #ffff00;\n\
  font-weight: bold;\n\
  font-size: 8pt;\n\
  cursor: hand;\n\
}\n\
-->\n\
</style>\n\
</head>\n\
<body text=\"" + strFore + "\" bgcolor=\"" + strBgcolor + "\">\n\
<h1 style=\"color: " + strFore + "\">Message Box</h1>\n\
" + strMsg + "\n\
<form name=\"frmNavigate\">\n\
<input type=\"button\" name=\"cmdBack\" class=\"button\" value=\"Back\" onclick=\"history.go(-1)\" onmouseover=\"this.style.backgroundColor='#ff0000'\" onmouseout=\"this.style.backgroundColor=''\" />\n\
<input type=\"button\" name=\"cmdClose\" class=\"button\" value=\"Close\" onclick=\"window.close()\" onmouseover=\"this.style.backgroundColor='#ff0000'\" onmouseout=\"this.style.backgroundColor=''\" />\n\
<input type=\"button\" name=\"cmdBlur\" class=\"button\" value=\"Blur\" onclick=\"window.blur()\" onmouseover=\"this.style.backgroundColor='#ff0000'\" onmouseout=\"this.style.backgroundColor=''\" />\n\
</form>\n\
</body>\n\
</html>\n\
");
//
  d.close();
  w.focus();
  return w;
}

//useless:
if(nsOK)
{
//document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
//document.onmouseover = routeEvent;
//document.onmouseout = routeEvent;
}