/*
 * <form> related functions used in Schedule and Choral Society pages.
 * the signUp element itself is built by the xsl file.
 */

function showForm() {
  document.getElementById("signUp").style.display = 'block';
  if (document.getElementById("iContent"))
    document.getElementById("iContent").style.visibility = 'hidden';
}
function closeForm() {
  document.mailForm.reset();
  document.getElementById("signUp").style.display = 'none';
  if (document.getElementById("iContent"))
    document.getElementById("iContent").style.visibility = 'visible';
}
function showModify(cn) {
  message = document.mailForm.getElementsByTagName("p")[0];
  message.innerHTML = "Yes! I plan to sing the "
    +cn +" with the Choral Society";
  document.mailForm.CC_mailList.value = cn;
  showForm();
}


/*
 * Utilities for  Clear Default Text Input
 */

function addEvent(element, eventType, handler, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, handler, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, handler);
        return r;
    } else {
        return false;
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
	target.style.color="#500";
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
	target.style.color="#aaa";
    }
}

function setInputHandlers() {
  var formInputs = document.getElementsByTagName('input');
  for (var i = 0; i < formInputs.length; i++) {
    var theInput = formInputs[i];
        
    if (theInput.type == 'text' && theInput.className.match(/\bclearDefault\b/)) {
    //    on the other hand, why not just test for a default value
    //if (theInput.type == 'text' && theInput.value.length >0) {
    //  alert("found: "+theInput.value);
      /* Add event handlers */          
      addEvent(theInput, 'focus', clearDefaultText, false);
      addEvent(theInput, 'blur', replaceDefaultText, false);
      theInput.style.color="#aaa";
      
      /* Save the current value */
      //      if (theInput.value != '') {
      if (theInput.value != '') {
	theInput.defaultText = theInput.value;
      }
    }
  }
}

