var numInputs = 1;
var numAttrs = 0;

function changeVars() {
  numInputs = $('draw_method_nvars').selectedIndex + 1;
  var ary = new Array(numAttrs+numInputs);
  for (i=0; i<numInputs; i++) {
      if (i==0)
	  ary[i] = 'gphys';
      else
	  ary[i] = 'gphys' + i;
  }
  ary[numInputs] = "opt";
  Element.update('vizshot_args', ary.join(", "));
  ary[numInputs] = "newfrm";
  ary[numInputs+1] = "opt";
  Element.update('ggraph_args', ary.join(", "));
}

var numAttrMax=0;
function changeAttributes() {
  numAttrs = $('attribute_num').selectedIndex;
  changeVars();

  for (i=0; i<[numAttrs,numAttrMax].min(); i++)
      Element.show('attr_'+i);
  for (i=numAttrs;i<numAttrMax; i++)
      Element.hide('attr_'+i);

  html = "";
  for (i=numAttrMax; i<numAttrs; i++) {
    html += "<div id='attr_" + i + "'>\n";
    html += "<h4>attribute " + i +"</h4>\n";
    html += "<table>\n";
    html += "  <tr>\n";
    html += "    <td>\n";
    html += "      <label for='attribute_" + i + "_name'>name</label>\n";
    html += "    </td>\n";
    html += "    <td>\n";
    html += "      <input type='text' name='attribute[" + i + "][name]' id='attribute_" + i + "_name'></input>\n";
    html += "    </td>\n";
    html += "  </tr>\n";
    html += "  <tr>\n";
    html += "    <td>\n";
    html += "      <label for='attribute_" + i + "_default'>default</label>\n";
    html += "    </td>\n";
    html += "    <td>\n";
    html += "      <input type='text' size='10' name='attribute[" + i + "][default]' id='attribute_" + i + "_default'/>\n";
    html += "    </td>\n";
    html += "  </tr>\n";
    html += "  <tr>\n";
    html += "    <td>\n";
    html += "      <label for='attribute_" + i + "_value_type'>value type</label>\n";
    html += "    </td>\n";
    html += "    <td>\n";
    html += "      <select id='attribute_" + i + "_value_type' name='attribute[" + i + "][value_type]'>\n";
    html += "        <option selected>int</option>\n";
    html += "        <option>float</option>\n";
    html += "        <option>string</option>\n";
    html += "        <option>boolean</option>\n";
    html += "        <option>array_int</option>\n";
    html += "        <option>array_float</option>\n";
    html += "      </select>\n";
    html += "    </td>\n";
    html += "  </tr>\n";
    html += "  <tr>\n";
    html += "    <td>\n";
    html += "      <label for='attribute_" + i + "_parser'>parser</label>\n";
    html += "    </td>\n";
    html += "    <td>\n";
    html += "      <select id='attribute_" + i + "_parser' name='attribute[" + i + "][parser]'>\n";
    html += "        <option selected>vizshot</option>\n";
    html += "        <option>ggraph</option>\n";
    html += "      </select>\n";
    html += "    </td>\n";
    html += "  </tr>\n";
    html += "</table>\n";
    html += "</div>\n";
    numAttrMax = i+1;
  }
  new Insertion.Bottom('attributes_table', html);
}

