// JavaScript Document

  function myvalidate(formToValidate)
  {
  
//  JB for this pattern, -1 is good, 0 >= is bad
    var pattern=/[^0-9]/;
    //var outstring = "";
    var returnVal = true;
               
    for(j = 0; j < formToValidate.elements.length; j++) 
    {
        var formElement = formToValidate.elements[j];  
        //var searchresult = formElement.value.search(pattern);
        if(formElement.value != "" && formElement.getAttribute("minimum") != null)
        {
            if(formElement.value.search(pattern) >= 0 || Number(formElement.value) < Number(formElement.getAttribute("minimum")))
            {
                formElement.className = "invalid"
                formElement.onchange = validateOnChange;
                returnVal = false;
                var searchresult = formElement.value.search(pattern);
                var minimum = formElement.getAttribute("minimum");
                //outstring = outstring + '<' + formElement.name + '> : ' + formElement.value + ' : ' + searchresult + ' : ' + minimum + "\n";
            }
        }  
    }
    
    if(returnVal == false)
      alert("You have entered an invalid quantity.");
      //alert(outstring);

    return returnVal;
}

  function validateOnChange() 
  {
        var textfield = this;                            // the textfield
        //  JB for this pattern, -1 is good, 0 >= is bad
        var pattern=/[^0-9]/;
        var value = this.value;                          // the user's input

        if (value != "" && (value.search(pattern) >= 0  || Number(value) < Number(textfield.getAttribute("minimum"))) ) 
          textfield.className = "invalid";
        else 
          textfield.className = "valid";
  }

