var Validations = {
	isIntegerInRange: function (s, a, b) {
		if (this.isEmpty(s))
	    if (this.isIntegerInRange.arguments.length == 1) return false;
	    else return (this.isIntegerInRange.arguments[1] == true);

		// Catch non-integer strings to avoid creating a NaN below,
		// which isn't available on JavaScript 1.0 for Windows.
		if (!this.isInteger(s, false)) return false;

		// Now, explicitly change the type to integer via parseInt
		// so that the comparison code below will work both on
		// JavaScript 1.2 (which typechecks in equality comparisons)
		// and JavaScript 1.1 and before (which doesn't).
		var num = parseInt (s);
		return ((num >= a) && (num <= b));
  },

  isInteger: function (s){
    var i;

    if (this.isEmpty(s))
      if (this.isInteger.arguments.length == 1) return 0;
      else return (this.isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++) {
      var c = s.charAt(i);
      if (!this.isDigit(c)) return false;
    }

    return true;
  },

	isEmpty: function(s) {
    return ((s == null) || (s.length == 0))
  },

  isDigit: function(c) {
    return ((c >= "0") && (c <= "9"))
  },

	isSignedInteger: function (s) {
	  if (this.isEmpty(s))
      if (this.isSignedInteger.arguments.length == 1) return false;
      else return (this.isSignedInteger.arguments[1] == true);

      else {
         var startPos = 0;
         var secondArg = false;

         if (this.isSignedInteger.arguments.length > 1)
            secondArg = this.isSignedInteger.arguments[1];

         // skip leading + or -
         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
            startPos = 1;
         return (this.isInteger(s.substring(startPos, s.length), secondArg))
      }
   },

	isPositiveInteger: function (s) {
		var secondArg = false;

	if (this.isPositiveInteger.arguments.length > 1)
		secondArg = this.isPositiveInteger.arguments[1];

	// The next line is a bit byzantine.  What it means is:
	// a) s must be a signed integer, AND
	// b) one of the following must be true:
	//    i)  s is empty and we are supposed to return true for
	//        empty strings
	//    ii) this is a positive, not negative, number
	return (this.isSignedInteger(s, secondArg)
		&& ( (this.isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
  }
}
