var f = 0;
function addInput () {
if (f < 4 ) {
  if (document.all || document.getElementById) {
    var table = document.all ? document.all.formElems :
      document.getElementById('formElems');
    var row = table.insertRow(++f);
    if (document.all) {
      var cell = row.insertCell(0);
      cell.innerHTML =
        '<INPUT TYPE="file" NAME="attachment' + f + '"'
        + ' ONCHANGE="addInput()">';
    }
    else {
      cell = row.insertCell(0);
      input = document.createElement('INPUT');
      input.setAttribute('type', 'file');
      input.name = 'attachment' + f;
      input.onchange = function () { addInput(); };
      cell.appendChild(input);
    }
  }
}
}
