// *********************************************** //
// ** STRING PROTOTYPES
// ** extends the _JavaScript STRING object with
// ** additional functionality
// ********************************************** //

// 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(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);
	}

