//鼠标跟踪事件处理：进入数据区时变换数据区底色
function onMouseOverTR(currRow) {
  //alert("onMouseOverTR");
    currRow.bgColor= "yellow";
}

//鼠标跟踪事件处理：离开数据区时变换数据区底色
function onMouseOutTR(currRow) {
  //alert("onMouseOutTR");
    currRow.bgColor= "#F1F1F1";
}

//分页处理
function first(id_name) {
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    if(pageCount == 0)
     	return;
    if(currentPage == 1) {
    	alert("已经到达首页！");
    	return;
    } else {
    	if(currentPage != 0) {//不是重新指定显示页大小
    	   var i, currentPageNo;
    	   if(pageSize*currentPage > rowCount)
          	 currentPageNo = rowCount;
    	   else
         	 currentPageNo = pageSize*currentPage;
    	   //隐藏掉正显示的页
    	   for ( i = pageSize*(currentPage-1)+1; i <= currentPageNo; i++ )
                 eval( id_name + i ).style.display = "none";
        }
        //显示第一页
        var j, firstPageNo;
        if(pageSize > rowCount)
            firstPageNo = rowCount;
        else
            firstPageNo = pageSize;
        for ( j = 1; j <=firstPageNo ; j++ )
            eval( id_name + j ).style.display = "";

        document.all(id_name+'currentPage').innerText = 1;
    }
    removeCheckState(id_name);//remove checked state
}

function next(id_name) {
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    if(pageCount == 0)
     	return;
    if(currentPage == pageCount) {
         alert("已经到达尾页！");
         return;
    } else {
         var i;
    	//隐藏掉正显示的页
    	for ( i = pageSize*(currentPage-1)+1; i <= pageSize*currentPage; i++ )
        	eval( id_name + i ).style.display = "none";
    	//显示下一页
    	var j, nextPageNo;
    	if((rowCount - currentPage*pageSize) >= pageSize )
    	       	nextPageNo = currentPage*pageSize+pageSize;
    	else
        	nextPageNo = rowCount;
        for ( j = pageSize*currentPage+1; j <=nextPageNo ; j++ )
        	eval( id_name + j ).style.display = "";

        document.all(id_name+'currentPage').innerText = ++currentPage;

    }
    removeCheckState(id_name);//remove checked state
}

function previse(id_name) {
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    if(pageCount == 0)
     	return;
    if(currentPage == 1) {
    	alert("已经到达首页！");
        return;
    } else {
    	var i, currentPageNo;
    	if(pageSize*currentPage > rowCount)
        	 currentPageNo = rowCount;
    	else
        	 currentPageNo = pageSize*currentPage;
    	//隐藏掉正显示的页
    	for ( i = pageSize*(currentPage-1)+1; i <= currentPageNo; i++ )
        	eval( id_name + i ).style.display = "none";
    	//显示前一页
    	var j, previousPageNo;
    	previousPageNo = (currentPage-1)*pageSize;
    	for ( j = pageSize*(currentPage-2)+1; j <=previousPageNo ; j++ )
        	eval( id_name + j ).style.display = "";

    	document.all(id_name+'currentPage').innerText = --currentPage;
    }
    removeCheckState(id_name);//remove checked state
}

function last(id_name) {
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    if(pageCount == 0)
     	return;
    //隐藏掉正显示的页
    if(currentPage == pageCount) {
    	alert("已经到达尾页！");
    	return;
    } else {
    	var i;
        for ( i = pageSize*(currentPage-1)+1; i <= pageSize*currentPage; i++ )
            eval( id_name + i ).style.display = "none";
        //显示下一页
        var j, lastPageNo;
        lastPageNo = rowCount;

        for ( j = pageSize*(pageCount-1)+1; j <=lastPageNo ; j++ )
            eval( id_name + j ).style.display = "";

        document.all(id_name+'currentPage').innerText = pageCount;
    }
    removeCheckState(id_name);//remove checked state
}

function changePageSize(id_name, pageSizeCombox, pageSelectCombox) {
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    if(pageCount == 0)
     	return;

    var newPageSize = parseInt(pageSizeCombox.options[pageSizeCombox.selectedIndex].value);
    var newPageCount = parseInt((rowCount+newPageSize-1) / newPageSize);

    //先清空当前页的内容
    var i, currentPageNo;
    if(pageSize*currentPage > rowCount)
         currentPageNo = rowCount;
    else
       	 currentPageNo = pageSize*currentPage;
    //隐藏掉正显示的页
    for ( i = pageSize*(currentPage-1)+1; i <= currentPageNo; i++ )
       	eval( id_name + i ).style.display = "none";

    //重新设置
    document.all(id_name+'currentPage').innerText = 0;
    document.all(id_name+'pageSize').innerText = newPageSize;
    document.all(id_name+'pageCount').innerText = newPageCount;
    //更新页数下拉框pageSelectCombox.options[pageSelectCombox.selectedIndex].value);
    pageSelectCombox.length = newPageCount;
    for(var j=0;j<newPageCount;j++) {
    	pageSelectCombox.options[j].value = j+1;
        pageSelectCombox.options[j].text = j+1;
    }

    first(id_name);
}

function goPage(id_name, pageSelectCombox) {
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    var newPage = parseInt(pageSelectCombox.options[pageSelectCombox.selectedIndex].value);

    //先清空当前页的内容
    var i, currentPageNo;
    if(pageSize*currentPage > rowCount)
         currentPageNo = rowCount;
    else
       	 currentPageNo = pageSize*currentPage;
    //隐藏掉正显示的页
    for ( i = pageSize*(currentPage-1)+1; i <= currentPageNo; i++ )
       	eval( id_name + i ).style.display = "none";

    //显示新设定的页
    var j, newPageNo;
    if(newPage*pageSize > rowCount)
         newPageNo = rowCount;
    else
         newPageNo = newPage*pageSize;
    for ( j = pageSize*(newPage-1)+1; j <=newPageNo ; j++ )
       	eval( id_name + j ).style.display = "";
    removeCheckState(id_name);//remove checked state
    //重新设置
    document.all(id_name+'currentPage').innerText = parseInt(newPage);
}

function selectAllDisplayItems(id_name, selectAllCheckBox) {
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    //var newPage = parseInt(selectAllCheckBox.options[selectAllCheckBox.selectedIndex].value);
    var i, currentPageNo;
    if(pageSize*currentPage > rowCount)
         currentPageNo = rowCount;
    else
       	 currentPageNo = pageSize*currentPage;
    //隐藏掉正显示的页
    var flag = selectAllCheckBox.checked;
    for ( i = pageSize*(currentPage-1)+1; i <= currentPageNo; i++ ) {
         document.all(id_name+"checkbox_"+i).checked = flag;
    }

}
function removeCheckState(id_name){
	try{
	var rows = parseInt(document.all(id_name+'rowCount').innerText);
	document.all(id_name+"checkAll").checked = false;
        for( var k = 1;k<rows+1;k++){
	   document.all(id_name+"checkbox_"+k).checked = false;
        }
}catch(Exception){
	
}
}
function checksome(id_name,checkbox){
    var currentPage = parseInt(document.all(id_name+'currentPage').innerText);
    var pageSize = parseInt(document.all(id_name+'pageSize').innerText);
    var pageCount = parseInt(document.all(id_name+'pageCount').innerText);
    var rowCount = parseInt(document.all(id_name+'rowCount').innerText);

    var i, currentPageNo;
    if(pageSize*currentPage > rowCount)
         currentPageNo = rowCount;
    else
       	 currentPageNo = pageSize*currentPage;
    var flag = checkbox.checked;
    var sameFlag = new Boolean(true);
    if(flag ==true)
    for ( i = pageSize*(currentPage-1)+1; i <= currentPageNo; i++ ) {
         if(document.all(id_name+"checkbox_"+i).checked != flag){
             sameFlag = false;
             document.all(id_name+"checkAll").checked = false;
             break;
         }
    }
    if(sameFlag == true)
    	document.all(id_name+"checkAll").checked = flag;
}