/* -- DO NOT REMOVE --
 * jQuery DCalendar and DCalendar Picker 2.1 plugin
 *
 * Author: Dionlee Uy
 * Email: dionleeuy@gmail.com
 *
 * Date: Thursday, May 12 2016
 *
 * @requires jQuery
 * -- DO NOT REMOVE --
 */
 if("undefined"===typeof jQuery)throw Error("DCalendar.Picker: This plugin requires jQuery");
 +function(f){Date.prototype.getDays=function(){return(new Date(this.getFullYear(),this.getMonth()+1,0)).getDate()};var v="January February March April May June July August September October November December".split(" "),y="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),A="Sun Mon Tue Wed Thu Fri Sat".split(" "),B=[9,112,113,114,115,116,117,118,119,120,121,122,123],x=function(a,d){this.elem=f(a);this.options=d;this.calendar=null;this.today=new Date;this.date=""===this.elem.val()?new Date:
 this.reformatDate(this.elem.val()).date;this.viewMode="days";this.minDate=this.elem.data("mindate");this.maxDate=this.elem.data("maxdate");this.rangeFromEl=this.elem.data("rangefrom");this.rangeToEl=this.elem.data("rangeto");this.selected=new Date(this.date.getFullYear(),this.date.getMonth(),this.date.getDate());var b=this;this.create(this.viewMode);this.calendar.find(".calendar-head-card .calendar-date-wrapper").click(function(){b.selected=new Date(b.today.getFullYear(),b.today.getMonth(),b.today.getDate());
 b.selectDate();b.selectedView()});this.calendar.find(".calendar-prev").click(function(){b.getNewMonth("left",!0)});this.calendar.find(".calendar-next").click(function(){b.getNewMonth("right",!0)});this.calendar.find(".calendar-curr-month").click(function(){b.getMonths()});this.calendar.find(".calendar-date-holder").on("click",".calendar-dates .date.month a",function(){var e=parseInt(f(this).parent().attr("data-month"));b.viewMode="days";b.date.setMonth(e);b.getNewMonth(null,!1)});this.getNewMonth(null,
 !1)};x.prototype={constructor:x,reformatDate:function(a,d){var b="undefined"===typeof d?this.options.format:d,e=(b.match(/d/g)||[]).length,c=(b.match(/m/g)||[]).length,k=(b.match(/y/g)||[]).length,q=4==c,l=1==c,r=1==e,t=a.length,h=b.indexOf("m"),g=b.indexOf("d"),m=b.indexOf("y"),n="",p="",u="";if(q){var w=-1;f.each(v,function(z,C){0<=a.indexOf(C)&&(w=z)});n=v[w];b=b.replace("mmmm",n);g=b.indexOf("d");m=m<h?b.indexOf("y"):b.indexOf("y",b.indexOf(n)+n.length)}else!r&&!l||r&&!l&&h<g?n=a.substr(h,c):
 (n=b.lastIndexOf("m"),c=b.substring(h-1,h),p=b.substring(n+1,n+2),n=n==b.length-1?a.substring(a.indexOf(c,h-1)+1,t):0==h?a.substring(0,a.indexOf(p,h)):a.substring(a.indexOf(c,h-1)+1,a.indexOf(p,h+1)));!r&&!l||!r&&l&&g<h?p=a.substr(g,e):(e=b.lastIndexOf("d"),c=b.substring(g-1,g),p=b.substring(e+1,e+2),p=e==b.length-1?a.substring(a.indexOf(c,g-1)+1,t):0==g?a.substring(0,a.indexOf(p,g)):a.substring(a.indexOf(c,g-1)+1,a.indexOf(p,g+1)));!l&&!r||l&&r&&m<h&&m<g||!l&&r&&m<g||l&&!r&&m<h?u=a.substr(m,k):(c=
 b.substring(m-1,m),u=a.substr(a.indexOf(c,m-1)+1,k));return{m:n,d:p,y:u,date:isNaN(parseInt(n))?new Date(n+" "+p+", "+u):new Date(u,n-1,p)}},formatDate:function(a){var d=new Date(this.selected),b=d.getDate(),e=d.getMonth(),c=d.getFullYear();return a.replace(/(yyyy|yy|mmmm|mmm|mm|m|dd|d)/gi,function(k){switch(k.toLowerCase()){case "d":return b;case "dd":return 10>b?"0"+b:b;case "m":return e+1;case "mm":return 10>e+1?"0"+(e+1):e+1;case "mmm":return y[e];case "mmmm":return v[e];case "yy":return c.toString().substr(2,
 2);case "yyyy":return c}})},selectDate:function(){var a=this.formatDate(this.options.format);a=f.Event("dateselected",{date:a});this.elem.trigger(a)},disabledDate:function(a){var d=null,b=null,e=null,c=null,k=null,q=null,l=new Date;l=new Date(l.getFullYear(),l.getMonth(),l.getDate());this.minDate&&(k="today"===this.minDate?l:new Date(this.minDate));this.maxDate&&(q="today"===this.maxDate?l:new Date(this.maxDate));this.rangeFromEl&&(d=f(this.rangeFromEl),e=d.data("dcalendar"),fromFormat=e.options.format,
 fromVal=d.val(),d=this.reformatDate(fromVal,fromFormat).date,e="today"===e.minDate?l:new Date(e.minDate));this.rangeToEl&&(b=f(this.rangeToEl),c=b.data("dcalendar"),toFormat=c.options.format,toVal=b.val(),b=this.reformatDate(toVal,toFormat).date,c="today"===c.maxDate?l:new Date(c.maxDate));return k&&a<k||q&&a>q||d&&a<d||b&&a>b||e&&a<e||c&&a>c},getMonths:function(){this.today.getFullYear();this.today.getMonth();if("days"===this.viewMode){var a=this.calendar;curr=a.find(".calendar-dates");dayLabel=
 a.find(".calendar-labels");currMonth=a.find(".calendar-curr-month");container=a.find(".calendar-date-holder");cElem=curr.clone();rows=[];cells=[];count=0;this.viewMode="months";currMonth.text(this.date.getFullYear());dayLabel.addClass("invis");for(a=1;4>a;a++){for(var d=[f("<span class='date month'></span>"),f("<span class='date month'></span>"),f("<span class='date month'></span>"),f("<span class='date month'></span>")],b=0;4>b;b++)d[b].html("<a href='javascript:void(0);'>"+y[count]+"</a>").attr("data-month",
 count),count++;rows.push(d)}f.each(rows,function(e,c){var k=f('<span class="cal-row"></span>'),q=c.length;for(e=0;e<q;e++)k.append(c[e]);cells.push(k)});container.parent().height(container.parent().outerHeight(!0));cElem.empty().append(cells).addClass("months load").appendTo(container);curr.addClass("hasmonths");setTimeout(function(){cElem.removeClass("load")},10);setTimeout(function(){curr.remove()},300)}},getDays:function(a,d){var b=new Date(a.getFullYear(),a.getMonth(),a.getDate()),e=new Date(this.today.getFullYear(),
 this.today.getMonth(),this.today.getDate());b=b.getDays();for(var c=1,k=new Date(a.getFullYear(),a.getMonth(),a.getDate()),q=1,l=[],r=[],t=1;6>=t;t++){for(var h=[f('<span class="date"></span>'),f('<span class="date"></span>'),f('<span class="date"></span>'),f('<span class="date"></span>'),f('<span class="date"></span>'),f('<span class="date"></span>'),f('<span class="date"></span>')];c<=b;){k.setDate(c);var g=k.getDay();g--; -1===g&&(g=6);k.getTime()==e.getTime()&&h[g].addClass("current");this.disabledDate(k)&&
 h[g].addClass("disabled");if(1===t&&0===g)break;else if(6>g)k.getTime()==this.selected.getTime()&&h[g].addClass("selected"),h[g].html('<a href="javascript:void(0);">'+c++ +"</a>");else{k.getTime()==this.selected.getTime()&&h[g].addClass("selected");h[g].html('<a href="javascript:void(0);">'+c++ +"</a>");break}}if(1===t||4<t)if(1===t){var m=new Date(a.getFullYear(),a.getMonth()-1,1);m.getMonth();var n=0;n=m.getDays();for(g=6;0<=g;g--)""===h[g].text()&&(m.setDate(n),h[g].html('<a href="javascript:void(0);">'+
 n--+"</a>").addClass("pm"),this.disabledDate(m)&&h[g].addClass("disabled"),m.getTime()==this.selected.getTime()&&h[g].addClass("selected"),m.getTime()==e.getTime()&&h[g].addClass("current"))}else if(4<t)for(m=new Date(k.getFullYear(),k.getMonth()+1,1),g=0;6>=g;g++)""===h[g].text()&&(m.setDate(q),h[g].html('<a href="javascript:void(0);">'+q++ +"</a>").addClass("nm"),this.disabledDate(m)&&h[g].addClass("disabled"),m.getTime()==this.selected.getTime()&&h[g].addClass("selected"),m.getTime()==e.getTime()&&
 h[g].addClass("current"));l.push(h)}f.each(l,function(p,u){var w=f('<span class="cal-row"></span>'),z=u.length;for(p=0;p<z;p++)w.append(u[p]);r.push(w)});d(r)},getNewMonth:function(a,d){var b=this.calendar;curr=b.find(".calendar-dates:not(.left):not(.right)");lblTodayDay=b.find(".calendar-dayofweek");lblTodayMonth=b.find(".calendar-month");lblTodayDate=b.find(".calendar-date");lblTodayYear=b.find(".calendar-year");lblMonth=b.find(".calendar-curr-month");container=b.find(".calendar-date-holder");"days"===
 this.viewMode?(d&&(this.date.setDate(1),this.date.setMonth(this.date.getMonth()+("right"===a?1:-1))),(d||"calendar"===this.options.mode||curr.hasClass("months"))&&this.getDays(this.date,function(e){if(d){var c=curr.clone();c.addClass(a).empty().append(e)["left"==a?"prependTo":"appendTo"](container);setTimeout(function(){curr.addClass("left"==a?"right":"left");c.removeClass(a);setTimeout(function(){b.find(".calendar-dates."+("left"==a?"right":"left")).remove()},300)},10)}else curr.hasClass("months")?
 (c=curr.clone(),f(".calendar-labels").removeClass("invis"),c.empty().append(e).addClass("hasmonths").appendTo(container),curr.addClass("load"),setTimeout(function(){c.removeClass("hasmonths")},10),container.parent().removeAttr("style"),setTimeout(function(){c.removeClass("months");setTimeout(function(){b.find(".calendar-dates.months").remove()},300)},10)):curr.append(e)}),lblMonth.html(v[this.date.getMonth()]+'<hr class="lbg_evento_calendar-hr"><span class="lbg_evento_calendar-curr-year">'+this.date.getFullYear()+
 "</span>"),d||curr.hasClass("months")||(lblTodayDay.text(A[this.today.getDay()]),lblTodayMonth.text(y[this.today.getMonth()]),lblTodayDate.text(this.today.getDate()),lblTodayYear.text(this.today.getFullYear()))):(this.date.setYear(this.date.getFullYear()+("right"===a?1:-1)),lblMonth.text(this.date.getFullYear()));jQuery.lbg_evento.calendarNextMonth(this.date.getMonth(),this.date.getFullYear(),this.options.lbgInstanceName,this.options.lbgOptions,this.options.lbgCurrent_obj)},selectedView:function(){var a=
 this.calendar;curr=a.find(".calendar-dates:eq(0)");lblMonth=a.find(".calendar-curr-month");lblDays=a.find(".calendar-labels");this.getDays(this.selected,function(d){curr.html(d)});lblMonth.html(v[this.selected.getMonth()]+'<hr class="lbg_evento_calendar-hr"><span class="lbg_evento_calendar-curr-year">'+this.selected.getFullYear()+"</span>");lblDays.removeClass("invis");this.viewMode="days"},create:function(){var a=this,d=a.options.mode,b=a.options.theme,e=f('<div class="calendar-overlay"></div>'),
 c=f('<div class="calendar-wrapper load"></div>'),k=f('<section class="calendar-head-card"><span class="calendar-year"></span><span class="calendar-date-wrapper" title="Select current date."><span class="calendar-dayofweek"></span>, <span class="calendar-month"></span> <span class="calendar-date"></span></span></section>'),q=f('<div class="calendar-container"></div>'),l=f('<section class="calendar-top-selector"><span class="calendar-prev">&lsaquo;</span><span class="calendar-curr-month"></span><span class="calendar-next">&rsaquo;</span></section>'),
 r=f('<section class="calendar-grid"><div class="calendar-labels"><span>Mo</span><span>Tu</span><span>We</span><span>Th</span><span>Fr</span><span>Sa</span><span>Su</span></div><div class="calendar-date-holder"><section class="calendar-dates"></section></div></section>');l.appendTo(q);r.appendTo(q);e.click(function(t){a.hide()});c.click(function(t){t.stopPropagation()});c.append(k).append(q).appendTo("calendar"===d?a.elem:e);a.calendar="calendar"===d?a.elem:c;switch(b){case "red":case "blue":case "green":case "purple":case "indigo":case "teal":c.attr("data-theme",
 b);break;default:c.attr("data-theme",f.fn.dcalendar.defaults.theme)}"calendar"!==d&&(c.addClass("picker"),e.appendTo("body"))},show:function(){f("body").attr("datepicker-display","on");this.date=new Date(this.selected.getFullYear(),this.selected.getMonth(),this.selected.getDate());this.selectedView();this.calendar.parent().fadeIn("fast");this.calendar.removeClass("load")},hide:function(a){var d=this;d.calendar.addClass("load");d.calendar.parent().fadeOut(function(){f("body").removeAttr("datepicker-display");
 a&&a();d.elem.is("input")&&d.elem.focus()})}};f.fn.dcalendar=function(a){return f(this).each(function(d,b){var e=f(this),c=f(this).data("dcalendar"),k=f.extend({},f.fn.dcalendar.defaults,e.data(),"object"===typeof a&&a);c||e.data("dcalendar",c=new x(this,k));if("string"===typeof a)c[a]()})};f.fn.dcalendar.defaults={mode:"calendar",format:"mm/dd/yyyy",theme:"blue",readOnly:!0,lbgInstanceName:"aaa",lbgOptions:"aaa",lbgCurrent_obj:"aaa"};f.fn.dcalendar.Constructor=x;f.fn.dcalendarpicker=function(a){return f(this).each(function(){var d=
 f(this);a?(a.mode="datepicker",d.dcalendar(a)):d.dcalendar({mode:"datepicker"});d.on("click",function(b){d.data("dcalendar").show();this.blur()}).on("dateselected",function(b){var e=d.data("dcalendar");d.val(b.date).trigger("onchange");e.hide(function(){d.trigger(f.Event("datechanged",{date:b.date}))})}).on("keydown",function(b){if(0>B.indexOf(b.which)&&d.data("dcalendar").options.readOnly)return!1});f(document).on("keydown",function(b){27==b.keyCode&&d.data("dcalendar").hide()})})}}(jQuery);
