function mOver (theRow) {
  theRow.style.cursor = "hand";
  theRow.style.backgroundColor = "FFFFE0";
}

function mOut (theRow) {
  theRow.style.cursor = "";
  theRow.style.backgroundColor = "";
}

function rowClicked (theRow) {
  var teamId;

  //
  // EVENT ID (add/edit event or register for event)
  // 

  if (theRow.EVENT_ID != null) {
    if (document.getElementById("team") == null) {
      // add/edit event page
      window.location.href="event.php?action=e&event=" + theRow.EVENT_ID;
    } else {
      // event registration page
      // THIS IS PROBABLY OBSOLETE WITH THE registerForEvent() FUNCTION
      teamId = document.getElementById("team").value;
      if (teamId == "") {
        alert ("Please select a team to register members for.");
        return false;
      }
      window.location.href="eventRegistrationStep2.php?event=" +
                                       theRow.EVENT_ID + "&team=" + teamId;
    }
  }

  //
  // TEAM ID (add/edit team)
  //
  // SHOULD NOT BE REQUIRED WITH editTeam()
  if (theRow.TEAM_ID != null) {
    window.location.href="team.php?team=" + theRow.TEAM_ID;
  }

  //
  // TEAM MEMBER ID (add/edit team member)
  //
  // NOT REQUIRED WITH editTeamMember()
  if (theRow.TEAM_MEMBER_ID != null) {
    window.location.href="teamMember.php?action=e&teamMember=" + 
                                    theRow.TEAM_MEMBER_ID;
  }

  //
  // THIS IS PROBABLY FROM THE OLD EVENT REGISTRATION WHERE THE
  // TEAMS EXPANDED TO REGISTER ANY TEAM.  PROBABLY OBSOLETE.
  //

  if (theRow.id != null) {
    switch (theRow.id.substr(0, 12)) {
      case "TEAM_HEADER_" :
        teamId = theRow.id.substr(12, theRow.id.length - 12);
        teamDetailRow = document.getElementById("TEAM_DETAIL_" + teamId);
        if (teamDetailRow != null) {
          if (teamDetailRow.style.display == "") {
            teamDetailRow.style.display = "none";
          } else {
            teamDetailRow.style.display = "";
          }
        }
        break;
      case "TEAM_DETAIL_" :
        break;
    }
  }
}

function registerForEvent (eventId) {
  var teamId;
  teamId = document.getElementById("team").value;
  if (teamId == "") {
    alert ("Please select a team to register members for.");
    return false;
  }
  window.location.href="eventRegistrationStep2.php?event=" +
                                   eventId + "&team=" + teamId;
}

function editTeam (teamId) {
  window.location.href="team.php?team=" + teamId;
}

function editEvent (eventId) {
  window.location.href="event.php?action=e&event=" + eventId;
}

function editTeamMember (teamMemberId) {
  window.location.href="teamMember.php?action=e&teamMember=" + 
                                  teamMemberId;
}

function validateInfo_Team () {
  teamName=document.getElementById("teamName");
  teamCode=document.getElementById("teamCode");
  contactName=document.getElementById("contactName");
  contactPhone=document.getElementById("contactPhone");
  contactEmail=document.getElementById("contactEmail");
  if (teamName.value == "") {
    alert("Team name is required.");
    teamName.focus();
    return false;
  }
  if (teamCode.value == "") {
    alert("Team code is required.");
    teamCode.focus();
    return false;
  }
  if (contactName.value == "") {
    alert("Primary contact name is required.");
    contactName.focus();
    return false;
  }
  if (contactPhone.value == "") {
    alert("Primary contact phone is required.");
    contactPhone.focus();
    return false;
  }
  return true;
}

function validateInfo_TeamMember () {
  firstName=document.getElementById("firstName");
  lastName=document.getElementById("lastName");
  grade=document.getElementById("grade");
  expirationMM=document.getElementById("expirationMM");
  expirationYY=document.getElementById("expirationYY");
  if (firstName.value == "") {
    alert("First name is required.");
    firstName.focus();
    return false;
  }  if (lastName.value == "") {
    alert("Last name is required.");
    lastName.focus();
    return false;
  }
  if (expirationMM.value != "") {
    if (isNaN(expirationMM.value)) {
      alert("Expiration month must be a number.");
      expirationMM.focus();
      return false;
    }
    if (parseFloat(expirationMM.value) < 1 || parseFloat(expirationMM.value) > 12) {
      alert("Expiration month must be a number from 1 to 12.");
      expirationMM.focus();
      return false;
    }
  }
  if (grade.value == "") {
    alert("Grade is required.");
    grade.focus();
    return false;
  }
  return true;
}

function validateInfo_Event () {
  eventName=document.getElementById("eventName");
  eventDate=document.getElementById("date");
  section1=document.getElementById("section01");
  if (eventName.value == "") {
    alert("Name is required.");
    eventName.focus();
    return false;
  }
  if (eventDate.value == "") {
    alert("Date is required.");
    eventDate.focus();
    return false;
  }
  section1.value = allTrim(section1.value)
  if (section1.value == "") {
    alert("Registration section #1 must contain a value.");
    section1.focus();
    return false;
  }
  // enable all sections (01-13) so the values get posted
  document.getElementById('section01').disabled = false;
  document.getElementById('section02').disabled = false;
  document.getElementById('section03').disabled = false;
  document.getElementById('section04').disabled = false;
  document.getElementById('section05').disabled = false;
  document.getElementById('section06').disabled = false;
  document.getElementById('section07').disabled = false;
  document.getElementById('section08').disabled = false;
  document.getElementById('section09').disabled = false;
  document.getElementById('section10').disabled = false;
  document.getElementById('section11').disabled = false;
  document.getElementById('section12').disabled = false;
  document.getElementById('section13').disabled = false;
  return true;
}

function validateInfo_EventRegistration () {
  for (i = 0; i < document.frmEventRegistration.theCheckbox.length; i++) {
    if (document.frmEventRegistration.theCheckbox[i].checked) {
      if (document.frmEventRegistration.section[i].value == 0) {
        alert ("A section must be selected for each player registering for the event.");
        return false;
      }
    }
  }
  return true;
}

//----------------------------------------------------------------------------------

function leftTrim(sString) {
  while (sString.substring(0,1) == ' ') {
    sString = sString.substring(1, sString.length);
  }
  return sString;
}

function rightTrim(sString) {
  while (sString.substring(sString.length-1, sString.length) == ' ') {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}

function allTrim(sString) {
  while (sString.substring(0,1) == ' ') {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ') {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}