// JavaScript Document
function setColor(thisFld) {
  thisFld.style.backgroundColor = '#FFFF99';
  thisFld.style.borderColor = 'red';
}

function unsetColor(thisFld) {
  thisFld.style.backgroundColor = '';
  thisFld.style.borderColor = '';
}

function intOnFocus(numFld) {
  setColor(numFld);
  window.status = "Please enter integer numbers 0 thru 9 only ";
  n = parseInt(numFld.value);
  numFld.value = n;
  numFld.select();
}

function intOnBlur(numFld) {
  unsetColor (numFld);
  var n = numFld.value;
  if ( n == "" ) {    // if field is blank then make zero
    n = 0;
  }
  if ( isNaN (n) ) {
    alert ("This is an integer field only numbers 0 thru 9");
    numFld.focus();
    numFld.select();
  } else {
    n = parseInt(n);
    doCalc();
  }
  numFld.value = n.toFixed(0);
  window.status = "";
}

function numOnFocus(numFld) {
  setColor(numFld);
  window.status = "Please enter numeric values only";
  var regExp = /\,/g;
  var n = numFld.value.replace (regExp, "");
  n = parseFloat(n);
  numFld.value = n;
  numFld.select();
}

function numOnBlur(numFld) {
  unsetColor(numFld);
  var n = numFld.value;
  if ( n == "" ) {    // if field is blank then make zero
    n = 0;
  }
  if ( isNaN (n) ) {
    alert ("Please enter a numeric values only!");
    numFld.focus();
    numFld.select();
  } else {
    n = parseFloat(n);
    doCalc();
  }
  numFld.value = n.toFixed(2);
  window.status = "";
}

function dateOnFocus(dateFld) {
  setColor(dateFld);
  window.status = "Enter a valid date in the format YYYY-MM-DD";
  dateFld.select();
}

function dateOnBlur(dateFld) {
  unsetColor(dateFld);
  fld = dateFld.value;
  var regExp = /\.+/g;
  fld = fld.replace (regExp, "-");
  dateFld.value = fld;
  fld = validateDate(fld, "J", "A") ;
  if (!fld) {
    alert ("You have entered and invalid date\n" +
           "Please use the format YYYY-MM-DD");
    dateFld.focus();
    dateFld.select();
  }

  window.status = "";
}
