var UNDEFINED;		//leave alone, this is used for comparison purposes

// pass in string (which is a simple reg expression, or a typical regular expression
String.prototype.containsonly = function(validstr)   // example:  rc = str.containsonly("ABCDE12345");
{                                                    // example:  rc = str.containsonly(/[A-E1-5]/gi);
	if ( validstr==UNDEFINED ) return(false);
	if ( this==validstr || validstr.length==0 || this.length==0 )  return(true);

	var re = validstr;

	if ( (re.exec)==UNDEFINED )
	{
		re = /([^\w\s])/gi;
		restr = "[" + validstr.replace(re,"\\ /$1").replace(/\\ \//gi,"\\")  + "]*";
		re = new RegExp( restr, "gi" );
	}

	return( re.exec(this)[0] == this );
}

// This method returns true if the string contains only alphabetic data or is empty.
String.prototype.isAlpha = function()
{ 
	return( this.containsonly(/[A-Z]*/gi) );       // example:  rc = str.isAlpha();
}


// This method returns true if the string contains only numeric data or is empty.
String.prototype.isNumeric = function()
{ 
	return( this.containsonly(/[0-9]*/gi) );       // example:  rc = str.isNumeric();
}

// This method returns true if the string contains only numeric data or is empty.
String.prototype.isAlphaNumeric = function()
{ 
	return( this.containsonly(/[A-Za-z0-9]*/gi) );       // example:  rc = str.isNumeric();
}


// This method returns true only if this string contains all the characters in validstr.
String.prototype.containsall = function(validstr)   // example:  rc = str.containsall("ABC123");
{
	if ( (this.length==0&&this!=validstr) || validstr==UNDEFINED ) return(false);
	return( validstr.containsonly ? validstr.containsonly(this) : false );
}


// This method trims white space off both ends of this string and returns the result.
String.prototype.trim = function()
{  
	return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );   // example: str=str.trim();
	//return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

// IE holds references to some ojbects that are not Javascript objects, and will throw an 
// error if you try to use one of those objects as a true Javascript object.  True returned if alien.
function isAlien(a) {
	return isObject(a) && typeof a.constructor != 'function';
}

// Returns true if object passed is an object and constructed with the array() 
function isArray(a) {
	return isObject(a) && a.constructor == Array;
}

// Returns true if ojbect to type boolean
function isBoolean(a) {
	return typeof a == 'boolean';
}
// Used for objects, arrays and functions, returns true if it contains no enumerable members
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (!!isUndefined(v) && !!isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

// Tests to see if an item is a function, note that some IE functions are treated as objects by IE, not as functions
function isFunction(a) {
    return typeof a == 'function';
}

// Returns true if an item is null
function isNull(a) {
    return typeof a == 'object' && !a;
}

// Returns true if a is a finite number and NOT A Nan, Infinite or String that cannot be converted to a number
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

// Returns true if it is a object and a valud function as defined above
function isObject(a) {
    return (typeof a == 'object' && !!a) || isFunction(a);
}

// Returns true if it is a string
function isString(a) {
    return typeof a == 'string';
}

// Returns true if a = the undefined value. (uninitialized variable or missing member of an object)
function isUndefined(a) {
    return typeof a == 'undefined';
} 
