// Javascript functions for SITV version 1.08 with support for 
// Netscape Navigator 6,7
var butTgt = new Array(2);
butTgt[0] = "";
butTgt[1] = "";
var curPart = "";
var scrlMax = 9999;
//****************************************************************
function ButInit (pPrev,pNext)
{
  butTgt[0] = pPrev;
  butTgt[1] = pNext;
//  var args = GetArgs ("but=");
//  if (args != "")
//  {
//     var i = args.indexOf(",");
//     if (i > 0)
//     {
//       butTgt[0] = args.substr(0,i);
//       butTgt[1] = args.substr(i+1);
//     }
//  }
  ButCheck (0);
  ButCheck (1);
}
//****************************************************************
function GetArgs (Key)
{
  var args = location.search;
  var ans = "";
  var i = -1;
  if (args.substr(0,1) == "?")
  {
    i = args.indexOf(Key);
  }
  if (i > 0)
  {
    args = args.substr(i + Key.length);
    i = args.indexOf(";");
    if (i > 0)
    {
      ans = args.substr(0,i);
    }
  }
  return ans;
}
//****************************************************************
function ButCheck (nBut)
{
  if ( (butTgt[nBut] == "") || (butTgt[nBut].charAt(0) == "@"))
  {
    butTgt[nBut] = "";
    var img = document.images["BUT" + nBut]
    var pSrc = img.src;
    var i = pSrc.lastIndexOf (".");
    pSrc = pSrc.substr(0,i) + "g" + pSrc.substr(i);
    img.src = pSrc;
    if (img.style)
    { //IE only
      img.style.cursor = "default";
    }
  }
  var i = butTgt[nBut].toUpperCase().indexOf(".HTM");
  if (i > 0)
  {
    butTgt[nBut] = butTgt[nBut].substr(0,i);
  }
}
//****************************************************************
function ButShow (nBut,bShow)
{
  if ((bShow == "1")&&(butTgt[nBut] != ""))
  {
    window.status = butTgt[nBut] + ".htm"; // 8-11-02 lower case ext 
  }
  else
  {
    window.status = "";
  }
  return true;
}
//****************************************************************
function ButLink (nBut)
{
  if (butTgt[nBut] != "")
  {
    parent.location.href = butTgt[nBut] + ".htm"; // 8-11-02 lower case ext
  }
  return false;
}
//****************************************************************
function scrlSet (xPos,yPos)
{
  var pImg = document.images["I0"];
  var x0, y0, cx, cy;
  if ( (location.search == "") && 
       (parent.F0 == self) && 
       (parent.location.search != ""))
  {
    location.search = parent.location.search;
  } 
//  alert ("top="+parent.location.search+" local="+location.search);
  var args = GetArgs ("scroll=");
  if (args != "")
  {
     var i = args.indexOf(",");
     if (i > 0)
     {
       xPos = args.substr(0,i);
       yPos = args.substr(i+1);
     }
  }
  if ( (xPos > 0) || (yPos > 0))
  {
     if (!window.innerWidth) // note(1)
     { // IE
        x0 = pImg.offsetLeft;
        y0 = pImg.offsetTop;
        cx = document.body.offsetWidth;
        cy = document.body.offsetHeight;
     }
     else
     { // NN
        x0 = pImg.x;
        y0 = pImg.y;
        cx = window.innerWidth;
        cy = window.innerHeight;
     }
     xPos = x0 + Math.floor( (xPos*pImg.width/1000) - (cx/2) );
     yPos = y0 + Math.floor( (yPos*pImg.height/1000) - (cy/2) );
     window.scrollBy (xPos, yPos);
  }
  else
  {
     args = GetArgs ("AbsScroll=");
     if (args != "")
     {
        i = args.indexOf(",");
        if (i > 0)
        {
           xPos = args.substr(0,i);
           yPos = args.substr(i+1);
        }
     }
     window.scrollTo (xPos, yPos);
  }
}
//****************************************************************
function LinkArgs(evt,elem,Mag,buts,top)
{
  var pTgt = GetHref(evt);
  if (Mag != 0)
  {
    Mag *= 10;
    var pImg = document.images["I"+elem];
    var Cx = pImg.width;
    var Cy = pImg.height;
    var xPos, yPos, xScrl, ySrcl, pTgt;
    if (evt.offsetX)
    {  // IE
      xPos = evt.offsetX;
      yPos = evt.offsetY;
      xScrl = document.body.scrollLeft;
      yScrl = document.body.scrollTop;
    }
    else
    {  // NN
      xPos = evt.pageX - pImg.x;
      yPos = evt.pageY - pImg.y;
      xScrl = window.pageXOffset;
      yScrl = window.pageYOffset;
    }
    xPos = Math.floor (xPos * Mag / Cx);
    yPos = Math.floor (yPos * Mag / Cy);
    pTgt += "?scroll=" + xPos + "," + yPos + ";";
    if ((xScrl > 0) || (yScrl > 0))
    {
      pTgt += "RtnScroll=" + xScrl + "," + yScrl + ";";
    }
//  alert (pTgt);
  }
//  if (buts == "1")
//  {
//    pTgt += "but=" + butTgt[0] + "," + butTgt[1] + ";";
//    alert (pTgt);
//  }
  window.status = pTgt;
  if (top != "0")
  {
    parent.location.href = pTgt;
  }
  else
  {
    location.href = pTgt;
  }
  return false;
}
//****************************************************************
function scrlRtn(evt,top)
{
  var pTgt = GetHref(evt);
  var args = GetArgs ("RtnScroll=");
  if (args != "")
  {
    pTgt += "?AbsScroll=" + args + ";";
  }
//  alert (pTgt);
  window.status = pTgt;
  if (top != "0")
  {
    parent.location.href = pTgt;
  }
  else
  {
    location.href = pTgt;
  }
  return false;
}
//****************************************************************
function GetHref(evt)
{
  var pTgt;
  if (evt.offsetX)
  {  // IE
    pTgt = document.activeElement.href;
  }
  else
  {  // NN
    pTgt = evt.target;
    if (pTgt.tagName && (pTgt.tagName == "IMG"))
    { // NN6
      pTgt = document.getElementById ("A"+pTgt.name);
    }
  }
  return pTgt;
}
//****************************************************************
function scrlTgt(evt,elem,Mag)
{
  Mag *= 10;
  var pImg = document.images["I"+elem];
  var Cx = pImg.width;
  var Cy = pImg.height;
  var xPos, yPos, pTgt;
  if (evt.offsetX)
  {  // IE
     xPos = evt.offsetX;
     yPos = evt.offsetY;
     pTgt = document.activeElement.href;
  }
  else
  {  // NN
     xPos = evt.pageX - pImg.x;
     yPos = evt.pageY - pImg.y;
     pTgt = evt.target;
  }
  xPos = Math.floor (xPos * Mag / Cx);
  yPos = Math.floor (yPos * Mag / Cy);
  pTgt = pTgt + "?scroll=" + xPos + "," + yPos + ";";
// alert (pTgt);
  window.status = pTgt;
  location.href = pTgt;
  return false;
}
//****************************************************************
function cWidth (cols)
{
  var cx=800;
  if (window.innerWidth)
  {
     cx=window.innerWidth;
  }
  else if (document.body.offsetWidth)
  {
    cx=document.body.offsetWidth;
  }
  return Math.floor(cx*cols/1000);
}
//****************************************************************
function GenMap (ArtN, ArtCx, Ix, left, top, right, bottom)
{
  var pImg = document.images["I"+ArtN];
  if (!pImg)
  { // NN
     pImg = document.Q0.document.images["I"+ArtN];
  }
  var Cx = pImg.width;
  left = Math.floor (left * Cx / ArtCx);
  right = Math.floor (right * Cx / ArtCx);
  top = Math.floor (top * Cx / ArtCx);
  bottom = Math.floor (bottom * Cx / ArtCx);
  var rect = ' coords="' + left + ',' + top + ',' + right + ',' + bottom + '"';
  var clk = ' onClick="return Compl(' + Ix + ')"';
  var ln = '<AREA href="IX'+Ix+'" id="IX'+Ix+'"' + rect + clk + '>';
  if (Ix < 4)
  {
//    alert (ln);
  }
  document.writeln(ln);
  eval("partLeft"+ArtN)[Ix] = left + 2;
  eval("partTop"+ArtN)[Ix] = top + 2;
  eval("partCx"+ArtN)[Ix] = right-left;
  eval("partCy"+ArtN)[Ix] = bottom-top;
}
//****************************************************************
function Compl (Ix)
{
  if (parent.COMPL)
  {
    var PrevIx = parent.curPart;
    if (Ix == "")
    { // loading/reloading component list
      if (PrevIx == "")
      { // first load - get first component list item
	PrevIx = parent.COMPL.curPart;
        parent.curPart = PrevIx;
      }
      Ix = PrevIx;
      if (document.all)
      { // IE
        parent.COMPL.window.scrollTo (0,9999);
        scrlMax = parent.COMPL.document.body.scrollTop;
      }
    }
    if (document.all)
    { // IE
      ComplIE (Ix, PrevIx);
    }
    else
    { // NN
      ComplNN (Ix, PrevIx);
    }
    parent.curPart = Ix;  // save current position in FrameSet
    if (parent.bPartsLoaded != 1)
    {
//      alert ("Parts not loaded");
      window.setTimeout ("PartsDelay()", 500);
    }
    else
    {
       Parts (Ix);
    }
  }
  return false;
}
//****************************************************************
function PartsDelay ()
{
  Parts (parent.curPart);
}
//****************************************************************
function ComplIE (Ix, PrevIx)
{
  var pDoc = parent.COMPL.document;
  if (PrevIx != "")
  {
    pDoc.all["IX"+PrevIx].style.backgroundColor = "";
  }
  var link = pDoc.all["IX"+Ix];
  link.style.backgroundColor = "red";
  var scrl = pDoc.body.scrollTop;
  var cy = pDoc.body.offsetHeight;
  link.scrollIntoView (1);
  var y = pDoc.body.scrollTop;
//  alert ("y="+y+",scrl="+scrl+",cy="+cy+",scrlMax="+parent.COMPL.scrlMax);
  if ( (y < scrl) || (y > (scrl+cy-20)) || (y >= parent.COMPL.scrlMax) )
  {
    scrl = y;
  }
  parent.COMPL.window.scrollTo (0,scrl);
}
//****************************************************************
function ComplNN (Ix, PrevIx)
{
  var link, y;
  if (PrevIx != "")
  {
    link = eval ("parent.COMPL.document.IX"+PrevIx);
    if (!link)
    { // NN6
      link = parent.COMPL.document.getElementById("IX"+PrevIx);
      link.style.backgroundColor = "";
    }
    else
    {
      link.bgColor = "white";
    }
  }
  link = eval ("parent.COMPL.document.IX"+Ix);
  if (!link)
  { // NN6
    link = parent.COMPL.document.getElementById("IX"+Ix);
    link.style.backgroundColor = "red";
    y = link.offsetTop;
  }
  else
  {
    link.bgColor = "red";
    y = link.pageY;
  }
  var scrl = parent.COMPL.window.pageYOffset;
  var cy = parent.COMPL.window.innerHeight;
//  alert ("link="+link+",y="+y+",scrl="+scrl+",cy="+cy);
  if ( (y < scrl) || (y > (scrl+cy)) )
  {
    parent.COMPL.window.scrollTo (0,y-20);
  }
}
//****************************************************************
function Parts (Ix)
{
  var i = 0;
  var img;
  var x, y, Cx, Cy;
  var GotIx = 0;
  var obj ;
  if (parent.PARTS)
  {
    while (1)
    { // scan all artworks
      img = parent.PARTS.document.images["I"+i];
      if (!img)
      {
        break;
      }
      x = eval("parent.PARTS.partLeft"+i)[Ix];
      y = eval("parent.PARTS.partTop"+i)[Ix];
      Cx = eval("parent.PARTS.partCx"+i)[Ix];
      Cy = eval("parent.PARTS.partCy"+i)[Ix];
      if (parent.PARTS.document.all)
      { // IE
        GotIx = PartsRectIE(i,img,x,y,Cx,Cy,GotIx);
      }
      else
      { // NN
//      alert ("rect "+i+" - "+Ix);
        GotIx = PartsRectNN(i,img,x,y,Cx,Cy,GotIx);
      }
      i++;
    }
  }
  return false;
}
//****************************************************************
function PartsRectIE (ArtN,img,x,y,Cx,Cy,GotIx)
{
  var rect = eval("parent.PARTS.document.all.P"+ArtN);
  if (rect)
  {
    if ( !isNaN(x) )
    {
      var dx = img.offsetLeft;
      var dy = img.offsetTop;
//    alert("x="+x+",y="+y+",Cx="+Cx+",Cy="+Cy+",dx="+dx+",dy="+dy);
      rect.style.pixelLeft = x+dx;
      rect.style.pixelTop = y+dy;
      rect.style.clip = "rect(0 "+Cx+" "+Cy+ " 0)";
      if (!GotIx) 
      {
        scrlParts (x+dx, x+dx+Cx, y+dy, y+dy+Cy);
        GotIx = 1;
      }
    }
    else
    {
      rect.style.clip = "rect(0 0 0 0)";
    }
  }
  return GotIx;
}
//****************************************************************
function PartsRectNN (ArtN,img,x,y,Cx,Cy,GotIx)
{
  var layer = eval("parent.PARTS.document.P"+ArtN);
  if (layer)
  { // NN 4
    if ( !isNaN(x) )
    {
      var dx = img.x;
      var dy = img.y;
//    alert("x="+x+",y="+y+",Cx="+Cx+",Cy="+Cy+",dx="+dx+",dy="+dy);
      layer.moveTo (x+dx,y+dy);
      layer.resizeTo (Cx+1,Cy+1);
      if (!GotIx) 
      {
        scrlParts (x+dx, x+dx+Cx, y+dy, y+dy+Cy);
        GotIx = 1;
      }
    }
    else
    {
      layer.resizeTo (0,0);
    }
  }
  else
  { // NN 6
    var rect = parent.PARTS.document.getElementById("P"+ArtN);
    if (rect)
    {
      if ( !isNaN(x) )
      {
        var dx = img.offsetLeft;
        var dy = img.offsetTop;
//      alert("x="+x+",y="+y+",Cx="+Cx+",Cy="+Cy+",dx="+dx+",dy="+dy);
        rect.style.left = (x+dx)+"px";
        rect.style.top = (y+dy)+"px";
        rect.style.clip = "rect(0 "+Cx+" "+Cy+ " 0)";
        if (!GotIx) 
        {
          scrlParts (x+dx, x+dx+Cx, y+dy, y+dy+Cy);
          GotIx = 1;
        }
      }
      else
      {
        rect.style.clip = "rect(0 0 0 0)";
      }
    }
  }
  return GotIx;
}
//****************************************************************
function scrlParts (rLeft,rRight,rTop,rBot)
{
  rLeft -= 20;
  if (rLeft < 0)
  {
    rLeft = 0;
  }
  rRight += 30;
  rTop -= 20;
  if (rTop < 0)
  {
    rTop = 0;
  }
  rBot += 30;
//alert ("Rect="+rLeft+","+rRight+","+rTop+","+rBot);
  var wLeft = 0, wRight = 0, wTop = 0, wBot = 0;
  var pWin = parent.PARTS.window;
  var pDoc = parent.PARTS.document.body;
  if ( pWin && ((rRight > rLeft) || (rBot > rTop)))
  {
    if (pWin.innerWidth)
    { // NN
      wLeft = pWin.pageXOffset;
      wRight = wLeft + pWin.innerWidth;
      wTop = pWin.pageYOffset;
      wBot = wTop + pWin.innerHeight;
    }
    else if (pDoc)
    { // IE
      wLeft = pDoc.scrollLeft;
      wRight = wLeft + pDoc.offsetWidth;
      wTop = pDoc.scrollTop;
      wBot = wTop + pDoc.offsetHeight;
    }
//  alert ("VP="+wLeft+","+wRight+","+wTop+","+wBot);
    var xScrl = wLeft, yScrl = wTop;
    if (rLeft < wLeft)
    {
      xScrl = rLeft;
    }
    else if (rRight > wRight)
    {
      xScrl = rRight - (wRight - wLeft);   
    }
    if (rTop < wTop)
    {
      yScrl = rTop;
    }
    else if (rBot > wBot)
    {
      yScrl = rBot - (wBot - wTop);   
    }
    pWin.scrollTo (xScrl, yScrl);
  }
}
//****************************************************************
function Reload ()
{
  top.bPartsLoaded = 0;
  top.PARTS.location.href = top.PARTS.location.href;
  top.COMPL.location.href = top.COMPL.location.href;
}
//****************************************************************
function IxZoom ()
{
  parent.bZoom ^= 1; // invert flag
  Reload();
  return false;
}
//****************************************************************
function ZmWidth (nwidth,zwidth)
{
  var width = nwidth; // normal width
  if (window.innerWidth && (nwidth.indexOf("%") > 0))
  { // NN6 increases window width later if no scroll. Note(2)
     width = window.innerWidth * parseInt(nwidth) / 100;
     width -= 30; 
  }
  if (parent.bZoom == "1") // Note(1)
  {
     width = zwidth;  // zoomed width
  }
//  alert ( "width= " + width);
  return width;
}
//****************************************************************