function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateTitle(theForm.title);
  reason += validateAccno(theForm.accno);
  reason += validateLocation(theForm.location);
  reason += checkDate(theForm.date);
      
  if (reason != "") {
    alert(reason);
    return false;
  }

  return true;
}

function validateTitle(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "Please enter a title for this item record.\n";
    } else if (fld.value.length < 3)  {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "Please enter a valid title (minimum length: 3 characters).\n";
    } else {
        fld.style.background = 'White';
        fld.style.border = '1px solid #555';
    }
    return error;
}

function validateAccno(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "Please provide the Accession Number for this item.\n";
    } else if (fld.value.length < 3)  {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "The Accession Number must be of the form \"A-1.\"\n";
    } else {
        fld.style.background = 'White';
        fld.style.border = '1px solid #555';

    }
    return error;
}

function validateLocation(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "Please provide the location for this item.\n";
    } else if (fld.value.length < 3)  {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "The location must be at least three characters in length.\n";
    } else {
        fld.style.background = 'White';
        fld.style.border = '1px solid #555';
    }
    return error;
}

/* The date is not required, but if entered, check format.
function checkDate(fld) {
 var error = "";
 var slashCount = 0;
 if (fld.value !="") {
 if (fld.value.length !=10)
 {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "The date field must have the format mm/dd/yyyy.\n";
 } 

 for(var j = 0; j < fld.value.length; j++)
 {
 var c = fld.value.charAt(j);

  if (c != '/' && (c < '0' || c > '9'))
  {
        fld.style.border = '1px solid #a81933';
        fld.style.background = '#f2f2f2'; 
        error = "The date field may contain only numbers and forward slashes.\n";
  }
 }
}
 return error;
}
*/

