// Contains routines to navigate in a paged table named 'listTDC' with pagesize set
// bound to a Table Data Control named 'tableTDC'.

var totalItems, totalPages, currentPage, pageSize;

function initPagenav(pSize, hide){
  if(hide==1){
    navRow.style.visibility="hidden";
    navRow2.style.visibility="hidden";
  }else{
    try{
      totalItems=tableTDC.recordset.recordCount;
      pageSize=pSize;
      pageCount();
    } 
    catch(e){
      listTDC.dataPageSize = 100;
    }
  }
}

// The pageCount() function handles the recordset navigation within a page.
// It also sets up and updates the navigation items in the 
//page as recordset navigation occurs.
function pageCount(direction) {
    switch (direction) {
        case "+":
            if (currentPage != totalPages) {
                listTDC.nextPage();
			// Navigate the recordset
                currentPage = currentPage + 1;
			// Set the current page
            }
            break;
        case "++":
            if (currentPage != totalPages) {
                for (i=currentPage;i<=totalPages;i++) {
                    listTDC.nextPage();
                }
		currentPage=totalPages;
            }
            break;
        case "-":
            if (currentPage != 1) {
                listTDC.previousPage();
                currentPage = currentPage - 1;
            }
            break;
        case "--":
            if (currentPage != 1) {
                for (i=currentPage;i>=1;i--) {
                    listTDC.previousPage();
                }
                currentPage=1;
            }
            break;
        default:
            totalPages = Math.ceil(totalItems / pageSize);
// Figure out how many pages exist (based on the items per page and total items found
            currentPage = 1;// Set the initial page
    }
// Fill in the current page and current positions in the recordset
    document.all.item("pageno").innerText = currentPage;
    document.all.item("nopages").innerText = totalPages;
    document.all.item("pageno2").innerText = currentPage;
    document.all.item("nopages2").innerText = totalPages;

// Set visibility according to totalPages
    if(totalPages > 1){
	document.all.item("navRow").style.visibility="visible";
	document.all.item("navRow2").style.visibility="visible";
    }else{
	document.all.item("navRow").style.visibility="hidden";
	document.all.item("navRow2").style.visibility="hidden";
    }
}


