function hw_autocomplete(event)
{
if(event.keyCode == 13)
{
searchHostels();
}
}
function searchHostels()
{
var key = document.getElementById('place_input_key').value.split(',');
var country_sel = document.getElementById('hw_country_select');
var index;
if(key.length==1)	{
if(country_sel.style.display != 'block')
{
country_sel.style.display = 'block';
return false;
}
else
{
index = document.getElementById('h_country').selectedIndex
if(!index)
{
msgBox('warning','Please select country for this location.');
return false;
}
}
}
else if(key[1] == 0 )
{
msgBox('warning','Please type/choose name of the city.');
return false;
}
var date = document.getElementById('h_date').value;
var nights = document.getElementById('h_nights').value;
if(date != "")
{
if(nights=="")
{
msgBox('warning',"If you have choosen date please type how many nights you plan to stay.");
return false;
}
}
else
{
if(nights!="")
{
document.getElementById('h_nights').value = "0";
}
}
document.getElementById('h_date_value').value = date;
document.hostels.submit();
}
function checkBookingAvailability(form, tab){
var dStart;
var dEnd;
var currency;
var persons;
var startDate;
var EndDate;
switch (tab){
case 'booking_hostel':
dStart = $('HostelsDate').value.split('-');
dEnd = $('HostelsDateEnd').value.split('-');
currency = $("h_currency").value;
persons = $("h_persons").value;
$("h_dateIn").value = $('HostelsDate').value;
$("h_dateOut").value = $('HostelsDateEnd').value;
$("h_dateInInput").value = $('HostelsDateInput').value;
$("h_dateOutInput").value = $('HostelsDateEndInput').value;
$("h_personsPage").value = persons;
$("h_currencyPage").value = currency;
break;
default:
dStart = $('h_dateIn').value.split('-');
dEnd = $('h_dateOut').value.split('-');
break;
}
var xmlRequest = null;
if(form.name == "hostelsform"){
startDate = $("h_dateInInput").value ;
EndDate = $("h_dateOutInput").value ;
dStart = startDate.split('/');
dEnd = EndDate.split('/');
var _nights = (Date.parse(dEnd[1]+'/'+dEnd[0]+'/'+dEnd[2]) - Date.parse(dStart[1]+'/'+dStart[0]+'/'+dStart[2]))/86400000;
$('h_nights').value = _nights;
var numnights = _nights; //document.getElementById("h_nights").value;
persons = $("h_personsPage").value;
persons_index = $("h_personsPage").selectedIndex;
var prop = $("h_property").value;
currency = $("h_currencyPage").value;
currency_index = $("h_currencyPage").selectedIndex;
var placeKey = $("h_placeKey").value;
}else{
startDate = $("h_date2").value ;
EndDate = $("h_dateOut2").value ;
dStart = startDate.split('/');
dEnd = EndDate.split('/');
var _nights = (Date.parse(dEnd[1]+'/'+dEnd[0]+'/'+dEnd[2]) - Date.parse(dStart[1]+'/'+dStart[0]+'/'+dStart[2]))/86400000;
$("h_nights2").value= _nights;
var numnights = _nights; //document.getElementById("h_nights2").value;
persons = $("h_persons2").value;
persons_index = $("h_persons2").selectedIndex;
var prop = $("h_property2").value;
currency = $("h_currency2").value;
currency_index = $("h_currency2").selectedIndex;
var placeKey = $("h_placeKey2").value;
}
var fromToday = (Date.parse(dStart[1]+'/'+dStart[0]+'/'+dStart[2]) - new Date())/86400000;
if(fromToday > 330){
alert('Bookings cannot be made more than 11 months in advance. Please review your check-in date.');
return;
}
if(fromToday < 1){
alert('Please revise your selection. You must use a future date for a new check-in.');
return;
}
if(numnights < 1){
alert('Please enter a check-out date which occurs after the check-in date.');
return;
}
if(numnights > 14){
alert('Please revise your reservation dates. The number of nights should not exceed 14.');
return;
}
var bookDiv = document.getElementById("bookingDiv");
var tmpMessage='<div style="height:160px;padding-top:60px;" align="center"><img src="'+appproxypath+'images/loading.gif"><div style="margin:5px;"><b>Please wait whilst checking availability...</b></div></div>';
bookDiv.innerHTML = tmpMessage;
ShowPlaceInfo('4');
var qs = "/wayntravels.html?wci=place&wce=getbox&box=bookavailability";
qs = qs + "&StartDate=" + startDate;
qs = qs + "&Property=" + prop;
qs = qs + "&NightNum=" + numnights;
qs = qs + "&Persons=" + persons;
qs = qs + "&Currency=" + currency;
qs = qs + "&placekey=" + placeKey;
try{
xmlRequest = new Ajax.Request (
qs,
{
method : 'GET',
onSuccess : function ( resp ) {
responseXml = resp.responseXML;
for (var i = responseXml.firstChild; i != null; i = i.nextSibling) {
for (var j = i.firstChild; j != null; j = j.nextSibling) {
if(j.nodeValue != null && j.nodeValue != ''){
bookDiv.innerHTML = "";
bookDiv.innerHTML = j.nodeValue;
}
}
}
var divcHostels = document.createElement('div');
divcHostels.setAttribute("id", "HostelsDateContainer");
var scrHostels = document.createElement('script');
var txtHostels = 'new DatetimeToolbocks({ inputValue:"' + startDate + '", elementId:"HostelsDate",startDate:"true",elementNextId:"HostelsDateEnd",calendarOptions: {textDateClass:"textBlackDefault"}})';
scrHostels.text = txtHostels;
var divcHostelsEnd = document.createElement('div');
divcHostelsEnd.setAttribute("id", "HostelsDateEndContainer");
var scrHostelsEnd = document.createElement('script');
var txtHostelsEnd = 'new DatetimeToolbocks({ inputValue:"' + EndDate + '", elementId:"HostelsDateEnd",startDate:"false",elementNextId:"HostelsDate",calendarOptions: {textDateClass:"textBlackDefault"}})';
scrHostelsEnd.text = txtHostelsEnd;
var cellHostels = $('h_dateContainer');
var cellHostelsEnd = $('h_dateContainerBOut');
cellHostels.appendChild(divcHostels);
cellHostels.appendChild(scrHostels);
cellHostelsEnd.appendChild(divcHostelsEnd);
cellHostelsEnd.appendChild(scrHostelsEnd);
if(currency_index)
{
$('h_currency').selectedIndex = currency_index;
}
if(persons_index)
{
$('h_persons').selectedIndex = persons_index;
}
},
onFailure : function ( resp ) {
document.getElementById("bookingDiv").innerHTML = '<center><b>Sorry we\'re unable to load data at the moment. We will try again in few seconds.</b></center>';
//						var tm = setTimeout("updateBox('" + BoxName + "','" + BoxID + "', '" + who + "', '" + addons + "');",3000);
return;
},
onException: function ( resp ) {
//alert('888err');
document.getElementById("bookingDiv").innerHTML = '<center><b>Sorry we\'re unable to load data at the moment. We will try again in few seconds.</b></center>';
//						var tm = setTimeout("updateBox('" + BoxName + "','" + BoxID + "', '" + who + "', '" + addons + "');",3000);
return;
}
}
);
}
catch(err)
{
msgBox('error',err);
}
}
function changeBookCurrency(currency)
{
document.getElementById('b_currency').value = currency;
document.currencyChangeForm.submit();
}
function printConfirmation(elem)
{
window.print();
}
function ReviewFocus() {
if ($('add_review_focus').value == 'focus') {
$('review_title').focus();
}
}
function BookingHostelClick(){
try{
xmlRequest = new Ajax.Request ("/wayntravels.html?wci=place&wce=savestats&clickbooking=hostel",
{
method : 'GET',
onSuccess : function  ( resp )  {},
onFailure : function  ( resp )  {},
onException: function ( resp )  {}
}
);
}
catch(err){
}
// submit is more important
document.bookPlaceForm.submit();
}
