(function(d){function B(a,b){a.addClass("row_chked");if(a.data("picked"))return b();var e=a[0].id.substr(5),h=n.find(">div.btn_area>select").val();h="spiderid="+e+"&catid="+a.find("input").val()+"&status="+h;var c=a.find("img.del").hide(),g;if((g=c.next("img")).length)g.attr("src","images/loading.gif");else{g=d('<img width="16" height="16" src="images/loading.gif" />');c.after(g)}d.ajax({url:"?app=spider&controller=spider&action=spider",data:h,type:"post",dataType:"json",success:function(f){if(f.state){a.data("picked",
1);g.attr("src","images/sh.gif");l.deleteRow(e);m.deleteRow(e);q.addRow(f.data);setTimeout(function(){a.fadeOut(function(){r.remove(e)})},5E3)}else{g.attr("src","images/warn.png");c.show()}b()},error:function(){g.attr("src","images/warn.png");c.show();b()}})}function x(a){a=d.extend({},a);if(C)a=d.extend(a,C);r.add(a)}var o,D,n,v,E,s,F,I,J,G,K,L,M,N,O,P,j,l,m,q,r,t="0",Q=function(){var a=ct.innerHeight();if(a>250){a=a-I-J;var b=a-N;o.height(d.boxModel?b:a);E.height(b-G);a=b-G-K;s.height(a);F.height(a)}a=
ct.innerWidth();if(a>700){a=a-L;b=a-M;o.width(d.boxModel?b:a);a=b-O;v.width(parseInt(a*0.6));a-=v[0].offsetWidth;n.width(a-P)}},i=null,V=function(){var a=d('<div class="loading" style="width:120px;display:none;position:fixed;"><sub></sub> \u8f7d\u5165\u4e2d\u2026\u2026</div>');a.appendTo(document.body);a.ajaxStart(function(){a.css({left:ct.innerWidth()/2-130,top:ct.innerHeight()/2-50}).show()}).ajaxStop(function(){a.hide()})},u=function(a){var b=a.taskid,e=d('<li id="task_'+b+'"><a href="javascript:;" title="'+
a.title+'">'+a.title+"</a></li>").hover(function(){e.addClass("hover")},function(){e.removeClass("hover")}).click(function(){if(i!=e){i&&i.removeClass("focus");i=e;e.addClass("focus");l.load("taskid="+b,function(){m.load("taskid="+b,function(){q.load("taskid="+b)})})}}).contextMenu("#right_menu",function(h){y[h](b,e,a)});return e},R=function(){var a=d('<li id="task_temp"><a href="javascript:;">\u4e34\u65f6\u91c7\u96c6\u4efb\u52a1</a></li>').hover(function(){a.addClass("hover")},function(){a.removeClass("hover")}).click(function(){i&&
i.removeClass("focus");i=a;a.addClass("focus");l.load("taskid=temp",function(){m.load("taskid=temp",function(){q.load("taskid=temp")})})});return a},S=function(a,b){if(b.hasClass("viewed")||b.hasClass("spiden"))l.deleteRow(a);else{var e=b.data("json");d.post("?app=spider&controller=spider&action=viewedone&spiderid="+a,function(){e.status="viewed";b.addClass("viewed");l.deleteRow(a);m.addRow(e)})}},T=function(a){d(a[0].url).keyup(function(){this.value&&d.getJSON("?app=spider&controller=manager&action=matchRule&url="+
encodeURIComponent(this.value),function(b){if(b.state)a[0].ruleid.value=b.ruleid})}).keyup()},z=0,k=null,A=null,C=null,y={init:function(a){C=a;o=d("#box");D=d("#leftBox");v=d("#centerBox");n=d("#rightBox");E=d("#leftList");s=d("#centerList");F=d("#rightList");a=D.find("h3");var b=v.find("div.btn_area");I=o.offset().top;J=5;G=a[0].offsetHeight;K=b[0].offsetHeight;L=parseFloat(o.css("marginLeft"))*2;M=parseFloat(o.css("borderLeftWidth"))*2;N=parseFloat(o.css("borderTopWidth"))*2;O=D[0].offsetWidth;
P=n[0].offsetWidth-n.width();d(window).bind("resize",Q);Q();var e=s.find("ul").hide(),h=v.find("h3>span").each(function(){var c=d(this).click(function(){e.hide();h.removeClass("active");c.addClass("active");t=c.attr("index");b.find("button:last").css("visibility",t=="0"?"visible":"hidden");e.eq(c.attr("index")).show()})});h.eq(0).click();l=new scrollFeed(e[0],{template:'\t\t<li id="item_{spiderid}" param="spiderid={spiderid}" class="{status}">\t\t\t<h3 class="item-header">\t\t\t\t<span class="header-right">\t\t\t\t\t<img src="images/txt.gif" title="\u6807\u8bb0\u5df2\u8bfb" class="markread" height="16" width="16">\t\t\t\t\t<img class="marktask" width="16" height="16" title="\u6dfb\u52a0\u5230\u91c7\u96c6\u4efb\u52a1" src="images/add_1.gif" />\t\t\t\t</span>\t\t\t\t<span class="header-left">{title}</span>\t\t\t\t<a target="_blank" href="{url}"><img width="16" height="16" alt="\u8bbf\u95ee\u539f\u59cb\u5730\u5740" title="\u8bbf\u95ee\u539f\u59cb\u5730\u5740" src="images/view.gif" /></a>\t\t\t</h3>\t\t</li>',
baseUrl:"?app=spider&controller=spider&action=loadlist&status=new",rowReady:function(c,g){c.find("img.marktask").click(function(f){f.stopPropagation();x(g)});c.find("img.markread").click(function(f){f.stopPropagation();S(g.spiderid,c)});c.find("a").click(function(f){f.stopPropagation()})},rowFirstClick:function(c,g,f){c.html('<img width="16" height="16" src="images/loading.gif" />');c.load("?app=spider&controller=spider&action=loaddetail",g.attr("param"));f.status="viewed";g.addClass("viewed");m.addRow(f)},
countRow:function(c){d("em",h[0]).text(c)},pageCtrl:s});m=new scrollFeed(e[1],{template:'\t\t<li id="item_{spiderid}" param="spiderid={spiderid}" class="{status}">\t\t\t<h3 class="item-header">\t\t\t\t<span class="header-right">\t\t\t\t\t<img class="marktask" width="16" height="16" title="\u6807\u8bb0\u91c7\u96c6" src="images/add_1.gif" />\t\t\t\t</span>\t\t\t\t<span class="header-left">{title}</span>\t\t\t\t<a target="_blank" href="{url}"><img width="16" height="16" alt="\u8bbf\u95ee\u539f\u59cb\u5730\u5740" title="\u8bbf\u95ee\u539f\u59cb\u5730\u5740" src="images/view.gif" /></a>\t\t\t</h3>\t\t</li>',
baseUrl:"?app=spider&controller=spider&action=loadlist&status=viewed",rowReady:function(c,g){c.find("img.marktask").click(function(f){f.stopPropagation();x(g)});c.find("a").click(function(f){f.stopPropagation()})},rowFirstClick:function(c,g){c.html('<img width="16" height="16" src="images/loading.gif" />');c.load("?app=spider&controller=spider&action=loaddetail",g.attr("param"))},countRow:function(c){d("em",h[1]).text(c)},pageCtrl:s});q=new scrollFeed(e[2],{template:'\t\t<li id="item_{spiderid}" param="spiderid={spiderid}" class="{status}">\t\t\t<h3 class="item-header">\t\t\t\t<span class="header-right">\t\t\t\t\t<img class="marktask" width="16" height="16" title="\u6807\u8bb0\u91c7\u96c6" src="images/add_1.gif" />\t\t\t\t</span>\t\t\t\t<span class="header-left">{title}</span>\t\t\t\t<a target="_blank" href="{url}"><img width="16" height="16" alt="\u8bbf\u95ee\u539f\u59cb\u5730\u5740" title="\u8bbf\u95ee\u539f\u59cb\u5730\u5740" src="images/view.gif" /></a>\t\t\t</h3>\t\t</li>',
baseUrl:"?app=spider&controller=spider&action=loadlist&status=spiden",rowReady:function(c,g){c.find("img.marktask").click(function(f){f.stopPropagation();x(g)});c.find("a").click(function(f){f.stopPropagation()})},rowFirstClick:function(c,g){c.html('<img width="16" height="16" src="images/loading.gif" />');c.load("?app=spider&controller=spider&action=loaddetail",g.attr("param"))},countRow:function(c){d("em",h[2]).text(c)},pageCtrl:s});r=new taskList(F.find("table"),{template:'\t\t<tr id="task_{spiderid}">\t\t\t<td>\t\t\t\t<a target="_blank" href="{url}">{title}</a>\t\t\t</td>\t\t\t<td width="100" class="t_c"><span title="\u70b9\u51fb\u4fee\u6539" class="catname"><input type="hidden" value="{catid}" />[<b>{catname}</b>]</span></td>\t\t\t<td width="50" class="t_c">\t\t\t\t<img width="16" height="16" class="hand del" src="images/del.gif" />\t\t\t</td>\t\t</tr>',
rowReady:function(c,g){g.find("img.del").click(function(H){H.stopPropagation();r.remove(c)});var f=g.find("span.catname").click(function(H){H.stopPropagation();var p=f.next("select"),w=p[0],U=f.find("input"),W=f.find("b");if(p.length){f.hide();p.show().focus()}else d.get("?app=spider&controller=spider&action=getcat",function(X){p=d(X).blur(function(){p.hide();f.show()}).change(function(){W.text(d.trim(w.options[w.selectedIndex].text));U.val(this.value)});w=p[0];w.value=U.val();f.hide().after(p);w.focus()})})},
countRow:function(c){n.find(">h3:first em").text(c)}});j=E.find("ul");d.getJSON("?app=spider&controller=spider&action=tasklist",function(c){for(var g=0,f;f=c[g++];j.append(u(f)));j.find("li:first").click()});d("#keyword").autocomplete({itemSelected:function(){y.tempGrap()},itemFormat:function(c,g){return g?c.title.replace(RegExp(g,"ig"),function(f){return"<strong>"+f+"</strong>"})+"<br/>"+c.url.replace(RegExp(g,"ig"),function(f){return"<strong>"+f+"</strong>"}):c.title+"<br/>"+c.url},itemPrepared:function(c){c.height(50)}});
d("#status").change(function(){d.post("?app=spider&controller=spider&action=memstatus","status="+this.value)});V()},clearTask:function(){r.clear()},viewedAll:function(){var a=l.allRow();for(var b in a)S(b,a[b])},addAlltask:function(){var a=(t=="0"?l:t=="1"?m:q).allRow();for(var b in a)x(a[b].data("json"))},addTask:function(){ct.form("\u6dfb\u52a0\u76d1\u63a7\u4efb\u52a1","?app=spider&controller=manager&action=addTask",400,240,function(a){if(a.state){ct.tips("\u6dfb\u52a0\u91c7\u96c6\u4efb\u52a1\u6210\u529f",
"success");j.append(u(a.data));return true}},T)},editTask:function(a,b){ct.form("\u7f16\u8f91\u76d1\u63a7\u4efb\u52a1","?app=spider&controller=manager&action=editTask&taskid="+a,400,240,function(e){if(e.state){ct.tips("\u7f16\u8f91\u91c7\u96c6\u4efb\u52a1\u6210\u529f","success");var h=i==b;e=u(e.data);b.replaceWith(e);h&&e.click();return true}})},delTask:function(a,b){var e="\u6b64\u64cd\u4f5c\u4e0d\u53ef\u6062\u590d\uff0c\u786e\u5b9a\u8981\u5220\u9664\u76d1\u63a7\u4efb\u52a1\u201c"+b.text()+"\u201d\u5417\uff1f";
ct.confirm(e,function(){d.getJSON("?app=spider&controller=manager&action=delTask&taskid="+a,function(h){if(h.state){if(i==b)i=null;b.remove();ct.tips("\u5220\u9664\u6210\u529f","success")}else ct.tips("\u5220\u9664\u5931\u8d25","error")})})},tempGrap:function(){var a=d("#keyword").val();a&&d.post("?app=spider&controller=spider&action=tempGrap","url="+a,function(b){if(b.state)if(b.taskid)d("#task_"+b.taskid).click();else{b=d("#task_temp");if(b.length)b.click();else{b=R();j.append(b);b.click();d("#saveTempBtn").show()}}else{d("#saveTempBtn").hide();
b={"\u9009\u62e9\u89c4\u5219":function(){y.selectRule(a);e.dialog("close")},"\u6dfb\u52a0\u89c4\u5219":function(){e.dialog("close");ct.assoc.open("?app=spider&controller=manager&action=addrule&url="+encodeURIComponent(a),"newtab")},"\u53d6\u6d88":function(){e.dialog("close")}};var e=d("<div></div>").html('<div class="bk_5"></div><p class="ct_msg"><sup></sup>\u5f53\u524d\u7f51\u5740\u65e0\u6cd5\u91c7\u96c6\uff0c\u7cfb\u7edf\u89c4\u5219\u5e93\u91cc\u6ca1\u6709\u5bf9\u5e94\u89c4\u5219\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u6216\u8005\u9009\u62e9\u5df2\u6709\u89c4\u5219\u3002</p>');
e.dialog({bgiframe:true,closeOnEscape:false,height:"auto",width:360,resizable:false,modal:true,close:function(){e.dialog("destroy").remove()},title:"\u6dfb\u52a0\u6216\u9009\u62e9\u91c7\u96c6\u89c4\u5219",buttons:b})}},"json")},selectRule:function(a){ct.form("\u9009\u62e9\u5bf9\u5e94\u7684\u89c4\u5219","?app=spider&controller=manager&action=selectRule&url="+encodeURIComponent(a),400,240,function(b){if(b.state)if(b.data){b=u(b.data);j.append(b);b.click()}else{b=d("#task_temp");if(b.length)b.click();
else{b=R();j.append(b);b.click();d("#saveTempBtn").show()}}})},tempSave:function(){ct.form("\u4fdd\u5b58\u4e34\u65f6\u91c7\u96c6\u4efb\u52a1","?app=spider&controller=manager&action=saveTempTask",400,240,function(a){if(a.state){d("#saveTempBtn").hide();var b=d("#task_temp"),e=b.hasClass("focus");a=u(a.data);b.replaceWith(a);e&&a.click();return true}},T)},refreshNav:function(){var a=null;if(i)a=i.attr("id");j.empty();d.getJSON("?app=spider&controller=spider&action=tasklist",function(b){for(var e=0,
h;h=b[e++];j.append(u(h)));a&&j.find("#"+a).click()})},refreshItem:function(){if(i){var a="taskid="+i[0].id.substr(5);if(t=="0")l.load(a);else t=="1"?m.load(a):q.load(a)}},run:function(){k=r.first();var a=n.find(">div.btn_area>*"),b=a.filter(":lt(3)"),e=a.eq(3).show();b.css("visibility","hidden");var h=function(){k=null;b.css("visibility","visible");e.hide()};if(!k.length)return h();var c=function(){k.removeClass("row_chked");k=k.next();if(k.length)if(z)A=function(){B(k,c)};else B(k,c);else h()};
B(k,c)},pause:function(a){if(z){a.innerHTML="\u6682\u505c";z=0;if(A){A();A=null}}else{a.innerHTML="\u7ee7\u7eed";z=1}}};window.App=y})(jQuery);
