$.widget("ui.Apkad",{options:{addHistory:$.noop},defaultValues:{useAd:!1,adsense:"domob",adPosition:"banner",publisherId:"",inlineAdPositionId:"",splashAdPositionId:"",interstitialAdPositionId:"",realtimeAd:!1},adPositionConfig:{banner:["inlineAdPositionId"],rotateBanner:["inlineAdPositionId"],splash:["splashAdPositionId","realtimeAd"],splash_Banner:["inlineAdPositionId","splashAdPositionId","realtimeAd"],splash_RotateBanner:["inlineAdPositionId","splashAdPositionId","realtimeAd"],interstitial:["interstitialAdPositionId"]},_create:function(){var i=this.element,t=this,n=$.utils.getRandom(1e4);i.append("<label for = 'use-ad-"+n+"'>"+i18n("use_ad")+"</label><input id = 'use-ad-"+n+"' type = 'checkbox' name = 'use-ad' class = 'use-ad'/>").find(".use-ad").customInput().click(function(){t.onchange("useAd",{useAd:$(this).customInput("checked")})});$("<div class = 'edit-apkad'></div>").appendTo(i).form({columns:[{label:i18n("adsense"),widget:"<div class = 'select-adsense'></div>"},{label:i18n("ad_position"),widget:"<div class = 'select-ad-position'></div><label class = 'apk-ad-position-tip'>("+i18n("apk_ad_position_tip")+")</label>"},{label:"*publisher ID: ",widget:"<input class = 'ui-widget-content ui-corner-all publisherId'/>"},{label:"*"+i18n("inlineAdPositionId"),widget:"<input class = 'ui-widget-content ui-corner-all inlineAdPositionId'/>"},{label:"*"+i18n("splashAdPositionId"),widget:"<input class = 'ui-widget-content ui-corner-all splashAdPositionId'/>"},{label:"*"+i18n("interstitialAdPositionId"),widget:"<input class = 'ui-widget-content ui-corner-all interstitialAdPositionId'/>"},{label:"",widget:"<label for = 'real-time-ad-"+n+"'>"+i18n("realtime_ad")+"</label><input id = 'real-time-ad-"+n+"' type = 'checkbox' name = 'realtime-ad' class = 'realtimeAd'/>"}]});i.find(".select-adsense").RadioGroup({options:["domob","admob","baidu"],defaultValue:"domob",name:"adsense",onchange:function(i){t.onchange("adsense",{adsense:i})}});i.find(".select-ad-position").select({options:["banner","rotateBanner","splash","splash_Banner","splash_RotateBanner","interstitial"],select:function(i){t.onchange("adPosition",{adPosition:i})}});["publisherId","inlineAdPositionId","splashAdPositionId","interstitialAdPositionId"].forEach(function(n){i.find("."+n).keyup(function(){var i={};i[n]=$(this).val();t.onchange(n,i)})});i.find(".realtimeAd").customInput().click(function(){t.onchange("realtimeAd",{realtimeAd:$(this).customInput("checked")})})},value:function(i){var t=this.defaultValues;if(void 0===i){i={};i.useAd=this.useAd();if(!i.useAd)return i;i.adsense=this.adsense();i.adPosition=this.adPosition();i.publisherId=this.publisherId();if(!i.publisherId){$.utils.alert(i18n("not_null","publisher ID"));return!1}for(var n=this.adPositionConfig[i.adPosition]||[],e=0,d=n.length;d>e;e++){var s=n[e];i[s]=this[s]&&this[s]();void 0===i[s]&&(i[s]=t[s]);if("string"==typeof i[s]&&!i[s]){$.utils.alert(i18n("not_null",i18n(s)));return!1}}return i}i||(i={});for(var a in t)this[a]&&this[a](void 0===i[a]?t[a]:i[a])},onchange:function(i,t){var n=this;if("function"==typeof this[i]){var e=this[i]();if(t[i]!==e){this[i](t[i]);this.addHistory({oldValue:e,newValue:t[i],undo:function(t){n[i](t)},redo:function(t,e){n[i](e)}})}}},addHistory:function(i){this.options.addHistory&&this.options.addHistory(i)},useAd:function(i){var t=this.element.find(".use-ad");if(void 0===i)return t.data("useAd");t.data("useAd",!!i).customInput("checked",!!i);this.element.find(".edit-apkad")[i?"show":"hide"]()},adsense:function(i){var t=this.element.find(".select-adsense");if(void 0===i)return t.data("adsense");t.data("adsense",i).RadioGroup("value",i);return void 0},adPosition:function(i){var t=this.element.find(".select-ad-position");if(void 0===i)return t.data("adPosition");t.data("adPosition",i).select("value",i);this.element.find(".inlineAdPositionId, .splashAdPositionId, .interstitialAdPositionId, .realtimeAd").closest("tr").hide();var n=this.adPositionConfig[i];this.element.find("."+n.join(",.")).closest("tr").show()},publisherId:function(i){var t=this.element.find(".publisherId");if(void 0===i)return t.data("publisherId");t.data("publisherId",i);t.val()!==i&&t.val(i)},inlineAdPositionId:function(i){var t=this.element.find(".inlineAdPositionId");if(void 0===i)return t.data("inlineAdPositionId");t.data("inlineAdPositionId",i);t.val()!==i&&t.val(i)},splashAdPositionId:function(i){var t=this.element.find(".splashAdPositionId");if(void 0===i)return t.data("inlineAdPositionId");t.data("inlineAdPositionId",i);t.val()!==i&&t.val(i)},interstitialAdPositionId:function(i){var t=this.element.find(".interstitialAdPositionId");if(void 0===i)return t.data("inlineAdPositionId");t.data("inlineAdPositionId",i);t.val()!==i&&t.val(i)},realtimeAd:function(i){var t=this.element.find(".realtimeAd");if(void 0===i)return t.data("realtimeAd");t.data("realtimeAd",!!i).customInput("checked",!!i);return void 0}});