
var listingsVersion=1;function handleWebServiceError(msg){if((msg!=null)&&(msg!=''))
$.jGrowl(msg,{header:'Error',life:10000,theme:'growl-error'});else
$.jGrowl("An error occurred.",{header:'Error',life:10000,theme:'growl-error'});}
function handleMoveDisabling(){$("#trip-planner a.move-up").removeClass("move-disabled");$("#trip-planner a.move-down").removeClass("move-disabled");$("#trip-planner ul li:first a.move-up").addClass("move-disabled");$("#trip-planner ul li:last a.move-down").addClass("move-disabled");}
function moveTripItemDown(tripId,currElement){var currentItem=currElement.parent().parent();var sepItem=currElement.parent().parent().next("li.trip-separator");var nextItem=currElement.parent().parent().next("li").next("li").children("div.trip-item").parent();if((currentItem!=null)&&(nextItem!=null)&&(sepItem!=null)){var itemId=currElement.parent().prev("input").val();$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/MoveTripItemDown",data:"{'tripId':'"+tripId+"', 'itemId':"+itemId+"}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){sepItem.before(nextItem);sepItem.after(currentItem);},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to move the item down.');return false;}});handleMoveDisabling();}}
function moveTripItemUp(tripId,currElement){var currentItem=currElement.parent().parent();var sepItem=currElement.parent().parent().prev("li.trip-separator");var prevItem=currElement.parent().parent().prev("li").prev("li").children(".trip-item").parent();if((currentItem!=null)&&(prevItem!=null)&&(sepItem!=null)){var itemId=currElement.parent().prev("input").val();$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/MoveTripItemUp",data:"{'tripId':'"+tripId+"', 'itemId':"+itemId+"}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){sepItem.before(currentItem);sepItem.after(prevItem);},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to move the item up.');return false;}});handleMoveDisabling();}}
function removeTripItem(tripId,currElement){var itemId=currElement.parent().parent().prev().prev("input").val();var sep=currElement.parent().parent().parent().prev("li");var itemToRemove=currElement.parent().parent().parent();$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/DeleteTripItem",data:"{'tripId':'"+tripId+"', 'itemId':"+itemId+"}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(sep!=null)
sep.remove();itemToRemove.remove();},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to remove the item.');return false;}});}
function updateTripTitle(tripId,currElement){var itemParent=currElement.parent();var text=itemParent.children(".title-box").val().replace(/\'/gi,"\\'");$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/EditTripTitle",data:"{'tripId':'"+tripId+"', 'text':'"+text+"'}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){itemParent.hide();itemParent.prev(".read-title").show();itemParent.parent().children(".read-title").children(".title-text").text(itemParent.children(".title-box").val());},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to update the title.');return false;}});}
function updateTripItemNote(tripId,currElement){var itemParent=currElement.parent();var text=itemParent.children(".note-box").val();var itemId=itemParent.parent().parent().next("input").val();var inputter=currElement;$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/UpdateTripItemNote",data:"{'tripId':'"+tripId+"', 'itemId':"+itemId+", 'note':'"+text.replace(/\'/gi,"\\'")+"'}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){itemParent.hide();itemParent.prev(".read-note").show();if(text==''){inputter.val("Add");inputter.parent().parent().hide();inputter.parent().parent().prev(".add-note").show();}else{inputter.val("Update");}
itemParent.parent().children(".read-note").children(".note-text").text(text);},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to update the note.');return false;}});}
function initializeTripPlanner(){$("span.note-text").each(function(){if($(this).text()==''){$(this).parent().parent().hide();}else{$(this).parent().parent().parent().children(".add-note").hide();}});handleMoveDisabling();$("a.add-note").live("click",function(){$(this).parent().next().show();$(this).parent().next().children(".read-note").hide();$(this).parent().next().children(".edit-note").show();$(this).parent().next().children(".edit-note").children(".note-box").focus();$(this).parent().next().children(".edit-note").children(".update-note").val("Add");$(this).parent().hide();return false;});$(".move-down").live("click",function(){var currElement=$(this);var id='TripPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetTripId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var tripId=msg.d;moveTripItemDown(tripId,currElement);},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your trip information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:60,path:'/'});var tripId=$.cookie(id);moveTripItemDown(tripId,currElement);}
return false;});$(".move-up").live("click",function(){var currElement=$(this);var id='TripPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetTripId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var tripId=msg.d;moveTripItemUp(tripId,currElement);},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your trip information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:60,path:'/'});var tripId=$.cookie(id);moveTripItemUp(tripId,currElement);}
return false;});$(".remove-item").live("click",function(){var currElement=$(this);var id='TripPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetTripId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var tripId=msg.d;removeTripItem(tripId,currElement);},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your trip information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:60,path:'/'});var tripId=$.cookie(id);removeTripItem(tripId,currElement);}
return false;});$("span.edit-title a").live("click",function(){$(this).parent().parent().hide();$(this).parent().parent().next(".edit-title").show();$(this).parent().parent().next(".edit-title").children(".title-box").focus();return false;});$("a.cancel-title").live("click",function(){$(this).parent().hide();$(this).parent().prev(".read-title").show();return false;});$("input.update-title").live("click",function(){var currElement=$(this);var id='TripPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetTripId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var tripId=msg.d;updateTripTitle(tripId,currElement);},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your trip information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:60,path:'/'});var tripId=$.cookie(id);updateTripTitle(tripId,currElement);}
return false;});$("span.edit-note a").live("click",function(){$(this).parent().parent().hide();$(this).parent().parent().next(".edit-note").show();$(this).parent().parent().next(".edit-note").children(".note-box").focus();return false;});$("a.cancel-note").live("click",function(){if($(this).parent().parent().children(".read-note").children("span.note-text").text()==''){$(this).parent().parent().hide();$(this).parent().parent().parent().children(".add-note").show();}else{$(this).parent().hide();$(this).parent().parent().children(".read-note").show();}
return false;});$("input.update-note").live("click",function(){var currElement=$(this);var id='TripPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetTripId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var tripId=msg.d;updateTripItemNote(tripId,currElement);},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your trip information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:60,path:'/'});var tripId=$.cookie(id);updateTripItemNote(tripId,currElement);}
return false;});}
function initializeTripEvents(){$(".trip-add").click(function(){var id='TripPlannerId';var currElement=$(this);if($.cookie(id)==null){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetTripIdOrStartNewTrip",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){var tripId=msg.d;toggleListingInTrip(tripId,currElement,true);},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your trip information.');}});}else{$.cookie(id,$.cookie(id),{expires:60,path:'/'});var tripId=$.cookie(id);toggleListingInTrip(tripId,currElement,true);}
return false;});$(".event_details input").each(function(){if($.inArray($(this).val(),listings)!=-1){var tripAdd=$(this).parent().children(".listing-add-to").children(".trip-add");tripAdd.removeClass("trip-add");tripAdd.addClass("trip-remove");tripAdd.text("added to trip planner");tripAdd.next("span").show();}});}
function hideEmptyNotes(){$("span.note-text").each(function(){if($(this).text()==''){$(this).parent().parent().hide();}else{$(this).parent().parent().parent().children(".add-note").hide();}});}
function createCloud(msg){var links='';if((msg!=null)&&(msg.length>0)){var numLinks=msg.length;for(var keyword in msg){var kwc=msg[keyword];links+='<a class="'+createCssClass(kwc.Count)+'" href="/enjoying_lake_county/listings.aspx?keyword='+kwc.Keyword+'">'+kwc.Keyword+'</a>';if(keyword!=(numLinks-1))
links+=' <span class="sep">&#8226;</span> ';}}else
links+='Click search to search all listings.';links+='&nbsp; <a id="listings-all" href="#">show all &raquo;</a>';$("#tagCloud").html(links);$(".tags").show();$(".tagsAll").hide();}
function toggleAllListings(){$("#listings-all").live("click",function(){$(".tags").toggle();$(".tagsAll").toggle();return false;});}
function createCssClass(count){switch(count){case 1:return'tag1';case 2:case 3:case 4:return'tag2';case 5:case 6:return'tag3';case 7:case 8:return'tag4';default:return'tag5';}}
function buildTagCloud(searchBox){var keyword=searchBox.value;if(keyword.length>=2){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetRelatedKeywords",data:"{'keyword':'"+keyword+"'}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){createCloud(msg.d);},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to retrieve the related keywords.');return false;}});}}
function search_KeyUp(event){clearTimeout(timeoutId);var _self=this;timeoutId=setTimeout(function(){buildTagCloud(_self);},500);}
function addListingToTrip(tripId,currElement,isEvent){var listingId=currElement.parent().next("input").val();var url='/enjoying_lake_county/TripPlannerService.asmx/AddListingToTrip';var data="{'tripId':'"+tripId+"', 'listingId':"+listingId+"}";if(isEvent==true){url='/enjoying_lake_county/TripPlannerService.asmx/AddEventToTrip';data="{'tripId':'"+tripId+"', 'eventId':"+listingId+"}";}
$.ajax({type:"POST",url:url,data:data,contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){currElement.removeClass("trip-add");currElement.addClass("trip-remove");currElement.text("added to trip planner");currElement.next("span").show();},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to add the item to your trip planner.');}});}
function deleteListingFromTrip(tripId,currElement,isEvent){var listingId=currElement.parent().next("input").val();var url='/enjoying_lake_county/TripPlannerService.asmx/DeleteListingFromTrip';var data="{'tripId':'"+tripId+"', 'listingId':"+listingId+"}";if(isEvent==true){url='/enjoying_lake_county/TripPlannerService.asmx/DeleteEventFromTrip';data="{'tripId':'"+tripId+"', 'eventId':"+listingId+"}";}
$.ajax({type:"POST",url:url,data:data,contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){currElement.removeClass("trip-remove");currElement.addClass("trip-add");currElement.text("add to trip planner");currElement.next("span").hide();},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to remove the item from your trip planner.');}});}
function toggleListingInTrip(tripId,currElement,isEvent){if(currElement.hasClass("trip-add")){addListingToTrip(tripId,currElement,isEvent);}else{deleteListingFromTrip(tripId,currElement,isEvent);}}
function initializeSearch(){if($(".tagsearch :text").val()=="")
$(".tagsearch :text").css({color:"#666"});$(".tagsearch :text").focus(function(){if(($(this).val()=="Enter your search here")||($(this).val()=="Search accommodations & activities...")){$(".tagsearch :text").css({color:"#000"});$(".tagsearch :text").val("");}});$(".tagsearch :text").keyup(search_KeyUp);$(".trip-add").click(function(){var id='TripPlannerId';var currElement=$(this);if($.cookie(id)==null){$.ajax({type:"POST",url:"/enjoying_lake_county/TripPlannerService.asmx/GetTripIdOrStartNewTrip",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){var tripId=msg.d;toggleListingInTrip(tripId,currElement,false);},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your trip information.');}});}else{$.cookie(id,$.cookie(id),{expires:60,path:'/'});var tripId=$.cookie(id);toggleListingInTrip(tripId,currElement,false);}
return false;});$(".listing-result input").each(function(){if($.inArray($(this).val(),listings)!=-1){var tripAdd=$(this).parent().children(".listing-add-to").children(".trip-add");tripAdd.removeClass("trip-add");tripAdd.addClass("trip-remove");tripAdd.text("added to trip planner");tripAdd.next("span").show();}});}