;// bundle: page___af0c051a3b7bf9ec90753f82c014ee28_m
;// files: ItemPurchase.js

;// ItemPurchase.js
var Roblox=Roblox||{};$(function(){Roblox.ItemPurchase=function(){function h(n){n+="",x=n.split("."),x1=x[0],x2=x.length>1?"."+x[1]:"";for(var t=/(\d+)(\d{3})/;t.test(x1);)x1=x1.replace(t,"$1,$2");return x1+x2}function e(n){$.modal.close("."+n)}function l(){window.location.href="/login/Default.aspx?ReturnUrl="+encodeURIComponent(location.pathname+location.search)}function i(n){var t={overlayClose:!0,opacity:80,overlayCss:{backgroundColor:"#000"}};typeof n!="undefined"&&n!==""&&$.modal.close("."+n),$("#ProcessingView").modal(t)}function f(n,u){var f;if(i(u),f=$(n),!f.hasClass("BtnDisabled")){var s=f.attr("data-item-id"),o=parseInt(f.attr("data-expected-price")),e=f.attr("data-expected-currency");$.ajax({type:"POST",url:"/API/Item.ashx?rqtype=purchase&assetID="+s+"&expectedCurrency="+e+"&expectedPrice="+o,contentType:"application/json; charset=utf-8",success:function(n){$.modal.close(".ProcessingView"),t(n)},error:function(n){$.modal.close(".ProcessingView");var t=$.parseJSON(n.responseText);r(t)}})}}function r(t){var i=$("#"+t.showDivID);t.showDivID==="TransactionFailureView"?(i.find(".titleBar").text(t.title),i.find(".PurchaseModalMessageText").text(t.errorMsg)):t.showDivID==="InsufficientFundsView"?(i.find(".shortfall-price").text(t.shortfallPrice),i.find(".current-currency").addClass("CurrencyColor"+t.currentCurrency),i.find(".PurchaseModalMessageText").html(text),t.currentCurrency==1?i.find(".tickets").remove():i.find(".robux").remove()):t.showDivID==="PriceChangedView"&&(i.find(".expected-price").text(t.expectedPrice),i.find(".expected-currency").addClass("CurrencyColor"+t.expectedCurrency),i.find(".current-price").text(t.currentPrice),i.find(".current-currency").addClass("CurrencyColor"+t.currentCurrency),i.find(".ImageButton.btn-buynow2").attr("onclick","return false;").click(function(){var n=$(".PurchaseButton[data-item-id="+t.AssetID+"][data-expected-currency="+t.expectedCurrency+"][data-expected-price="+t.expectedPrice+"]");Roblox.ItemPurchase.purchaseItem(n,"PurchaseVerificationView")})),i.modal(n)}function o(t){var f=$(t),a,o,v;if(!f.hasClass("BtnDisabled")){var y=f.attr("data-item-name"),p=f.attr("data-item-id"),l=parseInt(f.attr("data-expected-price")),e=f.attr("data-expected-currency"),b=f.attr("data-expected-seller-id"),w=f.attr("data-seller-name"),i=$("#PurchaseVerificationView");if(u==="true"){Roblox.ItemPurchase.redirectToLogin();return}if(a=e=="1"?parseInt(c):parseInt(s),o=a-l,i.find(".roblox-item-image").attr("data-item-id",p),i.find(".asset-name").text(y),i.find(".seller-name").text(w),i.find(".PurchaseModalMessageText .currency").attr("class","currency CurrencyColor"+(l==0?"Free":e)).text(l==0?"Free":l),i.find(".balance-after-transaction").text((e=="1"?"R$":"Tx")+h(o)),o<0){v={shortfallPrice:0-o,currentCurrency:e,showDivID:"InsufficientFundsView"},r(v);return}i.find(".ImageButton.btn-buynow2").attr("onclick","return false;").click(function(){Roblox.ItemPurchase.purchaseItem(t,"PurchaseVerificationView")}),Roblox.require("Widgets.ItemImage",function(n){n.load(i.find(".roblox-item-image"))}),i.modal(n)}}function t(t){t.Currency=t.Currency==0?"Free":t.Currency;var i=$("#PurchaseConfirmationView");i.find(".transaction-verb").text(t.TransactionVerb),i.find(".asset-name").text(t.AssetName),i.find(".asset-type").text(t.AssetType),i.find(".seller-name").text(t.SellerName),i.find(".asset-price").text(t.Price),i.find(".roblox-item-image").attr("data-item-id",t.AssetID),i.find(".currency-color").addClass("CurrencyColor"+t.Currency),$("[data-item-id="+t.AssetID+"]").addClass("BtnDisabled").tipsy(),Roblox.require("Widgets.ItemImage",function(n){n.load(i.find(".roblox-item-image"))}),i.modal(n)}var n={escClose:!0,opacity:80,overlayCss:{backgroundColor:"#000"}},u=$("#ItemPurchaseAjaxData").attr("data-authenticateduser-isnull"),c=$("#ItemPurchaseAjaxData").attr("data-user-balance-robux"),s=$("#ItemPurchaseAjaxData").attr("data-user-balance-tickets");return{showProcessingModal:i,purchaseItem:f,openPurchaseVerificationView:o,openPurchaseConfirmationView:t,redirectToLogin:l,ModalClose:e}}()});
