var activeProdId=0;var newlyAddedAddressId=0;var activeProdImage=0;var prodImgTimeout=null;var previewVendor=false;function SelectCategory(a){if($("#CategoryList").css("display")=="none"){return}$("#CategoryList li").each(function(b){this.className=(this.id=="CategoryItem"+a)?"selectedcategory":"category"});if(a==0){$("ul.Products").css("display","block");$("div.catHead").css("display","block")}else{$(".Products").each(function(b){this.style.display=(this.id=="prods"+a)?"block":"none"});$("div.catHead").each(function(b){this.style.display=(this.id=="catHead"+a)?"block":"none"})}window.scrollTo(0,0)}function UpdateBasketTotals(d){var h=$(d).find("VendorDiscount").text();var e=$(d).find("SubTotal").text();var m=$(d).find("Discount").text();var f=$(d).find("SalesTax").text();var a=$(d).find("ServiceCharge").text();var l=$(d).find("DeliveryCharge").text();var k=$(d).find("Tip").text();var j=$(d).find("Total").text();var g=$(d).find("TimeEstimate").text();var b=$(d).find("TimeWarning").text();var c="";if($("#bSubTotal").length==1&&$("#bSubTotal").text()!=e){for(i=0;i<e/2;i+=0.25){c+="<option value='"+i+"'";if(i==k){c+=" selected='selected'"}c+=">$"+parseFloat(i).toFixed(2)+"</option>"}$("#selTip").html(c)}$("#bDiscount").text(m);$("#bVendorDiscount").text(h);$("#bDeliveryFee").text(l);$("#bSubTotal").text(e);$("#bTax").text(f);$("#bTotal").text(j);$("#BasketDiscount").css("display",(m>0)?"block":"none");$("#BasketVendorDiscount").css("display",(h>0)?"block":"none");$("#BasketDeliveryFee").css("display",(l>0)?"block":"none");$("#WantedTimeWarning").text(b);$("#WantedTimeWarning").css("display",(b!="")?"block":"none")}function basketHtml(b){var a="";$(b).find("BasketProduct").each(function(d,e){var f=$(e).attr("Id");var c=$(e).attr("ProductName");var g=$(e).attr("Quantity");a+='<li id="proddisplay'+f+'"><span class="quantity">'+g+'x</span><span class="product">'+c+'</span><span class="money">$'+$(e).attr("Cost")+'</span><div class="controls">[ <a href="javascript:edit('+f+');">edit</a> | <a href="javascript:del('+f+');">remove</a> ]</div><div class="options">'+$(e).attr("Choices")+"</div></li>"});return a}function add(a){activeProdId=a;ShowDialog("/Order/Customize.aspx?prodId="+a,"Customize Product",880,600,{"Add to Cart":function(){if(previewVendor){alert("Unable to create orders for menus in the preview stage.")}else{SaveCustomize()}},Cancel:function(){CloseDialog()}})}function edit(a){activeProdId=a;ShowDialog("/Order/EditProduct.aspx?prodId="+a+"&basket="+BasketGuid,"Modify "+$("#proddisplay"+a+" .product").text(),880,600,{"Save Product":function(){SaveEditCustomize()},Cancel:function(){CloseDialog()}});$(".InlineCustomize").remove()}function customize(b,a){activeProdId=b;$(".InlineCustomize").remove();$.get("/Order/Customize.aspx?prodId="+b+"&mode=inline",function(c){$("#"+a).append("<div class='InlineCustomize'>"+c+"</div>")})}function validateCustomize(){var b=$("#frmCustomize #qty").val();if(b!=parseInt(b)||b<1||b>99){$("#custError").text("Please enter a valid quantity for this product").attr("className","MissingField");return"error"}$("#frmCustomize div").removeClass("MissingField");$("#frmCustomize .OptionGroup:has(:radio):not(:has(:checked))").each(function(){$("#og_"+$(this).find("input:first").attr("name")).addClass("MissingField")});$("#frmCustomize .LimitedOptions").each(function(){var c=this.id.split("_");count=$("#og_"+c[1]+" :checkbox:checked").length;if(count<c[2]||count>c[3]){$(this).addClass("MissingField")}});if($("#frmCustomize .MissingField").length>0){$("#custError").text("Please review all options with red headings and complete.").attr("className","MissingField");return"error"}else{var a="";$("#frmCustomize :checkbox:checked").each(function(){a+="&Choice="+this.id.substring(4,this.id.length)});$("#frmCustomize :radio:checked").each(function(){a+="&Choice="+this.value.substring(4,this.value.length)});return a}}function SaveCustomize(a){var b=validateCustomize();if(b!="error"){$.get("/ajax/AddBasketProduct.aspx?"+(BasketGuid!=""?"basket="+BasketGuid:"vendor="+VendorId)+"&vp="+activeProdId+"&instructions="+escape($("#instructions").val())+"&qty="+$("#frmCustomize #qty").val()+b,function(c){if(ajaxOk(c)){if(basketProductCount==0&&BasketGuid==""){self.location="Order.aspx"}else{basketProductCount++;UpdateBasketTotals(c);$("#BasketProducts").html(basketHtml(c))}}});if(a!=null){a()}else{CloseDialog()}}}function SaveInlineCustomize(){SaveCustomize(CloseInlineCustomize)}function CloseInlineCustomize(){$(".InlineCustomize").remove()}function SaveEditCustomize(){var a=validateCustomize();if(a!="error"){$.get("/ajax/UpdateBasketProduct.aspx?basket="+BasketGuid+"&bp="+activeProdId+"&instructions="+escape($("#instructions").val())+"&qty="+$("#frmCustomize #qty").val()+a,function(b){if(ajaxOk(b)){UpdateBasketTotals(b);$("#BasketProducts").html(basketHtml(b))}});CloseDialog()}}function del(a){activeProdId=a;if(window.confirm("Are you sure you wish to remove this product?")){$.get("/ajax/DeleteBasketProduct.aspx?basket="+BasketGuid+"&bp="+a,function(c){if(ajaxOk(c)){var b=$("#proddisplay"+activeProdId);if(b.hasClass("reward")){window.location=window.location}else{basketProductCount--;UpdateBasketTotals(c);b.slideUp("fast",function(){$(this).remove()})}}})}}function ShowDeliveryOptions(b,c){var d=$("#deliveryoptions");if(b=="delivery"){isDelivery="true";d.css("display","block");var a=$("#"+selAddressId).val();if(a==-1){a=0}$.get("/ajax/setDeliveryMode.aspx?basket="+BasketGuid+"&mode=Delivery&AddressId="+a,function(e){if(!ajaxOk(e)){$("#deliveryoptions").css("display","none");$("#"+radPickupClientId).attr("checked",true)}else{UpdateBasketTotals(e);var f=$(e).find("ContactNumber");if(f.length>0){$("#txtContactNumber").val(f.text())}}})}else{isDelivery="false";d.css("display","none");$.get("/ajax/setDeliveryMode.aspx?basket="+BasketGuid+"&mode=Pickup",function(e){if(ajaxOk(e)){UpdateBasketTotals(e);$("#txtContactNumber").val(userContactNumber)}else{$("#"+radPickupClientId).attr("checked",false)}})}}function ShowTimeOptions(a){var b=$("#timeoptions");if(a=="later"){b.css("display","block")}else{b.css("display","none");$.get("/ajax/updateBasketWantedTime.aspx?basket="+BasketGuid+"&type=Now",function(c){if(!ajaxOk(c)){$("#timeoptions").css("display","block");$("#"+WantedLaterOptionId).attr("checked",true)}else{UpdateBasketTotals(c)}})}}function ChangeAdvanceTime(){var b=$("#DatePicker").val();var a=$("#selTimeWanted :selected").val();if(a==""){alert("Please select a valid time");return}$.get("/ajax/updateBasketWantedTime.aspx?basket="+BasketGuid+"&type=Later&year="+b.substring(6,10)+"&month="+b.substring(0,2)+"&day="+b.substring(3,5)+"&hour="+a.substring(0,2)+"&min="+a.substring(3,5),function(c){if(ajaxOk(c)){self.location=self.location}else{$("#selTimeWanted").val(oldTimeWanted);$("#DatePicker").val(oldDateWanted)}})}function ValidateOrderDate(){var a=$("#DatePicker").val();$.get("/ajax/validateOrderDate.aspx?basket="+BasketGuid+"&year="+a.substring(6,10)+"&month="+a.substring(0,2)+"&day="+a.substring(3,5),function(b){if(!ajaxOk(b)){$("#DatePicker").val(oldDateWanted)}})}function updateTip(){var a=$("#selTip :selected").val();$.get("/ajax/updateBasketTip.aspx?basket="+BasketGuid+"&Tip="+a,function(b){if(ajaxOk(b)){UpdateBasketTotals(b)}})}function Checkout(){if(basketProductCount==0){alert("Your basket is empty, please select at least one product.");return}if(Upsell=="True"){$.get("/ajax/CheckUpselling.aspx?basket="+BasketGuid,function(a){if(a!=null&&a!=""){$("#PopupDialog").html(a);$("#PopupDialog").dialog({title:"May We Suggest",width:500,height:600,modal:true,position:"center",close:function(b,c){CloseDialog();GoToCheckout()}})}else{GoToCheckout()}})}else{GoToCheckout()}}function GoToCheckout(){self.location="Checkout.aspx"}function SaveFave(){if($("#favedesc").val().length==0){alert("Please supply a name for your Favorite.");return}document.forms.frmCheckout.submit()}function PlaceOrder(){if(!CheckSelectDelivery()){return}if(document.frmCheckout.ContactNumber.value.length<10){alert("Please enter a contact telephone number for the restaurant in case of any issues during preparation (e.g. item out of stock)");return}if(isDelivery.toLowerCase()=="true"){if(parseFloat($("#bSubTotal").text())<parseFloat(minDeliveryOrder)){alert("Your sub-total is below this restaurant's delivery minimum of $"+minDeliveryOrder+".\r\nPlease click Modify below to add to your order if you wish to order for delivery.");return}}else{if(parseFloat($("#bSubTotal").text())<parseFloat(minOrder)){alert("Your basket value is below the minimum amount of $"+minOrder+".\nPlease increase the amount to proceed.");return}}if($("#"+WantedLaterOptionId).attr("checked")&&$("#selTimeWanted :selected").val()==""){alert("Please select a valid time slot");return}if($("input[name='BillingAccount']").length>0&&!$("input[name='BillingAccount']:checked").val()){alert("Please select your billing method");return}$("#CheckoutButtons").html("Processing... please wait...");document.forms.frmCheckout.submit()}function CheckSelectDelivery(){var a=(canPickup=="True"&&$("#"+radPickupClientId).attr("checked"));var b=(canDeliver=="True"&&$("#"+radDeliveryClientId).attr("checked"));if(canDeliver=="True"){if(!a&&!b){if(canPickup!="True"){$("#"+radDeliveryClientId).attr("checked",true)}else{alert("Please select either Pickup or Delivery.");return false}}if(b&&$("#"+selAddressId).val()<=0){alert("Please select a delivery location.");return false}}else{if(!a){if(confirm("Click OK to confirm that this will be a Pickup order. This restaurant does not offer delivery.")){$("#"+radPickupClientId).attr("checked",true);return true}return false}}return true}function ProcessNewAddress(b){if(ajaxOk(b)){CloseDialog();newlyAddedAddressId=$(b).find("DeliveryAddressId").attr("Id");var a=document.getElementById(selAddressId);a.options[a.length]=new Option(AddressName,""+newlyAddedAddressId);$.get("/ajax/setDeliveryMode.aspx?basket="+BasketGuid+"&mode=Delivery&AddressId="+newlyAddedAddressId,function(c){isDelivery="true";if(!ajaxOk(c)){$("#"+selAddressId).val(lastDeliveryAddressId)}else{$("#"+selAddressId).val(newlyAddedAddressId);$("#txtContactNumber").val($(c).find("ContactNumber").text())}})}}function ChangedDeliveryAddress(b){selAddressId=b;var a=$("#"+b).val();if(a=="0"){CreateNewAddress()}else{isDelivery="true";if(a!="-1"){$.get("/ajax/setDeliveryMode.aspx?basket="+BasketGuid+"&mode=Delivery&AddressId="+a,function(c){if(!ajaxOk(c)){$("#"+selAddressId).val(lastDeliveryAddressId)}else{lastDeliveryAddressId=$("#"+selAddressId).val();$("#txtContactNumber").val($(c).find("ContactNumber").text())}})}}}function showTimes(b){var a="/ajax/listTimeSlots.ashx?basket="+BasketGuid+"&year="+b.substring(6,10)+"&month="+b.substring(0,2)+"&day="+b.substring(3,5);$("#selTimeWanted").load(a)}function LoadLoyaltyBoxes(a){$("#LoyaltyScheme"+a).html("Loading...");$.get("/ajax/CheckForRewards.aspx?basket="+BasketGuid+"&scheme="+a,function(b){$("#LoyaltyScheme"+a).html(b)},"html")}function linkLoyaltyCard(a){var d=$("#SchemeMemberNo"+a).val();var c=$("#LoyaltyScheme"+a);var b=c.html();c.html("Checking Membership...");$.get("/ajax/linkLoyaltyCard.aspx?scheme="+a+"&member="+escape(d),function(e){if(ajaxOk(e)){LoadLoyaltyBoxes(a,d)}else{c.html(b)}})}function removeLoyaltyCard(a){if(confirm("Are you sure you want to remove this loyalty card?")){$.get("/ajax/removeLoyaltyCard.aspx?scheme="+a,function(b){if(ajaxOk(b)){window.location=window.location}})}}function ApplyReward(a,b){$("#LoyaltyScheme"+a).html("Applying Reward...");$.get("/ajax/applyReward.aspx?basket="+BasketGuid+"&scheme="+a+"&ref="+b,function(c){if(ajaxOk(c)){window.location=window.location}})}function removeRewards(){$.get("/ajax/removeRewards.aspx?basket="+BasketGuid,function(a){if(ajaxOk(a)){window.location=window.location}})}function nest(c,a,b){$.get("/ajax/listNestedOptions.aspx?choice="+a,function(d){$("#nest_"+b).remove();$(".OptionContainer:has(#og_"+b+")").after(d).slideDown("fast")})}function unnest(a){$("#nest_"+a).slideUp("fast");$("#nest_"+a).remove()}function multinest(a,d){var c=$("#multinest_"+a);var b=$("#chk_"+a);if(b.attr("checked")){$.get("/ajax/listNestedOptions.aspx?type=multi&choice="+a,function(e){if(b.attr("checked")&&c.length==0){$(".OptionContainer:has(#og_"+d+")").after(e).slideDown("fast")}})}else{c.slideUp("fast").remove()}}function saveContactNo(){cn=$("#txtContactNumber").val();if(cn!=userContactNumber){$.get("/ajax/updateContactNumber.aspx?basket="+BasketGuid+"&number="+cn)}}function GroupOrder(){$("#PopupDialog").load("/Invite/StartGroupOrder.aspx?vendor="+VendorId,function(){$("#PopupDialog").dialog({title:"Group Ordering",width:580,height:350,modal:true,resizable:false,draggable:false,buttons:{Thanks:function(){CloseGroupOrder()}},close:function(){CloseGroupOrder()}})})}function CloseGroupOrder(){CloseDialog();if(!IsGroupOrder){self.location="Order.aspx"}}function EmailGroupOrder(){ShowDialog("/Invite/SendGroupInvite.aspx","Invite Guests",600,350,{"Send Invites":function(){SendInvites()},Cancel:function(){CloseDialog()}})}function EnterCouponCode(a){var b=$("#CouponCodeText").val();if(b.length==0){alert("Please enter a coupon code.");return false}$.get("/ajax/ApplyCoupon.aspx?code="+b+"&basket="+a,function(c){if(ajaxOk(c)){window.location=window.location}});return false}function RemoveCouponCode(a){$.get("/ajax/RemoveCoupon.aspx?basket="+a,function(b){if(ajaxOk(b)){window.location=window.location}});return false}function showProdImage(a){prodId=a.target.id.substring(4,a.target.id.length);if(prodImgTimeout!=null){clearTimeout(prodImgTimeout)}if(prodId==activeProdImage){return}else{$("#Tooltip").hide()}activeProdImage=prodId;$("#Tooltip").load("/ajax/ProductDetails.aspx?prod="+activeProdImage,function(){$("#Tooltip").css("left",a.pageX+8);$("#Tooltip").css("top",a.pageY-$("#Tooltip").height()/2);$("#Tooltip").fadeIn("fast")})}function hideProdImage(){prodImgTimeout=setTimeout(function(){$("#Tooltip").fadeOut("fast");activeProdImage=0;prodImgTimeout=null},500)}function validatePos(){$.get("/ajax/ValidatePos.aspx?basket="+BasketGuid,function(a){if(ajaxOk(a)){$("#lblSalesTax").text("Tax");$("#lblTotal").text("Total");$("#bSalesTax").text($(a).find("tax").text());$("#bTotal").text($(a).find("total").text())}})};