var jsCalendar=function(){function n(){arguments.length!==0&&this._construct(arguments)}return n.version="v1.4.2",n.prototype._construct=function(n){n=this._parseArguments(n);this._init(n.options);this._setTarget(n.target);this._initTarget();this._setDate(n.date);this._create();this._update()},n.prototype.languages={en:{months:["январь","февраль","март","апрель","май","июнь","июль","август","сентябрь","октябрь","ноябрь","декабрь"],days:["вс","пн","вт","ср","чт","пт","сб"]}},n.prototype._init=function(n){this._elements={};this._events={};this._events.date=[];this._events.month=[];this._now=null;this._date=null;this._selected=[];this.language={};this._parseOptions(n);this._selectedClassName=""},n.prototype._parseArguments=function(n){var t={target:null,date:new Date,options:{}};if(n.length===0)throw new Error("jsCalendar: No parameters were given.");else if(n.length===1)if((typeof HTMLElement=="object"?n[0]instanceof HTMLElement:n[0])&&typeof n[0]=="object"&&n[0]!==null&&n[0].nodeType===1&&typeof n[0].nodeName=="string"||typeof n[0]=="string")t.target=n[0];else{if(t.options=n[0],typeof n[0].target!="undefined")t.target=n[0].target;else throw new Error("jsCalendar: Not target was given.");typeof n[0].date!="undefined"&&(t.date=n[0].date)}else t.target=n[0],n.length>=2&&(t.date=n[1]),n.length>=3&&(t.options=n[2]);return t},n.prototype._parseOptions=function(n){this._options={language:"en",zeroFill:!1,monthFormat:"month",dayFormat:"D",firstDayOfTheWeek:1,navigator:!0,navigatorPosition:"both",min:!1,max:!1};typeof n.zeroFill!="undefined"&&(this._options.zeroFill=n.zeroFill!=="false"&&n.zeroFill?!0:!1);typeof n.monthFormat!="undefined"&&(this._options.monthFormat=n.monthFormat);typeof n.dayFormat!="undefined"&&(this._options.dayFormat=n.dayFormat);typeof n.navigator!="undefined"&&(this._options.navigator=n.navigator!=="false"&&n.navigator?!0:!1);typeof n.navigatorPosition!="undefined"&&(this._options.navigatorPosition=n.navigatorPosition);typeof n.language=="string"&&typeof this.languages[n.language]!="undefined"&&(this._options.language=n.language);this.setLanguage(this._options.language);typeof n.fdotw!="undefined"&&(n.firstDayOfTheWeek=n.fdotw);typeof n.firstDayOfTheWeek!="undefined"&&(typeof n.firstDayOfTheWeek=="number"&&n.firstDayOfTheWeek>=1&&n.firstDayOfTheWeek<=7&&(this._options.firstDayOfTheWeek=n.firstDayOfTheWeek),typeof n.firstDayOfTheWeek=="string"&&(n.firstDayOfTheWeek.match(/^[1-7]$/)?this._options.firstDayOfTheWeek=parseInt(n.firstDayOfTheWeek,10):(this._options.firstDayOfTheWeek=this.language.days.indexOf(n.firstDayOfTheWeek)+1,(this._options.firstDayOfTheWeek<1||this._options.firstDayOfTheWeek>7)&&(this._options.firstDayOfTheWeek=1))));typeof n.min!="undefined"&&n.min!=="false"&&n.min!==!1&&(this._options.min=this._parseDate(n.min));typeof n.max!="undefined"&&n.max!=="false"&&n.max!==!1&&(this._options.max=this._parseDate(n.max))},n.prototype._setTarget=function(n){var t=this._getElement(n);if(t)this._target=t;else throw new Error("jsCalendar: Target was not found.");},n.prototype._getElement=function(n){if(!n)return null;if(typeof n=="string"){if(n[0]==="#")return document.getElementById(n.substring(1));if(n[0]===".")return document.getElementsByClassName(n.substring(1))[0]}else if(n.tagName&&n.nodeName&&n.ownerDocument&&n.removeAttribute)return n;return null},n.prototype._initTarget=function(){this._target.className.length>0&&(this._target.className+=" ");this._target.className+="jsCalendar";this._elements.table=document.createElement("table");this._elements.head=document.createElement("thead");this._elements.table.appendChild(this._elements.head);this._elements.body=document.createElement("tbody");this._elements.table.appendChild(this._elements.body);this._target.appendChild(this._elements.table)},n.prototype._isDateInRange=function(n){return this._options.min===!1&&this._options.max===!1?!0:(n=this._parseDate(n),this._options.min!==!1&&this._options.min.getTime()>n.getTime())?!1:this._options.max!==!1&&this._options.max.getTime()<n.getTime()?!1:!0},n.prototype._setDate=function(n){this._isDateInRange(n)&&(this._now=this._parseDate(n),this._date=new Date(this._now.getFullYear(),this._now.getMonth(),1))},n.prototype._parseDate=function(n){if(typeof n=="undefined"||n===null||n==="now")n=new Date;else if(typeof n=="string")if(n=n.replace(/-/g,"/").match(/^(\d{1,2})\/(\d{1,2})\/(\d{4,4})$/i),n!==null){var t=parseInt(n[2],10)-1;if(n=new Date(n[3],t,n[1]),!n||n.getMonth()!==t)throw new Error("jsCalendar: Date does not exist.");}else throw new Error("jsCalendar: Failed to parse date.");else if(typeof n=="number")n=new Date(n);else if(!(n instanceof Date))throw new Error("jsCalendar: Invalid date.");return new Date(n.getTime())},n.prototype._parseToDateString=function(n,t){var i=this.language;return t.replace(/(MONTH|month|MMM|mmm|mm|m|MM|M|DAY|day|DDD|ddd|dd|d|DD|D|YYYY|yyyy)/g,function(t){switch(t){case"MONTH":case"month":return i.months[n.getMonth()];case"MMM":case"mmm":return i.months[n.getMonth()].substring(0,3);case"mm":return i.months[n.getMonth()].substring(0,2);case"m":return i.months[n.getMonth()].substring(0,1);case"MM":return(n.getMonth()<9?"0":"")+(n.getMonth()+1);case"M":return n.getMonth()+1;case"DAY":case"day":return i.days[n.getDay()];case"DDD":case"ddd":return i.days[n.getDay()].substring(0,3);case"dd":return i.days[n.getDay()].substring(0,2);case"d":return i.days[n.getDay()].substring(0,1);case"DD":return(n.getDate()<=9?"0":"")+n.getDate();case"D":return n.getDate();case"YYYY":case"yyyy":return n.getYear()+1900}})},n.prototype._getVisibleMonth=function(n){var t,i;n=typeof n=="undefined"?this._date:this._parseDate(n);t=new Date(n.getTime());t.setDate(1);i=t.getDay()-(this._options.firstDayOfTheWeek-1);i<0&&(i+=7);var r=this.language,f=this._options.monthFormat.replace(/(MONTH|month|MMM|mmm|##|#|YYYY|yyyy)/g,function(n){switch(n){case"MONTH":case"month":return r.months[t.getMonth()];case"MMM":case"mmm":return r.months[t.getMonth()].substring(0,3);case"##":return(t.getMonth()<9?"0":"")+(t.getMonth()+1);case"#":return t.getMonth()+1;case"YYYY":case"yyyy":return t.getYear()+1900}}),e=this._getVisibleDates(n),o=new Date(t.getYear()+1900,t.getMonth()+1,0).getDate(),u=-1;return t.getYear()===this._now.getYear()&&t.getMonth()===this._now.getMonth()&&(u=i+this._now.getDate()-1),{name:f,days:e,start:i+1,current:u,end:i+o}},n.prototype._getVisibleDates=function(n){var i,r,u,t,f;for(n=typeof n=="undefined"?this._date:this._parseDate(n),i=[],r=new Date(n.getTime()),r.setDate(1),u=r.getDay()-(this._options.firstDayOfTheWeek-1),u<0&&(u+=7),t=new Date(r.getTime());u>0;)t.setDate(t.getDate()-1),i.unshift(new Date(t.getTime())),u--;t=new Date(r.getTime());do i.push(new Date(t.getTime())),t.setDate(t.getDate()+1);while(t.getDate()!==1);for(f=42-i.length;f>0;)i.push(new Date(t.getTime())),t.setDate(t.getDate()+1),f--;return i},n.prototype._create=function(){var t=this,n,i,f,u,r;for(this._elements.created=!0,this._elements.headRows=[],n=0;n<2;n++)this._elements.headRows.push(document.createElement("tr")),this._elements.head.appendChild(this._elements.headRows[n]);for(i=document.createElement("th"),i.setAttribute("colspan",7),this._elements.headRows[0].className="jsCalendar-title-row",this._elements.headRows[0].appendChild(i),this._elements.headLeft=document.createElement("div"),this._elements.headLeft.className="jsCalendar-title-left",i.appendChild(this._elements.headLeft),this._elements.month=document.createElement("div"),this._elements.month.className="jsCalendar-title-name",i.appendChild(this._elements.month),this._elements.headRight=document.createElement("div"),this._elements.headRight.className="jsCalendar-title-right",i.appendChild(this._elements.headRight),this._options.navigator&&(this._elements.navLeft=document.createElement("div"),this._elements.navLeft.className="jsCalendar-nav-left",this._elements.navRight=document.createElement("div"),this._elements.navRight.className="jsCalendar-nav-right",this._options.navigatorPosition==="left"?(this._elements.headLeft.appendChild(this._elements.navLeft),this._elements.headLeft.appendChild(this._elements.navRight)):this._options.navigatorPosition==="right"?(this._elements.headRight.appendChild(this._elements.navLeft),this._elements.headRight.appendChild(this._elements.navRight)):(this._elements.headLeft.appendChild(this._elements.navLeft),this._elements.headRight.appendChild(this._elements.navRight)),this._elements.navLeft.addEventListener("click",function(n){t.previous();t._eventFire_monthChange(n,t._date)},!1),this._elements.navRight.addEventListener("click",function(n){t.next();t._eventFire_monthChange(n,t._date)},!1)),this._elements.headRows[1].className="jsCalendar-week-days",i.className="jsCalendar-title",this._elements.days=[],n=0;n<7;n++)this._elements.days.push(document.createElement("th")),this._elements.headRows[1].appendChild(this._elements.days[this._elements.days.length-1]),u=this.language.days[(n+this._options.firstDayOfTheWeek-1)%7],f=this._options.dayFormat.replace(/(DAY|day|DDD|ddd|DD|dd|D)/g,function(n){switch(n){case"DAY":case"day":return u;case"DDD":case"ddd":return u.substring(0,3);case"DD":case"dd":return u.substring(0,2);case"D":return u.substring(0,1)}}),this._elements.days[this._elements.days.length-1].textContent=f;for(this._elements.bodyRows=[],this._elements.bodyCols=[],n=0;n<6;n++)for(this._elements.bodyRows.push(document.createElement("tr")),this._elements.body.appendChild(this._elements.bodyRows[n]),r=0;r<7;r++)this._elements.bodyCols.push(document.createElement("td")),this._elements.bodyRows[n].appendChild(this._elements.bodyCols[n*7+r]),this._elements.bodyCols[n*7+r].addEventListener("click",function(n){return function(i){t._eventFire_dateClick(i,t._active[n])}}(n*7+r),!1)},n.prototype._selectDates=function(n){n=n.slice();for(var t=0;t<n.length;t++)n[t]=this._parseDate(n[t]),n[t].setHours(0,0,0,0),n[t]=n[t].getTime();for(t=n.length-1;t>=0;t--)this._selected.indexOf(n[t])<0&&this._selected.push(n[t])},n.prototype._unselectDates=function(n){var t,i;for(n=n.slice(),t=0;t<n.length;t++)n[t]=this._parseDate(n[t]),n[t].setHours(0,0,0,0),n[t]=n[t].getTime();for(t=n.length-1;t>=0;t--)i=this._selected.indexOf(n[t]),i>=0&&this._selected.splice(i,1)},n.prototype._unselectAllDates=function(){while(this._selected.length)this._selected.pop()},n.prototype._update=function(){var t=this._getVisibleMonth(this._date),r,i,n,u;for(this._active=t.days.slice(),this._elements.month.textContent=t.name,r="",this._options.zeroFill&&(r="0"),n=t.days.length-1;n>=0;n--)i=t.days[n].getDate(),this._elements.bodyCols[n].textContent=i<10?r+i:i,this._selected.indexOf(t.days[n].getTime())>=0?(u=this._elements.bodyCols[n],$(u).hasClass("jsCalendar-selected")||(this._elements.bodyCols[n].className="jsCalendar-selected "+this._selectedClassName)):this._elements.bodyCols[n].removeAttribute("class");for(n=0;n<t.start-1;n++)this._elements.bodyCols[n].className="jsCalendar-previous";for(t.current>=0&&(this._elements.bodyCols[t.current].className.length>0?this._elements.bodyCols[t.current].className+=" jsCalendar-current":this._elements.bodyCols[t.current].className="jsCalendar-current"),n=t.end;n<t.days.length;n++)this._elements.bodyCols[n].className="jsCalendar-next"},n.prototype._eventFire_dateClick=function(n,t){for(var i=0;i<this._events.date.length;i++)(function(i){setTimeout(function(){i(n,new Date(t.getTime()))},0)})(this._events.date[i])},n.prototype._eventFire_monthChange=function(n,t){var r=new Date(t.getTime()),i;for(r.setDate(1),i=0;i<this._events.month.length;i++)(function(t){setTimeout(function(){t(n,new Date(r.getTime()))},0)})(this._events.month[i])},n.prototype.onDateClick=function(n){if(typeof n=="function")this._events.date.push(n);else throw new Error("jsCalendar: Invalid callback function.");return this},n.prototype.onMonthChange=function(n){if(typeof n=="function")this._events.month.push(n);else throw new Error("jsCalendar: Invalid callback function.");return this},n.prototype.set=function(n){return this._setDate(n),this.refresh(),this},n.prototype.min=function(n){return this._options.min=n?this._parseDate(n):!1,this.refresh(),this},n.prototype.max=function(n){return this._options.max=n?this._parseDate(n):!1,this.refresh(),this},n.prototype.refresh=function(n){return typeof n!="undefined"&&this._isDateInRange(n)&&(this._date=this._parseDate(n)),this._elements.created===!0&&this._update(),this},n.prototype.next=function(n){typeof n!="number"&&(n=1);var t=new Date(this._date.getFullYear(),this._date.getMonth()+n,1);return this._isDateInRange(t)?(this._date=t,this.refresh(),this):this},n.prototype.previous=function(n){typeof n!="number"&&(n=1);var t=new Date(this._date.getFullYear(),this._date.getMonth()-n,1);return this._isDateInRange(t)?(this._date=t,this.refresh(),this):this},n.prototype.goto=function(n){return this.refresh(n),this},n.prototype.reset=function(){return this.refresh(this._now),this},n.prototype.select=function(n,t){return(this._selectedClassName=t,typeof n=="undefined")?this:(n instanceof Array||(n=[n]),this._selectDates(n),this.refresh(),this)},n.prototype.unselect=function(n){return typeof n=="undefined"?this:(n instanceof Array||(n=[n]),this._unselectDates(n),this.refresh(),this)},n.prototype.clearselect=function(){return this._unselectAllDates(),this.refresh(),this},n.prototype.clearSelected=n.prototype.clearselect,n.prototype.getSelected=function(n){var t,i;if(typeof n!="object"&&(n={}),t=this._selected.slice(),n.sort&&(n.sort===!0?t.sort():typeof n.sort=="string"&&(n.sort.toLowerCase()==="asc"?t.sort():n.sort.toLowerCase()==="desc"&&(t.sort(),t.reverse()))),n.type&&typeof n.type=="string")if(n.type.toLowerCase()==="date")for(i=t.length-1;i>=0;i--)t[i]=new Date(t[i]);else if(n.type.toLowerCase()!=="timestamp")for(i=t.length-1;i>=0;i--)t[i]=this._parseToDateString(new Date(t[i]),n.type);return t},n.prototype.isSelected=function(n){return typeof n=="undefined"||n===null?!1:(n=this._parseDate(n),n.setHours(0,0,0,0),n=n.getTime(),this._selected.indexOf(n)>=0?!0:!1)},n.prototype.isVisible=function(n){if(typeof n=="undefined"||n===null)return!1;n=this._parseDate(n);n.setHours(0,0,0,0);n=n.getTime();var t=this._getVisibleDates();return t[0].getTime()<=n&&t[t.length-1].getTime()>=n?!0:!1},n.prototype.isInMonth=function(n){var t,i;return typeof n=="undefined"||n===null?!1:(t=this._parseDate(n),t.setHours(0,0,0,0),t.setDate(1),i=this._parseDate(this._date),i.setHours(0,0,0,0),i.setDate(1),t.getTime()===i.getTime()?!0:!1)},n.prototype.setLanguage=function(n){if(typeof n!="string")throw new Error("jsCalendar: Invalid language code.");if(typeof this.languages[n]=="undefined")throw new Error("jsCalendar: Language not found.");return this._options.language=n,this.language.months=this.languages[this._options.language].months,this.language.days=this.languages[this._options.language].days,this.refresh(),this},n.autoFind=function(){for(var t=document.getElementsByClassName("auto-jsCalendar"),i,r,n=0;n<t.length;n++)if(t[n].getAttribute("jsCalendar-loaded")!=="true"){t[n].setAttribute("jsCalendar-loaded","true");i={};for(r in t[n].dataset)i[r]=t[n].dataset[r];i.target=t[n];new jsCalendar(i)}},n.tools={},n.tools.parseDate=function(){return n.prototype._parseDate.apply({},arguments)},n.tools.stringToDate=n.tools.parseDate,n.tools.dateToString=function(t,i,r){var u=n.prototype.languages;return r&&u.hasOwnProperty(r)||(r="en"),n.prototype._parseToDateString.apply({language:u[r]},[t,i])},n.new=function(){var t=new n;return t._construct(arguments),t},n.addLanguage=function(t){if(typeof t=="undefined")throw new Error("jsCalendar: No language object was given.");if(typeof t.code!="string")throw new Error("jsCalendar: Invalid language code.");if(!(t.months instanceof Array))throw new Error("jsCalendar: Invalid language months.");if(t.months.length!==12)throw new Error("jsCalendar: Invalid language months length.");if(!(t.days instanceof Array))throw new Error("jsCalendar: Invalid language days.");if(t.days.length!==7)throw new Error("jsCalendar: Invalid language days length.");n.prototype.languages[t.code]={months:t.months.slice(),days:t.days.slice()}},function(){if(typeof window.jsCalendar_language2load!="undefined"){while(window.jsCalendar_language2load.length)setTimeout(function(t){return function(){n.addLanguage(t)}}(window.jsCalendar_language2load.pop()),0);delete window.jsCalendar_language2load}}(),n}();(function(){window.addEventListener("load",function(){jsCalendar.autoFind()},!1)})()