// JavaScript Document
var r = 1;
var f = 0;
function addInput () {
  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.className = 'tableeditfields';
      cell.innerHTML =
        '<font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Ficheiro</font>';
      cell = row.insertCell(1);
      cell.innerHTML = 
        '<input name="doc[nome][]" type="text" class="fieldfiles" size="50"><br><INPUT TYPE="text" NAME="doc[ficheiro][]" ID="doc'+f+'"'
        + ' class="fieldfiles" size="40"> <input type="button" name="Button" value="..." onClick="imanager.filebrowser(\'doc'+f+'\',\'image\',window);" class="button"> <INPUT TYPE="button" VALUE="+"' +
        ' ID="addButton' + f + '"' +
        ' ONCLICK="addInput();" class="button">';
      document.all['addButton' + (f - 1)].outerHTML = '';
    
	} else {
      var cell = row.insertCell(0);
      var input = document.createElement('INPUT');
      input.setAttribute('type', 'button');
      input.id = 'addButton' + f;
      input.value = '+';
      //input.onclick = function () { addInput(); };
      cell.appendChild(input);
      cell = row.insertCell(1);
      input = document.createElement('INPUT');
      input.setAttribute('type', 'text');
      input.name = 'ficheiro' + f;
      //input.onchange = function () { addInput(); };
      cell.appendChild(input);
      var oldButton = document.getElementById('addButton' + (f - 1));
      oldButton.parentNode.removeChild(oldButton);
    }
  }
}
