/*
 * Date prototype extensions. Doesn't depend on any
 * other code. Doens't overwrite existing methods.
 *
 * Adds dayNames, abbrDayNames, monthNames and abbrMonthNames static properties and isLeapYear,
 * isWeekend, isWeekDay, getDaysInMonth, getDayName, getMonthName, getDayOfYear, getWeekOfYear,
 * setDayOfYear, addYears, addMonths, addDays, addHours, addMinutes, addSeconds methods
 *
 * Copyright (c) 2006 Jörn Zaefferer and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 *
 * Additional methods and properties added by Kelvin Luck: firstDayOfWeek, dateFormat, zeroTime, asString, fromString -
 * I've added my name to these methods so you know who to blame if they are broken!
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */

Date.dayNames=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];Date.abbrDayNames=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];Date.monthNames=['January','February','March','April','May','June','July','August','September','October','November','December'];Date.abbrMonthNames=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];Date.firstDayOfWeek=1;Date.format='dd/mm/yyyy';Date.fullYearStart='20';(function(){function add(a,b){if(!Date.prototype[a]){Date.prototype[a]=b}};add("isLeapYear",function(){var y=this.getFullYear();return(y%4==0&&y%100!=0)||y%400==0});add("isWeekend",function(){return this.getDay()==0||this.getDay()==6});add("isWeekDay",function(){return!this.isWeekend()});add("getDaysInMonth",function(){return[31,(this.isLeapYear()?29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()]});add("getDayName",function(a){return a?Date.abbrDayNames[this.getDay()]:Date.dayNames[this.getDay()]});add("getMonthName",function(a){return a?Date.abbrMonthNames[this.getMonth()]:Date.monthNames[this.getMonth()]});add("getDayOfYear",function(){var a=new Date("1/1/"+this.getFullYear());return Math.floor((this.getTime()-a.getTime())/86400000)});add("getWeekOfYear",function(){return Math.ceil(this.getDayOfYear()/7)});add("setDayOfYear",function(a){this.setMonth(0);this.setDate(a);return this});add("addYears",function(a){this.setFullYear(this.getFullYear()+a);return this});add("addMonths",function(a){var b=this.getDate();this.setMonth(this.getMonth()+a);if(b>this.getDate())this.addDays(-this.getDate());return this});add("addDays",function(a){this.setTime(this.getTime()+(a*86400000));return this});add("addHours",function(a){this.setHours(this.getHours()+a);return this});add("addMinutes",function(a){this.setMinutes(this.getMinutes()+a);return this});add("addSeconds",function(a){this.setSeconds(this.getSeconds()+a);return this});add("zeroTime",function(){this.setMilliseconds(0);this.setSeconds(0);this.setMinutes(0);this.setHours(0);return this});add("asString",function(a){var r=a||Date.format;if(r.split('mm').length>1){r=r.split('mmmm').join(this.getMonthName(false)).split('mmm').join(this.getMonthName(true)).split('mm').join(k(this.getMonth()+1))}else{r=r.split('m').join(this.getMonth()+1)}r=r.split('yyyy').join(this.getFullYear()).split('yy').join((this.getFullYear()+'').substring(2)).split('dd').join(k(this.getDate())).split('d').join(this.getDate());return r});Date.fromString=function(s){var f=Date.format;var d=new Date('01/01/1970');if(s=='')return d;s=s.toLowerCase();var a='';var b=[];var r=/(dd?d?|mm?m?|yy?yy?)+([^(m|d|y)])?/g;var c;while((c=r.exec(f))!=null){switch(c[1]){case'd':case'dd':case'm':case'mm':case'yy':case'yyyy':a+='(\\d+\\d?\\d?\\d?)+';b.push(c[1].substr(0,1));break;case'mmm':a+='([a-z]{3})';b.push('M');break}if(c[2]){a+=c[2]}}var e=new RegExp(a);var g=s.match(e);for(var i=0;i<b.length;i++){var h=g[i+1];switch(b[i]){case'd':d.setDate(h);break;case'm':d.setMonth(Number(h)-1);break;case'M':for(var j=0;j<Date.abbrMonthNames.length;j++){if(Date.abbrMonthNames[j].toLowerCase()==h)break}d.setMonth(j);break;case'y':d.setYear(h);break}}return d};var k=function(a){var s='0'+a;return s.substring(s.length-2)}})();
