function showHelpWin(query)
{
   var link = 'explain.html#' + query;
   win=window.open(link, 'Explain', 'width=600,height=270,resizable=1,scrollbars=1');
   win.focus();
}


function FileUploadManager()
{
  this.count = 0;
  
  this.getCount = function() { return this.count; }
  
  this.getFileID = function(count) { return "pdbFile-"+count; }
  this.getPdbID = function(count) { return "pdbId-"+count; }
  this.getErrID = function(count) { return "pdbErr-"+count; }

  this.addFileUpload = function()
    {
      var protInput = document.createElement("input");
      var id = this.getFileID(this.count);
      protInput.setAttribute("type", "file");
      protInput.setAttribute("id", id);
      protInput.setAttribute("name", id);
      protInput.setAttribute("size", "45");
      // to ensure "onchange" fires in both IE and FF cannot use:
      //	    protInput.setAttribute("onchange", "guessPdb("+this.count+");");
      // need to use:
      var index = this.count;
      protInput.onchange = function() { guessPdb(index); }

      var sep = document.createElement("span");
      sep.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;"
      
      var chainInput = document.createElement("input");
      id = this.getPdbID(this.count);
      chainInput.setAttribute("type", "text");
      chainInput.setAttribute("id", id);
      chainInput.setAttribute("name", id);
      chainInput.setAttribute("size", "4");
      chainInput.setAttribute("maxlength", "4");
      // to ensure "onchange" fires in both IE and FF cannot use:
      //            chainInput.setAttribute("onblur", "showPdbChangeError("+this.count+");");
      // need to use:
      var index = this.count;
      chainInput.onblur = function() { showPdbChangeError(index); }

	    
      var chainErr = document.createElement("span");
      id = this.getErrID(this.count);
      chainErr.setAttribute("id", id);
      chainErr.setAttribute("name", id);
      chainErr.className = "error"; //setAttribute("class", "error");
	    
      var localFiles = document.getElementById("localFiles");
      var row = localFiles.insertRow(localFiles.rows.length-1);

      var cell = row.insertCell(-1);
      cell.appendChild(protInput);
      cell.appendChild(sep);
	    
      cell = row.insertCell(-1);
      cell.appendChild(chainInput);
      cell.appendChild(chainErr);
	    
      this.count++;
    }

  this.addHeader = function()
    {
      var localFiles = document.getElementById("localFiles");
      var row = localFiles.insertRow(0);

      var label = document.createElement("span");
      label.className = "label"; //setAttribute("class", "label");
      label.innerHTML = "Local Files ";

      var cell = row.insertCell(-1);
      cell.appendChild(label);

      var explain = document.createElement("img");
      explain.src = "images/help.gif";
      explain.onclick = function() { showHelpWin('files'); }
      cell.appendChild(explain);

      var label = document.createElement("span");
      label.className = "label"; //setAttribute("class", "label");
      label.innerHTML = "PDB ID ";

      var cell = row.insertCell(-1);
      cell.appendChild(label);

      var explain = document.createElement("img");
      explain.src = "images/help.gif";
      explain.onclick = function() { showHelpWin('files'); }
      cell.appendChild(explain);

      var moreBtn = document.createElement("input");
      moreBtn.setAttribute("type", "button");
      moreBtn.setAttribute("value", "More >>>");
      moreBtn.onclick = function() { fileManager.addFileUpload(); }

      row = localFiles.insertRow(1);
      var cell = row.insertCell(-1);
      cell.appendChild(moreBtn);
    }

  this.setArchiveUpload = function()
    {
      this.clear();

      document.getElementById("archiveRadio").checked = 'checked';

      var localFiles = document.getElementById("localFiles");
      var row = localFiles.insertRow(0);

      var label = document.createElement("span");
      label.innerHTML = "Local Archive ";
      label.className = "label"; //setAttribute("class", "label");

      var cell = row.insertCell(-1);
      cell.appendChild(label);

      var explain = document.createElement("img");
      explain.src = "images/help.gif";
      explain.onclick = function() { showHelpWin('archive'); }
      cell.appendChild(explain);

      var archive = document.createElement("input");
      archive.setAttribute("type", "file");
      archive.setAttribute("id", "archive");
      archive.setAttribute("name", "archive");
      archive.setAttribute("size", "57");

      var row = localFiles.insertRow(1);
      var cell = row.insertCell(-1);
      cell.appendChild(archive);
    }

  this.setMultiUpload = function(n)
    {
      this.clear();
      document.getElementById("multifileRadio").checked = 'checked';
      this.addHeader();
      for (var i = 0; i < n; ++i) {
	this.addFileUpload();
      }
    }

  this.clear = function()
    {
      var localFiles = document.getElementById("localFiles");
      while(localFiles.rows.length > 0) {
	localFiles.deleteRow(0);
      }
      this.count = 0;
    }
}
