/* VERIFY.JS - Validation Library
** ============================================
**
** This library contains functions for validating
** the fields of the form.
*/

function isTextBoxValid(str)  // is text-box str valid?
  {
  if (isBlank(str) || str.indexOf("|") != -1)  // no - blank and/or |s
    return false;
  else                        // yes
    return true;
  }

function isListBoxValid(num)  // is list-box num valid?
  {
  if (num == 0)               // no - blank (first) item selected
    return false;
  else                        // yes - nonblank item selected
  return true;
  }

function isEMailValid(str)                   // is email str valid?
  {
  if (isBlank(str) || str.indexOf("|") != -1)  // no - blank and/or |s
    {
    return false
    }
  var atsignPos = str.indexOf("@", 0)        // check for @
  if (atsignPos == -1)	                     // no - @ missing
    {
    return false
    }
  if (str.indexOf(".", atsignPos) == -1)     // no - . after @ missing
    {
    return false
    }
  return true                                // yes
  }

function isBlank(str)              // is str blank?
  {
  if (str.length == 0)             // yes - nothing entered
    return true
  for (i=0; i<=str.length-1; i++)  // yes - all spaces
    if (str.charAt(i) != " ")
      return false
  return true                      // no
  }
  
 function isRadioValid(arr)			// are there one checked?
 {
 for (i=0; i<=arr.length-1; i++){		
  if (arr[i].checked){		         // this is checked
     return true		  			// yes
  }
 }
 return false;						// none so no
 }
 
 function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isNumber (s)
{   var i;
    var dotAppeared;
    dotAppeared = false;

    if (isBlank(s)) 
	return false;
     
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c)) return false;
        } else { 
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

