/*
 *  @filename     dom_functions.js
 *  @title        DOM Functions
 *  @author       Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @created      07.30.2006
 *  @modified     01.09.2008
 *  @modified     02.10.2008
 *
 *  @description  This file contains functions for accessing and
 *                enhancing JavaScript's interface with the Document
 *                Object Model.
 */

/*
 *  @function getByID
 *
 *  @comment  An enhanced version of the getElementByID method.
 *
 *  @author   Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @param    id            ID of element to be retrieved.
 *  @return   myElement     Element retrieved based upon ID parameter.
 */
function getByID(id){
  var myDocument = window.document;
  var myElement;

  if(myDocument.getElementById){
    myElement = myDocument.getElementById(id);
  }// end if(myDocument.getElementById)
  else if (myDocument.all){
    myElement = myDocument.all[id];
  }// end if(myDocument.all)

  return myElement;
}// end function getByID(id)

/*
 *  @function changeClassByID
 *
 *  @comment  Changes the "class" attribute of a given HTML element
 *            which corresponds to the supplied ID.
 *
 *  @author   Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @param    id              The ID attribute of element to be changed.
 *  @param    newclass        The new value of the class attribute.
 *  @return   true            Boolean true.
 */
function changeClassByID(id,newClass){
  var toChange = getByID(id);
  toChange.className = newClass;
  return true;
}// end changeClassByID(id,newClass)

/*
 *  @function changeClassByIDs
 *
 *  @comment  Changes the "class" attributes of a given list of HTML
 *            elements which corresponds to the supplied array of
 *            IDs.
 *
 *  @author   Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @param    id              The ID attribute of the element.
 *  @param    newclass        The new value of the class attribute.
 *  @return   true            Boolean true.
 */
function changeClassByIDs(ids,newClass){
  var currentID;

  for(var i=0;i<ids.length;i++){
    currentID = ids[i];
    changeClassByID(currentID,newClass);
  }// end for(var i=0;i<ids.length;i++);

  return true;
}// end function changeClassByIDs(ids,newClass)

/*
 *  @function changeDisplayByID
 *
 *  @comment  Sets the display attribute of the element corresponding
 *            to the supplied ID to the supplied value.
 *
 *  @author   Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @param    id              ID of element.
 *  @param    newDisplay      New value of element's dispaly attribute.
 *  @return   true            Boolean true.
 */
function changeDisplayByID(id,newDisplay){
  var myElement = getByID(id);
  myElement.style.display = newDisplay;
  return true;
}// end function changeDisplayByID(id,newDisplay)

/*
 *  @function toggleClassByID
 *
 *  @comment  Checks an object with the supplied ID for each of two class
 *            strings, setting its class string to the secondary class if the
 *            primary class is detected, and vice-versa.
 *
 *            If neither class is detected, the function will do nothing.
 *
 *  @author   Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @param    id              ID of element.
 *  @param    primaryClass    Primary class value.
 *  @param    secondaryClass  Secondary class value.
 *  @return   true            Boolean true.
 */
function toggleClassByID(id,primaryClass,secondaryClass){
  var toToggle = getByID(id);
  currentClass = toToggle.className;
  if(currentClass==primaryClass) toToggle.className = secondaryClass;
  else if(currentClass==secondaryClass) toToggle.className = primaryClass;
  return true;
}// end function toggleClassByID(id,primaryClass,secondaryClass)

/*
 *  @function changeDisplayByIDs
 *
 *  @comment  Sets the display attribute of
 *            This function relies upon the GetByID function.
 *
 *  @author   Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @param    id              ID of element.
 *  @param    newDisplay      New value of element's dispaly attribute.
 *  @return   true            Boolean true.
 */
function changeDisplayByIDs(ids,newDisplay){
  var currentID;

  for(var i=0;i<ids.length;i++){
    currentID = ids[i];
    changeDisplayByID(currentID,newDisplay);
  }// end for(var i=0;i<ids.length;i++)

  return true;
}// end function changeDisplayByIDs(ids,newDisplay)

/*
 *  @function toggleDisplayByID
 *
 *  @comment  Toggles the display attribute of the element corresponding
 *            to the supplied ID.
 *
 *  @author   Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @param    id              ID of element.
 *  @return   true            Boolean true.
 */
function toggleDisplayByID(id){
  var myElement = getByID(id);

  if(myElement.style.display == "") myElement.style.display = "none";
  else if(myElement.style.display != "none") myElement.style.display = "none";
  else myElement.style.display = "block";

  return true;
}// end function toggleDisplayByID(id)