var M=[];function DL(a,b){this.type=a;this.data=this.status=null;this.updateCallback=[];this.UCID=[];switch(a){case"alias":this.url="/API?f=getAlias&id="+b.id;break;case"cat":this.url="/API?f=getCat";break;case"bookmarkInfo":this.url="/API?f=getBookmarkDetail&user="+b.user+"&catName="+b.catName+"&id="+b.id;break}}DL.prototype.process=function(a){if(this.status!="SUCCESS"){this.update(a)}else{a.call(this,this.data)}};DL.prototype.update=function(b){var a=this;$.getJSON(this.url+ajaxRand(),function(d){a.status=d.status;if(d.status!="SUCCESS"){if(b){b.call(this,null)}return}a.data=d.data;for(var c in a.updateCallback){a.updateCallback[c].call(this)}if(b){b.call(this,a.data)}})};DL.prototype.addUpdateCallback=function(c,b){if($.inArray(b,this.UCID)==-1){this.UCID.push(b);this.updateCallback.push(c)}$("#debugText2").text("");for(var a in this.UCID){$("#debugText2").append(this.UCID[a]+"\n")}};function deleteDir(a){if(!confirm("刪除資料夾後會把原本在裡面的分類移出資料夾, 您確定要繼續嗎?")){return}$("#cat2").cover("process");$.post("API","f=deleteDir&id="+a,function(b){if(b.status=="SUCCESS"){M.cat.update(function(){$("#cat2").uncover()})}else{$("#cat2").cover("failed",b.data)}},"json")}function deleteCat(a){$("#cat2").cover("process");$.post("API","f=deleteCat&id="+a,function(b){if(b.status=="SUCCESS"){M.cat.update(function(){$("#cat2").uncover()})}else{$("#cat2").cover("failed",b.data)}},"json")}function editDir(a){if($("#editDir"+a).length==0){$("body").append("<div><div><div id=editDir"+a+"></div></div></div>");$("#editDir"+a).parent().parent().ccDialog({width:330,bgiframe:true,resizable:false,title:"編輯資料夾",open:function(b,c){$("#editDir"+a).ccEditDir(a)},close:function(){$("#editDir"+a).parent().parent().remove()}},"l")}else{$("#editDir"+a).parent().parent().dialog("moveToTop")}}function editCat(a){if($("#editCat"+a).length==0){$("body").append("<div><div><div id=editCat"+a+"></div></div></div>");$("#editCat"+a).parent().parent().ccDialog({width:330,bgiframe:true,resizable:false,title:"編輯分類",open:function(b,c){$("#editCat"+a).ccEditCat(a)},close:function(){$("#editCat"+a).parent().parent().remove()}},"l")}else{$("#editCat"+a).parent().parent().dialog("moveToTop")}}(function(a){a.extend(a.fn,{ccLoadAlias:function(d,c){this.cover("load");if(M["alias"+d]==undefined){M["alias"+d]=new DL("alias",{id:d})}var b=a(this);b.html('<em>*</em><b>1.選擇收藏的名字：</b><br><ul id=nameTree style="padding-left:0;margin-left:0"></ul>');M["alias"+d].process(function(g){b.find("#nameTree").empty().append('<li><input id=alias0 type=radio name=alias>自訂：<input type=text style="width:140px" name=aliasname onfocus="$(\'#alias0\').click();">');var f=0;a.each(g,function(j,h){j++;b.find("#nameTree").append("<li><input id=alias"+j+" type=radio name=alias value='"+h+"'><label for=alias"+j+' onmouseover=\'$(this).css("color","red");\' onmouseout=\'$(this).css("color","black")\'>'+h+"</label>")});b.find("#nameTree input:radio").click(function(){b.find("#nameTree>li").css("font-weight","normal");b.parent().css("font-weight","bold")});b.find("#nameTree>li:eq(1)>input:radio").click();if(c!=""){c=htmlspecialchars_decode(c);var e=b.find("#nameTree>li>[name=alias][value="+c+"]");if(e.length>0){e.click()}else{b.find("#alias0").click();b.find("[name=aliasname]").val(c)}}b.uncover()})},ccAddCat:function(){var b=a(this);b.cover("load");if(M.cat==undefined){M.cat=new DL("cat")}b.html('<div style="margin:0 0 5px"><span class=ic_cat>&nbsp;</span><b>新增遊戲分類：</b></div><form><input name=catname type=text><button type=submit>送出</button></form>');b.find('input[name="catname"]').keyup(function(){if(!isBlank(this.value)){b.find("#addCatDirDiv").show()}});b.find("form").submit(function(){if(isBlank(this.catname.value)){b.find('[name="catname"]').showHint(hint_blank).one("focus",function(){a(this).hideHint()});return false}b.cover("process");a.post("API","f=addCat&"+b.find("form").serialize(),function(c){if(c.status=="SUCCESS"){M.cat.update(function(){b.cover("success");b.find("form input[name=dirname]").val("")})}else{b.cover("failed",c.data)}},"json");return false});M.cat.process(function(d){M.cat.addUpdateCallback(function(){b.ccAddCat()},b.attr("id")+"ccAddCat");var c="";a.each(d,function(e,f){if(f.type=="dir"){c+="<option value="+f.id+">"+f.name}});if(c!=""){b.find("form").append('<div id=addCatDirDiv class=hide>所屬資料夾：<select name=addCatDir><option value="">無'+c+"</select></div>")}b.uncover()})},ccAddDir:function(){this.html('<div style="margin:0 0 5px"><span class=ic_dir>&nbsp;</span><b>新增分類管理資料夾：</b></div><form><input name=dirname type=text><button type=submit>送出</button></form>');var b=a(this);this.find("form").submit(function(){if(isBlank(this.dirname.value)){b.find('[name="dirname"]').showHint(hint_blank).one("focus",function(){a(this).hideHint()});return false}b.cover("process");a.post("API","f=addDir&"+b.find("form").serialize(),function(c){if(c.status=="SUCCESS"){M.cat.update(function(){b.cover("success");b.find("form input[name=dirname]").val("")})}else{b.cover("failed",c.data)}},"json");return false})},ccEditDir:function(d){var b=a(this);b.cover("load");var c;M.cat.process(function(e){a.each(e,function(f,g){if(g.type=="dir"&&g.id==d){c=g.name}})});b.html("<form><span class=ic_dir>&nbsp;</span>資料夾名稱：<input name=dirname type=text value="+c+"><button type=submit>修改</button></form>");b.find("form").submit(function(){if(isBlank(this.dirname.value)){b.find('[name="dirname"]').showHint(hint_blank).one("focus",function(){a(this).hideHint()});return false}b.cover("process");a.post("API","f=editDir&id="+d+"&"+b.find("form").serialize(),function(e){if(e.status=="SUCCESS"){M.cat.update(function(){b.cover("success");setTimeout(function(){b.parent().parent().dialog("close")},1000)})}else{b.cover("failed",e.data)}},"json");return false});b.uncover()},ccEditCat:function(e){var c=a(this);c.cover("load");var b;var d;M.cat.process(function(f){a.each(f,function(g,h){if(h.type=="dir"){a.each(h.sub,function(i,k){if(k.id==e){b=k.name;d=h.id}})}else{if(h.id==e){b=h.name}}})});c.html("<form><span class=ic_cat>&nbsp;</span>分類名稱：<input name=catname type=text value="+b+"><button type=submit>修改</button></form>");M.cat.process(function(g){M.cat.addUpdateCallback(function(){c.ccEditCat(e)},c.attr("id")+"ccEditCat");var f="";a.each(g,function(h,j){if(j.type=="dir"){f+="<option value="+j.id+">"+j.name}});if(f!=""){c.find("form").append('<div id=editCatDirDiv><span class=ic>&nbsp;</span>所屬資料夾：<select name=editCatDir><option value="">無'+f+"</select></div>")}c.find('[name="editCatDir"]').val(d);c.uncover()});c.find("form").submit(function(){if(isBlank(this.catname.value)){c.find('[name="catname"]').showHint(hint_blank).one("focus",function(){a(this).hideHint()});return false}c.cover("process");a.post("API","f=editCat&id="+e+"&"+c.find("form").serialize(),function(f){if(f.status=="SUCCESS"){M.cat.update(function(){c.cover("success");setTimeout(function(){c.parent().parent().dialog("close")},1000)})}else{c.cover("failed",f.data)}},"json");return false})},ccLoadCat:function(e,b,d){this.cover("load");if(M.cat==undefined){M.cat=new DL("cat")}var c=a(this);c.html("<b>"+e+"：</b><ul id=catTree class=filetree></ul>");if(b=="select"){c.find("#catTree").before('<a href="" id=addCat class=options>[+新增/修改分類]</a>');c.find("#addCat").click(function(){if(a("#catAdminDiv").length==0){a("body").append('<div id=catAdminDiv class=hide><table style="width:100%" cellpadding=10><tr><td valign=top style="border-right:gray 1px dashed;width:50%"><div><div id=addCatDiv class=dd style="height:110px;border-bottom:1px dashed gray;margin-bottom:20px"></div></div><div><div id=addDirDiv class=dd style="height:110px"></div></div><td valign=top><div><div id=cat2 class=dd style="height:240px"></div></div></table></div>');a("#catAdminDiv").ccDialog({width:520,autoOpen:false,bgiframe:true,resizable:false,title:"新增／修改分類",open:function(f,g){a(this).find("#addCatDiv").ccAddCat();a(this).find("#addDirDiv").ccAddDir();a(this).find("#cat2").ccLoadCat("編輯分類","edit","")}},"l")}a("#catAdminDiv").dialog("open").dialog("moveToTop");return false});c.hover(function(){a(this).find("#addCat").show()},function(){if(M.cat.data!=""){a(this).find("#addCat").hide()}})}M.cat.process(function(f){M.cat.addUpdateCallback(function(){c.ccLoadCat(e,b,d)},c.attr("id")+"ccLoadCat"+e+b);c.find("#catTree").empty();if(f==""){a("#addCat").show();c.uncover();return}a.each(f,function(g,h){if(h.type=="dir"){if(b=="select"){c.find("#catTree").append("<li><span class=folder>"+h.name+"</span><ul id=d"+h.id+"></ul>")}else{c.find("#catTree").append("<li><span class=folder onmouseover='$(this).find(\".edit\").show();' onmouseout='$(this).find(\".edit\").hide();'>"+h.name+"<span class=edit> (<a href='' onclick='editDir(\""+h.id+"\");return false;'>編輯</a> | <a href='' onclick='deleteDir(\""+h.id+"\");return false;'>刪除</a>)</span></span><ul id=d"+h.id+"></ul>")}a.each(h.sub,function(i,k){if(b=="select"){c.find("#catTree #d"+h.id).append("<li><input id=c"+k.id+" name="+k.id+" type=checkbox><label for=c"+k.id+">"+k.name+"</label>")}else{c.find("#catTree #d"+h.id).append("<li onmouseover='$(this).find(\".edit\").show();' onmouseout='$(this).find(\".edit\").hide();'><span class=file>"+k.name+"<span class=edit> (<a href='' onclick='editCat(\""+k.id+"\");return false;'>編輯</a> | <a href='' onclick='deleteCat(\""+k.id+"\");return false;'>刪除</a>)</span></span>")}})}else{if(b=="select"){c.find("#catTree").append("<li><input id=c"+h.id+" name="+h.id+" type=checkbox><label for=c"+h.id+">"+h.name+"</label>")}else{c.find("#catTree").append("<li onmouseover='$(this).find(\".edit\").show();' onmouseout='$(this).find(\".edit\").hide();'><span class=file>"+h.name+"<span class=edit> (<a href='' onclick='editCat(\""+h.id+"\");return false;'>編輯</a> | <a href='' onclick='deleteCat(\""+h.id+"\");return false;'>刪除</a>)</span></span>")}}});c.find(".edit").hide();c.find("#catTree>li:gt(0)").addClass("closed");a.each(d,function(g,h){c.find("#c"+h.id).click().parents("li.closed").removeClass("closed")});c.find("#catTree").treeview();c.uncover()})}})})(jQuery);(function(a){a.extend(a.fn,{swapClass:function(e,d){var c=this.filter("."+e);this.filter("."+d).removeClass(d).addClass(e);c.removeClass(e).addClass(d);return this},replaceClass:function(d,c){return this.filter("."+d).removeClass(d).addClass(c).end()},hoverClass:function(c){c=c||"hover";return this.hover(function(){a(this).addClass(c)},function(){a(this).removeClass(c)})},heightToggle:function(c,d){c?this.animate({height:"toggle"},c,d):this.each(function(){jQuery(this)[jQuery(this).is(":hidden")?"show":"hide"]();if(d){d.apply(this,arguments)}})},heightHide:function(c,d){if(c){this.animate({height:"hide"},c,d)}else{this.hide();if(d){this.each(d)}}},prepareBranches:function(c){if(!c.prerendered){this.filter(":last-child:not(ul)").addClass(b.last);this.filter((c.collapsed?"":"."+b.closed)+":not(."+b.open+")").find(">ul").hide()}return this.filter(":has(>ul)")},applyClasses:function(c,d){this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(e){d.apply(a(this).next())}).add(a("a",this)).hoverClass();if(!c.prerendered){this.filter(":has(>ul:hidden)").addClass(b.expandable).replaceClass(b.last,b.lastExpandable);this.not(":has(>ul:hidden)").addClass(b.collapsable).replaceClass(b.last,b.lastCollapsable);this.prepend('<div class="'+b.hitarea+'"/>').find("div."+b.hitarea).each(function(){var e="";a.each(a(this).parent().attr("class").split(" "),function(){e+=this+"-hitarea "});a(this).addClass(e)})}this.find("div."+b.hitarea).click(d)},treeview:function(d){d=a.extend({cookieId:"treeview"},d);if(d.add){return this.trigger("add",[d.add])}if(d.toggle){var i=d.toggle;d.toggle=function(){return i.apply(a(this).parent()[0],arguments)}}function c(l,n){function m(o){return function(){f.apply(a("div."+b.hitarea,l).filter(function(){return o?a(this).parent("."+o).length:true}));return false}}a("a:eq(0)",n).click(m(b.collapsable));a("a:eq(1)",n).click(m(b.expandable));a("a:eq(2)",n).click(m())}function f(){a(this).parent().find(">.hitarea").swapClass(b.collapsableHitarea,b.expandableHitarea).swapClass(b.lastCollapsableHitarea,b.lastExpandableHitarea).end().swapClass(b.collapsable,b.expandable).swapClass(b.lastCollapsable,b.lastExpandable).find(">ul").heightToggle(d.animated,d.toggle);if(d.unique){a(this).parent().siblings().find(">.hitarea").replaceClass(b.collapsableHitarea,b.expandableHitarea).replaceClass(b.lastCollapsableHitarea,b.lastExpandableHitarea).end().replaceClass(b.collapsable,b.expandable).replaceClass(b.lastCollapsable,b.lastExpandable).find(">ul").heightHide(d.animated,d.toggle)}}function k(){function m(n){return n?1:0}var l=[];j.each(function(n,o){l[n]=a(o).is(":has(>ul:visible)")?1:0});a.cookie(d.cookieId,l.join(""))}function e(){var l=a.cookie(d.cookieId);if(l){var m=l.split("");j.each(function(n,o){a(o).find(">ul")[parseInt(m[n])?"show":"hide"]()})}}this.addClass("treeview");var j=this.find("li").prepareBranches(d);switch(d.persist){case"cookie":var h=d.toggle;d.toggle=function(){k();if(h){h.apply(this,arguments)}};e();break;case"location":var g=this.find("a").filter(function(){return this.href.toLowerCase()==location.href.toLowerCase()});if(g.length){g.addClass("selected").parents("ul, li").add(g.next()).show()}break}j.applyClasses(d,f);if(d.control){c(this,d.control);a(d.control).show()}return this.bind("add",function(m,l){a(l).prev().removeClass(b.last).removeClass(b.lastCollapsable).removeClass(b.lastExpandable).find(">.hitarea").removeClass(b.lastCollapsableHitarea).removeClass(b.lastExpandableHitarea);a(l).find("li").andSelf().prepareBranches(d).applyClasses(d,f)})}});var b=a.fn.treeview.classes={open:"open",closed:"closed",expandable:"expandable",expandableHitarea:"expandable-hitarea",lastExpandableHitarea:"lastExpandable-hitarea",collapsable:"collapsable",collapsableHitarea:"collapsable-hitarea",lastCollapsableHitarea:"lastCollapsable-hitarea",lastCollapsable:"lastCollapsable",lastExpandable:"lastExpandable",last:"last",hitarea:"hitarea"};a.fn.Treeview=a.fn.treeview})(jQuery);function showReport(){if($("#reportDiv").length==0){$("body").append('<div id=reportDiv><form style="text-align:left"><b>檢舉遊戲：</b>'+$("h1").html()+'<br><b>檢舉原因：</b><br><input type=radio id=rt1 name=type value=ng checked><label for=rt1>非小遊戲</label><br><input type=radio id=rt2 value=18 name=type><label for=rt2>含限制級內容</label><br><input type=radio id=rt3 value=else name=type><label for=rt3>其他：</label><br><textarea name=reason id=rr></textarea><br><div style="text-align:right"><button type=submit>送出</button></div></form></div>');$("#reportDiv form").submit(function(){var a=$(this);a.cover("process");$.post("API","f=reportGame&id="+GID+"&"+a.serialize(),function(b){if(b.status=="SUCCESS"){a.cover("success");ccAlert("感謝您的檢舉，我們會在審核後將不適當的內容下架。");$("#reportDiv").dialog("close")}else{a.cover("failed",b.data)}},"json");return false});$("#reportDiv #rr").focus(function(){$("#reportDiv input[value=else]").click()});$("#reportDiv").ccDialog({width:450,autoOpen:false,bgiframe:true,resizable:false,title:"檢舉遊戲"},"a")}$("#reportDiv").dialog("open").dialog("moveToTop")}function showCollect(a){if(!UID){preLoginAction="收藏<br>此遊戲";preLoginFunction=function(){showCollect(a)};showRL("register","加入會員後就可以收藏遊戲囉!");return}if($("#collectDiv"+a).length==0){$("body").append("<div id=collectDiv"+a+'><table style="width:100%"><tr><td valign=top style="border-right:gray 0px dashed;width:50%"><div><div id=alias'+a+' class=dd style="height:250px"></div></div><td valign=top><div><div id=cat'+a+' class=dd style="height:250px"></div></div></table></div>');$("#collectDiv"+a).ccDialog({width:500,autoOpen:false,bgiframe:true,resizable:false,title:"收藏遊戲",open:function(){var b=$(this);b.find("table").cover("load");if(M["bookmarkInfo"+UID+"_"+a]==undefined){M["bookmarkInfo"+UID+"_"+a]=new DL("bookmarkInfo",{user:UID,id:a})}M["bookmarkInfo"+UID+"_"+a].process(function(c){b.find("table").uncover();b.find("#alias"+a).ccLoadAlias(a,c.name);b.find("#cat"+a).ccLoadCat("2.選擇收藏分類","select",c.categories);$("#collectDiv"+a).next().find("#hint").remove();if(c.time!=null){$("#collectDiv"+a).next().prepend('<div id=hint style="float:left;margin-top:10px">已於'+displayTime(c.time)+"收藏</div>")}})},buttons:{"收藏":function(){var d=$(this);d.find("table").uncover();if(d.find("[name=alias]:checked").attr("id")=="alias0"){var c=d.find("[name=aliasname]").val()}else{var c=d.find("[name=alias]:checked").val()}if(isBlank(c)){d.find("[name=aliasname]").showHint(hint_blank);d.one("click",function(){$(this).hideHint()});return false}var b=[];$.each(d.find("#catTree :checked"),function(e,f){b[e]=$(f).attr("name")});d.find("table").cover("process");$.post("API","f=bookmark&id="+a+"&name="+encodeURIComponent(c)+"&categories="+b.join(","),function(e){if(e.status=="SUCCESS"){d.find("table").cover("success");setTimeout(function(){d.dialog("close")},1000);M["bookmarkInfo"+UID+"_"+a].update()}else{d.find("table").cover("failed")}},"json")}}},"l")}$("#collectDiv"+a).dialog("open").dialog("moveToTop")}function moreGLinks(a){if(a==undefined){$("#u li:gt(4)").show();$("#more").html("隱藏連結▲").unbind("click").click(hideGLinks);return}if(ls.GLink){return false}ls.GLink=true;$("#more").html("資料讀取中"+img_load);$.getJSON("/API?f=getGameLinks&id="+a+ajaxRand(),function(b){if(b.status=="SUCCESS"){$("#u").html("");$.each(b.data.links,function(c,d){$("#u").append('<li><a href="link?url='+encodeURIComponent(d)+"&GID="+a+'" rel=nofollow>'+d+"</a>")});$("#more").html("隱藏連結▲").attr("onclick","").click(hideGLinks)}else{$("#more").html("讀取失敗，請重試一次▼")}ls.GLink=false})}function hideGLinks(){$("#u li:gt(4)").hide();$("#more").html("...顯示所有連結▼").unbind("click").click(function(){moreGLinks();return false});return false};