function RequestObject(){this.payload={};this.bind=function(a){this.payload.listingId=listingId;this.payload.tid=a;this.payload.guestFirstName=$("#guestFirstName").val();this.payload.guestLastName=$("#guestLastName").val();this.payload.guestPhone=$("#phone1").val()+$("#phone2").val()+$("#phone3").val();
this.payload.guestEmail=$("#guestEmail").val();this.payload.nameOnCard=$("#nameOnCard").val();this.payload.address1=$("#address1").val();this.payload.address2=$("#address2").val();this.payload.cardNumber=$("#cardNumber").val();this.payload.city=$("#city").val();this.payload.state=$("#state").val();this.payload.zip=$("#zip").val();
this.payload.cardType=$("#cardType").val();this.payload.expirationYear=$("#expirationYear").val();this.payload.expirationMonth=$("#expirationMonth").val();};}var apiImplementation={requestObject:new RequestObject(),priceQuoteLock:false,handlers:{priceQuoteHandler:function(a){apiImplementation.priceQuoteLock=false;
hotpads.booking.bookingInterface.hideRateLoaders();if(a.errors!=null&&a.errors.length!=0){hotpads.booking.handleErrors(a.errors);hotpads.booking.bookingInterface.activateReservationDetailsLayer();return;}if(a.rates.length==0){a.errors.global="This hotel cannot accomodate your request for the chosen dates.";
return;}hotpads.booking.bookingInterface.showRates(a);},rulesHandler:function(a){if(a.errors!=null&&a.errors.length!=0){hotpads.booking.handleErrors(a.errors);hotpads.booking.bookingInterface.activateReservationDetailsLayer();return;}hotpads.booking.bookingInterface.showRules(a.rules);},doBookingHandler:function(a){$("#bookingLoader").hide();
if(a.errors!=null&&a.errors.length!=0){$("#bookingButtons").show();hotpads.booking.bookingInterface.encounterServerSideError();hotpads.booking.handleErrors(a.errors);return;}hotpads.booking.bookingInterface.completeTransaction(a.reservation);}},rateContainers:["ratesPreviewContainer","ratesContainer"],rateLoaders:["previewLoader","ratesLoader"],getPriceQuote:function(a){if(apiImplementation.priceQuoteLock){return;
}var b=apiImplementation.reservationInformationValidator.validate();if(b.length!=0){hotpads.booking.handleErrors(b);return;}hotpads.booking.bookingInterface.showRateLoaders();apiImplementation.priceQuoteLock=true;$.post("/api/booking/getRates",a,this.handlers.priceQuoteHandler,"json");},getRateRules:function(b,a,c){b.rateCode=a;
b.tid=c;$("#rateRulesLoader").show();$.post("/api/booking/getRules",b,this.handlers.rulesHandler,"json");},doBooking:function(a){this.requestObject.bind(a);$("#bookingLoader").show();$("#bookingButtons").hide();$("#summaryButtonContainer").hide();$.post("/api/booking/doBooking",this.requestObject.payload,this.handlers.doBookingHandler,"json");
},reservationInformationValidator:new Validator(function(){var a=[];return a;if(this.isEmpty($("#ratePreviewCheckInDate").val())){a.push({target:"checkInDate",text:"Please choose a check in date"});}else{if(!$("#ratePreviewCheckInDate").val().match(/^\d{1,2}\/\d{1,2}\/\d{4}$/)){a.push({target:"checkInDate",text:"Please choose a check-in date from the calendar or use the form DD/MM/YYYY"});
}}if(this.isEmpty($("#ratePreviewCheckOutDate").val())){a.push({target:"checkOutDate",text:"Please choose a check out date"});}else{if(!$("#ratePreviewCheckOutDate").val().match(/^\d{1,2}\/\d{1,2}\/\d{4}$/)){a.push({target:"checkOutDate",text:"Please choose a check-out date from the calendar or use the form DD/MM/YYYY"});
}}if(this.isEmpty($("#ratePreviewNumAdults").val())||!this.isNumeric($("#ratePreviewNumAdults").val())){a.push({target:"numAdults",text:"Please enter the number of adults"});}else{if($("#ratePreviewNumAdults").val()<1){a.push({target:"numAdults",text:"You must book at least 1 adult"});}if($("#ratePreviewNumAdults").val()>10){a.push({target:"numAdults",text:"You cannot book more than 20 adults"});
}}if(this.isEmpty($("#ratePreviewNumChildren").val())||!this.isNumeric($("#ratePreviewNumChildren").val())){a.push({target:"numChildren",text:"Please enter the number of children"});}else{if($("#ratePreviewNumChildren").val()<0){a.push({target:"numChildren",text:"You cannot have negative children"});
}if($("#ratePreviewNumChildren").val()>10){a.push({target:"numChildren",text:"You cannot book more than 10 children"});}}if(this.isEmpty($("#ratePreviewNumRooms").val())||!this.isNumeric($("#ratePreviewNumRooms").val())){a.push({target:"numRooms",text:"Please enter the number of rooms"});}else{if($("#ratePreviewNumRooms").val()<1){a.push({target:"numRooms",text:"You must book at least 1 room"});
}if($("#ratePreviewNumRooms").val()>10){a.push({target:"numRooms",text:"You cannot book more than 10 rooms at once"});}}return a;}),guestInformationValidator:new Validator(function(){var a=[];if(this.isEmpty($("#guestFirstName").val())){a.push({target:"guestFirstName",text:"Please enter your first name"});
}if(this.isEmpty($("#guestLastName").val())){a.push({target:"guestLastName",text:"Please enter your last name"});}if(this.isEmpty($("#guestEmail").val())){a.push({target:"guestEmail",text:"Please enter a valid e-mail address"});}if((this.isEmpty($("#phone1").val())||this.isEmpty($("#phone2").val())||this.isEmpty($("#phone3").val()))||(!this.isNumeric($("#phone1").val())||!this.isNumeric($("#phone2").val())||!this.isNumeric($("#phone3").val()))){a.push({target:"guestPhone",text:"Please enter a valid phone number"});
}return a;},"personalInformationLayer"),paymentInformationValidator:new Validator(function(){var a=[];if(this.isEmpty($("#nameOnCard").val())){a.push({target:"nameOnCard",text:"Please enter the name on the card"});}if(this.isEmpty($("#cardNumber").val())||!this.isNumeric($("#cardNumber").val())){a.push({target:"cardNumber",text:"Please enter your card number"});
}if(this.isEmpty($("#expirationMonth").val())||this.isEmpty($("#expirationYear").val())||!this.isNumeric($("#expirationMonth").val())){a.push({target:"expirationMonth",text:"Please enter your card's expiration date"});}if(this.isEmpty($("#address1").val())){a.push({target:"address1",text:"Please enter your address"});
}if(this.isEmpty($("#city").val())){a.push({target:"city",text:"Please enter your city name"});}if(this.isEmpty($("#state").val())){a.push({target:"state",text:"Please choose a state"});}if(this.isEmpty($("#zip").val())||!this.isNumeric($("#zip").val())){a.push({target:"zip",text:"Please enter a valid zip code"});
}return a;},"personalInformationLayer"),populateConfirmationDetails:function(){this.requestObject.bind(hotpads.booking.bookingInterface.selectedRate);$("#confirmationNumAdults").text(hotpads.booking.reservationDetails.numAdults);$("#confirmationNumChildren").text(hotpads.booking.reservationDetails.numChildren);
$("#confirmationNumRooms").text(hotpads.booking.reservationDetails.numRooms);$("#confirmationCheckInDate").text(hotpads.booking.reservationDetails.checkInDate);$("#confirmationCheckOutDate").text(hotpads.booking.reservationDetails.checkOutDate);$("#confirmationCost").text(hotpads.booking.bookingInterface.rules.costPrintable);
$("#confirmationTaxesAndFees").text(hotpads.booking.bookingInterface.rules.taxesAndFeesPrintable);$("#confirmationTotal").text(hotpads.booking.bookingInterface.rules.totalPrintable);if(hotpads.booking.bookingInterface.rules.hasUnknownTaxesAndFees){$("#confirmationTaxesAndFees").html("");$(".unknownTaxesAndFeesMessage").show();
}},populateReceiptDetails:function(a){$("#receiptFirstName").text(a.guestFirstName);$("#receiptLastName").text(a.guestLastName);$("#receiptNumAdults").text(a.numAdults);$("#receiptNumChildren").text(a.numChildren);$("#receiptNumRooms").text(a.numRooms);$("#receiptCheckInDate").text(a.checkInDate);$("#receiptCheckOutDate").text(a.checkOutDate);
$("#receiptBaseCost").text(a.costPrintable);$("#receiptConfirmationNumber").text(a.confirmationNumber);$("#receiptTax").text(a.taxesAndFeesPrintable);$("#receiptTotal").text(a.totalPrintable);if(a.hasUnknownTaxesAndFees){$("#receiptTax").html("");$(".unknownTaxesAndFeesMessage").show();}}};