window.eviivo=window.eviivo?window.eviivo:{};window.eviivo.availabilitySearch=window.eviivo.availabilitySearch?window.eviivo.availabilitySearch:{};window.eviivo.availabilitySearch=function(n){function wt(s){t=n.extend(ct,s);d=n(t.eviivoSearchBoxId+" div.column-outer").html();o=t.eviivoSearchBoxId+" div.column-inner";h=n(t.eviivoSearchBoxId+" div.cp-tooltip");c=n(t.eviivoSearchBoxId+" #btn-addRoom");l=n(t.eviivoSearchBoxId+" #btn-removeRoom");b=n(t.eviivoSearchBoxId+" button.cp-button-price");nt=n("#mod-results div.results-price button.cp-button-showprices");f=n(t.eviivoSearchBoxId+" input#eviivo-start-date");u=n(t.eviivoSearchBoxId+" input#eviivo-end-date");g=n(t.eviivoSearchBoxId+" .actions button");k=n(t.eviivoSearchBoxId+" div.column-inner:first-child span.column-adult span.ui-selectmenu-button");lt=n("#eviivo-availability-search");at=n("#ui-datepicker-div");yt=n("#submit-reservation #cbe");pt=n(".column-outer");tt=n(window).width();e=[];vt=!1;r=n("#datepicker-tooltip");a=n(".cp-tooltip-info");i=eviivo.utils.queryStringHelper;typeof i=="undefined"&&console.log("eviivo.utils.queryStringHelper was not loaded therefore this page might not work properly");var v=new Date;(t.defaultNightsServiced==null||t.isDefaultReferrer===!1)&&(t.defaultNightsServiced=0);v.setDate(v.getDate()+t.defaultNightsServiced);n.datepicker.setDefaults(n.extend({dateFormat:"dd/mm/yy",showOtherMonths:!0,selectOtherMonths:!0,minDate:v}));f.datepicker({onSelect:ei});u.datepicker({onSelect:oi});u.datepicker();c.on("click",ut);l.on("click",dt);r.on("click",p);g.on("click",y).on("blur",y);n(document).on("keydown",ni);n(t.eviivoSearchBoxId+" .icon-guest").on("click",et);n(t.eviivoSearchBoxId+" .icon-guest a").on("click",et);it(n(t.eviivoSearchBoxId+" div.column-inner:first-child select.cp-select"));n(document).on("click",gt);b.on("click",st);nt.on("click",ui);ii();fi();a.on("click",ti);ot(!0)}function it(n){var t=n.selectmenu({change:bt});e.push({adults:t[0],children:t[1]})}function v(){var r=0,i;n(t.eviivoSearchBoxId+" div.column-inner span.column-adult .ui-selectmenu-text").each(function(t,i){r+=w(n(i))});i=0;n(t.eviivoSearchBoxId+" div.column-inner span.column-child .ui-selectmenu-text").each(function(t,r){i+=w(n(r))});var u=n(o).length,e=n(t.eviivoSearchBoxId+" .cp-inputValues a span"),f="";f=u>1?t.resources.rooms:t.resources.room;e.html(r+" "+t.resources.adults+" "+i+" "+t.resources.children+" "+u+" "+f)}function bt(){v();var i=n(t.eviivoSearchBoxId+" .cp-inputValues a");i.fadeIn("slow",function(){i.css("color","#000")})}function kt(){var i=1;n(".column-outer .column-inner").each(function(){var r=t.resources.room+" "+i;n(this).find(".room").html(r);i++})}function rt(){var r=n(".column-outer .column-inner").length,i=n(".room-counter"),u,f,e;u=r>1?t.resources.roomsAdded:t.resources.roomAdded;f=u.replace(new RegExp("\\{0\\}","gm"),r);i.html(f);i.addClass("pulse");e=i.clone(!0);i.before(e);n(".room-counter:last").remove()}function ut(){var i=n(o).length;i1&&(n(t.eviivoSearchBoxId+" div.column-inner:last").remove(),v(),rt());ft()}function ft(){var i=n(o).length;i>1?l.removeAttr("disabled"):(l.attr("disabled","disabled"),c.focus());i2&&n(t.eviivoSearchBoxId+" div.column-outer").addClass("overflow")}function gt(t){n(t.target).hasClass("ui-menu-item")||n(t.target).hasClass("cp-tooltip")||n(t.target).parents("div.cp-tooltip").length!==0||y(t,!0)}function ni(n){n.keyCode===27&&y(n,!0)}function y(n,t){h.is(":visible")&&(h.hide(),t||b.focus())}function et(n){n!==null&&n.stopPropagation();h.is(":hidden")&&(h.show("fast"),k.focus())}function ti(){a.is(":visible")&&a.hide()}function ot(n){return f.val()===""&&u.val()===""?(n?r.addClass("infotip"):(f.addClass("invalid"),u.addClass("invalid")),r.show(),!1):f.val()===""?(n?r.addClass("infotip"):f.addClass("invalid"),r.show(),!1):u.val()===""?(n?r.addClass("infotip"):u.addClass("invalid"),r.show(),!1):(p(),!0)}function p(){f.removeClass("invalid");u.removeClass("invalid");r.removeClass("infotip");r.hide()}function ii(){var r=t.criteria,o=window.location.href,e=!1,u=i.getAllKeys(o),f;return u.startdate!==null&&(r.startDate=new Date(u.startdate)),u.enddate!==null&&(r.endDate=new Date(u.enddate)),u.nights!==null&&(f=parseInt(u.nights),isNaN(f)||(r.endDate=new Date(r.startDate.getFullYear(),r.startDate.getMonth(),r.startDate.getDate(),0,0,0),r.endDate.addHours(24*f))),u.simpleversion!==null&&(s=u.simpleversion),u.noofrooms!==null&&(e=u.noofrooms>=0),r.occupancy=[],n.each(u,function(n,i){var o=n.indexOf("adults")>=0,s=n.indexOf("children")>=0,h,f;if(o||s>0){if(h=new RegExp("[a-zA-Z]+([0-9]+)"),f=parseInt(h.exec(n)[1])-1,e&&f+1>parseInt(u.noofrooms))return!1;while(f>t.criteria.occupancy.length-1)r.occupancy.push({adults:0,children:0});o?r.occupancy[f].adults=i:s&&(r.occupancy[f].children=i)}}),r}function st(){if(ot()){var e=t.baseSearchUrl,l=window.location.href,o=i.getAllKeys(l),r=jQuery.extend({},o),h=f.datepicker("getDate"),c=u.datepicker("getDate");h!==null&&i.addKey(r,"startdate",ht(h));c!==null&&i.addKey(r,"enddate",ht(c));i.deleteKeyWithRegex(r,"adults");i.deleteKeyWithRegex(r,"children");i.deleteKeyWithRegex(r,"noofrooms");n(t.eviivoSearchBoxId+" div.column-inner").each(function(t,u){i.addKey(r,"adults"+(t+1),w(n(u).find("span.column-adult .ui-selectmenu-text")));i.addKey(r,"children"+(t+1),w(n(u).find("span.column-child .ui-selectmenu-text")))});s!==null&&s!==""&&s!==undefined&&i.addKey(r,"simpleversion",s);n("#ref").length>0&&n("#ref").val().length>0&&i.addKey(r,"ref",n("#ref").val());ri(o,r);i.addRandomizer(r);e+=i.toString(r);window.location.href=/e}}function ri(t,r){var f,u;i.deleteKey(r,"pce");f=n("#pce");f.length>0&&i.addKey(r,"pce",f.val());i.deleteKey(r,"peid");u=n("#peid");u.length>0&&u.val()!=null&&u.val()!==""&&i.addKey(r,"peid",u.val())}function ht(n){var r=n.getFullYear().toString(),t=(n.getMonth()+1).toString(),i=n.getDate().toString();return r+"-"+(t.length===2?t:"0"+t[0])+"-"+(i.length===2?i:"0"+i[0])}function ui(n){!tt<768&&eviivo.smoothScrolling.smoothScrollHandler(n,function(){f.datepicker("show")},this)}function fi(){n.each(t.criteria.occupancy,function(t,i){while(t>0&&t>e.length-1)ut();n(e[t].adults).val(i.adults);n(e[t].adults).selectmenu("refresh");n(e[t].children).val(i.children);n(e[t].children).selectmenu("refresh")});v()}function ei(n,t){var f=new Date(t.selectedYear,t.selectedMonth,parseInt(t.selectedDay),0,0,0,0),i=new Date(f).addHours(24);u.datepicker("option",{minDate:i});setTimeout(function(){u.datepicker("show");u.datepicker("setDate",i)},100);r.length>0&&r.is(":visible")&&p()}function oi(){f.val()===""?setTimeout(function(){f.datepicker("show")},100):k.focus();r.length>0&&r.is(":visible")&&p()}function w(n){return parseInt(n.text().slice(0,2).trim())}var ct={isDefaultReferrer:!0,defaultNightsServiced:0,roomsLimit:3,eviivoSearchBoxId:"#eviivo-availability-search",cultureLanguageCode:"en-GB",baseSearchUrl:"",resources:{adults:"Adults",children:"Children",rooms:"Room(s)",room:"Room"},criteria:{startDate:null,endDate:null,occupancy:[{adults:2,children:0}]}},t,d,o,s,h,c,l,b,f,u,g,e,k,nt,lt,at,tt,vt,yt,i,pt,r,a;return Date.prototype.addHours=function(n){return this.setHours(this.getHours()+n),this},Date.prototype.addHours=function(n){return this.setHours(this.getHours()+n),this},{init:wt,triggerSearch:st}}(jQuery)