
function verify(f) {
  var msg;
  var empty_fields = "";
  var errors = "";
  for(var i = 0; i < f.length; i++) {
    var e = f.elements[i];
    if ((e.type == "text") || (e.type == "file") || (e.type == "textarea") || (e.type == "password") || (e.type == "select-one") ) {
      if (((e.value == null) || (e.value == "") || isblank(e.value)) && e.required == "Y" && e.reqlabel !=null ) {
        empty_fields += "\n          " + e.reqlabel;
        continue;
      }
      if ((e.numeric == "Y" || (e.min != null) || (e.max != null)) && (e.value.length > 0) ) { 
        var v = parseFloat(e.value);
        if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
          errors += "- The field " + e.reqlabel + " must be a number";
          if (e.min != null) 
            errors += " that is greater than " + e.min;
          if (e.max != null && e.min != null) 
            errors += " and less than " + e.max;
          else if (e.max != null)
            errors += " that is less than " + e.max;
          errors += ".\n";
        }
      }
    }
    if (e.type == "select-multiple" && e.required == "Y") {
      var iCount = 0;
      for (var j=0; j < e.length; j++) {
        var o = e.options[j];
        if ( (o.selected == true) && !(o.value == null) && !(o.value == "") ) {
           iCount++;
        }
      }
      if (iCount == 0) {
        empty_fields += "\n          " + e.reqlabel;
      }
    }
  }
  if (!empty_fields && !errors) return true;
  msg  = "______________________________________________________\n\n"
  msg += "The form was not submitted because of the following error(s).\n";
  msg += "Please correct these error(s) and re-submit.\n";
  msg += "______________________________________________________\n\n"
  if (empty_fields) {
    msg += "- The following required field(s) are empty:" 
           + empty_fields + "\n";
    if (errors) msg += "\n";
  }
  msg += errors;
  alert(msg);
  return false;
}

function isblank(s) { for(var i = 0; i < s.length; i++) { var c = s.charAt(i); if ((c != ' ') && (c != '\n') && (c != '\t')) return false; } return true; }

function keypressMaxLength(e) {if(e.value.length > parseInt(e.maxlength)-1){ event.returnValue = false; }}
function keypressUpper() { var vchar = String.fromCharCode(event.keyCode); var vupper = vchar.toUpperCase(); event.keyCode = vupper.charCodeAt(0); }
function keypressAlphaNum() { var vchar = String.fromCharCode(event.keyCode); var vupper = vchar.toUpperCase(); var vvalid = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890-,;:.!@#$%^&*()_+=|"; var vpos = vvalid.indexOf(vupper); if(vpos < 0) { event.returnValue = false; } }
function keypressAlphaNum2(){ var vchar = String.fromCharCode(event.keyCode); var vupper = vchar.toUpperCase(); var vvalid = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_"; var vpos = vvalid.indexOf(vupper); if(vpos < 0) {event.returnValue = false;} }
function swapValues(e1, e2) { var e1value = e1.value; var e2value = e2.value; e1.value = e2value; e2.value = e1value; e2.focus(); }

function GetImage(src) {var image = new Image(); image.src = src; return image;}
function GetImageSrc(imageArray, index) {return(imageArray[index].src)}
function GetRandomIndex(low, high) {var range = high - low + 1; return Math.floor(Math.random() * range) + low;}
function GetNextIndex(current, total) {return (current + 1) % total;}


