(function(i,g){i.fn.datepicker_async=function(n){this.each(function(){var o=i(this);var q;n=i.extend({},n,{onChangeMonthYear:e});o.datepicker(n);q=b(o);var p=o.datepicker("getDate");if(p==null){p=Date()}e(p.getFullYear(),1+p.getMonth(),q)});return this};function e(o,r,p){p.asyncPrepareMonthPromise=null;a(p,null);if(!p.settings.onPrepareMonthBegin){return}var s=p.settings.onPrepareMonthBegin(o,r,p);if(s){p.asyncPrepareMonthPromise=s;a(p,"loading");var q=function(){l(p)};var n=setTimeout(q,0);i(h(p)).one("click",q);s.done(function(){clearTimeout(n);i(h(p)).off("click",q);if(p.asyncPrepareMonthPromise!=s){return}p.asyncPrepareMonthPromise=null;a(p,null);i(h(p)).datepicker("refresh")});s.fail(function(){clearTimeout(n);i(h(p)).off("click",q);if(p.asyncPrepareMonthPromise!=s){return}p.asyncPrepareMonthPromise=null;a(p,"failed")})}}function a(o,n){o.asyncRequestedMask=n;l(o)}function l(o){var n=k(o);if(n&&n!=o.asyncRequestedMask){c(o)}if(o.asyncRequestedMask&&o.asyncRequestedMask!=n){switch(o.asyncRequestedMask){case"loading":m(o);break;case"failed":f(o);break}}}function c(n){i(h(n)).find(".datepicker-async-mask").remove();i(h(n)).find("table.ui-datepicker-calendar tbody").css({visibility:"inherit"})}function m(n){i(h(n)).find("table.ui-datepicker-calendar").each(function(){var o=i(this).find("tbody");o.css({visibility:"hidden"});var p=i("
").addClass("datepicker-async-mask").data("mask","loading").css({position:j(o)?"fixed":"absolute"}).insertAfter(i(this));i("Loading...
").css({marginTop:"3.5em",width:"100%",textAlign:"center"}).appendTo(p);d(o,p)})}function f(n){i(h(n)).find("table.ui-datepicker-calendar").each(function(){var o=i(this).find("tbody");o.css({visibility:"hidden"});var p=i("").addClass("datepicker-async-mask").data("mask","failed").css({position:j(o)?"fixed":"absolute"}).insertAfter(i(this));i("Failed to load
").css({marginTop:"3.5em",width:"100%",textAlign:"center"}).appendTo(p);d(o,p)})}function k(n){return i(h(n)).find(".datepicker-async-mask").data("mask")}function j(n){var o=false;n.parents().each(function(){o|=i(this).css("position")==="fixed";return !o});return o}function d(n,p){var q=n.offset();var o=p.offset();p.css({width:n.width()+"px",height:n.height()+"px",marginLeft:q.left-o.left,marginTop:q.top-o.top})}function b(n){return n.data("datepicker")}function h(n){return n.input}})(jQuery);function reservationcalendar_getBaseUrlWithReservation(){var a="https://www.hawaiifun.org/reservation/";if(/reservation\/$/.test(a)||/reservation_test\/$/.test(a)||/reservation-alt\/$/.test(a)){}else{if(/perfecthawaiivacationguide.com$/.test(window.location.hostname)||/^(\w+\.)*hawaiifun\.org$/.test(window.location.hostname)||/^(\w+\.)*hawaiifunfusion\.com/.test(window.location.hostname)){a="https://www.hawaiifun.org/reservation/"}else{a+="reservation/"}}return a}(function(c){var b=[];var a=null;window.calendar=function(e,g,f,h,d){showAvailabilityCalendar2(e,g,{local:f,webBooking:true,minavailability:h,numberOfMonths:d})};window.showSimpleCalendar=function(f,e,g){var h=c("#"+f);var i=(e?c("#"+e):h);if(h.length==0){return}if(i.length==0){i=h}var k=reservationcalendar_createDatepickerPanel(i);var d={showOn:"none",showAnim:""};if(typeof g!="undefined"){c.extend(d,g)}k.datepicker(d);k.find(".ui-datepicker").addClass("ui-datepicker_availability");var j=Date.parse(h.val());k.datepicker("setDate",j?new Date(j):null);reservationcalendar_placePanelNearAnchor(k,i);reservationcalendar_connectDatepickerToField(k,h);k.css({visibility:"inherit"});a=k.get(0)};window.showAvailabilityCalendar=function(g,f,e,d,h){if(h==null){h=true}if(!/^\d+$/.test(g)||!g){alert("Please select activity");return}showAvailabilityCalendar2(g,e,{agencyId:f,anchorId:d,local:h})};window.showAvailabilityCalendar2=function(q,s,f){var j=(f.agencyId!=null?f.agencyId:0);var x=(f.blocksOnly!=null?f.blocksOnly:false);var i=(f.anchorId!=null?f.anchorId:null);var o=(f.local!=null?f.local:false);var h=(f.webBooking!=null?f.webBooking:true);var r=(f.hawaiifunBooking!=null?f.hawaiifunBooking:false);var d=(f.agencyBooking!=null?f.agencyBooking:false);var t=(f.minavailability!=null?f.minavailability:undefined);var k=(f.numberOfMonths!=null?f.numberOfMonths:undefined);var g=c.makeArray(q);var n=c.grep(g,function(y){return !/^\d+$/.test(y)||!y}).length;if(g.length==0||n){alert("Please select activity");return}var u=(o?"":reservationcalendar_getBaseUrlWithReservation());var p=c("#"+s);var l=(i?c("#"+i):p);var m=typeof(t)=="undefined"?"":JSON.stringify(t);var w=c.makeArray(q).join("|");if(p.length==0){console.log("showAvailabilityCalendar2: No data for field "+s);return}if(l.length==0){l=p}if(typeof(k)=="undefined"){k=1}var e=reservationcalendar_createDatepickerPanel(l);e.datepicker_async({numberOfMonths:typeof(k)=="undefined"?1:k,onPrepareMonthBegin:function(D,F,E){var B=[];for(var C=0,G=D,z=F;C12){z-=12;G++}if(!(w+"_"+j+"_"+G+"_"+z+"_"+m in b)){B.push(G+"_"+z)}}if(B.length==0){return null}var A=c.Deferred();c.ajax({type:"GET",url:u+"companyservlet",dataType:"jsonp",data:{action:"COMMON_AVAILABILITYCHECKJSON",activityid:w,agencyid:j,blocksonly:x,year_months:B.join("|"),webbooking:h,hawaiifunbooking:r,agencybooking:d,minavailability:m}}).done(function(y){for(C=0;C").css({paddingTop:"1px",paddingBottom:"1px",position:f?"fixed":"absolute",visibility:"hidden",zIndex:e.zIndex()}).appendTo(e.closest("body"))};window.reservationcalendar_placePanelNearAnchor=function(p,q){p.css({left:0,top:0});var f=p.offset();var k={width:p.outerWidth(),height:p.outerHeight()};var g=q.offset();var i={width:q.outerWidth(false),height:q.outerHeight(false)};var h=c(p.get(0).ownerDocument);var d=c(reservationcalendar_getElementWindow(p));var j={left:h.scrollLeft(),top:h.scrollTop(),width:d.width(),height:d.height()};var n={left:g.left,top:g.top+i.height};var l={left:g.left,top:g.top-k.height};var e=reservationcalendar_checkVerticalVisibility(n,k,j);var m=reservationcalendar_checkVerticalVisibility(l,k,j);var o=(!e&&m?l:n);if(o.left+k.width>j.left+j.width){o.left=Math.max(j.left,j.left+j.width-k.width)}p.css({left:(o.left-f.left)+"px",top:(o.top-f.top)+"px"})};window.reservationcalendar_connectDatepickerToField=function(k,g){var i=null;var f=null;var d=function(){if(i){clearTimeout(i)}g.off("input",h);g.off("onpropertychange",h);g.off("keyup",h);k.off("click",e);k.closest("html").off("click",j);k.datepicker("destroy");k.remove()};var h=function(n){var l=g.val();if(l===f){return}var m=Date.parse(l);k.datepicker("setDate",m?new Date(m):null);f=l};var j=function(l){d()};var e=function(l){l.stopPropagation()};k.datepicker("option","onSelect",function(m,l){g.val(m);g.change();d()});g.on("input",h);g.on("onpropertychange",h);g.on("keyup",h);i=setTimeout(function(){k.on("click",e);k.closest("html").on("click",j)},0)};window.reservationcalendar_getElementWindow=function(d){var e=d.get(0).ownerDocument;return e.defaultView||e.parentWindow};window.reservationcalendar_checkVerticalVisibility=function(f,d,e){return(f.top>=e.top&&f.top+d.height<=e.top+e.height)}})(jQuery);