////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2005-2006 Tom Bascom, Greenfield Technologies
// http://www.greenfieldtech.com
//
// tabfolder.js
//
// Based on an example found at:
//
//	http://www.imaputz.com/uportal/tabstyles.html
//
// Requires css/tab.css !!!
//
// In the <head> include:
//
// <link rel="stylesheet" type="text/css" href="css/tab.css"></link>
// <script type="text/javascript" src="js/tabfolder.js"></script>
//
// In the <body> designate list-items with an id of the form "li" + tid and
// designate the corresponding div as "div" + tid.  (Note that "li" and "div" are
// lower case.)  The tid can be any unique identifier for the tab (a simple number
// or a more meaningful string.)  i.e.
//
//   <ul id="tabBar" class="tabNavigation">
//    <li id="li1"><a href="#Tab1" onclick="selectTab('1');">Tab1</a></li>
//    <li id="li2"><a href="#Tab2" onclick="selectTab('2');">Tab2</a></li>
//  </ul>
//
//  <div id="div1" class="tabDiv"><p>Contents of Tab 1</p></div>
//  <div id="div2" class="tabDiv"><p>Contents of Tab 2</p></div>
//

function selectTab( tid ) {

  var i;
  var x;

  x = document.getElementsByTagName( "li" );

  for ( i = 0; i < x.length; i++ ) {
    if ( x[i].id != "li" + tid ) {
      if ( x[i].getAttribute( "class" ) == "selectedTab" ) {
        x[i].setAttribute( "class", "unselectedTab" );			// Mozilla calls it "class"
        x[i].setAttribute( "className", "unselectedTab" );		// IE calls it "className" -- grrr...
      }
    } else {
      x[i].setAttribute( "class", "selectedTab" );
      x[i].setAttribute( "className", "selectedTab" );
    }
  }

  x = document.getElementsByTagName( "div" );

  for ( i = 0; i < x.length; i++ ) {
    if ( x[i].id != "div" + tid ) {
      if ( x[i].getAttribute( "class" ) == "selectedTabDiv" ) {
        x[i].setAttribute( "class", "tabDiv" );
        x[i].setAttribute( "className", "tabDiv" );
      }
    } else {
      x[i].setAttribute( "class", "selectedTabDiv" );
      x[i].setAttribute( "className", "selectedTabDiv" );
    }
  }

  if ( eval( "window.onTab" + tid )) {
    eval( "onTab" + tid + "()" );
  }

}
