// Section page operations

// measure location object definition
function ML(measure, location, nodeColor, nodeColorRange, worstMColor, worstMColorRange, worstLColor, worstLColorRange, detailUrl, drillMeasureUrl, drillLocationUrl, textColor)
{
   this.measure = measure;
   this.location = location;
   this.nodeColor = nodeColor;
   this.nodeColorRange = nodeColorRange;
   this.worstMColor = worstMColor;
   this.worstMColorRange = worstMColorRange;
   this.worstLColor = worstLColor;
   this.worstLColorRange = worstLColorRange;
   this.detailUrl = detailUrl;
   this.drillMeasureUrl = drillMeasureUrl;
   this.drillLocationUrl = drillLocationUrl;
   this.textColor = textColor;
}

// definitin of URL object
function sUrl(caption, url)
{
   this.caption = caption;
   this.url = url;
}

// presents items title
function sInsertItemsTitle()
{
   document.write( toChapter( sSection + ' (' + getString("rJS_Section_Str_02") + ')' ) );
}

// presents description
function sInsertDesc()
{
   if (sBook != '')
   {
      document.write(toHeader(getString("rJS_Section_Str_03")) + '<br>' + toNormal(sBook));
   }
   if (sSection != '')
   {
      document.write('<br>' + toHeader(getString("rJS_Section_Str_01")) + '<br>' + toNormal(sSection));
   }
   if (sDesc != '')
   {
      document.write('<br>' + toHeader(getString("rJS_Section_Str_04")) + '<br>' + toNormal(sDesc));
   }
}

// presents linked document urls
function sInsertUrls()
{
   if (HasInstance(sUrls))
   {
      if (sUrls.length > 0)
      {
         document.write('<br>' + toHeader(getString("rJS_Section_Str_05")));
      }
      for (var i = 0; i < sUrls.length; i++)
      {
         document.write('<br><a href="' + sUrls[i].url + '">' + toNormal(sUrls[i].caption, true) + '</a>');
      }
   }
}

// formats next measure location
function insertNextMeasure(ml)
{
   var td_b = '<td align="left">';
   var td_e = '</td>';
   var td_d = '';
   var altstr = "";
   if (HasInstance(ml))
   {
      if (ml.nodeColor != '')
      {
         td_b = '<td align="left" bgcolor="' + ml.nodeColor +'">';
      }
      //measure - left half
      altstr = getString("rJS_Section_Str_06") + " \r\n" + getString("rJS_Common_Str_03") + ": " + ml.worstMColorRange.toString();
      document.write('<td align=center>' + getT(ml.worstMColor, ml.drillMeasureUrl, altstr) + '</td>');
      if (ml.detailUrl != '')
      {
         altstr = ml.measure + " \r\n" + getString("rJS_Common_Str_05") + ": " + ml.nodeColorRange;
         td_d += '<a title="' + altstr + '" href="' + ml.detailUrl + '"';
         if ( ml.textColor != '')
         {
            td_d += ' style="color: ' + ml.textColor + '"';
         }
         td_d += '>' + toNormal(ml.measure, true) + '</a>';
      }
      else
      {
         if ( ml.textColor != '')
         {
            td_d += '<font color="' + ml.textColor + '">';
         }
         td_d += toNormal(ml.measure);
         if ( ml.textColor != '')
         {
            td_d += '</font>';
         }
      }
      document.write(td_b + td_d + td_e);

      //location - right half
      td_d = "";
      altstr = getString("rJS_Section_Str_07") + " \r\n" + getString("rJS_Common_Str_04") + ": " + ml.worstLColorRange.toString();
      if (ml.location != '')
      {
         if ( ml.textColor != '')
         {
            td_d += '<font color="' + ml.textColor + '">';
         }
         td_d += toNormal(ml.location);
         if ( ml.textColor != '')
         {
            td_d += '</font>';
         }
      }
      document.write(td_b + td_d + td_e);
      document.write('<td align=center>' + getT(ml.worstLColor, ml.drillLocationUrl, altstr) + '</td>');
   }
}

function isHTML_RTL()
{
   var result = false;
  var el = document.dir;
  if ( el && el != null && el.toString().toLowerCase() == "rtl")
  {
      result = true;
   }
  return result;

}

// formats parents array and measure locations
function sInsertItems()
{
   var offset = '&nbsp;';

   var tempPeriod = "";
   var tempSeries = "";
   var isrtl = isHTML_RTL();

   if (sPeriod != '')
   {
      tempPeriod = toHeader(sPeriod);
   }
   if (sSeries != '')
   {
      tempSeries = toHeader(sSeries);
   }

   if ((sPeriod != '') || (sSeries != ''))
   {
      if (isrtl)
      {
        if (document.URL.indexOf('section.html') == -1)
        {
           document.write('<TABLE width="100%"><TR>');
           document.write('<td align="right">');
           insertAnimatedUrl('javascript:window.history.go(-1);', '../../images/up.gif', '../../images/up_h.gif', getString("rJS_Section_Str_11"));
           document.write('</td>');
           document.write('<TD width="50%" align="left">' + tempPeriod + '</td>');
           document.write('</tr><TR><TD align="left" colspan=2>' + tempSeries + '</td></tr></table>');
        }
        else
        {
           document.write('<TABLE width="100%"><TR><TD width="50%" align="right">' + tempSeries + '</td><TD align="left">' + tempPeriod + '</td></tr></table>');
        }
      }
      else
      {
        if (document.URL.indexOf('section.html') == -1)
        {
           document.write('<TABLE width="100%"><TR><TD width="50%" align="left">' + tempPeriod + '</td>');
           document.write('<td align="right">');
           insertAnimatedUrl('javascript:window.history.go(-1);', '../../images/up.gif', '../../images/up_h.gif', getString("rJS_Section_Str_11"))
           document.write('</td>');
           document.write('</tr><TR><TD align="left" colspan=2>' + tempSeries + '</td></tr></table>');
        }
        else
        {
           document.write('<TABLE width="100%"><TR><TD width="50%" align="left">' + tempPeriod + '</td><TD align="right">' + tempSeries + '</td></tr></table>');
        }
      }
   }

   document.write('<table border="0" cellpadding="2" cellspacing="2" width="100%">');

   // insert here link to section
   if (HasInstance(sParentUrls))
   {
      // this part is executed when parent history is defined
      document.write('<tr><td align="center" vAlign="middle">' + getT('', '', '') + '</td>');
      document.write('<td colspan="2">');
      for (var i = 0; i < sParentUrls.length; i++)
      {
         document.write(offset + '<a href="' + sParentUrls[i].url + '" title="' + getString("rJS_Common_Str_02") + '"><img border="0" src="../../images/parent.gif" alt="' + getString("rJS_Common_Str_02") + '"></a>&nbsp;');
         document.write('<a href="' + sParentUrls[i].url + '">'+ toNormal(sParentUrls[i].caption, true) + '</a><br>');
         offset += '&nbsp;';
      }
      document.write('</td>');
      document.write('<td align="center" vAlign="middle">' + getT('', '', '') + '</td>');
      document.write('</tr>');
   }

   // insert measure/locations
   if (HasInstance(sMeasures))
   {
      for (var i = 0; i < sMeasures.length; i++)
      {
         document.write('<tr>');
         insertNextMeasure(sMeasures[i]);
         document.write('</tr>');
      }
   }
   document.write('</table>');
}

// inserts vertical tabs
function sAddTabs()
{
   if (HasInstance(bTitles) && HasInstance(bUrls) && (bUrls.length == bTitles.length) )
   {
      document.write('<table bgcolor="transparent" border="0" cellpadding="0" cellspacing="0">');
      addVTab(getString("rJS_Section_Str_08"), '../../library.html', '../../', cLibraryTabColor, true);
      addVTab(getString("rJS_Section_Str_09"), '../book.html', '../../', cNonSelTabColor, false);
      for (var i = 0; i < bTitles.length; i++)
      {
         if (i == sSelectedIndex)
         {
            addVTab(bTitles[i], '', '../../', cSelTabColor, false);
         }
         else
         {
            addVTab(bTitles[i], '../' + bUrls[i], '../../', cNonSelTabColor, false);
         }
      }
      document.write('</table>');
   }
}

// convert RGB color for drill-down button to button image file
function getT(color, url, alt)
{
   if (url != '')
   {
      //the color string has the form '#RRGGBB', so we have to strip the leading '#'
      //to get the appropriate 'tRRGGBB.gif' image
      return '<a title="' + alt + '" href="' + url + '"><img border="0" src="../../images/t' + color.substr(1,6) + '.gif" width="12" height="12" alt="' + alt +'"></a>';
   }
   else
   {
      return '<img border="0" src="../../images/t.gif" width="12" height="12">';
   }
}

// inserts footer
function sInsertPublishedDate()
{
   document.write(toPublishedDate(sPublished));
}
// inserts footer
function sInsertFooter()
{
   document.write(toFooter(sLeftFooter, sCentreFooter, sRightFooter, sFooterBorder));
}
// inserts header
function sInsertGlobalHeader()
{
   document.write(toGlobalHeader(sLeftHeader, sCentreHeader, sRightHeader, sHeaderBorder));
}

