///***********************************************************************/
// functions for handling validation of forms involving reviews of submissions

///***********************************************************************/
// functions defined are:
//    cleanString (theField)
//    checkNumeric (theField, str, showPopUp)
//    checkButtonMarked(collection)

///***********************************************************************/
//Trim leading and trailing blanks from input strings.

function cleanString(theField)
{
   var count1 = 0;
   var count2 = 0;

   //Count the number of leading blanks.
      while ((count1 < theField.value.length) && (theField.value.charAt(count1) == " "))
         {
            count1++;
         }

   //Make a substring testString1 which excludes the leading blanks.    
      theField.value = theField.value.substring(count1, theField.value.length);

   //Determine the number of trailing blanks.
      count2 = theField.value.length-1;
      while ((count1 >= 0)&& (theField.value.charAt(count2) == " "))
         {
            count2--;
         }

   //Make another substring testString2 which excludes the trailing blanks.
      theField.value = theField.value.substring(0, count2+1);
}


///***********************************************************************   
//Check if the string is numeric 
function checkNumeric(theField, str, showPopUp)					
{
   var testString = theField.value;

   if (testString.length < 1)
   {
       if (showPopUp) 
          {
            alert("Invalid entry.  The " + str + " field must be non-empty and contain only numeric characters.");
            theField.focus();
          }
       return false;
   }

   for (i=0; i < testString.length;  i++)
   {
       if ((testString.charAt(i) >= "0") && (testString.charAt(i)<= "9"))
          {
                
           }
       else
           {
              if (showPopUp) 
              {
                  alert("Invalid entry.  The " + str + " field must contain only numeric characters.");
                  theField.focus();
              }
              theField.value = "";
              return false;
           }
    }
    return true;
}

///***********************************************************************/
// This function checks that some button has been marked
function checkButtonMarked(collection){
  var i;

  for (i=0;i < collection.length;i++) {
     if (collection[i].checked){
        return true;
     }
  }
  return false;
}

