
 /* ************************************************************* 
	Stenstrom.Net.String.js
	extends the _JavaScript STRING object with additional 
	functionality.

	Version 	: 1.1
	Release	: 8.01a
 /* ************************************************************* */

// string.trim()
    String.prototype.trim = function()
    {   
		return this.replace(/(^\s*)|(\s*$)/g, "");
    }
	
// string.ltrim()    
    String.prototype.ltrim = function()
    {
		return this.replace(/(^\s*)/g, "");
    }   
  
// string.rtrim()    
    String.prototype.rtrim = function()
    {
		return this.replace(/(\s*$)/g, "");
    }  
   

// string.isEmpty()    
    String.prototype.isEmpty = function()
    {
		if("undefined" == typeof(this))
			return(true);
			
		if( undefined == this)
			return(true);
			
		if(null == this)
			return(true);      
			  
		var sValue = this.trim();

		if(sValue.length > 0)
			return(false);
		else
			return(true);
    }     

    
// string.isPhone()
    String.prototype.isPhone = function()
    {
        var pattern = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
        return( this.trim().match(pattern) );
    }  
    
// string.isZipCode()
    String.prototype.isZipCode = function()
    {
        var pattern = /^\d{5}(-\d{4})?$/;
        return( this.trim().match(pattern) );
    }    
    
// string.isEmail()
    String.prototype.isEmail = function()
    {
        var pattern = /^([\w-]+\.)*?[\w-]+@[\w-]+\.([\w-]+\.)*?[\w]+$/;
        return( this.trim().match(pattern) ) ;
    }    
    
// string.isURL()
    String.prototype.isURL = function()
    {
        var pattern = /^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU|UK|INFO|US|NAME|BIZ|DE|TV|CC|BZ)$/;
        return( this.trim().match(pattern) );
    }    
    
// string.toHTML
    String.prototype.toHTML = function()
	{
		var result	= null;
		var pattern 	= /\n/g;
		result 		= this.replace(pattern, "<br/>");
		
		pattern		= /\r/g;
		result 		= result.replace(pattern, "<br/>");
		
		return(result);
	}

// string isNumeric
	String.prototype.isNumeric	= function()
	{
        var pattern = /^0$|^[1-9][0-9]*$|^[1-9][0-9]{0,2}(,[0-9]{3})$/;
        return( this.trim().match(pattern) );
	}
	
 /* ************************************************************* 
	Stenstrom.Net.Math.js
	extends the _JavaScript MATH object with additional 
	functionality.

	Version 	: 1.1
	Release	: 8.01a
 /* ************************************************************* */
// Math.FormatAsUSD
	Math.FormatAsUSD	= function( num ){
	
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
			num = "0";
			
		sign 	= (num == (num = Math.abs(num)));
		num 		= Math.floor(num*100+0.50000000001);
		cents 	= num%100;
		num 		= Math.floor(num/100).toString();
		if(cents<10)
			cents = "0" + cents;
			
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
	
/*  METHOD : isBetween(numToTest, lowNum, highNum)
	PARM : numToTest 	: the number being tested
	PARM : lowNum		: the lower boundary of the test range
	PARM : highNum		: the upper boundary of the test range
	
	RETURN : boolean 
		TRUE  - the number being tested DID occur within the specified range
		FALSE - the number being tested did NOT occur within the specified range

	Tests a number to see if it falls within a range defined by the High and Low 
	num parameters.
	
	EXAMPLE :
		Math.isBetween(5, 1, 7)  -- returns TRUE 
		Math.isBetween(5, 7, 10) -- returns FALSE
	
*/
	Math.isBetween = function(numToTest, lowNum, highNum)
	{
		if(numToTest < lowNum)
			return false;
		if(numToTest > highNum)
			return false;
		
		return true;
	}
	
	
	