function initForm()
{		
    var selects = document.getElementsByTagName('select');
    for (var i=0; i<selects.length; i++) {
      addEvent(selects[i], 'change', selectChanged);
      toggleExtra(selects[i]);
    }
    
    var helpSpans = document.getElementsByClassName('help');
    for (var i=0; i<helpSpans.length; i++) {
      var helpLink = document.createElement('a');
      helpLink.appendChild(document.createTextNode('?'));
      helpLink.setAttribute('href','javascript:void(0);');
      
      helpSpans[i].setAttribute('helptext',helpSpans[i].innerHTML);      
      helpSpans[i].innerHTML = '';
      helpSpans[i].appendChild(helpLink);
      
      addEvent(helpLink, 'click', helpClick);
    }
}

addEvent(window, 'load', initForm, false);

function helpClick(e) {		
  var target = getTarget(e);
  var helpSpan = target.parentNode;

  helpSpan.innerHTML = helpSpan.getAttribute('helptext');
}

function selectChanged(e) {	
  toggleExtra(getTarget(e));
}

function toggleExtra(e) {	 
  // If we are using master pages we need to trim off the start of the ID up to the last underscore
  var id = e.id.substring(e.id.lastIndexOf('_') + 1) + 'Extra';

  if ($(id)) {
    // There is an 'Extra' option
    if (e.selectedIndex == e.length - 1) {
      $(id).className = 'show';
    } else {
      $(id).className = 'hide';
    }
  }
}
  