Date.prototype.format=function(m,r){var d=this,a,fix=function(n,c){return(n=n+"").length<c?new Array(++c-n.length).join("0")+n:n};var r=r||{},f={j:function(){return d.getDate()},w:function(){return d.getDay()},y:function(){return(d.getFullYear()+"").slice(2)},Y:function(){return d.getFullYear()},n:function(){return d.getMonth()+1},m:function(){return fix(f.n(),2)},g:function(){return d.getHours()%12||12},G:function(){return d.getHours()},H:function(){return fix(d.getHours(),2)},h:function(){return fix(f.g(),2)},d:function(){return fix(f.j(),2)},N:function(){return f.w()+1},i:function(){return fix(d.getMinutes(),2)},s:function(){return fix(d.getSeconds(),2)},S:function(){return d.getSeconds()},ms:function(){return fix(d.getMilliseconds(),3)},a:function(){return d.getHours()>11?"pm":"am"},A:function(){return f.a().toUpperCase()},O:function(){return d.getTimezoneOffset()/60},z:function(){return(d-new Date(d.getFullYear()+"/1/1"))/864e5>>0},L:function(){var y=f.Y();return(!(y&3)&&(y%1e2||!(y%4e2)))?1:0},t:function(){var n;return(n=d.getMonth()+1)==2?28+f.L():n&1&&n<8||!(n&1)&&n>7?31:30},W:function(){var a=f.z(),b=364+f.L()-a,nd=(new Date(d.getFullYear()+"/1/1").getDay()||7)-1;return(b<=2&&((d.getDay()||7)-1)<=2-b)?1:(a<=2&&nd>=4&&a>=(6-nd))?new Date(d.getFullYear()-1+"/12/31").format("%W%"):(1+(nd<=3?((a+nd)/7):(a-(7-nd))/7)>>0);}}return m.replace(/%(.*?)%/g,function(t,s){return r[s]?r[s](d,function(s){return f[s]&&f[s]();}):f[s]?f[s]():"%"+(s&&s+"%");});}String.prototype.replaceAll=function(needle,replacement){var str=thiswhile(str.indexOf(needle)>-1){str=str.replace(needle,replacement);}return str;}String.prototype.pad=function(l,s,t){return s||(s=" "),(l-=this.length)>0?(s=new Array(Math.ceil(l/s.length)+1).join(s)).substr(0,t=!t?l:t==1?0:Math.ceil(l/2))+this+s.substr(0,l-t):this;};String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.substring(1).toLowerCase();}String.prototype.camelize=function(){var parts=this.split('-'),len=parts.length;if(len==1)return parts[0];var camelized=this.charAt(0)=='-'?parts[0].charAt(0).toUpperCase()+parts[0].substring(1):parts[0];for(var i=1;i<len;i++)camelized+=parts[i].charAt(0).toUpperCase()+parts[i].substring(1);return camelized;}String.prototype.toReadableDate=function(format){var date_arr=this.split("-");var day=date_arr[0];var month=date_arr[1];var year=date_arr[2];var d=new Date(year,month-1,day);var functions={DayName:function(d,f){return LOCALIZE.days[f('w')];},MonthName:function(d,f){return LOCALIZE.month[f('n')-1];}}return d.format(format,functions);}String.prototype.toReadableTime=function(format){var time_arr=this.split(/[\s\.,\/\+_,:=]+/);var hour=time_arr[0];var minute=time_arr[1];var second=time_arr[2];var d=new Date(1970,1,1,hour,minute,second);if(format)return d.format(format);elsereturn d;}String.prototype.toReadablePhone=function(){phoneString=this.replace(/([\\\/\.\-\(\)\s,])/ig,"");return phoneString.replace(/^00/g,"+");}String.prototype.toStructuredDate=function(){date_arr=this.toStructuredDateArray();var day=date_arr[0];var month=date_arr[1];var year=date_arr[2]||new Date().getUTCFullYear();if(year&&year.length<4)year="2".pad(4-year.length,"0",1)+year;return day.pad(2,"0")+"-"+(month&&month.pad(2,"0"))+"-"+year;}String.prototype.toStructuredDateArray=function(){val=this.replace(/^[\s]+/,"");return val.split(/[\s\.,\/\+_,:=\-]+/);}String.prototype.toStructuredTime=function(asArray){timeString=this.toLowerCase();timeString=timeString.replace(/^[\s]+/,"");timeString=timeString.replace(/[\s\.,\/\+_,=:\-]+/g,":");if((/[^0-9|u|h|m|s|:]+/).test(timeString))return false;if(timeString.match(/[u|h|m|s]/)){var hour=timeString.match(/(\d+)[h|u]/);var minute=timeString.match(/(\d+)m/);var second=timeString.match(/(\d+)s/);hour=(!hour)?"0":hour[1];minute=(!minute)?"0":minute[1];second=(!second)?"0":second[1];}else{var time_arr=timeString.split(":");var hour=time_arr[0]||"0";var minute=time_arr[1]||"0";var second=time_arr[2]||"0";}return(asArray)?new Array(hour,minute,second):hour.pad(2,"0")+":"+minute.pad(2,"0")+":"+second.pad(2,"0");}String.prototype.toStructuredUrl=function(assumeScheme){if(this.length==0)return;urlString=this.toLowerCase();urlString=urlString.replace(/\s+$/);if(assumeScheme&&!(/:\/\//).test(urlString))urlString=assumeScheme+"://"+urlString;return urlString;}String.prototype.removeSeperators=function(){return this.replace(/([\.\-\/\\\s,])/ig,"");}Array.prototype.indexOf=function(object){for(var i=0,length=this.length;i<length;i++)if(this[i]==object)return i;return-1;}