var whitespace = " \t\n\r";
var defaultEmptyOK = false;

function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

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;
}

function validEmail(email) {
	invalidChars = " /:,;"
	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) != -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	dblperiodPos = email.indexOf("..",1)
	if (dblperiodPos != -1) {
		return false
	}
	return true
}

function isLetter (c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")))
}

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

function isPoint (c) {
	return (c == ".")
}

function isComma (c) {
	return (c == ",")
}

function isAlphanumeric (s) {
	var i;
    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

function isInteger (s) {
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isIntegerOrX (s) {
	var i;
    if (isEmpty(s)) 
       if (isIntegerOrX.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerOrX.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c) && c != 'x' && c != 'X') return false;
    }

    // All characters are numbers.
    return true;
}

function isIntegerOrComma (s) {
	var i;
    if (isEmpty(s)) 
       if (isIntegerOrComma.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerOrComma.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c) && !isComma(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isCurrency(s) {
	var i;
    if (isEmpty(s)) 
       if (isCurrency.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if ((!isDigit(c)) && !(isPoint(c))) return false;
    }

    return true;
}

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isLength(s,lent) {
	return (s.length == lent);
}

function isLonger(s,lent) {
	if (s.length > lent)
		return true;
	else
		return false;
}

function isShorter(s,lent) {
	if (s.length < lent)
		return true;
	else
		return false;
}

function isWhiteOrInt(s) {
	if ((isWhitespace(s)) || (!isInteger(s)))
		return true;
	else
		return false;
}

function isWhiteOrCurrency(s) {
	if ((isWhitespace(s)) || (isCurrency(s)))
		return true;
	else
		return false;
}

function isOnlyInt(s) {
	if (!isWhitespace(s))
		if (!isInteger(s))
			return true;
		else
			return false;
}