// Last updated 2006-02-21
function addRowToTable()
{
  var tbl = document.getElementById('tblOrder');
  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);
 
  
  // right cell
  var cellRight = row.insertCell(0);
  var el = document.createElement('input');
  el.className = 'orderfield';  
  el.type = 'text';
  el.name = 'produkt[]' + iteration;
  el.id = 'produkt[]' + iteration;
  el.size = 50;
  
  el.onkeypress = keyPressTest;
  cellRight.appendChild(el);
  
  // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('input');
  el.className = 'orderfield';
  el.type = 'text';
  el.name = 'storlek[]' + iteration;
  el.id = 'storlek[]' + iteration;
  el.size = 17;
  
  el.onkeypress = keyPressTest;
  cellRight.appendChild(el);  
  
  // right cell
  var cellRight = row.insertCell(2);
  var el = document.createElement('input');
  el.className = 'orderfield';  
  el.type = 'text';
  el.name = 'antal[]' + iteration;
  el.id = 'antal' + iteration;
  el.size = 17;  
  
  el.onkeypress = keyPressTest;
  cellRight.appendChild(el);  
    
  // 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);
  */
}
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('tblOrder');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}


