var relateddata;
function related_select(a,c){var b=related_data();window.relateddata=b[0];window.relatedids=b[1];b=showModalDialog("?app=system&controller=related&action=search&contentid="+a+"&keywords="+encodeURIComponent(c),window,"dialogWidth:900px;dialogHeight:550px;help:0;status:0;center:yes;scroll:no");if(b!=null){for(var d="",e=0;e<b.length;e++){if(b[e][0])var f=b[e][0].substr(0,14);d+='<li><input type="hidden" name="related[]" id="related_'+e+'" value="'+b[e].join("|")+'"/><a href="'+b[e][2]+'" target="_blank">'+
f+"</a></li>\n"}$("#related_data").html(d)}}function related_data(){var a=[],c=[];$("#related_data input").each(function(b){a[b]=$(this).val();c[b]=parseInt($(this).val().split("|").pop())});return[a,c]}
function related_append(a){var c="";$.each(a,function(b,d){if(d.title)var e=d.title.substr(0,20);var f=window.dialogArguments.relatedids.indexOf(parseInt(d.contentid))!=-1?'checked="checked"':"";rid++;c+='<li id="'+d.contentid+'">';c+=' <input type="checkbox" name="related" id="related_'+d.contentid+'" value="'+d.title+"|"+d.thumb+"|"+d.url+"|"+d.time+"|"+d.contentid+'" class="checkbox_style" '+f+'" onclick="related_checked('+d.contentid+')"/>';c+='   <a href="'+d.caturl+'" target="_blank">'+d.catname+
'</a>\uff1a<a href="'+d.url+'" target="_blank">'+e+"</a>";c+='   <span class="date">'+d.time+"</span>";c+="</li>"});$("#data").append(c);init_panel()}function related_checked(a){if($("#related_"+a).attr("checked")==true)related_list_add(a,$("#related_"+a).val());else{$("#checked_"+a).parent().remove();checked_count--;$("#checked_count").html(checked_count)}init_panel()}
function init_panel(){$("#list").find("img").show().css("visibility","visible");if($("#list").children().length==1)$("#list").find("img:lt(2)").hide();else{$("#list li:first").find("img:eq(0)").hide();$("#list li:last").find("img:eq(1)").css("visibility","hidden")}}function related_checked_delete(a){$("#related_"+a).attr("checked",false);$("#checked_"+a).parent().remove();checked_count--;init_panel();$("#checked_count").html(checked_count)}
function related_checked_up(a){a=$("#checked_"+a).parent();if(a.prev().is("li")){var c=a.prev().html(),b=a.html();a.prev().html(b);a.html(c)}init_panel()}function related_checked_down(a){a=$("#checked_"+a).parent();if(a.next().is("li")){var c=a.next().html(),b=a.html();a.next().html(b);a.html(c)}init_panel()}
function related_search_ok(a){if(a.state){$("#data").empty();sort_mode="";related_append(a.data);count=a.data.length;total=a.total;$("#count").html(a.data.length);$("#total").html(a.total)}else alert(a.error)}function init(){checked_count++}
function related_list_add(a,c){checked_count++;var b=c.split("|");a=a?a:b[4];var d="";d+='<li class="layout">';d+='   <span id="checked_'+a+'" class="f_r"><img src="images/up.gif" alt="\u5411\u4e0a" title="\u5411\u4e0a" height="16" width="16" class="hand" onclick="related_checked_up(\''+a+'\')"/> <img src="images/down.gif" alt="\u5411\u4e0b" title="\u5411\u4e0b" height="16" width="16" class="hand" onclick="related_checked_down(\''+a+'\')"/> <img src="images/edit.gif" alt="\u7f16\u8f91" title="\u7f16\u8f91" height="16" width="16" class="hand" onclick="related_edit(\''+
a+'\')"/> <img src="images/del.gif" alt="\u53d6\u6d88" title="\u53d6\u6d88" height="16" width="16" class="hand" onclick="related_checked_delete(\''+a+"')\"/></span>";d+='   <span class="f_l"><input type="hidden" name="data_'+a+'" id="data_'+a+'" value="'+c+'" /><a id="a_'+a+'" href="'+b[2]+'" target="_blank">'+b[0].substr(0,20)+"</a></span>";d+="</li>";$("#list").append(d);$("#checked_count").html(checked_count)}
function related_list_edit(a,c){var b=c.split("|");$("#data_"+a).val(c);$("#a_"+a).html(b[0]);$("#a_"+a).attr("href",b[2])}function related_add(){ct.form("\u6dfb\u52a0\u76f8\u5173","?app=system&controller=related&action=add",400,200,null,null,function(a,c){rid++;var b=a.find("#title").val()+"|"+a.find('input[name="thumb"]').val()+"|"+a.find("#url").val()+"|"+a.find("#time").val()+"|"+(contentid+"_"+rid);related_list_add(contentid+"_"+rid,b);init_panel();c.dialog("close");return false})}
function related_edit(a){var c=$("#data_"+a).val().split("|");ct.form("\u4fee\u6539\u76f8\u5173","?app=system&controller=related&action=edit&rid="+a,400,200,null,function(b){b.find("#edit_title").val(c[0]);b.find('input[name="thumb"]').val(c[1]);b.find("#edit_url").val(c[2]);b.find("#edit_time").val(c[3])},function(b,d){var e=b.find("#edit_title").val()+"|"+b.find('input[name="thumb"]').val()+"|"+b.find("#edit_url").val()+"|"+b.find("#edit_time").val()+"|"+a;related_list_edit($("#edit_rid").val(),
e);d.dialog("close");return false})}var sort_mode="";
function related_sort(a){sort_mode=a;var c=[];$("#data > li").each(function(d){c[d]=[$(this).attr("id"),$(this).html(),$(this).children(".date").html(),$("#related_"+$(this).attr("id")).attr("checked")]});c.sort(function(d,e){return sort_mode=="asc"?d[2].localeCompare(e[2]):e[2].localeCompare(d[2])});var b="";$.each(c,function(d,e){b+='<li id="'+e[0]+'">'+e[1]+"</li>\n"});$("#data").html(b);$.each(c,function(d,e){e[3]==true&&$("#related_"+e[0]).attr("checked",true)})}
function related_ok(){var a=[];$("input[name*='data']").each(function(c){a[c]=$(this).val().split("|")});window.returnValue=a;window.close()}function related_cancel(){window.returnValue=null;window.close()}function async_form(a,c){$("#"+a).bind("submit.form-plugin",function(){$(this).ajaxSubmit({dataType:"json",success:function(b){if(b.state)if(b.redirect)window.location.href=b.redirect=="refresh"?window.location.href:b.redirect;c&&eval("("+c+")")(b)}});return false})};
