function onWindowLoad( ) {
  var thisObject = this; // store for later use

  thisObject.functions = new Array( );

  this.start = function( ) {
    for( var i = 0; i < thisObject.functions.length; ++i ) {
      thisObject.functions[ i ]( );
    }
  }
}
var windowLoad = new onWindowLoad( );
window.onload = windowLoad.start;

function loadEventListeners( ) {
  if( document.getElementById ) {
    // old school event handling for compatibility
    document.getElementById("searchUNLVField").onfocus = onSearchUNLVFocus;
    document.getElementById("searchUNLVField").onblur = onSearchUNLVBlur;
  }
}
windowLoad.functions[ windowLoad.functions.length ] = loadEventListeners;

function onSearchUNLVFocus( ) {
  if( document.getElementById ) {
    var searchInput = document.getElementById("searchUNLVField");
    if( searchInput.value == "Search UNLV" ) searchInput.value = "";
  }
}

function onSearchUNLVBlur( ) {
  if( document.getElementById ) {
    var searchInput = document.getElementById("searchUNLVField");
    if( searchInput.value == "" ) searchInput.value = "Search UNLV";
  }
}

function stripeTables( ) {
  // Adds dark backgrounds to even numbered rows

  if( document.getElementsByTagName ) {
    var tbodys = document.getElementsByTagName("tbody");
    for( var i = 0; i < tbodys.length; ++i ) {
      if( !hasClass( tbodys[ i ].className, "striped" ) ) {
        var even = false;
        var trs = tbodys[ i ].getElementsByTagName("tr");
        for( var j = 0; j < trs.length; j++ ) {
          if( trs[ j ].getElementsByTagName("th").length < 1 ) { // skip header rows
            if( even ) {
              trs[ j ].className += " even-row";
            }
            even = !even; // toggle even flag
          }
          else {
            trs[ j ].className += " header-row";
            even = false;
          }
        }
      }
    }
  }
}
windowLoad.functions[ windowLoad.functions.length ] = stripeTables;

function highlightHash( ) {
  // adds "hashed" class to anchor pointed to by fragment identifier

  if( document.getElementsByTagName ) {
    var hash = window.location.hash.substring( 1 );

    if( hash != "" && hash != "dars_top" ) {
      var anchors = document.getElementsByTagName("a");
      for( var i = 0; i < anchors.length; ++i ) {
        if( anchors[ i ].getAttribute( "name" ) == hash ) {
          anchors[ i ].className += " hashed";
        }
        else {
          anchors[ i ].className = removeClass( anchors[ i ].className, "hashed" );
        }
      }
    }
  }
}
windowLoad.functions[ windowLoad.functions.length ] = highlightHash;

function reHighlightHash( ) {
  if( window.setTimeout ) {
    // delay to ensure update of location.has
    window.setTimeout( highlightHash, 1 );
  }
  return true;
}

function activateInDocumentLinks( ) {
  // Makes in document links (i.e. href="#...") work with hash
  // highlighting by setting onclick events.

  if( document.getElementsByTagName ) {
    var anchors = document.getElementsByTagName("a");
    for( var i = 0; i < anchors.length; ++i ) {
      if( String( anchors[ i ].getAttribute( "href" ) ).charAt( 0 ) == "#" ) {
        anchors[ i ].onclick = reHighlightHash;
      }
    }
  }  
}
windowLoad.functions[ windowLoad.functions.length ] = activateInDocumentLinks;

/*****************************************************************************/

function hasClass( classesString, theClass ) {
  var hasIt = false;
  var classes = classesString.split(" ");
  for( var i = 0; i < classes.length; ++i ) {
    if( classes[ i ] == theClass ) {
      hasIt = true;
    }
  }
  return hasIt;
}

function removeClass( classesString, theClass ) {
  var classes = classesString.split( " " );
  var returnClass = "";
  for( var i = 0; i < classes.length; ++i ) {
    if( classes[ i ] != theClass && classes[ i ] != "" ) {
      returnClass += " " + classes[ i ];
    }
  }
  return returnClass;
}
