/*
* Title:  jMonthCalendar 1.3.0-beta
* Dependencies:  jQuery 1.3.0 +
* Author:  Kyle LeNeau
* Email:  kyle.leneau@gmail.com
* Project Hompage:  http://www.bytecyclist.com/projects/jmonthcalendar
* Source:  http://code.google.com/p/jmonthcalendar
*
*/
(function($){var _beginDate;var _endDate;var _boxes=[];var _eventObj={};var _workingDate=null;var _daysInMonth=0;var _firstOfMonth=null;var _lastOfMonth=null;var _gridOffset=0;var _totalDates=0;var _gridRows=0;var _totalBoxes=0;var _dateRange={startDate:null,endDate:null};var calendarEvents=[];var defaults={containerId:"#jMonthCalendar",headerHeight:50,firstDayOfWeek:0,calendarStartDate:new Date(),dragableEvents:true,activeDroppableClass:false,hoverDroppableClass:false,navLinks:{enableToday:true,enableNextYear:true,enablePrevYear:true,p:"&lsaquo; Prev",n:"Next &rsaquo;",t:"Today",showMore:"Show More"},onMonthChanging:function(dateIn){return true},onMonthChanged:function(dateIn){return true},onEventLinkClick:function(event){return true},onEventBlockClick:function(event){return true},onEventBlockOver:function(event){return true},onEventBlockOut:function(event){return true},onDayLinkClick:function(date){return true},onDayCellClick:function(date){return true},onDayCellDblClick:function(dateIn){return true},onEventDropped:function(event,newDate){return true},onShowMoreClick:function(eventArray){return true},locale:{days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],daysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"],daysMin:["Su","Mo","Tu","We","Th","Fr","Sa","Su"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],weekMin:"wk"}};jQuery.jMonthCalendar=jQuery.J=function(){};var _getDateFromId=function(dateIdString){return new Date(dateIdString.substring(6,10),dateIdString.substring(2,4)-1,dateIdString.substring(4,6))};var _getDateId=function(date){var month=((date.getMonth()+1)<10)?"0"+(date.getMonth()+1):(date.getMonth()+1);var day=(date.getDate()<10)?"0"+date.getDate():date.getDate();return"c_"+month+day+date.getFullYear()};var _getJSONDate=function(jsonDateString){var tDt,k;if(typeof jsonDateString=="string"){var isoRegPlus=/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{7})$/;var isoReg=/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})$/;var yyyyMMdd=/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;var newReg=/^new/;var stdReg=/^\\\/Date\(([0-9]{13})-([0-9]{4})\)\\\/$/;if(k=jsonDateString.match(isoRegPlus)){return new Date(k[1],k[2]-1,k[3],k[4],k[5],k[6])}else{if(k=jsonDateString.match(isoReg)){return new Date(k[1],k[2]-1,k[3],k[4],k[5],k[6])}else{if(k=jsonDateString.match(yyyyMMdd)){return new Date(k[1],k[2]-1,k[3])}}}if(k=jsonDateString.match(stdReg)){return new Date(k[1])}if(k=jsonDateString.match(newReg)){return eval("("+jsonDateString+")")}return tdt}};var _filterEventCollection=function(){if(calendarEvents&&calendarEvents.length>0){var multi=[];var single=[];jQuery.each(calendarEvents,function(){var ev=this;if(ev.StartDateTime){if(typeof ev.StartDateTime=="object"&&ev.StartDateTime.getDate){this.StartDateTime=ev.StartDateTime}if(typeof ev.StartDateTime=="string"&&ev.StartDateTime.split){this.StartDateTime=_getJSONDate(ev.StartDateTime)}}else{if(ev.Date){if(typeof ev.Date=="object"&&ev.Date.getDate){this.StartDateTime=ev.Date}if(typeof ev.Date=="string"&&ev.Date.split){this.StartDateTime=_getJSONDate(ev.Date)}}else{return}}if(ev.EndDateTime){if(typeof ev.EndDateTime=="object"&&ev.EndDateTime.getDate){this.EndDateTime=ev.EndDateTime}if(typeof ev.EndDateTime=="string"&&ev.EndDateTime.split){this.EndDateTime=_getJSONDate(ev.EndDateTime)}}else{this.EndDateTime=this.StartDateTime.clone()}if(this.StartDateTime.clone().clearTime().compareTo(this.EndDateTime.clone().clearTime())==0){single.push(this)}else{if(this.StartDateTime.clone().clearTime().compareTo(this.EndDateTime.clone().clearTime())==-1){multi.push(this)}}});multi.sort(_eventSort);single.sort(_eventSort);calendarEvents=[];jQuery.merge(calendarEvents,multi);jQuery.merge(calendarEvents,single)}};var _eventSort=function(a,b){return a.StartDateTime.compareTo(b.StartDateTime)};var _clearBoxes=function(){_clearBoxEvents();_boxes=[]};var _clearBoxEvents=function(){for(var i=0;i<_boxes.length;i++){_boxes[i].clear()}_eventObj={}};var _initDates=function(dateIn){var today=defaults.calendarStartDate;if(dateIn==undefined){_workingDate=new Date(today.getFullYear(),today.getMonth(),1)}else{_workingDate=dateIn;_workingDate.setDate(1)}_daysInMonth=_workingDate.getDaysInMonth();_firstOfMonth=_workingDate.clone().moveToFirstDayOfMonth();_lastOfMonth=_workingDate.clone().moveToLastDayOfMonth();_gridOffset=_firstOfMonth.getDay()-defaults.firstDayOfWeek;_totalDates=_gridOffset+_daysInMonth;_gridRows=Math.ceil(_totalDates/7);_totalBoxes=_gridRows*7;_dateRange.startDate=_firstOfMonth.clone().addDays((-1)*_gridOffset);_dateRange.endDate=_lastOfMonth.clone().addDays(_totalBoxes-(_daysInMonth+_gridOffset))};var _initHeaders=function(){var prevMonth=_workingDate.clone().addMonths(-1);var prevMLink=jQuery('<div class="MonthNavPrev"><a href="" class="link-prev">'+defaults.navLinks.p+"</a></div>").click(function(){jQuery.J.ChangeMonth(prevMonth);return false});var nextMonth=_workingDate.clone().addMonths(1);var nextMLink=jQuery('<div class="MonthNavNext"><a href="" class="link-next">'+defaults.navLinks.n+"</a></div>").click(function(){jQuery.J.ChangeMonth(nextMonth);return false});var prevYear=_workingDate.clone().addYears(-1);var prevYLink;if(defaults.navLinks.enablePrevYear){prevYLink=jQuery('<div class="YearNavPrev"><a href="">'+prevYear.getFullYear()+"</a></div>").click(function(){jQuery.J.ChangeMonth(prevYear);return false})}var nextYear=_workingDate.clone().addYears(1);var nextYLink;if(defaults.navLinks.enableNextYear){nextYLink=jQuery('<div class="YearNavNext"><a href="">'+nextYear.getFullYear()+"</a></div>").click(function(){jQuery.J.ChangeMonth(nextYear);return false})}var todayLink;if(defaults.navLinks.enableToday){todayLink=jQuery('<div class="TodayLink"><a href="" class="link-today">'+defaults.navLinks.t+"</a></div>").click(function(){jQuery.J.ChangeMonth(new Date());return false})}var navRow=jQuery('<tr><td colspan="7"><div class="FormHeader MonthNavigation"></div></td></tr>');var monthNavHead=jQuery(".MonthNavigation",navRow);monthNavHead.append(prevMLink,nextMLink);if(defaults.navLinks.enableToday){monthNavHead.append(todayLink)}monthNavHead.append(jQuery('<div class="MonthName"></div>').append(defaults.locale.months[_workingDate.getMonth()]+" "+_workingDate.getFullYear()));if(defaults.navLinks.enablePrevYear){monthNavHead.append(prevYLink)}if(defaults.navLinks.enableNextYear){monthNavHead.append(nextYLink)}var headRow=jQuery("<tr></tr>");for(var i=defaults.firstDayOfWeek;i<defaults.firstDayOfWeek+7;i++){var weekday=i%7;var wordday=defaults.locale.days[weekday];headRow.append('<th title="'+wordday+'" class="DateHeader'+(weekday==0||weekday==6?" Weekend":"")+'"><span>'+wordday+"</span></th>")}headRow=jQuery('<thead id="CalendarHead"></thead>').css({height:defaults.headerHeight+"px"}).append(headRow);headRow=headRow.prepend(navRow);return headRow};jQuery.J.DrawCalendar=function(dateIn){var now=new Date();now.clearTime();var today=defaults.calendarStartDate;_clearBoxes();_initDates(dateIn);var headerRow=_initHeaders();var isCurrentMonth=(_workingDate.getMonth()==today.getMonth()&&_workingDate.getFullYear()==today.getFullYear());var containerHeight=jQuery(defaults.containerId).outerHeight();var rowHeight=(containerHeight-defaults.headerHeight)/_gridRows;var row=null;var tBody=jQuery('<tbody id="CalendarBody"></tbody>');for(var i=0;i<_totalBoxes;i++){var currentDate=_dateRange.startDate.clone().addDays(i);if(i%7==0||i==0){row=jQuery("<tr></tr>");row.css({height:rowHeight+"px"});tBody.append(row)}var weekday=(defaults.firstDayOfWeek+i)%7;var atts={"class":"DateBox"+(weekday==0||weekday==6?" Weekend ":""),date:currentDate.toString("M/d/yyyy"),id:_getDateId(currentDate)};if(currentDate.compareTo(_firstOfMonth)==-1||currentDate.compareTo(_lastOfMonth)==1){atts["class"]+=" Inactive"}if(currentDate.compareTo(now)==0){atts["class"]+=" Today"}var dateLink=jQuery('<div class="DateLabel"><a href="">'+currentDate.getDate()+"</a></div>").click(function(e){defaults.onDayLinkClick(currentDate);e.stopPropagation()});var dateBox=jQuery("<td></td>").attr(atts).append(dateLink).dblclick(function(e){defaults.onDayCellDblClick(currentDate);e.stopPropagation()}).click(function(e){defaults.onDayCellClick(currentDate);e.stopPropagation()});if(defaults.dragableEvents){dateBox.droppable({hoverClass:"DateBoxOver",activeClass:defaults.activeDroppableClass,tolerance:"pointer",drop:function(ev,ui){var eventId=ui.draggable.attr("eventid");var newDate=new Date(jQuery(this).attr("date")).clearTime();var event;jQuery.each(calendarEvents,function(){if(this.EventID==eventId){var days=new TimeSpan(newDate-this.StartDateTime).days;this.StartDateTime.addDays(days);this.EndDateTime.addDays(days);event=this}});jQuery.J.ClearEventsOnCalendar();_drawEventsOnCalendar();defaults.onEventDropped(event,newDate)}})}_boxes.push(new CalendarBox(i,currentDate,dateBox,dateLink));row.append(dateBox)}tBody.append(row);var a=jQuery(defaults.containerId);var cal=jQuery('<table class="MonthlyCalendar" cellpadding="0" tablespacing="0"></table>').append(headerRow,tBody);a.hide();a.html(cal);a.fadeIn("normal");_drawEventsOnCalendar()};var _drawEventsOnCalendar=function(){_filterEventCollection();_clearBoxEvents();if(calendarEvents&&calendarEvents.length>0){var container=jQuery(defaults.containerId);jQuery.each(calendarEvents,function(){var ev=this;var tempStartDT=ev.StartDateTime.clone().clearTime();var tempEndDT=ev.EndDateTime.clone().clearTime();var startI=new TimeSpan(tempStartDT-_dateRange.startDate).days;var endI=new TimeSpan(tempEndDT-_dateRange.startDate).days;var istart=(startI<0)?0:startI;var iend=(endI>_boxes.length-1)?_boxes.length-1:endI;for(var i=istart;i<=iend;i++){var b=_boxes[i];var startBoxCompare=tempStartDT.compareTo(b.date);var endBoxCompare=tempEndDT.compareTo(b.date);var continueEvent=((i!=0&&startBoxCompare==-1&&endBoxCompare>=0&&b.weekNumber!=_boxes[i-1].weekNumber)||(i==0&&startBoxCompare==-1));var toManyEvents=(startBoxCompare==0||(i==0&&startBoxCompare==-1)||continueEvent||(startBoxCompare==-1&&endBoxCompare>=0))&&b.vOffset>=(b.getCellBox().height()-b.getLabelHeight()-32);if(toManyEvents){if(!b.isTooManySet){var moreDiv=jQuery('<div class="MoreEvents" id="ME_'+i+'">'+defaults.navLinks.showMore+"</div>");var pos=b.getCellPosition();var index=i;moreDiv.css({top:(pos.top+(b.getCellBox().height()-b.getLabelHeight())),left:pos.left,width:(b.getLabelWidth()-7),position:"absolute"});moreDiv.click(function(e){_showMoreClick(e,index)});_eventObj[moreDiv.attr("id")]=moreDiv;b.isTooManySet=true}b.events.push(ev)}else{if(startBoxCompare==0||(i==0&&startBoxCompare==-1)||continueEvent){var block=_buildEventBlock(ev,b.weekNumber);var pos=b.getCellPosition();block.css({top:(pos.top+b.getLabelHeight()+b.vOffset),left:pos.left,width:(b.getLabelWidth()-7),position:"absolute"});b.vOffset+=19;if(continueEvent){block.prepend(jQuery("<span />").addClass("ui-icon").addClass("ui-icon-triangle-1-w"));var e=_eventObj["Event_"+ev.EventID+"_"+(b.weekNumber-1)];if(e){e.prepend(jQuery("<span />").addClass("ui-icon").addClass("ui-icon-triangle-1-e"))}}_eventObj[block.attr("id")]=block;b.events.push(ev)}else{if(startBoxCompare==-1&&endBoxCompare>=0){var e=_eventObj["Event_"+ev.EventID+"_"+b.weekNumber];if(e){var w=e.css("width");e.css({width:(parseInt(w)+b.getLabelWidth()+1)});b.vOffset+=19;b.events.push(ev)}}}}if(i==iend&&endBoxCompare>0){var e=_eventObj["Event_"+ev.EventID+"_"+b.weekNumber];if(e){e.prepend(jQuery("<span />").addClass("ui-icon").addClass("ui-icon-triangle-1-e"))}}}});for(var o in _eventObj){_eventObj[o].hide();container.append(_eventObj[o]);_eventObj[o].show()}}};var _buildEventBlock=function(event,weekNumber){var block=jQuery('<div class="Event" id="Event_'+event.EventID+"_"+weekNumber+'" eventid="'+event.EventID+'"></div>');if(event.CssClass){block.addClass(event.CssClass)}block.click(function(e){defaults.onEventBlockClick(event);e.stopPropagation()});block.hover(function(){defaults.onEventBlockOver(event)},function(){defaults.onEventBlockOut(event)});if(defaults.dragableEvents){_dragableEvent(event,block,weekNumber)}var link=jQuery('<a href="'+event.URL+'">'+event.Title+"</a>");link.click(function(e){defaults.onEventLinkClick(event);e.stopPropagation()});block.append(link);return block};var _dragableEvent=function(event,block,weekNumber){block.draggable({zIndex:4,delay:50,opacity:0.5,revertDuration:1000,cursorAt:{left:5},start:function(ev,ui){for(var i=0;i<=_gridRows;i++){if(i==weekNumber){continue}var e=_eventObj["Event_"+event.EventID+"_"+i];if(e){e.hide()}}}})};var _showMoreClick=function(e,boxIndex){var box=_boxes[boxIndex];defaults.onShowMoreClick(box.events);e.stopPropagation()};jQuery.J.ClearEventsOnCalendar=function(){_clearBoxEvents();jQuery(".Event",jQuery(defaults.containerId)).remove();jQuery(".MoreEvents",jQuery(defaults.containerId)).remove()};jQuery.J.AddEvents=function(eventCollection){if(eventCollection){if(eventCollection.length>0){jQuery.merge(calendarEvents,eventCollection)}else{calendarEvents.push(eventCollection)}jQuery.J.ClearEventsOnCalendar();_drawEventsOnCalendar()}};jQuery.J.ReplaceEventCollection=function(eventCollection){if(eventCollection){calendarEvents=[];calendarEvents=eventCollection}jQuery.J.ClearEventsOnCalendar();_drawEventsOnCalendar()};jQuery.J.ChangeMonth=function(dateIn){if(defaults.onMonthChanging(dateIn)){jQuery.J.DrawCalendar(dateIn);defaults.onMonthChanged(dateIn)}};jQuery.J.Initialize=function(options,events){var today=new Date();options=jQuery.extend(defaults,options);if(events){jQuery.J.ClearEventsOnCalendar();calendarEvents=events}jQuery.J.DrawCalendar()}})(jQuery);function CalendarBox(d,c,a,b){this.id=d;this.date=c;this.cell=a;this.label=b;this.weekNumber=Math.floor(d/7);this.events=[];this.isTooMannySet=false;this.vOffset=0;this.echo=function(){alert("Date: "+this.date+" WeekNumber: "+this.weekNumber+" ID: "+this.id)};this.clear=function(){this.events=[];this.isTooMannySet=false;this.vOffset=0};this.getCellPosition=function(){if(this.cell){return this.cell.position()}return};this.getCellBox=function(){if(this.cell){return this.cell}return};this.getLabelWidth=function(){if(this.label){return this.label.innerWidth()}return};this.getLabelHeight=function(){if(this.label){return this.label.height()}return};this.getDate=function(){return this.date}}Date.CultureInfo={name:"en-US",englishName:"English (United States)",nativeName:"English (United States)",dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbreviatedDayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortestDayNames:["Su","Mo","Tu","We","Th","Fr","Sa"],firstLetterDayNames:["S","M","T","W","T","F","S"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],abbreviatedMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],amDesignator:"AM",pmDesignator:"PM",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"mdy",formatPatterns:{shortDate:"M/d/yyyy",longDate:"dddd, MMMM dd, yyyy",shortTime:"h:mm tt",longTime:"h:mm:ss tt",fullDateTime:"dddd, MMMM dd, yyyy h:mm:ss tt",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"MMMM dd",yearMonth:"MMMM, yyyy"},regexPatterns:{jan:/^jan(uary)?/i,feb:/^feb(ruary)?/i,mar:/^mar(ch)?/i,apr:/^apr(il)?/i,may:/^may/i,jun:/^jun(e)?/i,jul:/^jul(y)?/i,aug:/^aug(ust)?/i,sep:/^sep(t(ember)?)?/i,oct:/^oct(ober)?/i,nov:/^nov(ember)?/i,dec:/^dec(ember)?/i,sun:/^su(n(day)?)?/i,mon:/^mo(n(day)?)?/i,tue:/^tu(e(s(day)?)?)?/i,wed:/^we(d(nesday)?)?/i,thu:/^th(u(r(s(day)?)?)?)?/i,fri:/^fr(i(day)?)?/i,sat:/^sa(t(urday)?)?/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|after|from)/i,subtract:/^(\-|before|ago)/i,yesterday:/^yesterday/i,today:/^t(oday)?/i,tomorrow:/^tomorrow/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^min(ute)?s?/i,hour:/^h(ou)?rs?/i,week:/^w(ee)?k/i,month:/^m(o(nth)?s?)?/i,day:/^d(ays?)?/i,year:/^y((ea)?rs?)?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a|p)/i},abbreviatedTimeZoneStandard:{GMT:"-000",EST:"-0400",CST:"-0500",MST:"-0600",PST:"-0700"},abbreviatedTimeZoneDST:{GMT:"-000",EDT:"-0500",CDT:"-0600",MDT:"-0700",PDT:"-0800"}};Date.getMonthNumberFromName=function(b){var e=Date.CultureInfo.monthNames,a=Date.CultureInfo.abbreviatedMonthNames,d=b.toLowerCase();for(var c=0;c<e.length;c++){if(e[c].toLowerCase()==d||a[c].toLowerCase()==d){return c}}return -1};Date.getDayNumberFromName=function(b){var f=Date.CultureInfo.dayNames,a=Date.CultureInfo.abbreviatedDayNames,e=Date.CultureInfo.shortestDayNames,d=b.toLowerCase();for(var c=0;c<f.length;c++){if(f[c].toLowerCase()==d||a[c].toLowerCase()==d){return c}}return -1};Date.isLeapYear=function(a){return(((a%4===0)&&(a%100!==0))||(a%400===0))};Date.getDaysInMonth=function(a,b){return[31,(Date.isLeapYear(a)?29:28),31,30,31,30,31,31,30,31,30,31][b]};Date.getTimezoneOffset=function(a,b){return(b||false)?Date.CultureInfo.abbreviatedTimeZoneDST[a.toUpperCase()]:Date.CultureInfo.abbreviatedTimeZoneStandard[a.toUpperCase()]};Date.getTimezoneAbbreviation=function(b,d){var c=(d||false)?Date.CultureInfo.abbreviatedTimeZoneDST:Date.CultureInfo.abbreviatedTimeZoneStandard,a;for(a in c){if(c[a]===b){return a}}return null};Date.prototype.clone=function(){return new Date(this.getTime())};Date.prototype.compareTo=function(a){if(isNaN(this)){throw new Error(this)}if(a instanceof Date&&!isNaN(a)){return(this>a)?1:(this<a)?-1:0}else{throw new TypeError(a)}};Date.prototype.equals=function(a){return(this.compareTo(a)===0)};Date.prototype.between=function(c,a){var b=this.getTime();return b>=c.getTime()&&b<=a.getTime()};Date.prototype.addMilliseconds=function(a){this.setMilliseconds(this.getMilliseconds()+a);return this};Date.prototype.addSeconds=function(a){return this.addMilliseconds(a*1000)};Date.prototype.addMinutes=function(a){return this.addMilliseconds(a*60000)};Date.prototype.addHours=function(a){return this.addMilliseconds(a*3600000)};Date.prototype.addDays=function(a){return this.addMilliseconds(a*86400000)};Date.prototype.addWeeks=function(a){return this.addMilliseconds(a*604800000)};Date.prototype.addMonths=function(a){var b=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+a);this.setDate(Math.min(b,this.getDaysInMonth()));return this};Date.prototype.addYears=function(a){return this.addMonths(a*12)};Date.prototype.add=function(b){if(typeof b=="number"){this._orient=b;return this}var a=b;if(a.millisecond||a.milliseconds){this.addMilliseconds(a.millisecond||a.milliseconds)}if(a.second||a.seconds){this.addSeconds(a.second||a.seconds)}if(a.minute||a.minutes){this.addMinutes(a.minute||a.minutes)}if(a.hour||a.hours){this.addHours(a.hour||a.hours)}if(a.month||a.months){this.addMonths(a.month||a.months)}if(a.year||a.years){this.addYears(a.year||a.years)}if(a.day||a.days){this.addDays(a.day||a.days)}return this};Date._validate=function(d,c,a,b){if(typeof d!="number"){throw new TypeError(d+" is not a Number.")}else{if(d<c||d>a){throw new RangeError(d+" is not a valid value for "+b+".")}}return true};Date.validateMillisecond=function(a){return Date._validate(a,0,999,"milliseconds")};Date.validateSecond=function(a){return Date._validate(a,0,59,"seconds")};Date.validateMinute=function(a){return Date._validate(a,0,59,"minutes")};Date.validateHour=function(a){return Date._validate(a,0,23,"hours")};Date.validateDay=function(c,a,b){return Date._validate(c,1,Date.getDaysInMonth(a,b),"days")};Date.validateMonth=function(a){return Date._validate(a,0,11,"months")};Date.validateYear=function(a){return Date._validate(a,1,9999,"seconds")};Date.prototype.set=function(b){var a=b;if(!a.millisecond&&a.millisecond!==0){a.millisecond=-1}if(!a.second&&a.second!==0){a.second=-1}if(!a.minute&&a.minute!==0){a.minute=-1}if(!a.hour&&a.hour!==0){a.hour=-1}if(!a.day&&a.day!==0){a.day=-1}if(!a.month&&a.month!==0){a.month=-1}if(!a.year&&a.year!==0){a.year=-1}if(a.millisecond!=-1&&Date.validateMillisecond(a.millisecond)){this.addMilliseconds(a.millisecond-this.getMilliseconds())}if(a.second!=-1&&Date.validateSecond(a.second)){this.addSeconds(a.second-this.getSeconds())}if(a.minute!=-1&&Date.validateMinute(a.minute)){this.addMinutes(a.minute-this.getMinutes())}if(a.hour!=-1&&Date.validateHour(a.hour)){this.addHours(a.hour-this.getHours())}if(a.month!==-1&&Date.validateMonth(a.month)){this.addMonths(a.month-this.getMonth())}if(a.year!=-1&&Date.validateYear(a.year)){this.addYears(a.year-this.getFullYear())}if(a.day!=-1&&Date.validateDay(a.day,this.getFullYear(),this.getMonth())){this.addDays(a.day-this.getDate())}if(a.timezone){this.setTimezone(a.timezone)}if(a.timezoneOffset){this.setTimezoneOffset(a.timezoneOffset)}return this};Date.prototype.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this};Date.prototype.isLeapYear=function(){var a=this.getFullYear();return(((a%4===0)&&(a%100!==0))||(a%400===0))};Date.prototype.isWeekday=function(){return !(this.is().sat()||this.is().sun())};Date.prototype.getDaysInMonth=function(){return Date.getDaysInMonth(this.getFullYear(),this.getMonth())};Date.prototype.moveToFirstDayOfMonth=function(){return this.set({day:1})};Date.prototype.moveToLastDayOfMonth=function(){return this.set({day:this.getDaysInMonth()})};Date.prototype.moveToDayOfWeek=function(a,b){var c=(a-this.getDay()+7*(b||+1))%7;return this.addDays((c===0)?c+=7*(b||+1):c)};Date.prototype.moveToMonth=function(c,a){var b=(c-this.getMonth()+12*(a||+1))%12;return this.addMonths((b===0)?b+=12*(a||+1):b)};Date.prototype.getDayOfYear=function(){return Math.floor((this-new Date(this.getFullYear(),0,1))/86400000)};Date.prototype.getWeekOfYear=function(a){var i=this.getFullYear(),c=this.getMonth(),f=this.getDate();var k=a||Date.CultureInfo.firstDayOfWeek;var e=7+1-new Date(i,0,1).getDay();if(e==8){e=1}var b=((Date.UTC(i,c,f,0,0,0)-Date.UTC(i,0,1,0,0,0))/86400000)+1;var j=Math.floor((b-e+7)/7);if(j===k){i--;var g=7+1-new Date(i,0,1).getDay();if(g==2||g==8){j=53}else{j=52}}return j};Date.prototype.isDST=function(){console.log("isDST");return this.toString().match(/(E|C|M|P)(S|D)T/)[2]=="D"};Date.prototype.getTimezone=function(){return Date.getTimezoneAbbreviation(this.getUTCOffset,this.isDST())};Date.prototype.setTimezoneOffset=function(b){var a=this.getTimezoneOffset(),c=Number(b)*-6/10;this.addMinutes(c-a);return this};Date.prototype.setTimezone=function(a){return this.setTimezoneOffset(Date.getTimezoneOffset(a))};Date.prototype.getUTCOffset=function(){var b=this.getTimezoneOffset()*-10/6,a;if(b<0){a=(b-10000).toString();return a[0]+a.substr(2)}else{a=(b+10000).toString();return"+"+a.substr(1)}};Date.prototype.getDayName=function(a){return a?Date.CultureInfo.abbreviatedDayNames[this.getDay()]:Date.CultureInfo.dayNames[this.getDay()]};Date.prototype.getMonthName=function(a){return a?Date.CultureInfo.abbreviatedMonthNames[this.getMonth()]:Date.CultureInfo.monthNames[this.getMonth()]};Date.prototype._toString=Date.prototype.toString;Date.prototype.toString=function(c){var a=this;var b=function b(d){return(d.toString().length==1)?"0"+d:d};return c?c.replace(/dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?/g,function(d){switch(d){case"hh":return b(a.getHours()<13?a.getHours():(a.getHours()-12));case"h":return a.getHours()<13?a.getHours():(a.getHours()-12);case"HH":return b(a.getHours());case"H":return a.getHours();case"mm":return b(a.getMinutes());case"m":return a.getMinutes();case"ss":return b(a.getSeconds());case"s":return a.getSeconds();case"yyyy":return a.getFullYear();case"yy":return a.getFullYear().toString().substring(2,4);case"dddd":return a.getDayName();case"ddd":return a.getDayName(true);case"dd":return b(a.getDate());case"d":return a.getDate().toString();case"MMMM":return a.getMonthName();case"MMM":return a.getMonthName(true);case"MM":return b((a.getMonth()+1));case"M":return a.getMonth()+1;case"t":return a.getHours()<12?Date.CultureInfo.amDesignator.substring(0,1):Date.CultureInfo.pmDesignator.substring(0,1);case"tt":return a.getHours()<12?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;case"zzz":case"zz":case"z":return""}}):this._toString()};Date.now=function(){return new Date()};Date.today=function(){return Date.now().clearTime()};Date.prototype._orient=+1;Date.prototype.next=function(){this._orient=+1;return this};Date.prototype.last=Date.prototype.prev=Date.prototype.previous=function(){this._orient=-1;return this};Date.prototype._is=false;Date.prototype.is=function(){this._is=true;return this};Number.prototype._dateElement="day";Number.prototype.fromNow=function(){var a={};a[this._dateElement]=this;return Date.now().add(a)};Number.prototype.ago=function(){var a={};a[this._dateElement]=this*-1;return Date.now().add(a)};(function(){var g=Date.prototype,a=Number.prototype;var q=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),p=("january february march april may june july august september october november december").split(/\s/),o=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),n;var m=function(i){return function(){if(this._is){this._is=false;return this.getDay()==i}return this.moveToDayOfWeek(i,this._orient)}};for(var f=0;f<q.length;f++){g[q[f]]=g[q[f].substring(0,3)]=m(f)}var l=function(i){return function(){if(this._is){this._is=false;return this.getMonth()===i}return this.moveToMonth(i,this._orient)}};for(var d=0;d<p.length;d++){g[p[d]]=g[p[d].substring(0,3)]=l(d)}var e=function(i){return function(){if(i.substring(i.length-1)!="s"){i+="s"}return this["add"+i](this._orient)}};var b=function(i){return function(){this._dateElement=i;return this}};for(var c=0;c<o.length;c++){n=o[c].toLowerCase();g[n]=g[n+"s"]=e(o[c]);a[n]=a[n+"s"]=b(n)}}());Date.prototype.toJSONString=function(){return this.toString("yyyy-MM-ddThh:mm:ssZ")};Date.prototype.toShortDateString=function(){return this.toString(Date.CultureInfo.formatPatterns.shortDatePattern)};Date.prototype.toLongDateString=function(){return this.toString(Date.CultureInfo.formatPatterns.longDatePattern)};Date.prototype.toShortTimeString=function(){return this.toString(Date.CultureInfo.formatPatterns.shortTimePattern)};Date.prototype.toLongTimeString=function(){return this.toString(Date.CultureInfo.formatPatterns.longTimePattern)};Date.prototype.getOrdinal=function(){switch(this.getDate()){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th"}};(function(){Date.Parsing={Exception:function(i){this.message="Parse error at '"+i.substring(0,10)+" ...'"}};var a=Date.Parsing;var c=a.Operators={rtoken:function(i){return function(j){var l=j.match(i);if(l){return([l[0],j.substring(l[0].length)])}else{throw new a.Exception(j)}}},token:function(i){return function(j){return c.rtoken(new RegExp("^s*"+j+"s*"))(j)}},stoken:function(i){return c.rtoken(new RegExp("^"+i))},until:function(i){return function(j){var l=[],n=null;while(j.length){try{n=i.call(this,j)}catch(m){l.push(n[0]);j=n[1];continue}break}return[l,j]}},many:function(i){return function(j){var n=[],l=null;while(j.length){try{l=i.call(this,j)}catch(m){return[n,j]}n.push(l[0]);j=l[1]}return[n,j]}},optional:function(i){return function(j){var l=null;try{l=i.call(this,j)}catch(m){return[null,j]}return[l[0],l[1]]}},not:function(i){return function(j){try{i.call(this,j)}catch(l){return[null,j]}throw new a.Exception(j)}},ignore:function(i){return i?function(j){var l=null;l=i.call(this,j);return[null,l[1]]}:null},product:function(){var l=arguments[0],m=Array.prototype.slice.call(arguments,1),n=[];for(var j=0;j<l.length;j++){n.push(c.each(l[j],m))}return n},cache:function(l){var i={},j=null;return function(m){try{j=i[m]=(i[m]||l.call(this,m))}catch(n){j=i[m]=n}if(j instanceof a.Exception){throw j}else{return j}}},any:function(){var i=arguments;return function(l){var m=null;for(var j=0;j<i.length;j++){if(i[j]==null){continue}try{m=(i[j].call(this,l))}catch(n){m=null}if(m){return m}}throw new a.Exception(l)}},each:function(){var i=arguments;return function(l){var o=[],m=null;for(var j=0;j<i.length;j++){if(i[j]==null){continue}try{m=(i[j].call(this,l))}catch(n){throw new a.Exception(l)}o.push(m[0]);l=m[1]}return[o,l]}},all:function(){var j=arguments,i=i;return i.each(i.optional(j))},sequence:function(i,j,l){j=j||c.rtoken(/^\s*/);l=l||null;if(i.length==1){return i[0]}return function(p){var t=null,u=null;var w=[];for(var o=0;o<i.length;o++){try{t=i[o].call(this,p)}catch(v){break}w.push(t[0]);try{u=j.call(this,t[1])}catch(n){u=null;break}p=u[1]}if(!t){throw new a.Exception(p)}if(u){throw new a.Exception(u[1])}if(l){try{t=l.call(this,t[1])}catch(m){throw new a.Exception(t[1])}}return[w,(t?t[1]:p)]}},between:function(j,l,i){i=i||j;var m=c.each(c.ignore(j),l,c.ignore(i));return function(n){var o=m.call(this,n);return[[o[0][0],r[0][2]],o[1]]}},list:function(i,j,l){j=j||c.rtoken(/^\s*/);l=l||null;return(i instanceof Array?c.each(c.product(i.slice(0,-1),c.ignore(j)),i.slice(-1),c.ignore(l)):c.each(c.many(c.each(i,c.ignore(j))),px,c.ignore(l)))},set:function(i,j,l){j=j||c.rtoken(/^\s*/);l=l||null;return function(C){var m=null,o=null,n=null,t=null,u=[[],C],B=false;for(var w=0;w<i.length;w++){n=null;o=null;m=null;B=(i.length==1);try{m=i[w].call(this,C)}catch(z){continue}t=[[m[0]],m[1]];if(m[1].length>0&&!B){try{n=j.call(this,m[1])}catch(A){B=true}}else{B=true}if(!B&&n[1].length===0){B=true}if(!B){var x=[];for(var v=0;v<i.length;v++){if(w!=v){x.push(i[v])}}o=c.set(x,j).call(this,n[1]);if(o[0].length>0){t[0]=t[0].concat(o[0]);t[1]=o[1]}}if(t[1].length<u[1].length){u=t}if(u[1].length===0){break}}if(u[0].length===0){return u}if(l){try{n=l.call(this,u[1])}catch(y){throw new a.Exception(u[1])}u[1]=n[1]}return u}},forward:function(i,j){return function(l){return i[j].call(this,l)}},replace:function(j,i){return function(l){var m=j.call(this,l);return[i,m[1]]}},process:function(j,i){return function(l){var m=j.call(this,l);return[i.call(this,m[0]),m[1]]}},min:function(i,j){return function(l){var m=j.call(this,l);if(m[0].length<i){throw new a.Exception(l)}return m}}};var k=function(i){return function(){var j=null,n=[];if(arguments.length>1){j=Array.prototype.slice.call(arguments)}else{if(arguments[0] instanceof Array){j=arguments[0]}}if(j){for(var m=0,l=j.shift();m<l.length;m++){j.unshift(l[m]);n.push(i.apply(null,j));j.shift();return n}}else{return i.apply(null,arguments)}}};var g="optional not ignore cache".split(/\s/);for(var d=0;d<g.length;d++){c[g[d]]=k(c[g[d]])}var f=function(i){return function(){if(arguments[0] instanceof Array){return i.apply(null,arguments[0])}else{return i.apply(null,arguments)}}};var e="each any all".split(/\s/);for(var b=0;b<e.length;b++){c[e[b]]=f(c[e[b]])}}());(function(){var f=function(k){var l=[];for(var g=0;g<k.length;g++){if(k[g] instanceof Array){l=l.concat(f(k[g]))}else{if(k[g]){l.push(k[g])}}}return l};Date.Grammar={};Date.Translator={hour:function(g){return function(){this.hour=Number(g)}},minute:function(g){return function(){this.minute=Number(g)}},second:function(g){return function(){this.second=Number(g)}},meridian:function(g){return function(){this.meridian=g.slice(0,1).toLowerCase()}},timezone:function(g){return function(){var k=g.replace(/[^\d\+\-]/g,"");if(k.length){this.timezoneOffset=Number(k)}else{this.timezone=g.toLowerCase()}}},day:function(g){var k=g[0];return function(){this.day=Number(k.match(/\d+/)[0])}},month:function(g){return function(){this.month=((g.length==3)?Date.getMonthNumberFromName(g):(Number(g)-1))}},year:function(g){return function(){var k=Number(g);this.year=((g.length>2)?k:(k+(((k+2000)<Date.CultureInfo.twoDigitYearMax)?2000:1900)))}},rday:function(g){return function(){switch(g){case"yesterday":this.days=-1;break;case"tomorrow":this.days=1;break;case"today":this.days=0;break;case"now":this.days=0;this.now=true;break}}},finishExact:function(g){g=(g instanceof Array)?g:[g];var k=new Date();this.year=k.getFullYear();this.month=k.getMonth();this.day=1;this.hour=0;this.minute=0;this.second=0;for(var l=0;l<g.length;l++){if(g[l]){g[l].call(this)}}this.hour=(this.meridian=="p"&&this.hour<13)?this.hour+12:this.hour;if(this.day>Date.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.")}var m=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second);if(this.timezone){m.set({timezone:this.timezone})}else{if(this.timezoneOffset){m.set({timezoneOffset:this.timezoneOffset})}}return m},finish:function(g){g=(g instanceof Array)?f(g):[g];if(g.length===0){return null}for(var n=0;n<g.length;n++){if(typeof g[n]=="function"){g[n].call(this)}}if(this.now){return new Date()}var k=Date.today();var q=null;var o=!!(this.days!=null||this.orient||this.operator);if(o){var p,m,l;l=((this.orient=="past"||this.operator=="subtract")?-1:1);if(this.weekday){this.unit="day";p=(Date.getDayNumberFromName(this.weekday)-k.getDay());m=7;this.days=p?((p+(l*m))%m):(l*m)}if(this.month){this.unit="month";p=(this.month-k.getMonth());m=12;this.months=p?((p+(l*m))%m):(l*m);this.month=null}if(!this.unit){this.unit="day"}if(this[this.unit+"s"]==null||this.operator!=null){if(!this.value){this.value=1}if(this.unit=="week"){this.unit="day";this.value=this.value*7}this[this.unit+"s"]=this.value*l}return k.add(this)}else{if(this.meridian&&this.hour){this.hour=(this.hour<13&&this.meridian=="p")?this.hour+12:this.hour}if(this.weekday&&!this.day){this.day=(k.addDays((Date.getDayNumberFromName(this.weekday)-k.getDay()))).getDate()}if(this.month&&!this.day){this.day=1}return k.set(this)}}};var b=Date.Parsing.Operators,e=Date.Grammar,d=Date.Translator,j;e.datePartDelimiter=b.rtoken(/^([\s\-\.\,\/\x27]+)/);e.timePartDelimiter=b.stoken(":");e.whiteSpace=b.rtoken(/^\s*/);e.generalDelimiter=b.rtoken(/^(([\s\,]|at|on)+)/);var a={};e.ctoken=function(n){var m=a[n];if(!m){var o=Date.CultureInfo.regexPatterns;var l=n.split(/\s+/),k=[];for(var g=0;g<l.length;g++){k.push(b.replace(b.rtoken(o[l[g]]),l[g]))}m=a[n]=b.any.apply(null,k)}return m};e.ctoken2=function(g){return b.rtoken(Date.CultureInfo.regexPatterns[g])};e.h=b.cache(b.process(b.rtoken(/^(0[0-9]|1[0-2]|[1-9])/),d.hour));e.hh=b.cache(b.process(b.rtoken(/^(0[0-9]|1[0-2])/),d.hour));e.H=b.cache(b.process(b.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/),d.hour));e.HH=b.cache(b.process(b.rtoken(/^([0-1][0-9]|2[0-3])/),d.hour));e.m=b.cache(b.process(b.rtoken(/^([0-5][0-9]|[0-9])/),d.minute));e.mm=b.cache(b.process(b.rtoken(/^[0-5][0-9]/),d.minute));e.s=b.cache(b.process(b.rtoken(/^([0-5][0-9]|[0-9])/),d.second));e.ss=b.cache(b.process(b.rtoken(/^[0-5][0-9]/),d.second));e.hms=b.cache(b.sequence([e.H,e.mm,e.ss],e.timePartDelimiter));e.t=b.cache(b.process(e.ctoken2("shortMeridian"),d.meridian));e.tt=b.cache(b.process(e.ctoken2("longMeridian"),d.meridian));e.z=b.cache(b.process(b.rtoken(/^(\+|\-)?\s*\d\d\d\d?/),d.timezone));e.zz=b.cache(b.process(b.rtoken(/^(\+|\-)\s*\d\d\d\d/),d.timezone));e.zzz=b.cache(b.process(e.ctoken2("timezone"),d.timezone));e.timeSuffix=b.each(b.ignore(e.whiteSpace),b.set([e.tt,e.zzz]));e.time=b.each(b.optional(b.ignore(b.stoken("T"))),e.hms,e.timeSuffix);e.d=b.cache(b.process(b.each(b.rtoken(/^([0-2]\d|3[0-1]|\d)/),b.optional(e.ctoken2("ordinalSuffix"))),d.day));e.dd=b.cache(b.process(b.each(b.rtoken(/^([0-2]\d|3[0-1])/),b.optional(e.ctoken2("ordinalSuffix"))),d.day));e.ddd=e.dddd=b.cache(b.process(e.ctoken("sun mon tue wed thu fri sat"),function(g){return function(){this.weekday=g}}));e.M=b.cache(b.process(b.rtoken(/^(1[0-2]|0\d|\d)/),d.month));e.MM=b.cache(b.process(b.rtoken(/^(1[0-2]|0\d)/),d.month));e.MMM=e.MMMM=b.cache(b.process(e.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"),d.month));e.y=b.cache(b.process(b.rtoken(/^(\d\d?)/),d.year));e.yy=b.cache(b.process(b.rtoken(/^(\d\d)/),d.year));e.yyy=b.cache(b.process(b.rtoken(/^(\d\d?\d?\d?)/),d.year));e.yyyy=b.cache(b.process(b.rtoken(/^(\d\d\d\d)/),d.year));j=function(){return b.each(b.any.apply(null,arguments),b.not(e.ctoken2("timeContext")))};e.day=j(e.d,e.dd);e.month=j(e.M,e.MMM);e.year=j(e.yyyy,e.yy);e.orientation=b.process(e.ctoken("past future"),function(g){return function(){this.orient=g}});e.operator=b.process(e.ctoken("add subtract"),function(g){return function(){this.operator=g}});e.rday=b.process(e.ctoken("yesterday tomorrow today now"),d.rday);e.unit=b.process(e.ctoken("minute hour day week month year"),function(g){return function(){this.unit=g}});e.value=b.process(b.rtoken(/^\d\d?(st|nd|rd|th)?/),function(g){return function(){this.value=g.replace(/\D/g,"")}});e.expression=b.set([e.rday,e.operator,e.value,e.unit,e.orientation,e.ddd,e.MMM]);j=function(){return b.set(arguments,e.datePartDelimiter)};e.mdy=j(e.ddd,e.month,e.day,e.year);e.ymd=j(e.ddd,e.year,e.month,e.day);e.dmy=j(e.ddd,e.day,e.month,e.year);e.date=function(g){return((e[Date.CultureInfo.dateElementOrder]||e.mdy).call(this,g))};e.format=b.process(b.many(b.any(b.process(b.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),function(g){if(e[g]){return e[g]}else{throw Date.Parsing.Exception(g)}}),b.process(b.rtoken(/^[^dMyhHmstz]+/),function(g){return b.ignore(b.stoken(g))}))),function(g){return b.process(b.each.apply(null,g),d.finishExact)});var i={};var c=function(g){return i[g]=(i[g]||e.format(g)[0])};e.formats=function(k){if(k instanceof Array){var l=[];for(var g=0;g<k.length;g++){l.push(c(k[g]))}return b.any.apply(null,l)}else{return c(k)}};e._formats=e.formats(["yyyy-MM-ddTHH:mm:ss","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","d"]);e._start=b.process(b.set([e.date,e.time,e.expression],e.generalDelimiter,e.whiteSpace),d.finish);e.start=function(g){try{var k=e._formats.call({},g);if(k[1].length===0){return k}}catch(l){}return e._start.call({},g)}}());Date._parse=Date.parse;Date.parse=function(a){var b=null;if(!a){return null}try{b=Date.Grammar.start.call({},a)}catch(c){return null}return((b[1].length===0)?b[0]:null)};Date.getParseFunction=function(b){var a=Date.Grammar.formats(b);return function(c){var d=null;try{d=a.call({},c)}catch(f){return null}return((d[1].length===0)?d[0]:null)}};Date.parseExact=function(a,b){return Date.getParseFunction(b)(a)};TimeSpan=function(f,a,d,e,c){this.days=0;this.hours=0;this.minutes=0;this.seconds=0;this.milliseconds=0;if(arguments.length==5){this.days=f;this.hours=a;this.minutes=d;this.seconds=e;this.milliseconds=c}else{if(arguments.length==1&&typeof f=="number"){var b=(f<0)?-1:+1;this.milliseconds=Math.abs(f);this.days=Math.floor(this.milliseconds/(24*60*60*1000))*b;this.milliseconds=this.milliseconds%(24*60*60*1000);this.hours=Math.floor(this.milliseconds/(60*60*1000))*b;this.milliseconds=this.milliseconds%(60*60*1000);this.minutes=Math.floor(this.milliseconds/(60*1000))*b;this.milliseconds=this.milliseconds%(60*1000);this.seconds=Math.floor(this.milliseconds/1000)*b;this.milliseconds=this.milliseconds%1000;this.milliseconds=this.milliseconds*b;return this}else{return null}}};TimeSpan.prototype.compare=function(c){var b=new Date(1970,1,1,this.hours(),this.minutes(),this.seconds()),a;if(c===null){a=new Date(1970,1,1,0,0,0)}else{a=new Date(1970,1,1,c.hours(),c.minutes(),c.seconds())}return(b>a)?1:(b<a)?-1:0};TimeSpan.prototype.add=function(a){return(a===null)?this:this.addSeconds(a.getTotalMilliseconds()/1000)};TimeSpan.prototype.subtract=function(a){return(a===null)?this:this.addSeconds(-a.getTotalMilliseconds()/1000)};TimeSpan.prototype.addDays=function(a){return new TimeSpan(this.getTotalMilliseconds()+(a*24*60*60*1000))};TimeSpan.prototype.addHours=function(a){return new TimeSpan(this.getTotalMilliseconds()+(a*60*60*1000))};TimeSpan.prototype.addMinutes=function(a){return new TimeSpan(this.getTotalMilliseconds()+(a*60*1000))};TimeSpan.prototype.addSeconds=function(a){return new TimeSpan(this.getTotalMilliseconds()+(a*1000))};TimeSpan.prototype.addMilliseconds=function(a){return new TimeSpan(this.getTotalMilliseconds()+a)};TimeSpan.prototype.getTotalMilliseconds=function(){return(this.days()*(24*60*60*1000))+(this.hours()*(60*60*1000))+(this.minutes()*(60*1000))+(this.seconds()*(1000))};TimeSpan.prototype.get12HourHour=function(){return((h=this.hours()%12)?h:12)};TimeSpan.prototype.getDesignator=function(){return(this.hours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator};TimeSpan.prototype.toString=function(c){function d(){if(this.days()!==null&&this.days()>0){return this.days()+"."+this.hours()+":"+b(this.minutes())+":"+b(this.seconds())}else{return this.hours()+":"+b(this.minutes())+":"+b(this.seconds())}}function b(e){return(e.toString().length<2)?"0"+e:e}var a=this;return c?c.replace(/d|dd|HH|H|hh|h|mm|m|ss|s|tt|t/g,function(e){switch(e){case"d":return a.days();case"dd":return b(a.days());case"H":return a.hours();case"HH":return b(a.hours());case"h":return a.get12HourHour();case"hh":return b(a.get12HourHour());case"m":return a.minutes();case"mm":return b(a.minutes());case"s":return a.seconds();case"ss":return b(a.seconds());case"t":return((this.hours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator).substring(0,1);case"tt":return(this.hours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator}}):this._toString()};var TimePeriod=function(e,a,m,g,c,j,b){this.years=0;this.months=0;this.days=0;this.hours=0;this.minutes=0;this.seconds=0;this.milliseconds=0;if(arguments.length==2&&arguments[0] instanceof Date&&arguments[1] instanceof Date){var n=e.clone();var l=a.clone();var k=n.clone();var d=(n>l)?-1:+1;this.years=l.getFullYear()-n.getFullYear();k.addYears(this.years);if(d==+1){if(k>l){if(this.years!==0){this.years--}}}else{if(k<l){if(this.years!==0){this.years++}}}n.addYears(this.years);if(d==+1){while(n<l&&n.clone().addDays(n.getDaysInMonth())<l){n.addMonths(1);this.months++}}else{while(n>l&&n.clone().addDays(-n.getDaysInMonth())>l){n.addMonths(-1);this.months--}}var i=l-n;if(i!==0){var f=new TimeSpan(i);this.days=f.days;this.hours=f.hours;this.minutes=f.minutes;this.seconds=f.seconds;this.milliseconds=f.milliseconds}return this}};