$.widget("ui.InAppPurchase",{options:{addHistory:$.noop},surportPurchaseMethods:["mobile","unicom","telecom"],defaultValues:{mobile:{appid:"",appkey:""},unicom:"",telecom:!1},_create:function(){var e=this.element,i=this,t=$.utils.getRandom(1e4),n=this.surportPurchaseMethods,a=$("<fieldset class = 'purchase-methods'><legend>"+i18n("purchase_methods")+"</legend></fieldset>").appendTo(e),o=$("<fieldset class = 'purchase-settings'><legend>"+i18n("purchase_settings")+"</legend></fieldset>").appendTo(e);["mobile","unicom","telecom","paypal","wechat"].forEach(function(e){var l="use-"+e+"-purchase",s=l+"-"+t,c=$("<input id = '"+s+"' type = 'checkbox' name = 'purchase-method' class = '"+l+"'/><label for = '"+s+"'>"+i18n(e)+"</label>").appendTo(a).first().customInput().click(function(){var t=$(this).customInput("checked"),n="enable"+$.utils.firstLetterUpperCase(e),a={};a[n]=t;i.onchange(n,a)});c.customInput("disable",n.indexOf(e)<0);$("<div class = '"+e+"'></div>").appendTo(o).hide();var r="init"+$.utils.firstLetterUpperCase(e)+"Purchase";i[r]&&i[r]()})},initMobilePurchase:function(){var e=this,i=this.element.find(".mobile");$("<label>"+i18n("mobile")+": </label>").appendTo(i);var t=$("<div class = 'inner'></div>").appendTo(i).form({columns:[{label:"APPID",widget:"<input class = 'ui-widget-content ui-corner-all appid'/>"},{label:"APPKEY",widget:"<input class = 'ui-widget-content ui-corner-all appkey'/>"}]});t.find(".appid").keyup(function(){var i=JSON.parse(JSON.stringify(e.mobile()));i.appid=$(this).val();e.onchange("mobile",{mobile:i})});t.find(".appkey").keyup(function(){var i=JSON.parse(JSON.stringify(e.mobile()));i.appkey=$(this).val();e.onchange("mobile",{mobile:i})});$("<label class = 'mobile-appid-appkey-tip'>"+i18n("mobile_appid_appkey_tip")+"</label>").appendTo(t)},initUnicomPurchase:function(){this.element.find(".unicom")},initTelecomPurchase:function(){var e=this.element.find(".telecom");$("<label>"+i18n("telecom")+": </label>").appendTo(e);var i=$("<div class = 'inner'></div>").appendTo(e);$("<label class = 'telecom-appid-appkey-tip'>"+i18n("telecom_appid_appkey_tip")+"</label>").appendTo(i)},value:function(e){var i=this.defaultValues;if(void 0===e){e={};for(var t in i){var n="enable"+$.utils.firstLetterUpperCase(t),a="valid"+$.utils.firstLetterUpperCase(t);if(this[n]&&this[n]()){e[t]=this[t]&&this[t]()||i[t];if(this[a]&&!this[a](e[t]))return!1}}return e}for(var t in i){var n="enable"+$.utils.firstLetterUpperCase(t);this[n]&&this[n](!!e[t]);this[t]&&this[t](e[t]||i[t])}},onchange:function(e,i){var t=this;if("function"==typeof this[e]){var n=this[e]();if(n!==i[e]&&JSON.stringify(n)!==JSON.stringify(i[e])){this[e](i[e]);this.addHistory({oldValue:n,newValue:i[e],undo:function(i,n){t[e](i)},redo:function(i,n){t[e](n)}})}}},addHistory:function(e){this.options.addHistory&&this.options.addHistory(e)},enableMobile:function(e){var i=this.element.find(".use-mobile-purchase");if(void 0===e)return i.data("enableMobile");i.data("enableMobile",e).customInput("checked",!!e);var t=this.element.find(".mobile")[e?"show":"hide"]().parent(),n=0;t.children().each(function(e,i){"none"!==$(i).css("display")&&n++});t[n>1?"show":"hide"]()},enableUnicom:function(e){var i=this.element.find(".use-unicom-purchase");if(void 0===e)return i.data("enableUnicom");i.data("enableUnicom",e).customInput("checked",!!e);var t=this.element.find(".unicom")[e?"show":"hide"]().parent(),n=0;t.children().each(function(e,i){"none"!==$(i).css("display")&&n++});t[n>1?"show":"hide"]();this.unicom(!!e)},enableTelecom:function(e){var i=this.element.find(".use-telecom-purchase");if(void 0===e)return i.data("enableTelecom");i.data("enableTelecom",e).customInput("checked",!!e);var t=this.element.find(".telecom")[e?"show":"hide"]().parent(),n=0;t.children().each(function(e,i){"none"!==$(i).css("display")&&n++});t[n>1?"show":"hide"]();this.telecom(!!e)},mobile:function(e){var i=this.element.find(".mobile");if(void 0===e)return i.data("mobile");i.data("mobile",e);var t=i.find(".appid");t.val()!==e.appid&&t.val(e.appid);var n=i.find(".appkey");n.val()!==e.appkey&&n.val(e.appkey)},unicom:function(e){var i=this.element.find(".unicom");if(void 0===e)return i.data("unicom");i.data("unicom",e);return void 0},telecom:function(e){var i=this.element.find(".telecom");if(void 0===e)return i.data("telecom");i.data("telecom",e);return void 0},validUnicom:function(e){return!0},validTelecom:function(e){return!0},validMobile:function(e){if(!e.appid){$.utils.alert(i18n("not_null","APPID"));return!1}if(!e.appkey){$.utils.alert(i18n("not_null","APPKEY"));return!1}return!0}});