﻿if(!String) {
    var String = {};
}

String.Numeric = function(number, decimalPlaces) {
    decimalPlaces = decimalPlaces || 0;
    var n = Math.round(number);
    if(decimalPlaces > 0) {
        n = Math.round(number * (10 * decimalPlaces)) / (10 * decimalPlaces);
    }
    
    var nStr = n + '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
};

String.Format = function() {
    var s = "";
    if(arguments.length > 0) {
        s = arguments[0];
        for(var i = 0; i < arguments.length - 1; i++) {
            s = s.replace("{" + i + "}", arguments[i+1]);
        }
    }
    return s;
};

String.repeat = function(chr, count) {
    var str = "";
    for (var x = 0; x < count; x++) { str += chr };
    return str;
}

String.prototype.padLeft = function(width, pad) {
    if (!width || width < 1)
        return this;

    if (!pad) pad = " ";
    var length = width - this.length
    if (length < 1) return this.substr(0, width);

    return (String.repeat(pad, length) + this).substr(0, width);
} 