<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<title>我的留言本</title>
<link href="newskin.css" rel="stylesheet" type="text/css">
<style>
.napisdiv {left:10;top:0;width:150;height:100;position:absolute;z-index:3}
</style>
<script language="javascript" src="../include/dedeajax2.js"></script>
<script language='javascript' src='main.js'></script>
<script language="JavaScript">
var pageno = 1;
var totalrow = <?php echo $totalRow?>;
var pagesize = <?php echo $pagesize?>;
var orderby = '<?php echo $orderby?>';
var selitem = 0;
//加载列表
function ReloadPage(ordertype){
	orderby = ordertype;
	var listArea = $Obj('rslist');
	var errMsg = "网络通信出错！<br>[<a href=\"javascript:LoadPage('"+pageno+"')\"><u>点击此重新加载列表</u></a>]";
  var myajax = new DedeAjax(listArea,true,true,"",errMsg,"正在加载...");
  myajax.SendGet("guestbook_admin.php?dopost=getlist&pageno="+pageno+"&orderby="+ordertype);
}
//载入指定页的列表
function LoadPage(npage){
	pageno = npage;
	ReloadPage(orderby);
	ReloadPageNum(pageno);
}
//删除留言
function DelNote(nid){
	if(!window.confirm('你确定要删除这则留言吗?')){
		return false;
	}
	var listArea = $Obj('rslist');
	totalrow = totalrow - 1;
  var pagenum = Math.ceil(totalrow/pagesize);
  if(pagenum<=pageno) pageno = pagenum;
  var errMsg = "网络通信出错！<br>[<a href=\"javascript:LoadPage('"+pageno+"')\"><u>点击此重新加载列表</u></a>]";
	var myajax = new DedeAjax(listArea,true,true,"",errMsg,"正在处理...");
  myajax.SendGet("guestbook_admin.php?dopost=del&aid="+nid+"&pageno="+pageno);
  ReloadPageNum(pageno);
}
//获得选中文项的ID
function getCheckboxItem()
{
	var allSel="";
	selitem = 0;
	if(document.form1.ids.value){
		selitem++;
		return document.form1.ids.value;
	}
	for(i=0;i<document.form1.ids.length;i++){
		if(document.form1.ids[i].checked){
			if(allSel=="") allSel=document.form1.ids[i].value;
			else allSel=allSel+","+document.form1.ids[i].value;
			selitem++;
		}
	}
	return allSel;	
}
//批量删除留言
function DelNotes(){
	var listArea = $Obj('rslist');
	var aids = getCheckboxItem();
	if(selitem==0){
		alert("你没选中任何内容！");
		return false;
	}
	if(!window.confirm('你确定要删除这些留言吗?')){
		return false;
	}
	totalrow = totalrow - selitem;
  var pagenum = Math.ceil(totalrow/pagesize);
  if(pagenum<=pageno) pageno = pagenum;
  var errMsg = "网络通信出错！<br>[<a href=\"javascript:LoadPage('"+pageno+"')\"><u>点击此重新加载列表</u></a>]";
	var myajax = new DedeAjax(listArea,true,true,"",errMsg,"正在处理...");
  myajax.SendGet("guestbook_admin.php?dopost=del&ids="+aids+"&pageno="+pageno);
  ReloadPageNum(pageno);
}
//重新加载分页列表
function ReloadPageNum(startnum){
  var ListArea = $Obj('pagelist');
  var pagenum = Math.ceil(totalrow/pagesize);
  var listsize = 3;
  var ahtml = "";
  var startloop = 1;
  var endnum = 0;
  ahtml += "共："+totalrow+" 条记录/"+pagenum+"页 ";
  if(pageno>1) ahtml += "<a href='#' onclick='LoadPage("+(pageno-1)+")'>↑上页</a> ";
  if(startnum >= pagenum-listsize){
  	startloop = pagenum-(listsize*2);
  	if(startloop<1) startloop = 1;
  	for(i=startloop;i<=pagenum;i++){
  		if(i==pageno) ahtml += i+" ";
  		else ahtml += "<a href='#' onclick='LoadPage("+i+")'>["+i+"]</a> ";
  	}
  }
  else if(pagenum < listsize){
  	for(i=1;i<=pagenum;i++){
  		if(i==pageno) ahtml += i+" ";
  		else ahtml += "<a href='#' onclick='LoadPage("+i+")'>["+i+"]</a> ";
  	}
  }
  else{
  	startloop = startnum-listsize;
  	if(startloop<1){ startloop=1; endnum = startloop + (listsize*2); }
  	else{ endnum = startnum+listsize; }
  	if(endnum >= pagenum) endnum = pagenum;
  	for(i=startloop;i<=endnum;i++){
  		if(i==pageno) ahtml += i+" ";
  		else ahtml += "<a href='#' onclick='LoadPage("+i+")'>["+i+"]</a> ";
  	}
  }
  if(pageno<pagenum) ahtml += "<a href='#' onclick='LoadPage("+(pageno+1)+")'>下页↓</a> ";
  ListArea.innerHTML = ahtml;
}
</script>
</head>
<body leftmargin='0' topmargin='0'>
<div align="center">
<?php  include(dirname(__FILE__)."/head.htm"); ?>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="160" height="216" valign="top"> 
      <?php include(dirname(__FILE__)."/menu.php");?>
    </td>
    <td width="10">&nbsp;</td>
    <td  valign="top">
	  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" style="margin-bottom:3px">
        <tr align="right" bgcolor="#ffffff"> 
          <td height="25" colspan="6" background="img/nnnbg.gif" class="gdt"> 
            <table width='96%' align="center" cellpadding='0' cellspacing='0'>
              <tr> 
                <td width='30%'><b>　我的留言本：</b></td>
                <td align='right'>
				<input type="button" name="Submit" value="删除选中项" class="coolbg" onClick="DelNotes()"> 
                </td>
              </tr>
            </table></td>
        </tr>
		</table>
    <form name="form1">
    <span id='rslist'><?php  GetList($dsql,$pageno,$pagesize,'aid'); ?></span>
    </form>
      <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#D9EDC0">
        <tr height="24"> 
          <td height="32" bgcolor="#F9FCEF" align="center">
          	<span id='pagelist'></span>
            <script language='javascript'>
           	ReloadPageNum(1);
           	</script>
         </td>
        </tr>
      </table></td>
  </tr>
</table>
<?php  include(dirname(__FILE__)."/foot.htm"); ?>
</div>
</body>
</html>
