function ID(id) {
   return document.getElementById ? document.getElementById(id) : document.all[id];
}

function T(name, root) {
   return (root || document).getElementsByTagName(name);
}

function C(name,type) {
   var r = [];
   // Locate the class name (allows for multiple class names)
   var re = new RegExp("(^|\\s)" + name + "(\\s|$)");

   // Limit search by type, or look through all elements
   var e = document.getElementsByTagName(type || "*");
   for (var j = 0; j < e.length; j++)
      // If the element has the class, add it for return
      if (re.test(e[j].className)) r.push(e[j]);

   // Return the list of matched elements
   return r;
}

//--------------------------------------------------------------------------------------------------

// A function for setting the horizontal position of an element
function setX(element, pos) {
   // Set the left CSS property, using pixel units
   element.style.left = pos + "px";
}

// A function for setting the vertical position of an element
function setY(element, pos) {
   // Set the left CSS property, using pixel units
   element.style.top = pos + "px";
}

// A function for setting the width of an element
function setWidth(element, width) {
   // Set the width CSS property, using pixel units
   element.style.width = width + "px";
}

// A function for setting the height of an element
function setHeight(element, height) {
   // Set the height CSS property, using pixel units
   element.style.height = height + "px";
}

// Get a style property (name) of a specific element (element)
function getStyle(element, name) {
   // If the property exists in style[], then it's been set recently (and is current)
   if (element.style[name])
      return element.style[name];

   // Otherwise, try to use IE's method
   else if (element.currentStyle)
      return element.currentStyle[name];

   // Or the W3C's method, if it exists
   else if (document.defaultView && document.defaultView.getComputedStyle) {
      // It uses the traditional text-align style of rule writing, instead of textAlign
      name = name.replace(/([A-Z])/g,"-$1");
      name = name.toLowerCase();

      // Get the style object and get the value of the property (if it exists)
      var s = document.defaultView.getComputedStyle(element,"");
      return s && s.getPropertyValue(name);

   // Otherwise, were using some other browser
   } else
      return null;
}

//--------------------------------------------------------------------------------------------------

// A function for determining how far horizontally the browser is scrolled
function getScrollX() {
   // A shortcut, in case were using Internet Explorer 6 in Strict Mode
   var de = document.documentElement;

   // If the pageXOffset of the browser is available, use that
   return self.pageXOffset ||
   // Otherwise, try to get the scroll left off of the root node
   (de && de.scrollLeft) ||
   // Finally, try to get the scroll left off of the body element
   document.body.scrollLeft;
}

// A function for determining how far vertically the browser is scrolled
function getScrollY() {
   // A shortcut, in case were using Internet Explorer 6 in Strict Mode
   var de = document.documentElement;

   // If the pageYOffset of the browser is available, use that
   return self.pageYOffset ||
   // Otherwise, try to get the scroll top off of the root node
   (de && de.scrollTop) ||
   // Finally, try to get the scroll top off of the body element
   document.body.scrollTop;
}

// Find the height of the viewport
function getViewHeight() {
   // A shortcut, in case were using Internet Explorer 6 in Strict Mode
   var de = document.documentElement;

   // If the innerHeight of the browser is available, use that
   return self.innerHeight ||
   // Otherwise, try to get the height off of the root node
   (de && de.clientHeight) ||
   // Finally, try to get the height off of the body element
   document.body.clientHeight;
}

// Find the width of the viewport
function getViewWidth() {
   // A shortcut, in case were using Internet Explorer 6 in Strict Mode
   var de = document.documentElement;

   // If the innerWidth of the browser is available, use that
   return self.innerWidth ||
   // Otherwise, try to get the width off of the root node
   (de && de.clientWidth) ||
   // Finally, try to get the width off of the body element
   document.body.clientWidth;
}

// Get the actual height (using the computed CSS) of an element
function getActualHeight(element) {
   // Gets the computed CSS value and parses out a usable number
   return parseInt(getStyle(element, "height"));
}

// Get the actual width (using the computed CSS) of an element
function getActualWidth(element) {
   // Gets the computed CSS value and parses out a usable number
   return parseInt(getStyle(element, "width"));
}

// Returns the width of the web page
function getPageWidth() {
   //return document.body.scrollWidth;
   // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
   if (typeof window.innerWidth != 'undefined') {
      return window.innerWidth;
   }
   // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
   else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth !=
      'undefined' && document.documentElement.clientWidth != 0) {
      return document.documentElement.clientWidth;
   }
   // older versions of IE
   else {
      return document.getElementsByTagName('body')[0].clientWidth;
   }
}

// Returns the height of the web page
// (could change if new content is added to the page)
function getPageHeight() {
   //return document.body.scrollHeight;
   // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
   if (typeof window.innerWidth != 'undefined') {
      //alert('IE7 & other');
      return window.innerHeight;
   }
   // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
   else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth !=
      'undefined' && document.documentElement.clientWidth != 0) {
      //alert('IE6');
      //return document.documentElement.clientHeight;
      return document.getElementsByTagName('body')[0].clientHeight;
   }
   // older versions of IE
   else {
      //alert('IE5');
      return document.getElementsByTagName('body')[0].clientHeight;
   }
}

//--------------------------------------------------------------------------------------------------

// Set an opacity level for an element
// (where level is a number 0-100)
function setOpacity(element, level) {
   /*
   // If filters exist, then this is IE, so set the Alpha filter
   if (element.filters)
      element.filters.alpha.opacity = level;

   // Otherwise use the W3C opacity property
   else
      element.style.opacity = level / 100;
   */
   // Mozilla
   element.style.MozOpacity = level / 100;                // (floating number between 0 and 1)
   //IE uses
   element.style.filter     = 'alpha(opacity='+level+')'; // (integer number between 0 and 100)

}

// A function for enabling or disabling (using checkbox - element1) an element2
function control(element1, element2) {
   element2.disabled = !element1.checked;
}

// A function for showing (using display) an element
function show(element) {
   // Set the display property back to what it use to be, or use
   // block, if no previous display had been saved
   element.style.display = element.$oldDisplay || "block";
}

// A function for hiding (using display) an element
function hide(element) {
   // Find out what it's current display state is
   var curDisplay = getStyle(element, "display");

   //  Remember its display state for later
   if (curDisplay != "none")
      element.$oldDisplay = curDisplay;

   // Set the display to none (hiding the element)
   element.style.display = "none";
}

function fadeIn(element, to, speed) {
   // Start the opacity at  0
   setOpacity(element, 0);

   // Show the element (but you can see it, since the opacity is 0)
   show(element);

   // Were going to do a 20 frame animation that takes
   // place over one second
   for (var i = 0; i <= 100; i += 5) {
      // A closure to make sure that we have the right i
      (function(){
         var opacity = i;

         // Set the timeout to occur at the specified time in the future
         setTimeout(function(){

            // Set the new opacity of the element
            setOpacity(element, (opacity / 100) * to);

         }, (i + 1) * speed);
      })();
   }
}

function fadeOut(element, to, speed) {
   // Start the opacity at 1
   //setOpacity(element, 1);

   // Were going to do a 20 frame animation that takes
   // place over one second
   for (var i = 0; i < 100; i += 5) {
      // A closure to make sure that we have the right i
      (function(){
      		var opacity = i;

         // Set the timeout to occur at the specified time in the future
         setTimeout(function() {

            // Set the new opacity of the element
            setOpacity(element, 100 - opacity);

            if (opacity == 95)
               hide(element);

         }, (i + 1) * speed);
      })();
   }
}

//--------------------------------------------------------------------------------------------------

function setNext(element) {
   do {
      element = element.nextSibling;
   } while (element && element.nodeType != 1);
   return element;
}

function setPrev(element) {
   do {
      element = element.previousSibling;
   } while (element && element.nodeType != 1);
   return element;
}
