// Whitespace characters
var whitespace = " \t\n\r";

// Allowed input characters
var allowed = " _-,.@";


// isEmpty: string -> bool
// Returns true if str is an empty string and false otherwise
//
function isEmpty( str ) {
	return( (str == null) || (str.length == 0) );
}


// isWhitespace: string -> bool
// Returns true if str contains whitespace and false otherwise
//
function isWhitespace( str ) {
	for( var i = 0; i < str.length; i++ ) {
		if( whitespace.indexOf( str.charAt( i ) ) != -1 ) {
			return( true );
		}
	}

	return( false );
}


// isAlpha: string -> bool
// Returns true if str is alphabetic and false otherwise
//
function isAlpha( str ) {
	var str = str.toLowerCase( );

	for( var i = 0; i < str.length; i++ ) {
		var chr = str.charAt( i );

		if( !((chr >= 'a') && (chr <= 'z')) ) {
			return( false );
		}
	}

	return( true );
}


// isInput: string -> bool
// Returns true if str is a valid input and false otherwise
//
function isInput( str ) {
	var str = str.toLowerCase( );

	for( var i = 0; i < str.length; i++ ) {
	    var chr = str.charAt( i );

	    if( !((chr >= '0') && (chr <= '9')) && !((chr >= 'a') && (chr <= 'z')) && (allowed.indexOf( chr ) == -1) ) {
		return( false );
	    }
	}

	return( true );
    }


// isNumeric: string -> bool
// Returns true if str is alphanumeric and false otherwise
//
function isAlphaNumeric( str ) {
	var str = str.toLowerCase( );

	for( var i = 0; i < str.length; i++ ) {
		var chr = str.charAt( i );

		if( !((chr >= '0') && (chr <= '9')) && !((chr >= 'a') && (chr <= 'z'))) {
			return( false );
		}
	}

	return( true );
}


// isNumeric: string -> bool
// Returns true if str is numeric and false otherwise
//
function isNumeric( str ) {
	var str = str.toLowerCase( );

	for( var i = 0; i < str.length; i++ ) {
		var chr = str.charAt( i );

		if( !((chr >= '0') && (chr <= '9')) ) {
			return( false );
		}
	}

	return( true );
}


// isFloat: string -> boolean
// Returns true if str is a real number and false otherwise
//
function isFloat( str ) {
	var decpovar = false;

	if( str.charAt( 0 ) == '-' ) {
		str = str.substring( 1, (str.length - 1) );
	}

	for( var i = 0; i < str.length; i++ ) {
		var chr = str.charAt( i );

		if( (chr == '.') && (!decpovar) ) {
			decpovar = true;

		} else if( !((chr >= '0') && (chr <= '9')) ) {
			return( false );
		}
	}

	return( true );
}


// isInteger: string -> boolean
// Returns true if str an integer and false otherwise
//
function isInteger( str ) {
	if( str.charAt( 0 ) == '-' ) {
		str = str.substring( 1, (str.length - 1) );
	}

	return( isNumeric( str ) );
}


// isPosInteger: string -> boolean
// Returns true if str is a positive integer and false otherwise
//
function isPosInteger( str ) {
	return( isNumeric( str ) );
}


// isEmail: string -> bool
// Returns true if str is a valid email address and false otherwise
//
function isEmail( str ) {
	var length = str.length;

	if( isWhitespace( str ) || !isInput( str ) ) {
		return( false );
	}

	var at = str.indexOf( "@" );

	if( at != -1 ) {
		var sub = str.substr( (at + 1), (length - at) );

		if( sub.indexOf( "@" ) >= 0 ) return( false );

		var dot = str.lastIndexOf( "." );

		if( (at > 0) && (dot != -1) && (dot > (at + 1)) && ((dot = (length - 2)) || (dot = (length - 3)) || (dot = (length - 4))) ) {
			return( true );

		} else {
			return( false );
		}

	} else {
		return( false );
	}
}
