// Date Format Method
// copyright Stephen Chapman, 20th November 2007
// http://javascript.about.com
// permission to use this JavaScript on your web page is granted
// provided that all of the code below in this script (including these
// comments) is used without any alteration

Date.prototype.getMonthName = function () {'use strict'; var m = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; return m[this.getMonth()]; };
Date.prototype.getMonthShort = function () {'use strict'; var m = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']; return m[this.getMonth()]; };
Date.prototype.getDayName = function () {'use strict'; var d = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; return d[this.getDay()]; };
Date.prototype.getDayShort = function () {'use strict'; var d = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']; return d[this.getDay()]; };
Date.prototype.ordinal = function () {'use strict'; var d = this.getDay(); switch (d) { case 1: case 21: case 31: return 'st'; case 2: case 22: return 'nd'; case 3: case 23: return 'rd'; default: return 'th'; } };
Date.prototype.getDOY = function () {'use strict'; var onejan = new Date(this.getFullYear(), 0, 1); return Math.ceil((this - onejan) / 86400000); };
function daysInMonth(month, year) {'use strict'; var dd = new Date(year, month, 0); return dd.getDate(); }
Date.prototype.format = function (f) {'use strict'; var fmt = f.split(''), res = ''; for (var i = 0, l = fmt.length; i < l; i++) {switch(fmt[i]) {case 'd': var d = this.getDate();  res += ((d<10)?'0':'')+d;  break; case 'D': res += this.getDayShort(); break; case 'j': res += this.getDate(); break; case 'l': res += this.getDayName(); break; case 'S': res += this.ordinal(); break; case 'w': res += this.getDay(); break; case 'z': res += this.getDOY(); break; case 'F': res += this.getMonthName(); break; case 'm': var m = this.getMonth()+1;  res += ((m<10)?'0':'')+m;  break; case 'M': res += this.getMonthShort(); break; case 'n': res += (this.getMonth()+1); break; case 't': res += daysInMonth(this.getMonth()+1, this.getFullYear()); break; case 'L': res += (daysInMonth(2, this.getFullYear()) == 29)? 1:0; break; case 'Y': res += this.getFullYear(); break; case 'y': var y = this.getFullYear().toString().substr(3); res += ((y<10)?'0':'')+y; break; case 'a': res += (this.getHours()>11)?'pm':'am'; break; case 'A': res += (this.getHours()>11)?'PM':'AM'; break; case 'g': var h = this.getHours()%12; res += (h==0)?12:h; break; case 'G': res += this.getHours; break; case 'h': var h = this.getHours()%12; res += (h==0)?12:(h>9)?h:'0'+h; break; case 'H': var h = this.getHours; res += (h>9)?h:'0'+h; break; case 'i': var m = this.getMinutes(); res += (m>9)?m:'0'+m; break; case 's': var s = this.getSeconds(); res += (s>9)?s:'0'+s; break; case 'O': var m = this.getTimezoneOffset(); var s = (m<0)?'+':'-'; m = Math.abs(m); var h = (m/60).toFixed(0); m = m%60; res += s + ((h>9)?h:'0'+h) + ((m>9)?m:'0'+m); break; case 'P': var m = this.getTimezoneOffset(); var s = (m<0)?'+':'-'; m = Math.abs(m); var h = (m/60).toFixed(0); m = m%60; res += s + ((h>9)?h:'0'+h) + ':' + ((m>9)?m:'0'+m); break; case 'U': res += (this.getTime()/1000).toFixed(0); break; default: res += fmt[i];}}return res;};
