/**
 * Trims leading whitespace.
 *
 * @return (String) str
 */
String.prototype.ltrim = function() {
	return this.replace(/\s*((\S+\s*)*)/, "$1");
}

/**
 * Trims trailing whitespace.
 *
 * @return (String) str
 */
String.prototype.rtrim = function() {
	return this.replace(/((\s*\S+)*)\s*/, "$1");
}

/**
 * Trims leading and trailing whitespace.
 *
 * @return (String) str
 */
String.prototype.trim = function() {
	return this.ltrim().rtrim();
}

/**
 * Checks if string is a numeric value.
 *
 * @return (boolean) isNumeric
 */
String.prototype.isNumeric = function() {
	var isNumeric = true;
    var valid_chars = "0123456789.,-";
    if (typeof(this) == 'undefined' || this.length < 1) {
		isNumeric = false;
    } else {
	    for (var i=0; i<this.length; i++) {
	        if (valid_chars.indexOf(this.charAt(i)) == -1) {
				isNumeric = false;
				break;
	        }
	    }
    }
	return isNumeric;
}

/**
 * Checks if string is an integer value.
 *
 * @return (boolean) inInteger
 */
String.prototype.isInt = function() {
	var isInt = true;
    var inStr = this;
	inStr = inStr.replace(",","");
    if (inStr.indexOf(".")!=-1 || isNaN(inStr)) {
		isInt = false;
    }
    return isInt;
}

/**
 * Pads left of string to required length with passed string (char sequence).
 *
 *  @param (int) toLength
 *  @param (String) padStr
 *  @return (String) outStr
 */
String.prototype.strPadLeft = function(toLength, padStr) {
    var outStr = this;
    while (outStr.length < toLength) {
        outStr = padStr + toPad;
    }
    return outStr;
}

