
var hotel_search_form={init:function(){$('#date-check-in,#date-check-out').change(function(){if(isNaN(Date.parse($('#date-check-in').val()))||isNaN(Date.parse($('#date-check-out').val()))){return false;}
var date_diff=Math.round((YAHOO.voyages.calendar.parseFormat($('#date-check-out').val())-YAHOO.voyages.calendar.parseFormat($('#date-check-in').val()))/(1000*60*60*24));if(date_diff>0){$('#total_nights').show();$('#total_nights_text').show();$('#total_nights').html(date_diff);}else{$('#total_nights').hide();$('#total_nights_text').hide();}
return false;});$('#date-check-in').change();YAHOO.voyages.calendar.open_by('calendar-check-in-button',{input:'date-check-in',highlight:'date-check-out'});YAHOO.voyages.calendar.open_by('calendar-check-out-button',{input:'date-check-out',highlight:'date-check-in'});$('input[name*=city]').result(function(event,data,formatted){$('#hotel-city-id').val(data[1]);}).autocomplete(locale_prefix+'/hotels/hotel_cities',{minChars:3,delay:500,cacheLength:128,matchContains:true,mustMatch:false,multiple:false,max:10,scroll:false,multipleSeparator:'---',formatItem:hotel_search_form.format_item,notSearch:/(.*)\(.*\)/,loadingClass:'flight-form-text-loading',resultsClass:'flight-form-results',width:'auto'});$('a[hotel_search]').click(function(){$('a[hotel_search]').removeClass('tabs-a-act');$(this).addClass('tabs-a-act');if($(this).attr('hotel_search')=='city'){$('#hotel_search_by').val('city');$('#hotel_search_by_address').hide();}else{$('#hotel_search_by').val('address');$('#hotel_search_by_address').show();}
return false;});},prepare:function(parameters){$modify_form=$('#overlay-modify-search form');for(prop in parameters){$modify_form.find('[property='+prop+']').val(parameters[prop]);}
if(parameters.search_by=='city'){$('#hotel_search_by_address').hide();$('a[hotel_search=city]').addClass('tabs-a-act');}else{$('a[hotel_search=address]').addClass('tabs-a-act');}
$calendar_container.appendTo($modify_form);},format_item:function(data,i,total){return data[0].replace(/\((.*)\)/i,"<span>($1)</span>");}}
function checkSearchCompleted(){$.ajax({url:'/hotels/check_search_status/'+hotel_query_id,type:'POST',data:{authenticity_token:authenticity_token},dataType:'json',success:function(response){if(response['search_completed']){if(typeof(show_hotel)!='undefined'){clearTimeout(show_hotel);}
if(typeof(increment_progress)!='undefined'){clearTimeout(increment_progress);}
var user_progress=parseInt($('#search_progress').text());completeProgress(1/(100-user_progress));}}});}
function incrementProgress(intervals){var delay=intervals.shift();var user_progress=parseInt($('#search_progress').text());if(user_progress<98&&intervals.length>0){$('#search_progress').html((user_progress+1)+'%');$('#search_delay').html(delay);increment_progress=setTimeout(function(){incrementProgress(intervals);},delay*1000);}}
function completeProgress(time){var user_progress=parseInt($('#search_progress').text());if(user_progress<100){$('#search_progress').html((user_progress+1)+'%');setTimeout(function(){completeProgress(time);},time*1000);}else{$('#search_progress').html('100%');window.location=locale_prefix+"/hotels/search/"+hotel_query_id;}}
function showHotel(){var time=500;if(hotel_list[hotel_index]){$('#searching_hotel').html(hotel_list[hotel_index]);hotel_index++;show_hotel=setTimeout(showHotel,time);}else{$('#searching_hotel').html('');}}
function activateHotelTagCloudClickHandler(){$(".tag-cloud-search-hotel p a, .tag-cloud p a, #assume_cities a").click(function(event){text=$(this).attr('city')+', '+$(this).attr('country')+' ('+$(this).attr('total_hotels')+($(this).attr('total_hotels')>1?' hotels':' hotel')+')';$("#hotel-city-name").val(text);$("#hotel-city-id").val($(this).attr('hotel_city_id'));$("#hotel-city-name").click();return false;});}