var nGetImageObj,nLoadImg,nTarget,nXPoint,nYPoint,nTitle,nLock,nScrollbars;

function AutoMagnifyPicture(xLoadImg,xTarget,xXPoint,xYPoint,xTitle,xLock)
{
  nLoadImg         = xLoadImg;
  nTarget          = xTarget;
  nXPoint          = xXPoint;
  nYPoint          = xYPoint;
  nTitle           = xTitle;
  nLock            = xLock;
  nGetImageObj     = new Image();
  nGetImageObj.src = (nLoadImg);
  CheckImageReady();
}

function CheckImageReady()
{
  if ((nGetImageObj.width != 0) && (nGetImageObj.height != 0))
    AutoMagnifyPicturePlay();
  else
    setTimeout("CheckImageReady()",100);
}

function AutoMagnifyPicturePlay()
{
  var nDisplayWindowWidth,nDisplayWindowHeight,nNewScreenZoneWidth,nNewScreenZoneHeight,nScrollbars,nWScrollOpen,nHScrollOpen,iCounter;
  nDisplayWindowWidth  = nGetImageObj.width  + 10;
  nDisplayWindowHeight = nGetImageObj.height + 29;
  nNewScreenZoneWidth  = screen.width  - 00;
  nNewScreenZoneHeight = screen.height - 50;
  nScrollbars          = false;
  nWScrollOpen         = true;
  nHScrollOpen         = true;

  for (iCounter = 1 ; iCounter <= 2 ; iCounter++)
  {
    // 圖寬大於螢幕寬
    if ((iCounter == 1) || ((nHScrollOpen) && (iCounter == 2)))
    {
      if (nDisplayWindowWidth > nNewScreenZoneWidth)
      {
        nXPoint             = 0;
        nDisplayWindowWidth = nNewScreenZoneWidth;
        nScrollbars         = true;
      }
      else
      {
        nWScrollOpen        = false;
        if ((nXPoint + nDisplayWindowWidth) >= nNewScreenZoneWidth)
        {
          nXPoint = nNewScreenZoneWidth - nDisplayWindowWidth;
        }
      }
    }

    // 圖高大於螢幕高
    if ((iCounter == 1) || ((nWScrollOpen) && (iCounter == 2)))
    {
      if (nDisplayWindowHeight > nNewScreenZoneHeight)
      {
        nYPoint              = 0;
        nDisplayWindowHeight = nNewScreenZoneHeight;
        nScrollbars          = true;
      }
      else
      {
        nHScrollOpen         = false;
        if ((nYPoint + nDisplayWindowHeight) >= nNewScreenZoneHeight)
        {
          nYPoint = nNewScreenZoneHeight - nDisplayWindowHeight;
        }
      }
    }
    
    if (iCounter == 1)
    {
      nDisplayWindowWidth  += ((nHScrollOpen)?13:0);
      nDisplayWindowHeight += ((nWScrollOpen)?13:0);
    }
  }
  
  window.open(("AutoMagnifyPicture.htm?nLoadImg=" + nLoadImg + "&nTitle=" + nTitle + "&nXPoint=" + nXPoint + "&nYPoint=" + nYPoint + "&nLock=" + nLock + "&nScrollbars=" + nScrollbars + "&nDisplayWindowWidth=" + nDisplayWindowWidth + "&nDisplayWindowHeight=" + nDisplayWindowHeight),nTarget,("left=" + nXPoint + ",top=" + nYPoint + ",width=" + nDisplayWindowWidth + ",height=" + nDisplayWindowHeight + ",scrollbars=" + (nScrollbars?"yes":"no")));
}