function addEvent(func, event, obj)
{
  if(obj.addEventListener) {
    obj.addEventListener(event, func, false);}
  else if(obj.attachEvent)
  {
    var ieFunc = function() {
      func.call(obj);}
    obj.attachEvent("on" + event, ieFunc);
  }
}



// Add onfocus/onblur to inputs and selects.
// Onfocus display tip (if exists), and make right text invisible.
// Onblur hide tip, and make right text visible.
function addBubbles()
{
  var inputList = document.getElementsByTagName("input");
  var selectList = document.getElementsByTagName("select");
  // Loop through inputs
  for(var i = 0; i < inputList.length; i++)
  {
    if(inputList[i].parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("div")[0])
    {
      addEvent(function() {
        this.parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("div")[0].getElementsByTagName("div")[0].style.display = 'block';
        document.getElementById('welcometext').style.display = 'none';},
      'focus', inputList[i]);

      addEvent(function() {
        this.parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("div")[0].getElementsByTagName("div")[0].style.display = 'none';
        document.getElementById('welcometext').style.display = 'block';},
      'blur', inputList[i]);
    }
  }
  // Loop through selects
  for(var i = 0; i < selectList.length; i++)
  {
    if(selectList[i].parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("div")[0])
    {
      addEvent(function() {
        this.parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("div")[0].getElementsByTagName("div")[0].style.display = 'block';
        document.getElementById('welcometext').style.display = 'none';},
      'focus', selectList[i]);

      addEvent(function() {
        this.parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("div")[0].getElementsByTagName("div")[0].style.display = 'none';
        document.getElementById('welcometext').style.display = 'block';},
      'blur', selectList[i]);
    }
  }
}



// Add onfocus/onblur to textboxes.
// Onfocus change class to highlight class.
// Onblur change class back to original.
function addHighlight()
{
  var inputList = document.getElementsByTagName("input");
  for(var i = 0; i < inputList.length; i++)
  {
    if(inputList[i].type == 'text')
    {
      addEvent(function() {
        this.old = this.className;
        this.className = 'inputText2';},
      'focus', inputList[i]);

      addEvent(function() {
        this.className = this.old;},
      'blur', inputList[i]);
    }
  }
}



// Add onmousedown to labels.
// Onmousedown give focus to the input the label is for.
function addLabel()
{
  var labelList = document.getElementsByTagName("label");
  for(var i = 0; i < labelList.length; i++)
  {
    if(labelList[i].htmlFor)
    {
      addEvent(function(e) {
        if(e && e.stopPropagation) {
          e.stopPropagation();
          e.preventDefault();}
        else {
          window.event.cancelBubble = true;
          window.event.returnValue = false;}
        document.getElementById(this.htmlFor).focus()},
      'mousedown', labelList[i]);
    }
  }
}



// Add Bubble pop-ups, Hightlight, and Label mousedown effects on page load.
addEvent(addBubbles, 'load', window);
addEvent(addHighlight, 'load', window);
addEvent(addLabel, 'load', window);
