﻿function addRowToTable()
{
  var tbl = document.getElementById('tblAddress');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
//  var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);
 
  //  cell 0
  var cell0 = row.insertCell(0);
  var el = document.createElement('input');
  el.type = "file";
  el.name = "file_upload[]";
  cell0.appendChild(el);
 
  //cell 1
  var cell1 = row.insertCell(1);
  var el = document.createElement('input');
  el.type = "text";
  el.name = "caption[]";
  el.size = 30;
  cell1.appendChild(el);
  
  //cell 2
  var cell2 = row.insertCell(2);
  var el = document.createElement('input');
  el.type = 'button';
  el.value = 'Usuń';
  el.onclick = function() {return removeRowFromTable(this.parentNode.parentNode.rowIndex); }
  cell2.appendChild(el);
}

function removeRowFromTable(i){
	document.getElementById('tblAddress').deleteRow(i);
}

function addRowToTableQuestionnaire()
{
  var tbl = document.getElementById('tblAddress');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
//  var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);
   
  // cell 0
  var cell0 = row.insertCell(0);
  var el = document.createElement('input');
  el.type = "hidden";
  el.name = "type[]";
  cell0.appendChild(el);
 
  //cell 1
  var cell1 = row.insertCell(1);
  var el = document.createElement('input');
  el.type = "text";
  el.name = "label[]";
  el.size = 80;
  cell1.appendChild(el);
  
  //cell 2
  var cell2 = row.insertCell(2);
  var el = document.createElement('input');
  el.type = 'button';
  el.value = 'Usuń';
  el.onclick = function() {return removeRowFromTable(this.parentNode.parentNode.rowIndex); }
  cell2.appendChild(el);
  
  document.getElementById('answer').innerHTML = "Odpowiedzi:";
}
