//-----------------------------------------------------------------------------
// FormatPlant.js
//   Format the plant information text in the PlantFrame
//   Called by /Scripts/Genus species.htm. 
//   Copyright 2003-2008 Gabi and Cliff McLean
//-----------------------------------------------------------------------------

// Select the appropriate style sheet for the sceen resolution.
//   var CSSNumber = parent.parent.frames["DataFrame"].CSSNumber;
//    var  CSSNumber            = top.CSSNumber;
//var CSSNumber = 1;
   document.write(
                  '<LINK REL="StyleSheet" HREF="SiteStyle1.css" TYPE="text/css">'
                 +'<LINK REL="StyleSheet" HREF="../NAHWebSite.css" TYPE="text/css">'
                 );
//alert("CSSNumber is " + CSSNumber);
// Disable the IE6 Image Toolbar.
   document.write('<META HTTP-EQUIV="imagetoolbar" CONTENT="no">');

// Set font colors for mouseover.
//   var  DescInfoTermColor = top.DescInfoTermColor;
//   var  DescInfoTermOver  = top.DescInfoTermOver;
//   var  DescLineColor     = top.DescLineColor;
//   var  DescLineColorM    = top.DescLineColorM;
//   var  DescLineColorH    = top.DescLineColorH;
//   var  DescLineOver      = top.DescLineOver;
//   var  PhotoRatio        = top.PhotoRatio;

   var  LocalIndex, LocalMax;
   var  PlantRow;
   var  PlantRowArray = new Array();
   var  VarName, AddlName;
   var  VarSpace = " ";
   var  DescLine1 = DescLine2 = DescLine3 = DescLine4 = DescLine5 = ""; 
   var  DescLine1Q = DescLine2Q = DescLine3Q = DescLine4Q = DescLine5Q = "";
   var  BotNameQ = "";
   var  Icons = new Array();
//   top.GoingToBigPhoto = 0;
   var IconNumber;
   var ThumbNum = "";
   var FirstPhoto = "";

// Text for mouseover tool-tips on icons
var IconTextArray = new Array(
                              "Stems","Stems and Leaves",
                              "Leaves","Leaves", 
                              "Needles","Trunk and Needles", 
                              "Flowers","Flowers",
                              "Fruits","Fruits",
                              "Cones","Cones",
                              "Ferns","Ferns", 
                              "Habitat","Habitat",
                              "Range","Range with Map",  
                              "Related","Related and Similar Plants",  
                              "Garden","In the Garden",
                              "Birds","For Birds",
                              "Butterflies","For Butterflies",
                              "Fire","Fire Response",
                              "Names","About the Names",
                              "NewNames","About the Names - There is a new name."
                             );

//   var PhotoFolder = top.PhotoFolder;
//   var ScriptFolder = top.ScriptFolder;
//   var ButtonFolder = top.ButtonFolder;
//   var SoundFolder = top.SoundFolder;
   var SoundFolder = "Sounds/";
//   var CanPronounce = top.CanPronounce;

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

////////////////Code for pronounciation of botanical names./////////////////
//Object to handle pronouncing botanical names.
   if (document.getElementById && CanPronounce)
     {
      document.write('<object id="Pronouncer" height="0%" width="0%" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">');
      document.write('<param name="AutoStart" value="1" /><param name="FileName"  /></object>');
     }
// Function to pronounce a word 
function ClickPronounce(File)
         {
          if (document.getElementById)
            {
             if (CanPronounce)
               {
                document.getElementById("Pronouncer").FileName = SoundFolder + File + ".wav";
               }
             else
               {
                OpenSayitWin(File);
               }
            }
         }

//////////////End Code for pronounciation of botanical names./////////////////

// functions to format headings and prep to display photos
function StartDisplay()
         {

          // Set the space depending on the presence of a variable name.
          if (typeof AddlName == "undefined") AddlName = "";
          if (typeof VarName == "undefined") VarName = "";
          if (VarName == "") VarSpace = "";
          
          // Generate document body. 
          document.write('<body onUnload="CloseDependents()" onLoad="CheckMoreInfo()" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');        

document.write('<div id="NAHContainer">');

  POTMTitleBar("Plant of the Month", POTMMonth,"Quercus_durata_5112w.jpg","Erysimum_capitatum_2w.jpg");
  NAHIndexBar("");
  POTMInfoBarPlant();

document.write('<div class="MainSpaceDiv">');

//   var  QuizMode = top.QuizMode;
//   var  QuizMode = "1";  //for testing from ComName list
          
          // Format plant names and summary information.
          if (!QuizMode) //for normal (non-quiz) mode
          {
           document.write(
                          "<div class='PlantIdDiv'><span class='ComNameClass'>"
                          + DisplayName
                          + "</span><br /><span class='BotNameClass'>&nbsp;("
                          + BotName
                          + VarSpace
                          + VarName
                          + ")</span>"
                         ); 
           if (document.getElementById) document.write(
                          "&nbsp;&nbsp;<a onClick='ClickPronounce(\"" + FileName + "\")' >"
                          + "<img src='" + ButtonFolder + "Pronounce.gif' align='middle' "
                          + "onMouseOver='this.src=\"" + ButtonFolder + "PronounceOver.gif\"' "
                          + "onMouseOut='this.src=\"" + ButtonFolder + "Pronounce.gif\"' ></a>"
                         );
           document.write(
                          "<br /><span class='FamilyClass'>"
                          + AddlName
                          + ComFamily 
                          + " Family </span><br /><span class='BotFamilyClass'><i>&nbsp;(" 
                          + BotFamily 
                          + ")</i></span>"
                          );
           if (document.getElementById) document.write(
                          "&nbsp;&nbsp;<a onClick='ClickPronounce(\"" + BotFamily + "\")' >"
                          + "<img src='" + ButtonFolder + "Pronounce.gif' align='middle' "
                          + "onMouseOver='this.src=\"" + ButtonFolder + "PronounceOver.gif\"' "
                          + "onMouseOut='this.src=\"" + ButtonFolder + "Pronounce.gif\"' ></a>"
                          );
           document.write(
                          "<br /></div>"
                         );

           document.write(
                          "<div class='PlantTextDiv' ><SPAN class='PlantTextClass'>"
                          + DescLine1
                          + "<br />" 
                          + DescLine2
                          + "<br />"
                          + DescLine3
                          + "<br />"
                          + DescLine4
                          + "<br />"
                          + DescLine5
                          + "<br />");
           document.write("</span></div>");  
           document.write(
                          "<div class='PlantIconDiv' >");
           GenIcons(); 
           document.write("<br /></div>");     
          }
          //end normal (non-quiz) mode
           
          //for quiz mode
          else
          {	
           // Set up to use Quiz Mode descriptions, if provided
           if (DescLine1Q != "") DescLine1 = DescLine1Q;
           if (DescLine2Q != "") DescLine2 = DescLine2Q;
           if (DescLine3Q != "") DescLine3 = DescLine3Q;
           if (DescLine4Q != "") DescLine4 = DescLine4Q;
           if (DescLine5Q != "") DescLine5 = DescLine5Q;

           // Allow for Quiz Mode botanical name (e.g., Opuntia Xvaseyi)
           if (BotNameQ != "") BotName = BotNameQ;

          // Format page without names for quiz mode.
           document.write(
                          "<div class='PlantIdDiv'>"
                          + "<a href='javascript:void(0)' class='ComNameClassQuiz' title=\"Click to see the common name.\" "
                          + "onClick=\"this.className='ComNameClass';this.innerHTML='" + DisplayName + "';\"> "
                          + "Common Name"
                          + "</a><br />"
                          + "<a  href='javascript:void(0)' class='BotNameClassQuiz' title=\"Click to see the botanical name.\" "
                          + "onClick=\"this.className='BotNameClass';this.innerHTML='&nbsp;(" + BotName + VarSpace + VarName + ") ';\"> "
                          + "<i>&nbsp;(Botanical Name)</i></a><br />"
                          + "<a href='javascript:void(0)' class='FamilyClassQuiz' title=\"Click to see the common family name.\" "
                          + "onClick=\"this.className='FamilyClass';this.innerHTML='" + AddlName + ComFamily + " Family ';\"> "
                          + "Common Family </a><br />"
                          + "<a  href='javascript:void(0)' class='BotFamilyClassQuiz' title=\"Click to see the botanical family name.\" " 
                          + "onClick=\"this.className='BotFamilyClass';this.innerHTML='<i>&nbsp;(" + BotFamily + ")</i>';\"> "
                          + "<i>&nbsp;(Botanical Family)</i></a><br /></div>"
                         );
           
           document.write(
                          "<div class='PlantTextDiv' >"
                          + "<SPAN id='PlantTextSpan' "
                          + "title=\"Click to see the plant information.\" "
                          + "onClick=\"this.className='PlantTextClass';document.getElementById('PlantTextSpan').innerHTML='';"
                          + "document.getElementById('PlantTextSpan').innerHTML='"
                          + DescLine1
                          + "<br />" 
                          + DescLine2
                          + "<br />"
                          + DescLine3
                          + "<br />"
                          + DescLine4
                          + "<br />"
                          + DescLine5
                          + "';\">"
                          + "<a  href='javascript:void(0)' class='PlantTextClassQuiz'>Plant Information</a><br />"
                          + "</span><br /></div>"
                         );
          }
          //end quiz mode
          
          document.write('<div class="PlantPhotoDiv">');
         }
// end StartDisplay()

// function to display a photo
// Use ThumbNum if not empty, else use PhotoNum.
function DisplayPhoto()
         {
          DisplayWidth = PhotoWidth * PhotoRatio;
          DisplayHeight = PhotoHeight * PhotoRatio;
          if (ThumbNum == "") ThumbNum = PhotoNum;
//          document.write(
//                         '<a href="'
//                         + FileName
//                         + '_'
//                         + PhotoNum
//                         + '.htm" target="PlantFrame" onClick="GoingToBigPhoto=1;"><img src="'
//                         + PhotoFolder
//                         + FileName
//                         + '_'
//                         + ThumbNum
//                         + '.jpg" width='
//                         + DisplayWidth
//                         + ' height='
//                         + DisplayHeight
//                         + ' align="'
//                         + Align
//                         + '"  class="PhotoClass" title="'
//                         + PhotoSubject
//                         + '"/></a>'
//                        );
          document.write(
                         '<a href="'
                         + FileName
                         + '_'
                         + PhotoNum
                         + '.htm" onClick="GoingToBigPhoto=1;"><img src="'
                         + PhotoFolder
                         + FileName
                         + '_'
                         + ThumbNum
                         + '.jpg" width='
                         + DisplayWidth
                         + ' height='
                         + DisplayHeight
                         + ' align="'
                         + Align
                         + '"  class="PhotoClass" title="'
                         + PhotoSubject
                         + '"/></a>'
                        );
          ThumbNum = "";
         }

// Function to generate a variable sized horizontal spacer
function HSpace(pixels)
         {
          // Adjust for two added pixels of vspace/hspace border around the gif.
          pixels = pixels - 2;
          if (pixels < 0) pixels = 0;
          document.write('<img src='
                         + ScriptFolder
                         + 'Spacer.gif" height="1" width="'
                         + pixels
                         + '"vspace="1" hspace="1">'
                        );
         }

// Function to generate a variable sized vertical spacer
function VSpace(pixels)
         {
          // Adjust for two added pixels of vspace/hspace border around the gif.
          pixels = pixels - 2;
          if (pixels < 0) pixels = 0;
          document.write('<br /><img src="'
                         + ScriptFolder
                         + 'Spacer.gif" width="1" height="'
                         + pixels
                         + '"hspace="1" vspace="1"><br />'
                        );
         }

// Function to begin a new row of photos
function NewLine()
         {
          document.write('<br clear="all" />');
         }

// Function to generate icons and links to MoreInfo
function GenIcons()
         {
          if (CSSNumber == 2) IconNumber = 3; // Use same icons for CSS 2 and 3
          else IconNumber = CSSNumber;
          document.write(
                         "<a onClick='ClickMoreInfo(\"Info\")'>"
                         + "<img name='InfoIcon' title='Detailed information about the plant' class='GenIconClass' "
                         + "src='" + ButtonFolder + "InfoIcon" + IconNumber + ".gif' align='top' "
                         + "onMouseOver='InfoIcon.src=\"" + ButtonFolder + "InfoIcon" + IconNumber + "Over.gif\"'"
                         + "onMouseOut='InfoIcon.src=\"" + ButtonFolder + "InfoIcon" + IconNumber + ".gif\"'"
                         + ">"
                         + "</a>"
                              );
          document.write(
                         "<img name='SpacerIcon' class='GenIconClass' "
                         + "src='" + ButtonFolder + "SpacerIcon" + IconNumber + ".gif' align='top' "
                         + ">"
                        );  
          if (Icons.length > 0)
            {
             for(i=0; i<Icons.length; i++)
               {     
                for (j=0; j<IconTextArray.length; j=j+2)
                  {
                   if (IconTextArray[j] == Icons[i])  IconText = IconTextArray[j+1];
                  }
                document.write(
                               "<a onClick='ClickMoreInfo(\"" + Icons[i] + "\")'>"
                               + "<img name='" + Icons[i] + "Icon' class='GenIconClass' "
                               + "src='" + ButtonFolder + Icons[i] + "Icon" + IconNumber + ".gif' align='top' "
                               + "title='" + IconText + "' " 
                               + "onMouseOver='" + Icons[i] + "Icon.src=\"" + ButtonFolder + Icons[i] + "Icon" + IconNumber + "Over.gif\"'"
                               + "onMouseOut='" + Icons[i] + "Icon.src=\"" + ButtonFolder + Icons[i] + "Icon" + IconNumber + ".gif\"'"
                               + ">"
                               + "</a>"
                              );  
               }
            }

// icon to zoom to 1st photo
//          document.write('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
          document.write(
                         "<img name='SpacerIcon' class='GenIconClass' "
                         + "src='" + ButtonFolder + "SpacerIcon" + IconNumber + ".gif' align='top' "
                         + ">"
                        );
          if (FirstPhoto != "")
            {
             document.write(
                            '<a href="'
                            + FileName
                            + '_'
                            + FirstPhoto
                            + '.htm" onClick="GoingToBigPhoto=1;">'
                           );
             document.write( 
                            "<img name='ZoomIcon' class='PlantIconClass' "
                            + "src='" + ButtonFolder + "ZoomIcon" + IconNumber + ".gif' align='top' "
                            + "title='Enlarge 1st photo (Go to Photo Page)' " 
                            + "onMouseOver='ZoomIcon.src=\"" + ButtonFolder + "ZoomIcon" + IconNumber + "Over.gif\"'"
                            + "onMouseOut='ZoomIcon.src=\"" + ButtonFolder + "ZoomIcon" + IconNumber + ".gif\"'"
                            + ">"
                            + "</a>or "
                           ); 
            }
          document.write("click on any photo.");

          return;
         }

// Function to close out plant page display
function FinishDisplay()
         {
          document.write('</div>');
document.write('</div></div>'); /* MainSpaceDiv and NAHContainer */
         }

// Function to handle click of More Info with icons
function ClickMoreInfo(Icon)
         {
//          OpenMoreInfoWin(FileName, Icon);
          OpenMoreInfoWin(FileName, Icon);
         }

// Function to handle glossary term click.
function ClickGlossary(Term)
         {
          OpenWordGlossaryWin(Term);
          return false;
         }

// Function to leave focus on dependent windows if open when this one opens
function CheckMoreInfo()
         {
          if (MoreInfoWin  && 
              MoreInfoWin.open &&
              !MoreInfoWin.closed)
             {
              if (ReturningFromBigPhoto)
                 {
                  MoreInfoWin.focus();
                  ReturningFromBigPhoto = 0;
                 }
              else
                 MoreInfoWin.close();
             }
         }

// Function to close dependent windows when this one closes.
// If going to a BigPhoto page, don't close MoreInfoWin.  Give it focus instead.
function CloseDependents()
         {
CloseSayitWin();
          if (MoreInfoWin  && 
              MoreInfoWin.open &&
              !MoreInfoWin.closed)
             {
              if (GoingToBigPhoto)
                 {
                  MoreInfoWin.focus();
                 }
              else
                 {
                  MoreInfoWin.close();
                 }
             }
         }
