/*------------------------------------------------------------------------ Solidres - Hotel booking extension for Joomla ------------------------------------------------------------------------ @Author Solidres Team @Website https://www.solidres.com @Copyright Copyright (C) 2013 - 2019 Solidres. All Rights Reserved. @License GNU General Public License version 3, or later ------------------------------------------------------------------------*/ if(typeof Solidres==="undefined"){var Solidres={}}Solidres.context="frontend";Solidres.setCurrency=function(id){Solidres.jQuery.ajax({type:"POST",url:window.location.pathname,data:"option=com_solidres&format=json&task=currency.setId&id="+parseInt(id),success:function(msg){location.reload(true)}})};function isAtLeastOnRoomTypeSelected(){var numberRoomTypeSelected=0;Solidres.jQuery(".room-form").each(function(){if(Solidres.jQuery(this).children().length>0){numberRoomTypeSelected++;return}});if(numberRoomTypeSelected>0){Solidres.jQuery('#sr-reservation-form-room button[type="submit"]').removeAttr("disabled")}else{Solidres.jQuery('#sr-reservation-form-room button[type="submit"]').attr("disabled","disabled")}}Solidres.jQuery(function($){if(document.getElementById("sr-reservation-form-room")){$("#sr-reservation-form-room").validate()}if(document.getElementById("sr-checkavailability-form")){$("#sr-checkavailability-form").validate()}$(".roomtype-quantity-selection").change(function(){isAtLeastOnRoomTypeSelected()});if(document.getElementById("sr-availability-form")){$("#sr-availability-form").validate()}$(".coupon").on("click","#apply-coupon",function(){$.ajax({type:"POST",url:window.location.pathname,data:"option=com_solidres&format=json&task=coupon.applyCoupon&coupon_code="+$("#coupon_code").val()+"&raid="+$('input[name="id"]').val(),success:function(response){if(response.status){location.reload(true)}},dataType:"JSON"})});$("#sr-remove-coupon").click(function(e){e.preventDefault();$.ajax({type:"POST",url:window.location.pathname,data:"option=com_solidres&format=json&task=reservation.removeCoupon&id="+$(this).data("couponid"),success:function(response){if(response.status){location.reload(true)}else{alert(Joomla.JText._("SR_CAN_NOT_REMOVE_COUPON"))}},dataType:"JSON"})});$("button.load-calendar").click(function(){var self=$(this);var id=self.data("roomtypeid");var target=$("#availability-calendar-"+id);self.empty().html(' '+Joomla.JText._("SR_PROCESSING"));self.attr("disabled","disabled");if(target.children().length==0){$.ajax({url:Solidres.options.get("BaseURI")+"index.php?option=com_solidres&task=reservationasset.getAvailabilityCalendar&id="+id,success:function(html){self.removeAttr("disabled");if(html.length>0){target.show().html(html);self.empty().html(' '+Joomla.JText._("SR_AVAILABILITY_CALENDAR_CLOSE"))}}})}else{target.empty().hide();self.empty().html(' '+Joomla.JText._("SR_AVAILABILITY_CALENDAR_VIEW"));self.removeAttr("disabled")}if($("#more_desc_"+id).is(":visible")){$("#more_desc_"+id).hide();self.parent().find(".toggle_more_desc").empty().html(' '+Joomla.JText._("SR_SHOW_MORE_INFO"))}});function loadRoomForm(self){var rtid=self.data("rtid");var raid=self.data("raid");var tariffid=self.data("tariffid");var adjoininglayer=self.data("adjoininglayer");$.ajax({type:"GET",url:Solidres.options.get("BaseURI")+"index.php?option=com_solidres&task=reservationasset.getRoomTypeForm",data:{rtid:rtid,raid:raid,tariffid:tariffid,quantity:self.val()>0?self.val():1,adjoininglayer:adjoininglayer},success:function(data){self.parent().find(".processing").css({display:"none"});$("#room-form-"+rtid+"-"+tariffid).empty().show().html(data).find(".popover_payment_methods, .hasPopover").webuiPopover({trigger:"hover",placement:"auto-bottom"});$(".sr-reservation-form").validate();var updateChildAgeDropdown=false;$("#solidres .room #room-form-"+rtid+"-"+tariffid+" .trigger_tariff_calculating").trigger("change",[updateChildAgeDropdown]);isAtLeastOnRoomTypeSelected()}})}$(".roomtype-quantity-selection").each(function(){var self=$(this);if(self.val()>0){self.parent().find(".processing").css({display:"block"});$("#selected_tariff_"+self.data("rtid")+"_"+self.data("tariffid")).removeAttr("disabled");loadRoomForm(self)}});$(".roomtype-quantity-selection").change(function(){var self=$(this);var tariffid=self.data("tariffid");var rtid=self.data("rtid");var totalRoomsLeft=self.data("totalroomsleft");var isPrivate=self.data("isprivate");var currentQuantity=parseInt(self.val());var currentSelectedRoomTypeRooms=0;var totalSelectableRooms=0;if(currentQuantity>0){self.parent().find(".processing").css({display:"block"});$("#selected_tariff_"+rtid+"_"+tariffid).removeAttr("disabled");loadRoomForm(self);$("#tariff-holder-"+rtid+" .exclusive-hidden").prop("disabled",true)}else{$("#room-form-"+rtid+"-"+tariffid).empty().hide();$('input[name="jform[selected_tariffs]['+rtid+']"]').attr("disabled","disabled");$("#selected_tariff_"+rtid+"_"+tariffid).attr("disabled","disabled");isAtLeastOnRoomTypeSelected()}$(".quantity_"+rtid).each(function(){var s=$(this);var val=parseInt(s.val());if(val>0){currentSelectedRoomTypeRooms+=val}});totalSelectableRooms=totalRoomsLeft-currentSelectedRoomTypeRooms;$(".quantity_"+rtid).each(function(){var s=$(this);var val=parseInt(s.val());var from=0;if(val>0){from=val+totalSelectableRooms}else{from=totalSelectableRooms}disableOptions(s,from)});if(totalSelectableRooms>0&&totalSelectableRoomsfrom){$(this).attr("disabled","disabled")}else{$(this).removeAttr("disabled")}})}$(".guestinfo").on("click","input:checkbox",function(){var self=$(this);if(self.is(":checked")){$("."+self.data("target")).removeAttr("disabled")}else{$("."+self.data("target")).attr("disabled","disabled")}});$(".room-form").on("click","input:checkbox",function(){var self=$(this);if(self.is(":checked")){$("."+self.data("target")).removeAttr("disabled")}else{$("."+self.data("target")).attr("disabled","disabled")}});$(".trigger_checkinoutform").click(function(){var self=$(this);var tariffId=self.data("tariffid");var roomtypeId=self.data("roomtypeid");var oldLabel=self.text();if(tariffId!=""){$(".checkinoutform").empty();self.text(Joomla.JText._("SR_PROCESSING"));$.ajax({type:"GET",data:{Itemid:self.data("itemid"),id:self.data("assetid"),roomtype_id:roomtypeId,tariff_id:tariffId},url:Solidres.options.get("BaseURI")+"index.php?option=com_solidres&task=reservationasset.getCheckInOutForm",success:function(data){$(".checkinoutform").empty();$("#checkinoutform-"+roomtypeId+"-"+tariffId).show().empty().html(data);$("#room-form-"+roomtypeId+"-"+tariffId).empty();self.text(oldLabel)}})}});$("#solidres").on("click",".searchbtn",function(){var tariffid=$(this).data("tariffid");var roomtypeid=$(this).data("roomtypeid");if(Solidres.options.get("AutoScroll")==1){var target="#tariff-box-"+roomtypeid+"-"+tariffid;if(Solidres.options.get("AutoScrollTariff")==0){target="#srt_"+roomtypeid}$("#sr-checkavailability-form-component").attr("action",$("#sr-checkavailability-form-component").attr("action")+target)}$("#sr-checkavailability-form-component input[name=checkin]").val($("#tariff-box-"+roomtypeid+"-"+tariffid+' input[name="checkin"]').val());$("#sr-checkavailability-form-component input[name=checkout]").val($("#tariff-box-"+roomtypeid+"-"+tariffid+' input[name="checkout"]').val());$("#sr-checkavailability-form-component input[name=ts]").val($("input[name=fts]").val());$("#sr-checkavailability-form-component").submit()});$(".toggle_more_desc").click(function(){var self=$(this);$("#more_desc_"+self.data("target")).toggle();if($("#more_desc_"+self.data("target")).is(":visible")){self.empty().html(' '+Joomla.JText._("SR_HIDE_MORE_INFO"))}else{self.empty().html(' '+Joomla.JText._("SR_SHOW_MORE_INFO"))}});$("#sr-reservation-form-room").on("click",".checkin_roomtype",function(){if(!$(this).hasClass("disabledCalendar")){$(".checkin_datepicker_inline").slideToggle()}});$("#sr-reservation-form-room").on("click",".checkout_roomtype",function(){if(!$(this).hasClass("disabledCalendar")){$(".checkout_datepicker_inline").slideToggle()}});$(".guestinfo").on("click","#register_an_account_form",function(){var self=$(this);if(self.is(":checked")){$("."+self.attr("id")).show()}else{$("."+self.attr("id")).hide()}});$(".toggle-tariffs").click(function(){var self=$(this);var roomtypeid=self.data("roomtypeid");var target=$("#tariff-holder-"+roomtypeid);if($("#more_desc_"+roomtypeid).is(":visible")){$("#more_desc_"+roomtypeid).hide();self.parent().find(".toggle_more_desc").empty().html(' '+Joomla.JText._("SR_SHOW_MORE_INFO"))}if($("#availability-calendar-"+roomtypeid).is(":visible")){$("#availability-calendar-"+roomtypeid).empty().hide();self.parent().find(".load-calendar").empty().html(' '+Joomla.JText._("SR_AVAILABILITY_CALENDAR_VIEW"))}target.toggle();if(target.is(":hidden")){self.html(' '+Joomla.JText._("SR_SHOW_TARIFFS"))}else{self.html(' '+Joomla.JText._("SR_HIDE_TARIFFS"))}});var hash=location.hash;if(hash.indexOf("tariff-box")>-1){var $el=$(hash),x=1500,originalColor=$el.css("backgroundColor"),targetColor=$el.data("targetcolor");$el.css("backgroundColor","#"+targetColor);setTimeout(function(){$el.css("backgroundColor",originalColor)},x)}$(".filter_checkin_checkout").datepicker({numberOfMonths:1,showButtonPanel:true,dateFormat:"dd-mm-yy",firstDay:1});$("#toggle_login_form").click(function(){$("#solidres-inline-login-form").toggle()});$("html").click(function(e){if(!$(e.target).hasClass("datefield")&&!$(e.target).parent().hasClass("datefield")&&$(e.target).closest("div.ui-datepicker").length==0&&$(e.target).closest("a.ui-datepicker-prev").length==0&&$(e.target).closest("a.ui-datepicker-next").length==0&&$(e.target).closest("div.ui-datepicker-buttonpane").length==0){$(".datepicker_inline").hide()}})});