function cmdPaymentTotal(){var b=".btnAddLeague[value='Remove from Purchase']";if($(this).attr("loggedin")=="false"){showMessage("You must be logged in to complete this purchase. Click <a href='/login?source=/leaguepro'>HERE</a> to login.");return}if($(this).attr("leagues")=="false"){showMessage("You currently have not joined any leagues that are eligible for League PRO. Click <a href='/dashboard'>HERE</a> to create your own league and invite friends or browse existing leagues to join.");return}if(!$(b).length>0){showMessage("Please click 'Add to Purchase' for one or more of your leagues.");return}var a={};a.productid=$(".hfProductId").val();a.promoid=$(".hfPromoId").val();a.price=$(".hfAmountTotal").val();a.ordertype="MultiItem";a.country=$(".hfCountry").val();var c="";$(b).each(function(){c+=$(this).attr("leagueid")+";"});a.items=c;AjaxAction.prototype.perform({action:"payment/order",oncomplete:cmdPaymentTotalComplete,values:a})}function cmdPaymentTotalComplete(a){if(a.success())window.location.href=a.parameters().Items.redirect}function cmdApplyPromoCode(){var a={};a.promocode=$("#tbMPPromoCode").val();a.country=$(".hfCountry").val();AjaxAction.prototype.perform({action:"payment/promo",oncomplete:cmdApplyPromoCodeComplete,values:a})}function cmdApplyPromoCodeComplete(c){var i="#tbMPPromoCode",h=".spanAmountTotal",g="<SUP>*</SUP>",a="NZ$",f=".spanLPAmount",e=".hfPromoId";if(c.success()){var b=c.parameters().Items.promoamount;$(e).val(c.parameters().Items.promoid);$(".hfAmount").val(b);var d=parseFloat(b)*$(".btnAddLeague[value='Remove from Purchase']").length;$(".hfAmountTotal").val(d);if($(".hfCountry").val()=="NZ"){$(f).html(a+b+g);$(h).html(a+d.toFixed(2)+g)}else{$(f).html(a+b);$(h).html(a+d.toFixed(2))}$(i).css("border","green 4px solid")}else{$(".hfPromoAmount").val("0");$(e).val("");$(i).css("border","red 4px solid");if(c.parameters().Items.message=="expired")showMessage("The code you've entered was a limited offer that has expired and can't be used");else showMessage("The code you've entered is incorrect. Please check your code and try again.")}}function cmdGetPrice(){var a={};a.productid=$(".hfProductId").val();AjaxAction.prototype.perform({action:"payment/price",oncomplete:cmdGetPriceComplete,values:a})}function cmdGetPriceComplete(b){var e=".hfAmount",d="#pGSTText",c=".spanLPAmount";if(b.success()){var a="0";if($(".hfCountry").val()=="NZ"){a=b.parameters().Items.pricegst;$(c).html("NZ$"+a+"<SUP>*</SUP>");$(d).show();$(e).val(a)}else{a=b.parameters().Items.price;$(c).html("NZ$"+a);$(d).hide();$(e).val(a)}}}function cmdAddLeague(){var e=".spanAmountTotal",d=".btnPaymentTotal",c="Add to Purchase",b=".hfAmountTotal",g={},a=parseFloat($(b).val()),f=parseFloat($(".hfAmount").val());if($(this).val()==c){$(this).val("Remove from Purchase");a=a+f;$(b).val(a);$(d).show()}else{$(this).val(c);a=a-f;$(b).val(a);$(".btnAddLeague[value='Remove from Purchase']").length==0&&$(d).hide()}if($(".hfCountry").val()=="NZ")$(e).html("NZ$"+a.toFixed(2)+"<SUP>*</SUP>");else $(e).html("NZ$"+a.toFixed(2))}function cmdNoLeagues(){window.location.href="/dashboard"}function cmdNotLoggedIn(){window.location.href="/login?source=leaguepro"}function BindPageEvents(){var b="pointer",a="cursor";$(".btnAddLeague").unbind().click(cmdAddLeague).css(a,b);$("#btnMPPromoCode").unbind().click(cmdApplyPromoCode).css(a,b);$(".btnPaymentTotal").unbind().click(cmdPaymentTotal).css(a,b);$(".btnNoLeagues").unbind().click(cmdNoLeagues).css(a,b);$(".btnNotLoggedIn").unbind().click(cmdNotLoggedIn).css(a,b);$.get("https://ipinfo.io?token=b72fc7fd43307e",function(a){$(".hfCountry").val(a.country);cmdGetPrice()},"jsonp")}$(document).ready(function(){BindPageEvents()})