var id = 0;
// Usability Stats:
var usbTTC = 0;  // [T]o[t]al [C]licks
var usbOTC = 0;  // [O]n [T]ext [C]licks
function h( object) { // [H]ighlight
var pos = object.id.indexOf('_');
var objectID  = object.id.substring(0, pos); // pos+1-1
document.getElementById(objectID + '_checkboxCell').style.backgroundColor= '#CCFFCC';
document.getElementById(objectID + '_textCell').style.backgroundColor= '#CCFFCC';
}
function u( object) { // [U]nhighlight
var pos = object.id.indexOf('_');
var objectID  = object.id.substring(0, pos); // pos+1-1
if (!document.getElementById(objectID + '_checkboxItself').checked) {
document.getElementById(objectID + '_checkboxCell').style.backgroundColor= 'transparent';
document.getElementById(objectID + '_textCell').style.backgroundColor= 'transparent';
}
}
function c( object) { // [C]heck
usbTTC++;
var pos = object.id.indexOf('_');
var objectID  = object.id.substring(0, pos); // pos+1-1
var checkbox = new Object();
checkbox = document.getElementById(objectID + '_checkboxItself');
if (object == checkbox) {  
if (checkbox.checked) { h( object) }
else                  { u( object) }
}
else {
if (checkbox.checked) { checkbox.checked = false; u( object) }
else                  { checkbox.checked = true;  h( object) }
}
}
function setEvents( tableID) {
table = document.getElementById(tableID).children[0];
var tr = 0;
while ( table.children[tr] ) {
row = table.children[tr];
var td = 0;
while ( row.children[td] ) {
checkboxCell     = row.children[td];
checkboxItself   = row.children[td].children[0];
textCell         = row.children[td+1];
textCellBold     = row.children[td+1].children[0];  // maybe
if (checkboxItself) {
checkboxCell.id   = id + '_checkboxCell';
checkboxItself.id = id + '_checkboxItself'; // make sure to assign it an ID
textCell.id       = id + '_textCell';
if (textCellBold) { textCellBold.id = id + '_textCellBold'; } // make sure to assign it an ID if it exists
textCell.style.cursor = "default"; // or hand?
if (checkboxItself.checked) { // this handles the possibility of the form being shown by clicking the Back button
h( checkboxItself);
}
checkboxCell.onmouseover  = function () { h( window.event.srcElement) };
textCell.onmouseover      = function () { h( window.event.srcElement) };
checkboxCell.onmouseout   = function () { u( window.event.srcElement) };
textCell.onmouseout       = function () { u( window.event.srcElement) };
checkboxCell.onclick      = function () { c( window.event.srcElement) };
textCell.onclick          = function () { c( window.event.srcElement); usbOTC++ };
id++;
}
td += 2;
}
tr++;
}
// for (i=0; i<=500000; i++) {}
}
function submitIt() {
document.getElementById('usb').value = 'ttc-' + usbTTC + '_otc-' + usbOTC;
}
document.body.onload = function () { // This is necessary in order to highlight the items that may already be checked,
// i.e. when the user clicks the Back button.
// Such items will not respond to (item.checked == true) until document.body.onload!!
id = 0; // important!
var i = 0;
setEvents( 'table01'); setEvents( 'table02');
for (i=3; i<=9; i++) { setEvents( 'table0'+i+'_1'); setEvents( 'table0'+i+'_2'); } // 03..09
for (i=0; i<=2; i++) { setEvents( 'table1'+i+'_1'); setEvents( 'table1'+i+'_2'); } // 10..12
}

