//------------------------------------------------------------------------------
// Module: Widgets
// for creating Widgets for the Coe Library pages
// by Jon Frechette
//------------------------------------------------------------------------------


function Widgets() {} // empty constructor


Widgets.init = function()
  {
  if ( ! document.getElementById ) // ignore old browsers
    return;

  var node = document.getElementById( 'header' );
  if ( typeof node.innerHTML == 'undefined' ) // ignore old browsers
    return;

  var s = '';

  // the style for widgets are in home.css
  // the 'faq' and 'qpf' ids match id selectors in home.css

  s += Widgets.makeWidget1( 'faq' );

  s += Widgets.makeWidget2( 'qpf' );

  if ( s )
    {
    node.innerHTML += s;
    //Diag.showCode( s );
    }
  return;
  }


Widgets.makeWidget1 = function( pId )
  {
  var s = '';
  s += Widgets.makeOpt( "find a book ?",                    "http://207.210.135.202/", "notHere" );
  s += Widgets.makeOpt( "contact the library ?",            "../Info/Contact_Info.html" );
  s += Widgets.makeOpt( "know if the library is open ?",    "../Info/Schedule.html" );
  s += Widgets.makeOpt( "get a library card ?",             "../Info/Library_Cards.html" );
  s += Widgets.makeOpt( "get to the library ?",             "../Info/Directions.html" );
  s += Widgets.makeOpt( "renew a book, magazine, or CD ?",       "../Info/Circulation.html#renew" );
  s += Widgets.makeOpt( "find coming events ?",             "../Main/Activities_Events.html" );
  s += Widgets.makeOpt( "get an answer to a question ?",    "../Web/iWantToKnow.html" );
  s += Widgets.makeOpt( "see what new books you have ?",    "../Books/Recent_Titles.html" );
  s += Widgets.makeOpt( "see what's available for kids ?",  "../Web/Kids_Page.html" );
  s += Widgets.makeOpt( "see what's available for teens ?", "../Web/Teen_Corner.html" );
  s += Widgets.makeOpt( "see what services you offer ?",    "../Info/Library_Services.html" );
  s += Widgets.makeOpt( "see what you offer online ?",      "../Web/Resources.html" );
  s += Widgets.makeOpt( "support the library ?",            "../Info/Support_Us.html" );
  s += Widgets.makeOpt( "find out what's at the library ?", "../Library/Building.html" );
  s += Widgets.makeOpt( "rent a meeting space ?",           "../Info/Library_Services.html#hall" );
  s += Widgets.makeOpt( "talk like a librarian ?",          "../Web/Library_Terms.html" );

  s = Widgets.makeSelectWidget( pId, 'How do I', s )
  return s;
  }


Widgets.makeWidget2 = function( pId )
  {
  var s = '';

  s += Widgets.makeOpt( "Activities And Events",         "../Main/Activities_Events.html" );
  s += Widgets.makeOpt( "At The Library",                "../Library/Building.html" );
  s += Widgets.makeOpt( "Book Talk",                     "../Books/Book_Talk.html" );
  s += Widgets.makeOpt( "Contact Information",           "../Info/Contact_Info.html" );
  s += Widgets.makeOpt( "The Children's Room",           "../Library/Childrens_Room.html" );
  s += Widgets.makeOpt( "Circulation Policies",          "../Info/Circulation.html" );
  s += Widgets.makeOpt( "Dewey Decimal System Explorer", "../Web/DDS.html" );
  s += Widgets.makeOpt( "Directions To The Library",     "../Info/Directions.html" );
  s += Widgets.makeOpt( "Find A Book",                   "http://207.210.135.202/", "notHere" );
  s += Widgets.makeOpt( "iWantToKnow",                   "../Web/iWantToKnow.html" );
  s += Widgets.makeOpt( "The Kids' Page",                "../Web/Kids_Page.html" );
  s += Widgets.makeOpt( "Library Cards",                 "../Info/Library_Cards.html" );
  s += Widgets.makeOpt( "Library Services",              "../Info/Library_Services.html" );
  s += Widgets.makeOpt( "Library Schedule",              "../Info/Schedule.html" );
  s += Widgets.makeOpt( "Library Terms",                 "../Web/Library_Terms.html" );
  s += Widgets.makeOpt( "The Media Room",                "../Library/Media_Room.html" );
//s += Widgets.makeOpt( "New York Times Best-Sellers",   "../Books/NYT_BSL.html" );
//s += Widgets.makeOpt( "Newsletter",                    "../Main/Newsletter.html" );
  s += Widgets.makeOpt( "Non-fiction Book Series",       "../Books/Series_N.html" );
  s += Widgets.makeOpt( "Online Resources",              "../Web/Resources.html" );
  s += Widgets.makeOpt( "Our Staff",                     "../Info/Staff.html" );
  s += Widgets.makeOpt( "Our History",                   "../Info/History.html" );
  s += Widgets.makeOpt( "Readalikes",                    "../Books/Readalikes.html" );
  s += Widgets.makeOpt( "Recently Acquired Books",       "../Books/Recent_Titles.html" );
  s += Widgets.makeOpt( "The Stacks",                    "../Library/Stacks.html" );
  s += Widgets.makeOpt( "Staff Book Suggestions",        "../Books/Staff_Picks.html" );
  s += Widgets.makeOpt( "Support The Library",           "../Info/Support_Us.html" );
  s += Widgets.makeOpt( "Teen Corner",                   "../Web/Teen_Corner.html" );
  s += Widgets.makeOpt( "Web Links",                     "../Links/Links.html" );

  s = Widgets.makeSelectWidget( pId, 'Page Finder', s )
  return s;
  }


Widgets.makeSelectWidget = function( pId, pLabel, pOptions )
  {
  var s = '';
  s += '<div id="' + pId + '" class="widget">\n';
  s += ' <form onsubmit="return Widgets.gotoSelection( this )">\n';
  s += ' <table>\n';
  s += '  <tr>\n';
  s += '   <td>' + pLabel + '\n';
  s += '   <select onchange="return Widgets.gotoSelection( this )">\n';
  s += '    <option value="">&nbsp;----&nbsp; please make a selection &nbsp;----&nbsp;</option>\n';
  s += pOptions;
  s += '   </select>&nbsp;</td>\n';
  s += '   <td style="vertical-align: bottom;"><input type="image" src="../images/gui/go.gif" name="go" alt="go" /></td>\n';
  s += '  </tr>\n';
  s += ' </table>\n';
  s += ' </form>\n';
  s += '</div><!-- ' + pId + ' -->\n';
  return s;
  }


Widgets.makeOpt = function( pLabel, pHref, pClass )
  {
  var s = '    <option';
  if ( pClass )
    s += ' class="' + pClass + '"';
  s += ' value="' + pHref + '">' + pLabel + '</option>\n';
  return s;
  }


Widgets.gotoSelection = function( pObj )
  {
  if ( pObj.nodeName == 'FORM' )
    {
    var tmp = pObj.getElementsByTagName( 'select' );
    if ( ! tmp || tmp.length == 0 )
      return false;
    pObj = tmp[ 0 ];
    }

  var ndx = pObj.options.selectedIndex; // save selection
  //pObj.options.selectedIndex = 0; // clear selection

  var option = pObj.options[ ndx ];
  var value = option.value;
  if ( value == "" )
    {
    alert( 'Please make a selection' );
    }
  else
    {
    if ( option.className == "notHere" )
      window.open( value );
    else
      location.href = value;
    }

  pObj.blur();
  return false;
  }


// -----------------------------------------------------------------------------


