
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;});}
review={init:function(){$('#overlay-hotel-review').overlay({api:true,closeOnClick:false,oneInstance:false,onBeforeClose:function(){$('input[name^=hotel_review],textarea[name^=hotel_review]').val('');$('div.hotel-result-rating-big').css('width',54);$('span[rate]').text('2.5');}});$('#overlay-hotel-review-thanks').overlay({api:true,closeOnClick:true,oneInstance:false});$('.hotel-result-rating-big').mousemove(function(e){var rate=review.rate_position(e.clientX-$(this).offset().left);$(this).css('width',rate.width);$('span[rate='+$(this).attr('rate')+']').text(rate.value);}).mouseout(function(){var value=$('#hotel_review\\['+$(this).attr('rate')+'\\]').val();if(value==''){value='2.5'}
var rate=review.rate_position(value);$(this).css('width',rate.width);$('span[rate='+$(this).attr('rate')+']').html($('#hotel_review\\['+$(this).attr('rate')+'\\]').val()==''?value:'<span style="font-weight: bold; color: '+rate.color+'">'+rate.value+'</span>');}).click(function(e){var rate=review.rate_position(e.clientX-$(this).offset().left);$(this).css('width',rate.width);$('span[rate='+$(this).attr('rate')+']').html('<span style="font-weight: bold; color: '+rate.color+'">'+rate.value+'</span>');$('#hotel_review\\['+$(this).attr('rate')+'\\]').val(rate.value);});review.validate_review_form();review.assign_events();},assign_events:function(){$('a[overlay-hotel-review]').click(function(e){var overlay=$('#overlay-hotel-review').overlay();if(overlay.isOpened()){overlay.close();}
overlay.load();$("#hotel_review\\[hotel_id\\]").val($(this).attr("overlay-hotel-review"));return false;});},validate_review_form:function(){var validator=$("#hotel-review-form").validate({submitHandler:function(form){$(form).ajaxSubmit(function(response){resp=$.toJSON(response);review.review_thanks();var overlay=$('#overlay-hotel-review').overlay();overlay.close();});},focusInvalid:true,focusCleanup:false,rules:{"hotel_review[title]":{required:true},"hotel_review[name]":{required:true},"hotel_review[negative_aspect]":{required:function(element){return $("#hotel_review\\[positive_aspect\\]").val()=="";}},"hotel_review[positive_aspect]":{required:function(element){return $("#hotel_review\\[negative_aspect\\]").val()=="";}},"hotel_review[staff_rating]":{required:true},"hotel_review[service_rating]":{required:true},"hotel_review[comfort_rating]":{required:true},"hotel_review[value_for_money_rating]":{required:true},"hotel_review[cleanliness_rating]":{required:true}},messages:{"hotel_review[title]":{required:l("hotel_search.search_results.This field is required")},"hotel_review[name]":{required:l("hotel_search.search_results.This field is required")},"hotel_review[staff_rating]":{required:l("hotel_search.search_results.Please evaluate the hotel using all provided criteria")},"hotel_review[service_rating]":{required:l("hotel_search.search_results.Please evaluate the hotel using all provided criteria")},"hotel_review[comfort_rating]":{required:l("hotel_search.search_results.Please evaluate the hotel using all provided criteria")},"hotel_review[value_for_money_rating]":{required:l("hotel_search.search_results.Please evaluate the hotel using all provided criteria")},"hotel_review[cleanliness_rating]":{required:l("hotel_search.search_results.Please evaluate the hotel using all provided criteria")}},errorPlacement:function(error,element){var er=element.attr("id");if(element[0]['id']=="hotel_review[staff_rating]"||element[0]['id']=="hotel_review[service_rating]"||element[0]['id']=="hotel_review[comfort_rating]"||element[0]['id']=="hotel_review[value_for_money_rating]"||element[0]['id']=="hotel_review[cleanliness_rating]"){$("#rating_errors").html(error);}else{error.appendTo(element.prev());}}});},review_thanks:function(){var overlay_thanks=$('#overlay-hotel-review-thanks').overlay();if(overlay_thanks.isOpened()){overlay_thanks.close();}
overlay_thanks.load();return false;},rate_position:function(offset){var ticks=[2,12,23,33,44,55,65,76,86,97,107];var values=['0','0.5','1.0','1.5','2.0','2.5','3.0','3.5','4.0','4.5','5.0'];if(typeof(offset)=='string'){var i=values.indexOf(offset);return{width:ticks[i]-1,value:values[i],color:'#'+(157-i*10).toString(16)+(i*20).toString(16)+'00'};}else{for(var i=0;i<ticks.length;i++){if(offset<ticks[i]){return{width:ticks[i]-1,value:values[i],color:'#'+(157-i*10).toString(16)+(i*20).toString(16)+'00'};}}}
return{width:ticks[0],value:values[0],color:'#CDF0000'};}};results={init:function(){review.init();search_rates.init();$('a[hotel_class]').click(function(){$('input[type=checkbox][id^=hotel_class]').attr('checked',false);$('input#hotel_class_'+$(this).attr('hotel_class')).attr('checked',true);paginate();return false;});$('a[change_map]').click(function(){var map_type=$(this).attr('change_map');$('#'+map_type+'_map_holder').show()
$('#'+$(this).attr('self_map')+'_map_holder').hide();voyage_maps.change_map({canvas:map_type+'_map_canvas'});return false;});$('a[map_action=add_marker]').click(function(){voyage_maps.add_singleton_marker(function(e){$('#filter_latlng').val(e.lat()+','+e.lng());if(voyage_maps.circle!=null){voyage_maps.circle.set_center(e);}
filters.drop('distance');});voyage_maps.add_circle(parseInt($('#filter_radius').val()));$(this).hide();$('#map_marker_options').show();return false;});$('a[map_action=remove_marker]').click(function(){voyage_maps.remove_singleton_marker(function(e){$('#filter_latlng').val('');});voyage_maps.remove_circle();$('#map_marker_options').hide();$('a[map_action=add_marker]').show();return false;});results.assign_result_events();},assign_result_events:function(){$('div[display_hotel],a[display_hotel]').click(function(){voyage_maps.click_on_marker(parseInt($(this).attr('display_hotel')));window.scroll(0,200);return false;});}}
search_rates={init:function(){$('#overlay-hotel_rate_search').overlay({api:true,closeOnClick:false,oneInstance:false,onBeforeClose:function(){$('#calendar-container').prependTo($('form#new_hotel_query'));}});$('#rate-date-check-in,#rate-date-check-out').change(function(){if(isNaN(Date.parse($('#rate-date-check-in').val()))||isNaN(Date.parse($('#rate-date-check-out').val()))){return false;}
var date_diff=Math.round((YAHOO.voyages.calendar.parseFormat($('#rate-date-check-out').val())-YAHOO.voyages.calendar.parseFormat($('#rate-date-check-in').val()))/(1000*60*60*24));if(date_diff>0){$('#rate_total_nights').show();$('#rate_total_nights_text').show();$('#rate_total_nights').html(date_diff);}else{$('#rate_total_nights').hide();$('#rate_total_nights_text').hide();}
return false;});$('#rate-date-check-in').change();YAHOO.voyages.calendar.open_by('rate-calendar-check-in-button',{input:'rate-date-check-in',highlight:'rate-date-check-out'});YAHOO.voyages.calendar.open_by('rate-calendar-check-out-button',{input:'rate-date-check-out',highlight:'rate-date-check-in'});search_rates.assign_events();},assign_events:function(){$('a[hotel_rate_search]').click(function(e){var overlay=$('#overlay-hotel_rate_search').overlay();if(overlay.isOpened()){overlay.close();}
overlay.load();$('#calendar-container').prependTo($('form#hotel_rate_search_form'));var hotel_id=$(this).attr("hotel_rate_search");var hotel_name_element=$("a#hotel_name_"+hotel_id+"");$("#hotel_query\\[hotel_id\\]").val(hotel_id);$("#search_rate_hotel_name").text(hotel_name_element.text());return false;});}}