// http://www.electrumdigital.com/2009/06/a-comprehensive-javascript-pad-function/
String.prototype.pad=function(a,b,c){if(typeof a==="undefined"){throw new TypeError("String.pad(): a is a required argument.");}
if(typeof b==="undefined"){b=" ";}
if(typeof c==="undefined"){c="right";}else if(c!=="left"&&c!=="right"&&c!=="both"){throw new TypeError("String.pad(): argument c must be one of \"left\", \"right\", or \"both\".");}
if(a<=this.length){return this.toString();}
var d=a-this.length;switch(c){case"left":return new Array(Math.ceil(d/b.length+1)).join(b).substr(0,d)+this;break;case"right":return this+new Array(Math.ceil(d/b.length+1)).join(b).substr(0,d);break;case"both":var e=Math.ceil(d/2);var f=d-e;return new Array(Math.ceil(f/b.length+1)).join(b).substr(0,f)+this+new Array(Math.ceil(e/b.length+1)).join(b).substr(0,e);break;}};