//
// This is used to change two images with a single mouse over
//
function imageChange(imageID, imageName, imageID2, imageName2)
{
   document.images[imageID].src = imageName;
   document.images[imageID2].src = imageName2;
}

//
// This function builds a top button on the main menu bar.
// You pass in a button number, the original image, the mouse over image, and where the link goes to
//
function buildTopButton(iCount, origButton, replButton, replEKG, linkLocation)
{
   document.write('<TD ROWSPAN="3"><A HREF="' + linkLocation + '"><IMG NAME="Btn' + iCount +'" BORDER="0" SRC="'+ origButton + '" onMouseOver="imageChange(\'ekgScreen\', \'' + replEKG + '\', \'Btn' + iCount +'\', \'' + replButton + '\')" onMouseOut="imageChange(\'ekgScreen\', \'' + menuDir + 'ekg.gif\', \'Btn' + iCount +'\', \''+ origButton + '\')"></A></TD>');
}


//
// Changes the document title
//
function changeTitle(pszTitle)
{
   document.title = pszTitle;
}


//
// Iterates through the topButtons array and builds the main menu bar
//
function buildTopMenu()
{
   document.bgColor="BLACK";
   document.fgColor="WHITE";
   document.writeln(' \
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR> \
<TD ROWSPAN="3"><IMG SRC="' + menuDir + 'scr-left.gif"></TD> \
<TD ROWSPAN="1"><IMG SRC="' + menuDir + 'scr-top.gif"></TD> \
<TD ROWSPAN="3"><IMG SRC="' + menuDir + 'scr-rght.gif"></TD> \
<TD ROWSPAN="3" WIDTH="25%" ALIGN="RIGHT" BACKGROUND="' + menuDir + 'chrome.gif">&nbsp;</TD>');

   for (var i = 0; i < topButtonCount; i++)
   {
      buildTopButton(i, topButtons[i][0], topButtons[i][1], topButtons[i][2], topButtons[i][3]);
   }

   document.writeln(' \
<TD ROWSPAN="3"><IMG SRC="' + menuDir + 'end.gif"></TD></TR> \
<TR><TD><A HREF="' + homeHTTP + '"><IMG BORDER="0" NAME="ekgScreen" SRC="' + menuDir + 'ekg.gif"></A></TD></TR> \
<TR><TD><IMG SRC="' + menuDir + 'scr-bot.gif"></TD></TR> \
</TD></TR></TABLE>');
}


function buildSideButtons(pszPageName)
{
   var i = 0;
   var pszDecor = "";
   var pszDecorEnd = "";
   
   for (i = 0; i < sideButtonCount; i++)
   {
      if (sideButtons[i][0].length == 0)
      {
         document.write('<TR><TD COLSPAN="3"><IMG SRC="' + menuDir + 'sepbar2.gif"></TD></TR>');
      }
      else
      {
         if (sideButtons[i][0] == pszPageName)
         {
            pszDecor = '<FONT COLOR="GRAY">';
            pszDecorEnd = '</FONT>';
         }
         else
         {
            pszDecor = "";
            pszDecorEnd = "";
         }
         
         if (sideButtons[i][1] == "NOLINK")
         {
            document.write('<TR HEIGHT="20"><TD COLSPAN="3" BACKGROUND="' + menuDir + 'menuarea.gif"><FONT COLOR="GREEN">&nbsp;&nbsp;&nbsp;&nbsp;' + pszDecor + sideButtons[i][0] + pszDecorEnd + '</FONT></TD></TR>');
         }
         else
         {
            document.write('<TR HEIGHT="20" onClick="window.location=\'' + sideButtons[i][1] + '\'"><TD COLSPAN="3" BACKGROUND="' + menuDir + 'menuarea.gif">&nbsp;&nbsp;&nbsp;&nbsp;<A Class="sideMenu" HREF="' + sideButtons[i][1] + '">' + pszDecor + sideButtons[i][0] + pszDecorEnd + '</A></TD></TR>');
         }
      }
   }
}


function getRandomImage(maxNum)
{
   return (Math.floor(Math.random() * maxNum))
}


function buildSideTextAndImageScreen(pszSection, myIndex)
{
// TODO
}


function buildSideImageScreen(pszSection, myIndex)
{
document.write(' \
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD VALIGN="TOP"> \
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"> \
<TR><TD COLSPAN="3"><IMG SRC="' + menuDir + 'top.gif"></TD></TR> \
<TR><TD><IMG SRC="' + menuDir + 'top-l1.gif"></TD><TD ROWSPAN="3" WIDTH="130" VALIGN="TOP">');

document.write('<IMG SRC="' + sideImages[myIndex][0] + '" WIDTH="130" HEIGHT="');
document.write(sideImages[myIndex][1]);
document.write('">');

document.write('</TD><TD><IMG SRC="' + menuDir + 'top-r1.gif"></TD></TR><TR HEIGHT="');
document.write(sideImages[myIndex][1] - 37);
document.write('">');

document.write('<TD BACKGROUND="' + menuDir + 'top-l2.gif">&nbsp;</TD><TD BACKGROUND="' + menuDir + 'top-r2.gif">&nbsp;</TD></TR> \
<TR><TD><IMG SRC="' + menuDir + 'top-l3.gif"></TD><TD><IMG SRC="' + menuDir + 'top-r3.gif"></TD></TR> \
<TR><TD COLSPAN="3"><IMG SRC="' + menuDir + 'sepbar.gif"></TD></TR>');
}


function buildSideTextScreen(pszSection)
{
document.write(' \
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD VALIGN="TOP"> \
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"> \
<TR><TD COLSPAN="3"><IMG SRC="' + menuDir + 'top.gif"></TD></TR> \
<TR><TD><IMG SRC="' + menuDir + 'top-l1.gif"></TD><TD ROWSPAN="3" WIDTH="130" VALIGN="TOP">');

document.write('<BR><FONT COLOR="WHITE" FACE="Arial, Helvetica, sans-serif">&nbsp; <B>' + pszSection + '</B></FONT> <BR>');

document.write('</TD><TD><IMG SRC="' + menuDir + 'top-r1.gif"></TD></TR><TR HEIGHT="25">');

document.write('<TD BACKGROUND="' + menuDir + 'top-l2.gif">&nbsp;</TD><TD BACKGROUND="' + menuDir + 'top-r2.gif">&nbsp;</TD></TR> \
<TR><TD><IMG SRC="' + menuDir + 'top-l3.gif"></TD><TD><IMG SRC="' + menuDir + 'top-r3.gif"></TD></TR> \
<TR><TD COLSPAN="3"><IMG SRC="' + menuDir + 'sepbar.gif"></TD></TR>');
}


function finishSide()
{
document.write(' \
<TR><TD COLSPAN="3" VALIGN="BOTTOM"><IMG SRC="' + menuDir + 'bottom.gif"></TD></TR> \
</TABLE></TD><TD WIDTH="10">&nbsp;</TD><TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, sans-serif">');
}

function buildTrailer(mailAddr, lastUpdate, copyrightYear)
{
   document.write('</FONT></TD></TR></TABLE>');
   document.write('<P><CENTER><FONT COLOR="WHITE" SIZE="-1">Last Updated: ' + lastUpdate +
'<BR>[mailto: <A CLASS="MAILME" HREF="mailto:' + mailAddr + '">' + mailAddr + '</A>]<BR>Copyright &copy; '
+ copyrightYear + ' - All Rights Reserved.<BR></FONT></CENTER>');
}


function buildNullSideMenu()
{
   document.write('<TABLE><TR><TD><FONT FACE="Arial, Helvetica, sans-serif">');
}


// Modes: 1 = Use the provided text
//        2 = Use the named image
//        3 = Use a random image in the array
//        4 = Use the text and the named image
//        5 = Use the text and a random image
function buildSideMenu(iMode, pszSection, pszGraphic, iGraphicHeight, pszPageName)
{
   var myIndex = 0;
   
   if (iMode == 1)
   {
      buildSideTextScreen(pszSection);
   }
   
   if (iMode == 2)
   {
      sideImages[0][0] = pszGraphic;
      sideImages[0][1] = iGraphicHeight;
      buildSideImageScreen(pszSection, myIndex);
   }
   
   if (iMode == 3)
   {
      myIndex = getRandomImage(sideImageCount);
      buildSideImageScreen(pszSection, myIndex);
   }

   if (iMode == 4)
   {
      sideImages[0][0] = pszGraphic;
      sideImages[0][1] = iGraphicHeight;
      buildSideTextAndImageScreen(pszSection, myIndex);
   }
   
   if (iMode == 5)
   {
      myIndex = getRandomImage(sideImageCount);
      buildSideTextAndImageScreen(pszSection, myIndex);
   }

   buildSideButtons(pszPageName);
   finishSide();
}
