// Last updated 2006-02-21
function addRowToTable(arrayofthickness)
{
  var tbl = document.getElementById('generaterow');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
//  // left cell
//  var cellLeft = row.insertCell(0);
//  var textNode = document.createTextNode(iteration);
//  cellLeft.appendChild(textNode);
    // select cell
  var cellRightSel = row.insertCell(0);
  var sel = document.createElement('select');
  sel.name = 'selRow' + iteration;
  sel.options[0] = new Option('text zero', 'value0');
  sel.options[1] = new Option('text one', 'value1');
  cellRightSel.appendChild(sel);
    // select cell
  var cellRightSel = row.insertCell(1);
  var sel = document.createElement('select');
  sel.name = 'selRow' + iteration;
  sel.options[0] = new Option('text zero', 'value0');
  sel.options[1] = new Option('text one', 'value1');
  cellRightSel.appendChild(sel);


   // right cell
    var cellRight = row.insertCell(2);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'txtRow' + iteration;
  el.id = 'txtRow' + iteration;
  el.size =5;
   cellRight.appendChild(el);
    // right cell
  var cellRight = row.insertCell(3);
  var el3 = document.createElement('input');
  el3.type = 'text';
  el3.name = 'txtRow3' + iteration;
  el3.id = 'txtRow3' + iteration;
  el3.size =5;
  el3.onkeypress = keyPressTest;
  cellRight.appendChild(el3);
  
     // right cell
    var cellRight = row.insertCell(4);
  var el4 = document.createElement('input');
  el4.type = 'text';
  el4.name = 'txtRow4' + iteration;
  el4.id = 'txtRow4' + iteration;
  el4.size =5;
   cellRight.appendChild(el4);
   
   // right cell
var cellRight = row.insertCell(5);
  var el5 = document.createElement('input');
  el5.type = 'text';
  el5.name = 'txtRow5' + iteration;
  el5.id = 'txtRow5' + iteration;
  el5.size =5;
   cellRight.appendChild(el5);
  
    // right cell
    var cellRight = row.insertCell(6);
  var el6 = document.createElement('input');
  el6.type = 'text';
  el6.name = 'txtRow6' + iteration;
  el6.id = 'txtRow6' + iteration;
  el6.size =5;
   cellRight.appendChild(el6);
    // right cell
  var cellRight = row.insertCell(7);
  var el7 = document.createElement('input');
  el7.type = 'text';
  el7.name = 'txtRow7' + iteration;
  el7.id = 'txtRow7' + iteration;
  el7.size =5;
  el7.onkeypress = keyPressTest;
  cellRight.appendChild(el7);
  
     // right cell
    var cellRight = row.insertCell(8);
  var el8 = document.createElement('input');
  el8.type = 'text';
  el8.name = 'txtRow8' + iteration;
  el8.id = 'txtRow8' + iteration;
  el8.size =5;
   cellRight.appendChild(el8);
   
   // right cell
var cellRight = row.insertCell(9);
  var el9 = document.createElement('input');
  el9.type = 'text';
  el9.name = 'txtRow9' + iteration;
  el9.id = 'txtRow9' + iteration;
  el9.size =5;
   cellRight.appendChild(el9);
     // right cell
var cellRight = row.insertCell(10);
  var el10 = document.createElement('input');
  el10.type = 'text';
  el10.name = 'txtRow10' + iteration;
  el10.id = 'txtRow10' + iteration;
  el10.size =5;
   cellRight.appendChild(el10);
  

     // right cell
var cellRight = row.insertCell(11);
  var el11 = document.createElement('input');
  el11.type = 'checkbox';
  el11.name = 'txtRow11' + iteration;
  el11.id = 'txtRow11' + iteration;
  el11.size =5;
   el11.onclick='addRowToTable();'+ iteration;
   cellRight.appendChild(el11);
  
  document.getElementById('addnewrow').style.display='none';
  // select cell
//  var cellRightSel = row.insertCell(2);
//  var sel = document.createElement('select');
//  sel.name = 'selRow' + iteration;
//  sel.options[0] = new Option('text zero', 'value0');
//  sel.options[1] = new Option('text one', 'value1');
//  cellRightSel.appendChild(sel);
}
function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}
function removeRowFromTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
function openInNewWindow(frm)
{
  // open a blank window
  var aWindow = window.open('', 'TableAddRowNewWindow',
   'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
   
  // set the target to the blank window
  frm.target = 'TableAddRowNewWindow';
  
  // submit
  frm.submit();
}
function validateRow(frm)
{
  var chkb = document.getElementById('chkValidate');
  if (chkb.checked) {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
      var aRow = document.getElementById('txtRow' + i);
      if (aRow.value.length <= 0) {
        alert('Row ' + i + ' is empty');
        return;
      }
    }
  }
  openInNewWindow(frm);
}

