function StringHelper()
{

}

StringHelper.trim = function(stringToTrim) 
    {
        return stringToTrim.replace(/^\s+|\s+$/g,"");
    }
StringHelper.ltrim = function(stringToTrim) 
    {
        return stringToTrim.replace(/^\s+/,"");
    }

StringHelper.rtrim = function(stringToTrim) 
    {
        return stringToTrim.replace(/\s+$/,"");
    }
    
// Returns the left x characters of the string
StringHelper.left = function(str, count) 
    {
		if (str.length>count) {
            return str.substring(0, count);
		} else {
            return str;
		}
    }

// Returns the right x characters of the string
StringHelper.right = function(str, count) 
    {
		if (str.length>count) {
            return str.substring(str.length-count, str.length);
		} else {
            return str;
		}
    }

    
    
StringHelper.shorten = function(str, maxLength) 
    {
        var result;
        var preferredSize;
    
		if (!str) {
            result = null;
        } else if (str.length > maxLength) {
            preferredSize = maxLength - ('...'.length);
            
            if (preferredSize>0) {
                result = StringHelper.left(str, preferredSize) + '...';
            } else {
                result = StringHelper.left(str, maxLength);
            }
        } else {
            result = str;
        }
        
        return result;
    }
    
StringHelper.addSlashes = function(str) 
    {
		str=str.replace(/\'/g,'\\\'');
		str=str.replace(/\"/g,'\\"');
		str=str.replace(/\\/g,'\\\\');
		str=str.replace(/\0/g,'\\0');
		return str;
    }
    
StringHelper.stripSlashes = function(str) 
    {
		str=str.replace(/\\'/g,'\'');
		str=str.replace(/\\"/g,'"');
		str=str.replace(/\\\\/g,'\\');
		str=str.replace(/\\0/g,'\0');
		return str;
	}
	

StringHelper.htmlSpecialChars = function htmlspecialchars(p_string) 
    {
		p_string = p_string.replace(/&/g, '&amp;');
		p_string = p_string.replace(/</g, '&lt;');
		p_string = p_string.replace(/>/g, '&gt;');
		p_string = p_string.replace(/"/g, '&quot;');
		//p_string = p_string.replace(/'/g, '&#039;');
		return p_string;
	}
	
