function clearTable( sid)
{
	if ( sid == 0)
	{
		alert('点击专题名称可以展开该专题下的具体信息');
		return false;
	}
	for( var i=0; i< $('mytable').rows.length; i++)
	{
		var id  = $('mytable').rows[i].id;
		if( id.substr(0,7) != 'special' && id.substr(0,3) == 'aid')
		{
			$('mytable').deleteRow(i);
			i--;
		}
	}
	$('clear').disabled = true;
}

function delFromSpecial(aid, sid)
{
	if (!sid || !aid) alert("错误参数");
	var aids = new Array();
	var link = "system.php?sys=special&action=delfrom&channelid="+channelid+"&sid="+sid+"&aid="+aid;
	AJAX.request( link,
	{
		method		: 'get',
		onComplete	: function(json)
		{
			if ( json.status == 200)
			{
				clearTable( sid);
				showSpecial( sid, pg.CurrentPage);
			}
		}
	});
}
function delCheckedFromSpecial()
{
	$('specialCheck').disabled=true;
	var checkArray = new Array();
	var obj = document.getElementsByTagName('INPUT'); 
	for( var i=0, j=0; i<obj.length; i++ )
	{
		if ( obj[i].type == 'checkbox' && obj[i].id.substr(0,8) == 'checkbox' && obj[i].checked == true)
		{
			checkArray[j] = obj[i].value;
			j++;
		}
	}
	if( checkArray.length == 0)
	{
		alert('您没有选择任何要删除的信息');
		$('specialCheck').disabled=false;
		return;
	}
	else
	{
		delFromSpecial(checkArray.join(','), spid);
	}
}
function showSpecial( sid, pageno)
{
	if (!sid) alert("错误参数");
	if (!pageno) pageno = 1;
	if ( spid != sid)
	{
		pageno =1;
		pg.CurrentPage =1;
	}
	spid  = sid ;
	var link = "system.php?sys=special&action=show&channelid="+channelid+"&sid="+sid+"&pageno="+pageno;
	AJAX.request( link,
	{
		method		: 'get',
		onComplete	: function(json)
		{
			if ( json.status == 200)
			{
				clearTable( sid);
				var len = json.message.length;
				var obj = $('special_'+sid);
				var index = obj.rowIndex;
				for( var i=0; i<len; i++)
				{
					var _tr = $('mytable').insertRow(index+i+1);
						_tr.id      = 'aid_'+json.message[i].aid;
					var a   = _tr.insertCell(0);
						a.className = 'tablerowl';
					var b   = _tr.insertCell(1);
						b.colSpan   = '3';
						b.className = 'tablerow';
						b.innerHTML = "<input type=checkbox id='checkbox_"+json.message[i].aid+"' value='"+json.message[i].aid+"'>&nbsp;&nbsp;"+json.message[i].subject;
					var e   = _tr.insertCell(2);
						e.className = 'tablerowl';
						e.innerHTML = '属性:';
					var d   = _tr.insertCell(3);
						d.className = 'tablerow';
						d.align     = 'center';
						d.colSpan   = 2;
						d.innerHTML = "<span onclick='delFromSpecial("+json.message[i].aid+", "+sid+");' style='cursor:pointer'>从该专题中删除</span>";
				}
				var _tr = $('mytable').insertRow(index+i+1);
					_tr.id      = 'aid_'+sid+'xxxxxx';
				var a   = _tr.insertCell(0);
					a.className = 'tablerowl';
					a.colSpan   = 4;
					a.innerHTML = "<input type=button onclick='delCheckedFromSpecial();' value='从该专题中删除' id='specialCheck'>";
				var b   = _tr.insertCell(1);
					b.className = 'tablerowl';
					b.id        = 'aid_'+sid+'pager';
					b.colSpan   = 3;
				pg.Total    = json.total;
				pg.PageSize = json.pagesize;
				pg.PageButtonNumber = 5;
				document.getElementById('aid_'+sid+'pager').innerHTML = pg.ShowPagerBar();
				$('clear').disabled = false;
			}
			else
			{
				alert( lang[json.message]);
			}
		}
	});
}
Pager.prototype.goPrePage = function()
{
	this.CurrentPage--;
	showSpecial( spid, this.CurrentPage);
	$('aid_'+spid+'pager').innerHTML = this.ShowPagerBar();
}
Pager.prototype.goLastPage = function()
{
	this.CurrentPage = this.PageCount;
	showSpecial( spid, this.CurrentPage);
	$('aid_'+spid+'pager').innerHTML = this.ShowPagerBar();
}
Pager.prototype.goPage = function(n)
{
	this.CurrentPage = n;
	showSpecial( spid, n);
	$('aid_'+spid+'pager').innerHTML = this.ShowPagerBar();
}
Pager.prototype.goNextPage = function()
{
	this.CurrentPage++;
	showSpecial( spid, this.CurrentPage);
	$('aid_'+spid+'pager').innerHTML = this.ShowPagerBar();
}