/**
 * Write toggle buttons.
 * <p>
 * @param  active  active button index
 */
function writeToggles( active )
{  var titles = new Array( "Current Dollars (not adjusted)", 
      "Constant Fiscal Year 2000 Dollars (adjusted for inflation)", 
      "Percentage of Gross Domestic Product (adjusted for national wealth)" );
   var values = 
      new Array( "Current Dollars", "Adjusted for Inflation", "Adjusted for Wealth" );
   var defimages =
      new Array( "images/defcur.gif", "images/defcon.gif", "images/defgdp.gif" );
   var debtimages =
      new Array( "images/debtcur.gif", "images/debtcon.gif", "images/debtgdp.gif" );
   for( var i = 0; ( i < titles.length ); i++ )
   {  document.write( "<button type='button' style='font-size: small; padding: 1px 0 0 0; width: 150px;' id='toggle" + i + "'" );
      document.write( "   class=" + (( i == active ) ? "'active'" : "'up'" ));
      document.write( "   onmousedown='if( this.className != \"active\" ) this.className=\"down\";'" );
      document.write( "   onmouseover='if( this.className != \"active\" ) this.className=\"over\";'" );
      document.write( "   onmouseout='if( this.className != \"active\" ) this.className=\"up\";'" );
      document.write( "   onclick='if( this.className != \"active\" ) {" );   
      for( var j = 0; ( j < titles.length ); j++ )
      {  if( j == i )
            document.write( "      document.getElementById( \"toggle" + j + "\" ).className = \"active\";" ); 
         else
            document.write( "      document.getElementById( \"toggle" + j + "\" ).className = \"up\";" ); 
      }
      document.write( "      document.def.src=\"" + defimages[ i ] + "\";" );      
      document.write( "      document.debt.src=\"" + debtimages[ i ] + "\";" );      
      document.write( "   }' title='" + titles[ i ] + "'>" + values[ i ] + "</button><br />" );
   }
}

/**
 * Write navigation buttons.
 * <p>
 * @param  active     active button index [0..7]
 */
function writeButtons( active )
{  var locations = new Array( "index.html", "money.html", 
      "percentages.html", "budget.html", 
      "results.html", "questions.html", 
      "comments.html", "help" + active + ".html" );
   var names = new Array( "<img src='images/logo.gif' height=40 width=100 " +
      "alt='Budget Explorer' title='Budget Explorer'>", "Spending", 
      "Amounts", "Budget", 
      "Results", "Questions", 
      "Comments", "Help" );
   var titles = new Array( "Budget Explorer", "Where Does Your Money Go?", 
      "Current Spending Amounts", "The Complete US Federal Budget", 
      "Results of Your Changes", "Frequently Asked Questions", 
      "Visitors' Comments", "Help" );
   titles[ 7 ] = 
      ( active == 0 ) ? "How to use this site" :
      ( active == 1 ) ? "How to estimate current spending" :
      ( active == 2 ) ? "How to view current spending amounts" :
      ( active == 3 ) ? "How to explore the Federal Budget" :
      ( active == 4 ) ? "How to view results of your changes" :
      ( active == 5 ) ? "How to learn more about the Federal Budget" :
      ( active == 6 ) ? "How to add your own comments" :
      "Help";
   if(( active == 2 ) | ( active == 4 ))
   {  var cookies = document.cookie;
      var i = cookies.indexOf( "estimates=" ) + 10;
      var estimates = cookies.substring( i, i + 6 );
      locations[ 3 ] = "http://www.kowaldesign.com/cgi/Budget.pl?estimates=" + estimates;
   }
   else if( active == 3 )
   {  names[ 4 ] = "<center><applet code='com/kowaldesign/exp/Results.class' " +
         "name='results' width=100 height=18 " +
         "alt='Results of your changes' title='Results of your changes'>" +
         "<param name='text' value='Results'></applet></center>";
   }
   for( var i = 0; ( i < 8 ); i++ )
   {  if( i == active )
      {  document.write( "<button type='button' style='width:90%;' class='active'>" );
         document.write( names[ i ] + "</button><br />" );
      }
      else
      {  document.write( "<button type='button' style='width:90%;' class='up'" );
         document.write( "   onmouseover='this.className=\"over\";' onmousedown='this.className=\"down\";'" );
         if(( active == 3 ) && ( i == 4 ))
            document.write( "   onmouseout='this.className=\"up\";'" );
         else if( active == 6 )
            document.write( "   onmouseout='this.className=\"up\";' onclick='parent.location=\"" + locations[ i ] + "\";'" );
         else
            document.write( "   onmouseout='this.className=\"up\";' onclick='location=\"" + locations[ i ] + "\";'" );
         document.write( "   title='" + titles[ i ] + "'>" + names[ i ] + "</button><br />" );
      }
   }
}

/**
 * Write guestbook tabs.
 * <p>
 * @param  active  active tab, or <0 for "Add comments"
 */
function writeTabs( active )
{  document.write( "<center>" );
   document.write( "<table width='100%' cellpadding='0' cellspacing='0'>" );
   document.write( "<tr class='tab'>" );
   document.write( "<td>&nbsp;&nbsp;</td>" );
   var firstTab = 2006;
   var lastTab = 2010;
   for( var i = firstTab; ( i <= lastTab ); i++ )
   {  if( i == active )
      {  document.write( "<td class='tab active'" );
         document.write( "title='Comments for " + i + "'>&nbsp;" + i + "&nbsp;</td>" );
      }
      else
      {  document.write( "<td class='tab up'" );
         document.write( "onmouseover='this.className=\"tab over\";' onmousedown='this.className=\"tab down\";' " ); 
         document.write( "onmouseout='this.className=\"tab up\";' " );
         var j = i % 100;
         var s = ( j < 10 ) ? "0" + j : "" + j;
         document.write( "title='Comments for " + i + "'>&nbsp;<a class='tab' target='comments' href='book" + s + ".html'>" + i + "</a>&nbsp;</td>" );
      }
      document.write( "<td>&nbsp;</td>" );
   }
   if( active < 0 )
   {  document.write( "<td class='tab active'" );
      document.write( "title='Add comments'>&nbsp;Add&nbsp;comments&nbsp;</td>" );
   }
   else
   {  document.write( "<td class='tab up'" );
      document.write( "onmouseover='this.className=\"tab over\";' onmousedown='this.className=\"tab down\";' " ); 
      document.write( "onmouseout='this.className=\"tab up\";' " );
      document.write( "title='Add comments'>&nbsp;<a class='tab' target='comments' href='add.html'>Add&nbsp;comments</a>&nbsp;</td>" );
   }
   document.write( "<td width='100%'>&nbsp;</td>" );
   document.write( "</tr>" );
   document.write( "<tr><td colspan='" + ( 3 + 2 * ( lastTab - firstTab + 1 )) + "'><div class='tab'>&nbsp;</div></td></tr>" );
   document.write( "</table>" );
   document.write( "</center>" );
}