

// Filename: /javascript/shared/shortlist_view.js
// Was: 7610, now: 4637, compression: 39%

var ShortListView={hotel_source_url:location.protocol+"//"+location.hostname+"/tools/getHotelHtml.asp",notify:Notify,shortlistController:null,selectors:{shortlistItemPrefix:'ShortListItem_',removeLinkPrefix:"Remove_",shortlistContainer:"shortlistContents",viewShortListLink:'my-shortlist-link',shortlistInfo:'shortlist_info',removeAllLink:'RemoveAll'},messages:{emptyShortlist:'<p>Use the "Add to shortlist" button where ever you see a hotel you fancy and we will remember it for you!</p>'},AddHotelHandler:function(hotel_id){if($(this.selectors.shortlistContainer)){new Request.HTML({url:this.hotel_source_url,method:'get',data:{id:hotel_id},encoding:"windows-1252",onSuccess:function(responseTree){if(responseTree.length>0){var container=$(this.selectors.shortlistContainer);if(container){if(this.shortlistController.Count()<=1){container.empty();}
var hotel_div=responseTree[0];if(hotel_div){hotel_div.inject(container,'top');var link_selector=hotel_div.get('id')+' a.RemoveHotel';var remove_link=$(this.selectors.removeLinkPrefix+hotel_id);if(remove_link){remove_link.addEvent("click",function(e){this.shortlistController.Remove(hotel_id);e.stopPropagation();},this);}
var hotelSlide=new Fx.Slide(hotel_div).hide();hotelSlide.toggle();this.notify("This hotel has been added to your shortlist.");var view_shortlist_link=$(this.selectors.viewShortListLink);if(view_shortlist_link){view_shortlist_link.addClass("hidden");}}else{this.NotifyFailure(hotel_id);this.shortlistController.Remove(hotel_id);}}}else{this.NotifyFailure(hotel_id);this.shortlistController.Remove(hotel_id);}}.bind(this)}).send();}else{this.notify("This hotel has been added to your shortlist.");}},NotifyFailure:function(id,message){message=message?message:"There was a problem adding this hotel to your shortlist. Please try again later.";this.notify(message);},RemoveHotelHandler:function(hotel_id){var hotel=$(this.selectors.shortlistItemPrefix+hotel_id);if(hotel){var hotelSlide=new Fx.Slide(hotel);hotelSlide.slideOut();hotel.dispose();}
this.UpdateShortListInfo();return true;},UpdateShortListInfo:function(){if(typeof shortlist!="undefined"){var shortlistInfo=$(this.selectors.shortlistInfo);var container=$(this.selectors.shortlistContainer);var removeAll=$(this.selectors.removeAllLink);if(shortlist.Count()==0){if(shortlistInfo){shortlistInfo.empty();}
if(container){container.set("html",this.messages.emptyShortlist);}
if(removeAll){removeAll.addClass("hidden");}}else{if(shortlistInfo){shortlistInfo.set("html",this.RenderTotalHotels());var options={"href":(location.host.indexOf("ecom")>-1?"http://www.olympicholidays.com":"")+"/dynamicbrochure/email_shortlist.asp","text":"Share your shortlist","style":"margin-left: 5px;"}
var share_link=new Element("a",options);share_link.inject(shortlistInfo,"bottom");}
if(removeAll){removeAll.removeClass("hidden");}}}},RenderTotalHotels:function(){return"Total Hotels: "+this.shortlistController.Count()+" |";},HandleHotelExists:function(hotel_id){this.notify("You already have that hotel in your shortlist. You must really like it!");},HandleShortListFull:function(hotel_id){this.notify("Sorry, your shortlist already contains the maximum number of hotels allowed. Try removing one of your existing hotels before adding this one.");},HandleShortlistCleared:function(hotel_ids){if(hotel_ids.length>1){hotel_ids.split("|").each(function(hotel){var hotel=$(this.selectors.shortlistItemPrefix+hotel);var hotelSlide=new Fx.Slide(hotel);hotelSlide.slideOut();hotel.dispose();},this);this.notify("Your shortlist has been cleared");this.UpdateShortListInfo();}},getHotelIdFromElementId:function(element_id){var delimiter=element_id.indexOf("_");if(delimiter>-1){return element_id.substring(delimiter+1);}}}
window.addEvent("domready",function(){if(typeof(shortlist)!="undefined"){ShortListView.shortlistController=shortlist;$(document.body).getElements('a.ShortListAdd, a.RemoveHotel').each(function(elem){elem=$(elem);if(elem.hasClass("ShortListAdd")){if(elem.id){var id=ShortListView.getHotelIdFromElementId(elem.id);if($chk(id)){elem.removeEvents("click");elem.addEvent("click",function(e){shortlist.Add(id);e.stopPropagation();});}}}
if(elem.hasClass("RemoveHotel")){if(elem.id){var id=ShortListView.getHotelIdFromElementId(elem.id);if($chk(id)){elem.removeEvents("click");elem.addEvent("click",function(e){shortlist.Remove(id);});}}}});var remove_all_link=$('RemoveAll');if(remove_all_link){remove_all_link.addEvent("click",function(){if(confirm("Are you sure you want to clear your shortlist?")){shortlist.RemoveAll();}});}
ShortListView.UpdateShortListInfo();}},this);function AssertJSLoadedOk(){return true;}
