function ArrivalDateChange(){ScrollToDate(FindControl(".arrivaldate").val())}function BookingBlock(controlID,options){var daysDisplayed=options.daysDisplayed?options.daysDisplayed:14,clientId=options.clientId,bookingId=options.bookingId,meetsMinStay=options.meetsMinStay,currentCost=options.currentCost,isWidget=options.isWidget,currentDate,$=jQuery,oneDay=1e3*60*50*24,currentRoom;Init=function(){if($("#"+controlID)){currentDate=FindControl(".arrivaldate").val();FindControl(".previous a").click(function(){ScrollBy(-(daysDisplayed-1));return false});FindControl(".next a").click(function(){ScrollBy(daysDisplayed-1);return false});FindControl(".btn_booknow").click(function(){return ValidateBooking()});$(document).mousemove(function(e){if($(e.target).closest("th.room").length>0||$(e.target).hasClass("room")){var room=$(e.target).hasClass("room")?$(e.target):$(e.target).closest("th.room");if(currentRoom!=room.attr("id")){currentRoom=room.attr("id");ShowRoomInformation(room,currentRoom)}}else{currentRoom=null;HideRoomInformation()}});AddCheckBoxes();CorrectHeight();FindControl(".textbox_date").blur(function(){ScrollToDate(false)});FindControl(".textbox_date").keydown(function(event){if(event.keyCode==13){event.preventDefault();this.blur()}});FindControl(".guests").each(function(){$(this).change(function(){ScrollToDate(true)})})}};AddCheckBoxes=function(){FindControl("input.checkbox").each(function(i,o){var array=$(o).val().split(":"),roomId=array[0],date=array[1],expectedPrice=array[2],checkbox=$(document.createElement("input")).attr("type","checkbox");checkbox.insertAfter(o);checkbox.click(function(){ToggleBooking($(this),roomId,date,expectedPrice)});checkbox.attr("checked",$(o).attr("checked"))});FindControl("input.checkbox").remove();ShowHidePrevious()};ShowHidePrevious=function(){var today=Util_ParseDate(currentDate)-Util_Today()<=0;FindControl(".previous").toggle(!today);FindControl(".previous-fade").toggle(!today)};ScrollBy=function(days){var arrivalDate=new Date;arrivalDate.setTime(Util_ParseDate(FindControl(".arrivaldate").val()));arrivalDate.setDate(arrivalDate.getDate()+days);FindControl(".arrivaldate").val(Util_FormatDate_DDMMMMYYYY(arrivalDate));var today=Util_Today();if(arrivalDate.getTime()-today.getTime()<0){arrivalDate.setTime(Util_ParseDate(Util_FormatDate_DDMMMMYYYY(today)));FindControl(".arrivaldate").val(Util_FormatDate_DDMMMMYYYY(arrivalDate))}ScrollToDate(false)};ScrollToDate=function(forceUpdate){var uxArrivalDate=FindControl(".arrivaldate"),arrivalDate=new Date;arrivalDate.setTime(Util_ParseDate(uxArrivalDate.val()));if(isNaN(arrivalDate))return;var today=Util_Today();if(arrivalDate.getTime()-today.getTime()<0)return;var date=arrivalDate;date.getTime()-today.getTime()<0&&date.setTime(Util_ParseDate(Util_FormatDate_DDMMMMYYYY(today)));var daysApart=(date-Util_ParseDate(currentDate))/oneDay;if(!forceUpdate&&Math.abs(daysApart)<1)return;BindTable(date)};SelectedTickets=function(){var guests=[];$(".guests").each(function(){guests[guests.length]=parseInt($("OPTION:selected",this).val())});return guests};BindTable=function(date){var dateString=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();FindControl(".progress").show();Ajax("RenderBookingAvailability","{ isWidget: "+isWidget+", clientId:"+clientId+", arrivalDate:'"+dateString+"', tickets: ["+SelectedTickets()+"], nDays: "+daysDisplayed+" }",function(content){BasketCallback(content,date,null)})};CorrectHeight=function(){var height=$("#BookingBlockHeader").height();FindControl("#noscroll").animate({height:height},1e3);FindControl("#scroll").animate({height:height},1e3);FindControl(".previous-fade").height(height-38);FindControl(".next-fade").height(height-38)};UpdateRooms=function(replacementContent,daysApart,today){var originalTable=FindControl("#scroll table:first"),replacementTable=$(replacementContent);replacementTable.insertAfter(originalTable);AddCheckBoxes();var left=today?0:-22;originalTable.stop();replacementTable.stop();if(daysApart==0){replacementTable.css({left:left+"px"});CleanupOldTables()}else if(daysApart>0){replacementTable.css({left:originalTable.position().left+originalTable.width()+"px"});originalTable.animate({left:-originalTable.width()+left},1e3,"linear",CleanupOldTables);replacementTable.animate({left:left},1e3,"linear")}else{replacementTable.css({left:originalTable.position().left-replacementTable.width()+"px"});originalTable.animate({left:replacementTable.width()+left},1e3,"linear",CleanupOldTables);replacementTable.animate({left:left},1e3,"linear")}};CleanupOldTables=function(){FindControl("#scroll table:not(table:last)").remove()};ToggleBooking=function(checkbox,roomId,arrivalDate,quotedPrice){checkbox.roomId=roomId;checkbox.arrivalDate=arrivalDate;checkbox.quotedPrice=quotedPrice;$('<img width="16" height="16" border="0" src="/images/common/indicator.gif" alt=""/>').appendTo(checkbox.parent());checkbox.hide();if(checkbox.is(":checked"))AddToBasket(checkbox,roomId,arrivalDate,quotedPrice);else RemoveFromBasket(checkbox,roomId,arrivalDate,quotedPrice)};ShowRoomInformation=function(e,roomId){$("#modal-background").remove();$("#more-information-modal").remove();Ajax("RenderRoomInformation","{ clientId: "+clientId+", propertyId: '"+bookingId+"', roomId: '"+roomId+"'}",function(result){if(currentRoom==roomId){$("#modal-background").remove();$("#more-information-modal").remove();$("body").append("<div id='more-information-modal'><div class='close'>X</div><div class='clear'></div><div class='room-content'>"+result.html+"</div></div>");$modal=$("#more-information-modal");var top=e.offset().top-$(document).scrollTop(),left=e.offset().left+e.width()+10;if(top+$modal.height()+$(document).scrollTop()>$(window).height()+$(document).scrollTop())top=top-$modal.height()+e.height();if(left+$modal.width()+$(document).scrollLeft()>$(window).width()+$(document).scrollLeft())left+=$(window).width()+$(document).scrollLeft()-(left+$modal.width()+$(document).scrollLeft())-5;if(top<0)top=0;$("#more-information-modal").css({top:top,left:left});$("#more-information-modal .close").click(function(){$("#modal-background").remove();$("#more-information-modal").remove()})}})};HideRoomInformation=function(){$("#modal-background").remove();$("#more-information-modal").remove()};AddToBasket=function(checkbox,roomId,arrivalDate,quotedPrice){Ajax("AddToBasket","{ isWidget: "+isWidget+", clientId: "+clientId+", propertyId: '"+bookingId+"', roomId: '"+roomId+"', arrivalDate: "+arrivalDate+", guests: ["+SelectedTickets()+"], quotedPrice: "+quotedPrice+"}",function(result){result.priceChange=quotedPrice;BasketCallback(result,null,checkbox)})};RemoveFromBasket=function(checkbox,roomId,arrivalDate,quotedPrice){Ajax("RemoveRoomFromBasket","{ isWidget: "+isWidget+", clientId: "+clientId+", propertyId: "+bookingId+", roomId: "+roomId+", arrivalDate: "+arrivalDate+"}",function(result){result.priceChange=quotedPrice;BasketCallback(result,null,checkbox)})};BasketCallback=function(result,date,checkbox){FindControl(".progress").hide();result.bookingHeader&&FindControl("#noscroll").html(result.bookingHeader);if(result.bookingTable){var arrivalDate=Util_ParseDate(FindControl(".arrivaldate").val()),daysApart=(arrivalDate-Util_ParseDate(currentDate))/oneDay,today=arrivalDate-Util_Today()<=0;UpdateRooms(result.bookingTable,daysApart,today);ShowHidePrevious();if(date)currentDate=Util_FormatDate_DDMMMMYYYY(date);ShowHidePrevious();CorrectHeight()}result.processUrl&&$(".btn_booknow").attr("href",result.processUrl);meetsMinStay=result.meetsMinStay;if(checkbox){checkbox.show();checkbox.parent().find("img").remove();if(result.currentCell){checkbox.parent().removeClass("selected");checkbox.parent().html(result.currentCell)}else{checkbox.parent().toggleClass("selected",checkbox.is(":checked"));if(result.priceChange)currentCost+=result.priceChange*(checkbox.is(":checked")?1:-1)}}};ValidateBooking=function(){if(currentCost==0){alert("You have not selected any rooms or dates. Please select a room to make your instant booking");return false}if(!meetsMinStay){alert("You have not selected the minimum number of days required for this room type.  Please select additional days or choose another room type.");return false}return true};FindControl=function(control){return $("#"+controlID+" "+control)};Ajax=function(method,data,success){$.ajax({type:"POST",url:"/Services/JasonsBooking.asmx/"+method,data:data,dataType:"json",contentType:"application/json; charset=utf-8",success:function(content){success(eval(content.d))},error:ErrorCallback})};ErrorCallback=function(error){FindControl(".progress",false);alert("An error occured while trying to update the BookingBlock.\n"+error.responseText)};Init()}function BookingBlock_ValidateDate(sender,args){sender.errormessage="An invalid date was entered. Please make sure the date is in the correct format ("+Util_FormatDate_DDMMMMYYYY(Util_Today())+") and that the date is not in the past";args.IsValid=Util_DateIsValid(args.Value)}function BookingPopup_Update(clientId,currentBookings){SetDisplay("BookingPopup_Progress_"+clientId,true);Enlighten.Jasons.Site.Services.JasonsBooking.RenderBookingPopup(clientId,currentBookings,BookingPopup_BasketCallback,BookingBlock_ErrorCallback)}function BookingPopup_BasketCallback(result){SetDisplay("BookingPopup_Progress_"+result.clientId,false);if(result.bookingPopup){$get("bookings_"+result.clientId).innerHTML=result.bookingPopup;$get("bookingspopup_height"+result.clientId).value=result.height;jQuery("#bookings_"+result.clientId).animate({height:result.height},1e3)}}function Util_ReplaceTable(table,html){var newdiv=document.createElement("div");newdiv.innerHTML=html;newdiv.childNodes[0].style.left=table.style.left;table.parentNode.replaceChild(newdiv.childNodes[0],table)}function ShowBookingBlockPopupWidgetDialog(clientId,numOfRows,numOfDays,colorTheme){window.open("/Widgets/BookingBlockDialog.aspx?ClientId="+clientId+"&nrooms="+numOfRows+"&ndays="+numOfDays+"&colorTheme="+colorTheme+"&widget=1","BookingBlockDialog","status=false, width=750, height=520, resizable=0, scrollbars=1")}
