
﻿var weddingsVersion=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 updatePlanItemNote(planId,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:"/wedding_guide/WeddingPlannerService.asmx/UpdatePlanItemNote",data:"{'planId':'"+planId+"', '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 redirectToLogin(){var loc=location.href.replace('http://','');var index=loc.indexOf('/');loc=loc.substring(index);loc='/login/index.aspx?ReturnUrl='+escape(loc);window.location=loc;}
function initializeWeddingListings(){$("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='WeddingPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/wedding_guide/WeddingPlannerService.asmx/GetPlanId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var planId=msg.d;if(planId==''){return;}else{updatePlanTitle(planId,currElement);}},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your plan information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:450,path:'/'});var planId=$.cookie(id);updatePlanTitle(planId,currElement);}
return false;});$("span.note-text").each(function(){if($(this).text()==''){$(this).parent().parent().hide();}else{$(this).parent().parent().parent().children(".add-note").hide();}});$("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;});$("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='WeddingPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/wedding_guide/WeddingPlannerService.asmx/GetPlanId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var planId=msg.d;if(planId==''){return;}else{updatePlanItemNote(planId,currElement);}},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your plan information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:450,path:'/'});var planId=$.cookie(id);updatePlanItemNote(planId,currElement);}
return false;});var weddingItemAsk=null;$(".wedding-add.ask").live('click',function(){$.fn.colorbox({html:'<div class="text"><p>Would you like to add this as an accommodation suggestion for your guests, or as your event location?</p> <div style="text-align: center;"><a href="#" class="wedding-add-accommodation">Accommodation Suggestion</a><br />or<br /><a href="#" class="wedding-add-event-location">Event Location</a></div></div>',open:true,width:300,height:200});weddingItemAsk=$(this);return false;});$(".wedding-add-accommodation").live('click',function(){addWeddingPlanItem(weddingItemAsk,true);$.fn.colorbox.close();return false;});$(".wedding-add-event-location").live('click',function(){addWeddingPlanItem(weddingItemAsk,false);$.fn.colorbox.close();return false;});$(".wedding-add").click(function(){var currElement=$(this);if(currElement.hasClass("ask")&&currElement.hasClass("wedding-add"))
return;addWeddingPlanItem(currElement,true);return false;});function addWeddingPlanItem(currElement,isAccommodation){var id='WeddingPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/wedding_guide/WeddingPlannerService.asmx/GetPlanIdOrStartNewPlan",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){var planId=msg.d;if(planId==''){return;}else{toggleListingInPlan(planId,currElement);}},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your wedding plan information.');}});}else{$.cookie(id,$.cookie(id),{expires:540,path:'/'});var planId=$.cookie(id);toggleListingInPlan(planId,currElement,isAccommodation);}}
$(".listing input").each(function(){if($.inArray($(this).val(),weddingListings)!=-1){var tripAdd=$(this).next(".listing-add-to").children(".wedding-add");tripAdd.removeClass("wedding-add");tripAdd.addClass("wedding-remove");tripAdd.text("added to wedding planner");tripAdd.next("span").show();}});$(".remove-item").live("click",function(){var currElement=$(this);var id='WeddingPlannerId';if($.cookie(id)==null){$.ajax({type:"POST",url:"/wedding_guide/WeddingPlannerService.asmx/GetPlanId",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(msg.d=='')
return false;var planId=msg.d;if(planId==''){return;}else{removePlanItem(planId,currElement);}},error:function(xhr,status,error){handleWebServiceError('An error occurred while retrieving your wedding plan information.');return false;}});}else{$.cookie(id,$.cookie(id),{expires:450,path:'/'});var planId=$.cookie(id);removePlanItem(planId,currElement);}
return false;});}
function addListingToPlan(planId,currElement,isAccommodation){var listingId=currElement.parent().prev("input").val();var url='/wedding_guide/WeddingPlannerService.asmx/AddListingToPlan';if(isAccommodation==null)
isAccommodation=false;var data="{'planId':'"+planId+"', 'listingId':"+listingId+", 'isAccommodation':"+isAccommodation+"}";$.ajax({type:"POST",url:url,data:data,contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){currElement.removeClass("wedding-add");currElement.addClass("wedding-remove");currElement.text("added to wedding plan");currElement.next("span").show();},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to add the item to your wedding plan.');}});}
function removePlanItem(planId,currElement){var itemId=currElement.parent().parent().prev("input").val();var itemToRemove=currElement.parent().parent().parent();var sepItem=itemToRemove.prev("li.trip-separator");$.ajax({type:"POST",url:"/wedding_guide/WeddingPlannerService.asmx/DeletePlanItem",data:"{'planId':'"+planId+"', 'itemId':'"+itemId+"'}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){if(sepItem!=null)
sepItem.remove();itemToRemove.remove();},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to remove the item from your wedding plan.');return false;}});}
function deleteListingFromPlan(planId,currElement){var listingId=currElement.parent().prev("input").val();var url='/wedding_guide/WeddingPlannerService.asmx/DeleteListingFromPlan';var data="{'planId':'"+planId+"', 'listingId':"+listingId+"}";$.ajax({type:"POST",url:url,data:data,contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){currElement.removeClass("wedding-remove");currElement.addClass("wedding-add");currElement.text("add to wedding plan");currElement.next("span").hide();},error:function(xhr,status,error){handleWebServiceError('An error occurred while trying to remove the item from your wedding plan.');}});}
function toggleListingInPlan(planId,currElement,isAccommodation){if(currElement.hasClass("wedding-add")){addListingToPlan(planId,currElement,isAccommodation);}else{deleteListingFromPlan(planId,currElement);}}
function updatePlanTitle(tripId,currElement){var itemParent=currElement.parent();var text=itemParent.children(".title-box").val().replace(/\'/gi,"\\'");$.ajax({type:"POST",url:"/wedding_guide/WeddingPlannerService.asmx/EditPlanTitle",data:"{'planId':'"+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;}});}
