//Match spaces at beginning and end of text and replace with null strings
function strtrim() 
{
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

//Match spaces at beginning of text and replace with a null string
function strltrim() 
{
    return this.replace(/^\s+/,'');
}

//Match spaces at end of text and replace with a null string
function strrtrim() 
{
    return this.replace(/\s+$/,'');
}

// Add the trimming functions to JavaScript's String object
String.prototype.trim = strtrim;
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;