//
//GeneList Javascript, v0.01
//
//Jim Lund, University of Kentucky, Department of Biology.
//jiml <at> uky <dot> edu
//

//Spinner function.
//From: http://www-128.ibm.com/developerworks/opensource/library/os-php-dhtml1/?ca=dgr-lnxw01PHP-DHTML
//
function spin( obj )
{
  var spinner = document.getElementById( obj );
  var spinner_content = document.getElementById( obj+"_body" );
  if ( spinner_content.style.display == 'block' )
  {
/*
    spinner_content.style.visibility = 'hidden';
    spinner_content.style.height = '0px';
*/
    spinner.src = '../expand.jpg';
    spinner_content.style.display = 'none';
    spinner_content.style.margin = '0px';
  }
  else
  {
/*
    spinner.src = '../collapse.jpg';
    spinner_content.style.visibility = 'visible';
    spinner_content.style.height = 'auto';
*/
    spinner_content.style.display = 'block';
    spinner.src = '../collapse.jpg';
    spinner_content.style.margin = '3px 0px 3px 5px'; 
  }
}

//
//Copies rows from a source table into a display table.
//The indicated subset rows are copied to split the source table
//into viewing pages.
//

var page_last = 0;
var per_page_last = 50;

function pager ( obj, page, per_page)
{
  var table = document.getElementById( obj );
  var table_src = document.getElementById( obj+"_hid" );

//  var init = 0;
//  if (page == -2) { init =1; }

  if (page < 0)
  {
    page = page_last;
    per_page = per_page_last;
  }

  var row_copy = (page * per_page) + 1;
  var total_rows = per_page;

  if ((row_copy + total_rows - 1) >= table_src.rows.length) {
    total_rows = table_src.rows.length - row_copy;
  }
//
//Out of range means all rows.
//
  if (row_copy >= table_src.rows.length) { 
    row_copy = 1;
    total_rows = table_src.rows.length - 1;
  }

//
//Remove and re-add table rows.
//
  var body = table.tBodies[0];
  if (body) { table.removeChild(body); }
  body = table.appendChild(document.createElement("TBODY"));
/*
    for (var i = 0; i <= total_rows;i++) {
    body.appendChild(document.createElement("TR"));
  }
*/

//  var nwRow = document.createElement("TR");
//  if (init) { table.rows[0].innerHTML = table_src.rows[0].innerHTML; }
//    table.rows[0] = table_src.rows[0].cloneNode(1);
  body.appendChild(table_src.rows[0].cloneNode(true));

  for (var ti=1;ti <= total_rows;ti++) {
//    table.rows[ti].InnerHTML = table_src.rows[row_copy].InnerHTML;
    body.appendChild(table_src.rows[row_copy].cloneNode(true));
    row_copy++;
  }

//
//Highlight the selected page.
//
  if (document.getElementById( obj+"_pg"+page_last )) {
    document.getElementById( obj+"_pg"+page_last ).style.color = 'black';
    document.getElementById( obj+"_pg"+page_last ).style.fontWeight= 'normal';
    document.getElementById( obj+"_pg"+page ).style.color = 'blue';
    document.getElementById( obj+"_pg"+page ).style.fontWeight= 'bold';
  }

  page_last = page;
  per_page_last = per_page;
}




