var req = false, bookingResultDiv=0, bookingForm;
function bookingInit(bookingFormParam, doInstantUpdate) {
bookingForm = bookingFormParam;
bookingResultDiv = document.getElementById("bookingResult");
var booking = getMultiCookie('booking');
var hadCookie = true;
if(!booking) {
hadCookie = false;
var d = new Date();
d.setDate(d.getDate()+4);
booking = { 'day':d.getDate(), 'monthYear':d.getFullYear()+'-'+((d.getMonth()+1)<10?'0':'')+(d.getMonth()+1), 'nights':1, 'people':1, 'currency':'USD' };
}
setFormValues(bookingForm, 'booking', booking);
if(doInstantUpdate) {
if(hadCookie)
bookingUpdate(false);
else
bookingResultDiv.innerHTML = '
Online Booking Price Comparison — Search Every Booking Website at Once for Available Beds
Just choose your booking dates with the form above.
';
}
}
function bookingShowWait() {
bookingResultDiv.innerHTML = 'Searching All Booking Systems
';
}
/* submitPropType false for instant update (hostel pages) */
function bookingUpdate(submitPropType) {
var booking = getFormValues(bookingForm, 'booking');
if(bookingForm['booking[people]'].value == '9+') {
bookingForm['booking[people]'].value = 1;
window.location = 'http://www.hostelz.com/hostel-group-booking.php';
return false;
}
setMultiCookie('booking', booking);
bookingShowWait();
if(submitPropType) {
bookingForm.findAvail.value = submitPropType;
setTimeout('document.mainForm.submit()',1000);
}
else {
url = 'http://www.hostelz.com/bookingFetch.php?hostelID='+hostelID+'&'+'monthYear='+booking['monthYear']+'&day='+booking['day']+'&nights='+booking['nights']+'&people='+booking['people']+'¤cy='+booking['currency']+'&city='+encodeURIComponent(city)+'&cityURL='+encodeURIComponent(cityURL);
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv;
req.open("GET", url, true);
req.send();
}
}
}
return true;
}
function targetDiv() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
bookingResultDiv.innerHTML = req.responseText;
} else {
// alert("Problem: " + req.statusText);
}
}
}
function bookingSelectRoom(importedID, roomCode) {
bookingForm.importedID.value = importedID;
bookingForm.roomCode.value = roomCode;
bookingForm.submit();
}
var oldText;
function jumpToCitySearch(findPropType) {
oldText = bookingResultDiv.innerHTML;
bookingShowWait();
var a = document.bookingForm.action;
document.bookingForm.action = cityURL;
document.bookingForm.findAvail.value = findPropType;
document.bookingForm.submit();
document.bookingForm.action = a;
window.onunload = function() {
bookingResultDiv.innerHTML = oldText;
window.onunload = '';
};
}