//----------------------------------------------------------------------
//- tbaStatusUtilities: Display aids for Open/Close Status display
//----------------------------------------------------------------------
 var tba = new Object();
     tba.building        = 'Building';
     tba.nurserySchool   = 'Nursery School';
     tba.religiousSchool = 'Machane TBA';  //'Religious School';
     tba.blockId         = 'tbaBlock1';

 //---------------------------------------------------------------------
 //- tbaToggleText: Show/Hide a UI section given its Id
 //---------------------------------------------------------------------
 function tbaToggleText(id)
 {
  var field     = document.getElementById(id);
  var displayed = field.style.display == "";

  field.style.display = displayed ? "none" : "";
 }

 //---------------------------------------------------------------------
 //- tbaDisplayStatusIndicator: Show the status of the given indicator
 //---------------------------------------------------------------------
 function tbaDisplayStatusIndicator(indicator, blockId, noHeadlines)
 {
  var a = indicator.sort ? indicator : new Array(indicator);
  var w = 100/(2*a.length);
  var i;

  document.writeln('<table width="100%" align="center" border="0" cellspacing="10" cellpadding="0">');
//document.writeln('<table width="100%" align="center" border="0" cellspacing="5" cellpadding="10">');
  document.writeln(' <tr>');

  for (i=0; i<a.length; i++)
  {
   document.writeln('  <td valign="center" align="right" width="'+w+'%">');
   document.writeln('   <a href="javascript:tbaToggleText(\''+blockId+'\');"');
   document.writeln('      title="Click here for Status Code descriptions"><b>'+a[i]+'</b>');
   document.writeln('  </td>');
   document.writeln('  <td valign="center" align="left" width="'+w+'%">');
   document.write  ('   <a href="javascript:tbaToggleText(\''+blockId+'\');">');

   tbaDisplayStatusImage(a[i]);

   document.writeln('</a>');
   document.writeln('  </td>');
  }

//document.writeln(' </tr>');
//document.writeln(' <tr>');
//document.writeln('  <td style="display:none" id="'+blockId+'" colspan="'+i+'">');
//tbaDisplayStatusInformation(blockId);
//document.writeln('  </td>');
  document.writeln('</table>');
  tbaDisplayStatusInformation(blockId);

  if (noHeadlines)
   {return;}

  for (i=0; i<a.length; i++)
  {
   if (tbaGetHeadline(a[i]).length > 0)
   {
    document.writeln  ("<div align='center'>");
    document.write    (" <font size='+1'>");
    tbaDisplayHeadline(a[i]);
    document.writeln  ("</div>");
   }
  }
 }

 //---------------------------------------------------------------------
 //- tbaFrontPageHeadlines: Display the headlines front-page style
 //---------------------------------------------------------------------
 function tbaFrontPageHeadlines()
 {
   var any = false;
   if (tbaGetHeadline(tba.building).length > 0)
   {
      any = true;
      document.writeln  ("<br>");
      document.write    (" <center><font size='+1'>");
      tbaDisplayHeadline(tba.building);
      document.writeln  (" </font></center>");
   }

   if ((tbaGetHeadline(tba.religiousSchool).length > 0)
       && tbaIsHeadlineUrgent(tba.religiousSchool))
   {
      any = true;
      document.writeln  ("<br>");
      document.write    (" <center>");
      tbaDisplayHeadline(tba.religiousSchool, 1);
      document.writeln  ("</center>");
   }

   if ((tbaGetHeadline(tba.nurserySchool).length > 0)
       && tbaIsHeadlineUrgent(tba.nurserySchool))
   {
      any = true;
      document.writeln  ("<br>");
      document.write    (" <center>");
      tbaDisplayHeadline(tba.nurserySchool, 1);
      document.writeln  ("</center>");
   }

   if (any)
      {document.writeln("<br>");}
 }

 //---------------------------------------------------------------------
 //- tbaDisplayStatusInformation: Create and populate the text block
 //- that displays the Open/Close status indicators and Closing Policy.
 //---------------------------------------------------------------------
 function tbaDisplayStatusInformation(blockId)
 {
  var exists = document.getElementById(blockId)

  if (exists)
   {return;}

  document.writeln('<div style="display:none" id="'+blockId+'">');
  document.writeln(' <div align="right">');
  document.writeln('  <font size="1">Hide</font>');
  document.writeln('  <a href="javascript:tbaToggleText(\''+blockId+'\');">[X]</a>');
  document.writeln('  <br>');
  document.writeln(' </div>');
  document.writeln(' <TABLE cellSpacing="2" cellPadding="2" border="1" align="center">');
  document.writeln(' <TBODY>');
  document.writeln('  <TR>');
  document.writeln('   <TD><IMG src="http://www.bethami.org/_storage/Pages/1046/greenlight.gif"></TD>');
  document.writeln('   <TD><FONT size="2">Operating normal scheduled hours</FONT></TD>');
  document.writeln('  </TR>');
  document.writeln('  <TR>');
  document.writeln('   <TD><IMG src="http://www.bethami.org/_storage/Pages/1046/yellowlight.gif"></TD>');
  document.writeln('   <TD><FONT size="2">Opening delayed. Check website, TV, and Radio for updates</FONT></TD>');
  document.writeln('  </TR>');
  document.writeln('  <TR>');
  document.writeln('   <TD><IMG src="http://www.bethami.org/_storage/Pages/1046/redlight.gif"></TD>');
  document.writeln('   <TD><FONT size="2">Closed due to weather or other unusual circumstance</FONT></TD>');
  document.writeln('  </TR>');
  document.writeln('  <TR>');
  document.writeln('   <TD><IMG src="http://www.bethami.org/_storage/Pages/1046/bluelight.gif"></TD>');
  document.writeln('   <TD><FONT size="2">On a scheduled break or vacation</FONT></TD>');
  document.writeln(' </TR>');
  document.writeln(' </TBODY>');
  document.writeln(' </TABLE>');
  document.writeln(' <p>');
  document.writeln('  The Nursery and Religious Schools follow the Montgomery County Public ');
  document.writeln('  School (MCPS) schedule except that we are open on half days. If MCPS ');
  document.writeln('  closes for inclement weather, we are closed. If MCPS have a delayed ');
  document.writeln('  opening (however long), the Nursery School opens one hour late; the ');
  document.writeln('  Religious School meets on schedule.  If MCPS close early or cancel ');
  document.writeln('  evening or weekend programming, we are closed. Closings are announced ');
  document.writeln('  on the following radio stations, WTOP and WMAL. A message is also put ');
  document.writeln('  on the Temple\'s answering system, but the system can only handle a few ');
  document.writeln('  calls, so expect busy signals.');
  document.writeln(' </p><br> ');
  document.writeln('</div> ');
 }

//----------------------------------------------------------------------
 function tbaDisplayStatusImage(key)
 {
     document.write("<img src='"          + tbaGetImage(key)  + "'");
     document.write(" alt='Status is: "   + tbaGetStatus(key) + "'");
     document.write(" title='Status is: " + tbaGetStatus(key) + "'");
     document.write(" border='0'>");
 }

//----------------------------------------------------------------------
 function tbaDisplayHeadline(key, displayKey)
 {
     if (tbaIsHeadlineUrgent(key))
        document.write("<font color='red'>");

     if (displayKey == 1)
        document.write(key+": ");

     document.write(tbaGetHeadline(key));

     if (tbaIsHeadlineUrgent(key))
        document.write("</font'>");
 }

//----------------------------------------------------------------------
 function tbaGetImage(key)
 {
     return bethAmi[key]['image'];
 }

//----------------------------------------------------------------------
 function tbaGetStatus(key)
 {
     return bethAmi[key]['status'];
 }

//----------------------------------------------------------------------
 function tbaGetHeadline(key)
 {
     return bethAmi[key]['headline'];
 }

//----------------------------------------------------------------------
 function tbaGetHeadlineUrgent(key)
 {
     return bethAmi[key]['headlineUrgent'];
 }

//----------------------------------------------------------------------
 function tbaIsHeadlineUrgent(key)
 {
     return (tbaGetHeadlineUrgent(key) == 'y');
 }
//----------------------------------------------------------------------
