var whitespace = " \t\n\r";
// Returns true if string "s" is empty.
function isEmpty(s)
{
return ((s == null) || (s.length == 0));
}
// Returns true if string "s" contains only whitespace characters.
function isWhitespace(s)
{
var i;
if (isEmpty(s)) return true;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1) return false;
}
return true;
}
// Returns true if character "c" is empty.
function isDigit(c)
{
return ((c >= "0") && (c <= "9"));
}
// Returns true if string "s" contains only numbers.
function isInteger(s)
{
var i;
if (isEmpty(s)) return true;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (!isDigit(c)) return false;
}
return true;
}
// Returns true if string "s" is in the range "min" and "max".
function isIntegerInRange(s, min, max)
{
if (isEmpty(s)) return true;
if (!isInteger(s)) return false;
var num = parseInt(s, 10);
return ((num >= min) && (num <= max));
}
// strips leading and trailing whitespace from a string
function trimWhitespace(s)
{
  var i, j;
if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
{
    i = s.length - 1;
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
{
i--;
}
s = s.substring(0, i+1);
}
if (whitespace.indexOf(s.charAt(0)) != -1)
{
    j = 0; i = s.length;
while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
{
j++;
}
s = s.substring(j, i);
}
return s;
}

