﻿
var Catalog={Header:null,OutputPanel:null,OutputTable:null,Menus:[],_RootID:0,_SubID:0,Init:function(header,opanel,initialid)
{with(this)
{Header=header;OutputPanel=opanel;DateStyler.Init();Show(initialid?initialid:0,0);}},_Tag:null,Show:function(rootid,subid,forcerefresh)
{with(this)
{var tag=document.getElementById("_tag"+rootid);if(_Tag&&_Tag!=tag)
_Tag.className="tag";if(tag)
{tag.className="tagHL";_Tag=tag;}
if(!OutputPanel||((_SubID==subid)&&(_RootID==rootid)&&!forcerefresh))
return;_buildOutputTable();if(subid==0)
HideMenu();_RootID=rootid;_SubID=subid;var centry=_RootID+"_"+_SubID;if(CatalogData[centry]!=null)
FillInfo(CatalogData[centry]);else
AJAX.Load("/AJAX_Info.aspx?type=InfoList&cid="+_RootID+"&scid="+_SubID,"GET",null,Catalog.FillInfo,null,centry);}},CatalogData:{},FillInfo:function(infos,centry)
{var ifs=centry?eval(infos):infos;if(centry)
Catalog.CatalogData[centry]=ifs;with(Catalog.OutputTable)
{if(ifs.length==0)
{while(rows.length>2)
deleteRow(2);var r=Catalog.OutputTable.insertRow(rows.length);r.insertCell(0).colSpan=4;r.cells[0].innerHTML="<center><b>此分类下暂无信息</b></center>";return;}
var i=2,j=0;while(j<ifs.length)
{if(i<rows.length)
{if(rows[i].className!="Sep")
{Catalog._fillRow(rows[i],ifs[j++]);++i;}
else
{Catalog._sepRow(rows[i]);++i;}}
else
{if(i%2==0)
{Catalog._fillRow(Catalog.OutputTable.insertRow(rows.length),ifs[j++]);++i;}
if(ifs.length>0)
{Catalog._sepRow(insertRow(rows.length));++i;}}}
while(rows.length>i)
deleteRow(i);}},_sepRow:function(r)
{r.className="Sep";while(r.cells.length>0)
r.deleteCell(0);r.insertCell(0);r.cells[0].colSpan=4;r.cells[0].className="Sep";},_fillRow:function(row,info)
{if(row.cells.length==1)
row.deleteCell(0);if(row.cells.length==0)
for(var i=0;i<4;i++)
row.insertCell(row.cells.length);with(row)
{cells[0].innerHTML="<a href='Info.aspx?id="+info[0]+"' target='_blank'>"+info[1]+"</a>";cells[1].innerHTML=DateStyler.StandardDateStyle?this._convertDateStandard(info[2]):("<label title='"+info[2]+"'>"+DateStyler._convertDate(info[2])+"</label>");cells[2].innerHTML=info[6];cells[3].innerHTML=info[info[9]<0?8:10];cells[1].style.textAlign=cells[2].style.textAlign=cells[3].style.textAlign="center";onmouseover=DateStyler.RowFocus;onmouseout=DateStyler.RowBlur;}},_convertDateStandard:function(d)
{var dt=new Date(Date.parse(d));return dt.toLocaleDateString();},ShowMenu:function(menuid,items,e)
{with(this)
{if(!Menus[menuid])
{Menus[menuid]=new Menu(menuid,items);LMGR.Reg(document,LMGR.CLICK,Catalog.HideMenu,null,[$E_T(e),Menus[menuid]._menu]);}
for(var i=0;i<Menus.length;i++)
if(i!=menuid&&Menus[i])
Menus[i].Hide();var t=$E_T(e);t=document.getElementById("_tag"+menuid);Menus[menuid].Show($X(t)+3,$Y(t)+t.offsetHeight);}},HideMenu:function()
{if(Catalog.Menus[Catalog._RootID])
Catalog.Menus[Catalog._RootID].Hide();},_dateStylePicker:null,_buildOutputTable:function()
{if(!this.OutputTable)
{var t=document.createElement("table");with(t)
{id="INFOLIST";className="List";this.OutputTable=appendChild(document.createElement("tbody"));}
t.insertRow(0);var txt=[["标题","51%"],["日期","27%"],["类型","10%"],["地区","12%"]];with(t.rows[0])
{for(var i=0;i<4;i++)
{var c=document.createElement("th");c.innerHTML=txt[i][0];c.style.width=txt[i][1];appendChild(c);if(i==1)
{this._dateStylePicker=document.createElement("label");with(this._dateStylePicker)
{className="DateStyler";innerHTML=DateStyler.StandardDateStyle?"(精简)":"(标准)";title="选择日期格式";onclick=function(e)
{DateStyler.SetStandardDateStyle(!DateStyler.StandardDateStyle);with(Catalog)
{Show(_RootID,_SubID,true);_dateStylePicker.innerHTML=DateStyler.StandardDateStyle?"(精简)":"(标准)";}};}
c.appendChild(this._dateStylePicker);}}}
t.insertRow(1);with(t.rows[1].insertCell(0))
{className="Sep";colSpan=4;}
this.OutputPanel.appendChild(t);}}}