// JavaScript stuff for St John's Lay Clerks application.


// Sets the CSS class of the parent of the specified element to
// its value.
function setParentClass(elt) {
  elt.parentNode.className = elt.value;
}

// Compares the newPassword and newPasswordAgain values to ensure they
// have at least 4 characters and are the same as each other.
function checkPassword(frm) {
  var newPass = frm["newPassword"];
  var newPassAgain = frm["newPasswordAgain"];
  if (newPass.value != newPassAgain.value) {
    alert("Sorry, your two passwords do not match. Please re-enter them.");
    newPass.value = "";
    newPassAgain.value = "";
    newPass.focus();
    return false;
  }
  // Ignore empty passwords because they will not be set.
  if (newPass.value.length > 0 && newPass.value.length < 4) {
    alert("Sorry, your new password is too short. It must be at least 4 characters long. Please try again.");
    newPass.value = "";
    newPassAgain.value = "";
    newPass.focus();
    return false;
  }
  return true;
}

// Sanity check on singer details, including password.
function checkSinger(frm) {
  var username = frm["username"];
  if (username.value == "new") {
    alert("A singer cannot have the username ‘new’. Please create a different one.");
    username.focus();
    return false;
  }
  return checkPassword(frm);
}

function showDetails(serviceId) {
  var details = document.getElementById("svc_" + serviceId);
  details.style.top = mouseY - 10;
  details.style.left = mouseX + 30;
  details.style.visibility = "visible";
}

function hideDetails(serviceId) {
  document.getElementById("svc_" + serviceId).style.visibility = "hidden";
}

// Simple browser detection.
var IE = document.all ? true : false;

// If NS -- that is, !IE -- then set up for mouse capture
//if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Variables to hold mouse x-y positions.
var mouseX = 0;
var mouseY = 0;

// Function to retrieve mouse x-y positions.
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft;
    mouseY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX;
    mouseY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0;}
  if (mouseY < 0){mouseY = 0;}
  return true;
}

