}

    for ($idx = 0; $idx < $frmHolderElementCount; $idx++) {
      print("\t<tr width = \"$holderTableRowWidth\">\n");
      print("\t<td width = $holderTableColWidth>");
      print("$frmHolderElementText[$idx]");
      print("\t</td>\n");
      print("\t<td width = \"$holderTableColWidth\">");
      $fieldName = $frmHolderElementNames[$idx];
      $fieldType = $frmHolderElementTypes[$idx];
      if (IsSet($_POST[$fieldName])) {
        $fieldValue = $_POST[$fieldName];
      } else {
        $fieldValue = "";
      }
      writeTextBox($fieldName, $fieldValue);
      print("\t</td>");
      print("\t</tr>\n");
    }

    print("\t<tr>\n");
    print("\t<td>");
    writeButton("insertHolder", "Insert Holder", "javascript:addHolderToList();");

    print("\t</td>");
    print("\t</tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
      
      /* Add the operations list for the first row with
         a column span of size $frmPartElementCount */
      /* A list of operations that have been added for this part */
      if ($idx == 0) {
        print("\t<td>");
        print("Operations added:<br>");
        print("\t</td>");
      }
      if ($idx == 1) {
        print("\t<td valign=\"top\" rowspan=\"$frmPartElementCount\">");
        print("<select id = \"operationList\" size = \"$frmPartElementCount\" style=\"width:250\">\n");
        print("</select>");
	print("<br>");
	writeButton("addOperation", "Create Operation", "javascript:showAddOperation();");
	writeButton("addOperation", "Delete Operation", "javascript:deleteSelectedOperation();");
        print("\t</td>");
      }
      print("\t</tr>\n");
    }
    
    /* A hidden textbox to store the Operations for posting */
    writeTextBox("operationStore", "");
    writeTextBox("customerStore", "");
    writeTextBox("operationDeleteList", "");

    print("</table>\n");
    writeSubmit("addPart", "Add part");
    print("</form>\n");
    print("</div>\n");
?>
    print("\t</td>\n");

    print("\t<tr>");
    print("\t<td valign=\"center\">");
    print("Programs added:<br>");
    print("\t</td>");
    print("\t<td valign=\"center\">");
    writeSelectMultiline("opProgramList", 10, 275);
    print("<br>");
    writeButton("createProgram", "Create Program", "javascript:showAddProgram();");
    print("\t</td>");
    print("</tr>");

    print("\t<tr>\n");
    print("\t<td>\n");
    writeButton("addOperation", "Insert Operation", "javascript:addOperationToList();");
    print("\t</td>\n");
    print("\t<td>\n");
    writeButton("addOperation", "Cancel", "javascript:clearForm();showPreviousForm();");
    print("\t</td>\n");
    writeTextBox("programStore", "");
    writeTextBox("toolHolderStore", "");
    writeTextBox("machineStore", "");
    print("\t</td>");
    print("\t<td></td>");
    print("\t</tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
 function writeSelectAndAdd($selectId, $selectValues, $selectWidth, $addButtonName, $addButtonCaption, $javaScriptButtonAction) {
   print("<p>");
   if (IsSet($selectWidth)) {
     print("<select id = \"$selectId\" style=\"width:$selectWidth\" name = \"$selectId\">\n");
   } else {
     print("<select id = \"$selectId\" style=\"width:180\" name = \"$selectId\">\n");
   }
   $optionCount = count($selectValues);
   for ($idx = 0; $idx < $optionCount; $idx++) {
     print("<option value = \"$selectValues[$idx]\">$selectValues[$idx]</option>\n");
   }
   print("</select>\n");
   writeButton($addButtonName, $addButtonCaption, $javaScriptButtonAction);
   print("</p>");    
 }
    }

    for ($idx = 0; $idx < $frmInsertElementCount; $idx++) {
      print("\t<tr width = \"$insertTableRowWidth\">\n");
      print("\t<td width = $insertTableColWidth>");
      print("$frmInsertElementText[$idx]");
      print("\t</td>\n");
      print("\t<td width = \"$insertTableColWidth\">");
      $fieldName = $frmInsertElementNames[$idx];
      $fieldType = $frmInsertElementTypes[$idx];
      if (IsSet($_POST[$fieldName])) {
        $fieldValue = $_POST[$fieldName];
      } else {
        $fieldValue = "";
      }
      writeTextBox($fieldName, $fieldValue);
      print("\t</td>");
      print("\t</tr>\n");
    }

    print("\t<tr>\n");
    print("\t<td>");
    writeButton("addInsert", "Add Insert", "javascript:addInsertToSelect();");

    print("\t</td>");
    print("\t</tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
    if (IsSet($frmMachineTableWidth)) {
      print("<table border=\"$mainTableBorder\" width = \"$frmMachineTableWidth\">\n");
    } else {
      print("<table border=\"$mainTableBorder\" width = \"$masterTableWidth\">\n");
    }

    for ($idx = 0; $idx < $frmMachineElementCount; $idx++) {
      print("\t<tr width = \"$machineTableRowWidth\">\n");
      print("\t<td width = $machineTableColWidth>");
      print("$frmMachineElementText[$idx]");
      print("\t</td>\n");
      print("\t<td width = \"$machineTableColWidth\">");
      $fieldName = $frmMachineElementNames[$idx];
      $fieldType = $frmMachineElementTypes[$idx];
      $fieldValue = "";
      writeTextBox($fieldName, $fieldValue); 
      print("\t</td>");
      print("\t</tr>\n");
    }

    print("\t<tr>\n");
    print("\t<td>");
    writeButton("addMachine", "Add Machine", "javascript:addMachineToList();showPreviousForm();");

    print("\t</td>");
    print("\t</tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
      print("\t<td width = \"200\">");
      print("$frmOperationTHElementText[$idx]");
      print("\t</td>\n");
      print("\t<td width = \"200\">");
      $fieldName = $frmOperationTHElementNames[$idx];
      $fieldType = $frmOperationTHElementTypes[$idx];
      if ($fieldName == "operationTHHolderName") {
        writeSelectAndAdd($fieldName, $holderNames, 180, "addHolder", "Add New Holder", "javascript:showAddHolder();");
      } else if ($fieldName == "operationTHToolName") {
        writeSelectAndAdd($fieldName, $toolNames, 180, "addTool", "Add New Tool", "javascript:showAddToolSkipSubmit();");
      } else{
        writeTextBox($fieldName, $fieldValue);
      }
      print("\t</td>");
      print("\t</tr>\n");
    }

    print("\t<tr>\n");
    print("\t<td>");
    writeButton("insertHolder", "Insert Tool-Holder", "javascript:addNewToolHolderToList();");

    print("<input type=\"text\" id=\"holderStore\">\n</input>\n");
    print("<input type=\"text\" id=\"toolStore\">\n</input>\n");

    print("\t</td>");
    print("\t</tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
    }

    for ($idx = 0; $idx < $frmCustomerElementCount; $idx++) {
      print("\t<tr width = \"$customerTableRowWidth\">\n");
      print("\t<td width = $customerTableColWidth>");
      print("$frmCustomerElementText[$idx]");
      print("\t</td>\n");
      print("\t<td width = \"$customerTableColWidth\">");
      $fieldName = $frmCustomerElementNames[$idx];
      $fieldType = $frmCustomerElementTypes[$idx];
      if (IsSet($_POST[$fieldName])) {
        $fieldValue = $_POST[$fieldName];
      } else {
        $fieldValue = "";
      }
      writeTextBox($fieldName, $fieldValue);
      print("\t</td>");
      print("\t</tr>\n");
    }

    print("\t<tr>\n");
    print("\t<td>");
    writeButton("insertCustomer", "Insert Customer", "javascript:addNewCustomer();");

    print("\t</td>");
    print("\t</tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
      print("\t<td width = $operationTableColWidth>");
      print("$frmElementText[$idx]");
      print("\t</td>\n");
      print("\t<td width = \"$operationTableColWidth\">");
      $fieldName = $frmElementNames[$idx];
      $fieldType = $frmElementTypes[$idx];
      if (IsSet($_POST[$fieldName])) {
        $fieldValue = $_POST[$fieldName];
      } else {
        $fieldValue = "";
      }
      writeTextBox($fieldName, $fieldValue);
      if ($frmElementDBNames[$idx] == "MachineID") {
        print("\t<td>");
        writeButton("findMachineID","Find machine ID", "javascript:void();");
        print("\t</td>\n");
      }
      print("\t</td>");
      print("\t</tr>\n");
    }

    print("\t<tr>\n");
    print("\t<td>");
    writeButton("addOperation", "Add Operation", "javascript:void();");
    print("\t</td>");
    print("\t<\tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
      print("\t<td width = $programTableColWidth>");
      print("$frmProgramElementText[$idx]");
      print("\t</td>\n");
      print("\t<td width = \"$programTableColWidth\">");
      $fieldName = $frmProgramElementNames[$idx];
      $fieldValue = "";
      if ($fieldName == "programType") {
        print("\t<select id = \"programType\" name = \"programType\" style=\"width:180\">\n");
        print("\t<option selected>Main program</option>");
	print("\t<option>Sub-program</option>");
        print("\t</select>\n");
      } else if ($fieldName == "programCode") {
        writeTextArea($fieldName, $fieldValue, 5, 40);
      } else {
        writeTextBox($fieldName, $fieldValue);
      }
      print("\t</td>");
      print("\t</tr>\n");
    }

    print("\t<tr>\n");
    print("\t<td>");
    writeButton("addProgram", "Add Program", "javascript:addProgramToList();");

    print("\t</td>");
    print("\t</tr>\n");
    
    print("</table>\n");
    print("</div>\n");
?>
      } else {
        writeTextBox($fieldName, $fieldValue);
      }

      /* Add the inserts list for the first row with
         a column span of size $frmToolElementCount */
      /* A list of inserts that have been added for this tool */
      if ($idx == 0) {
        print("\t<td>");
        print("Inserts for the part:<br>");
        print("\t</td>");
      }
      if ($idx == 1) {
        print("\t<td valign=\"top\" rowspan=\"$frmToolElementCount\">");
        writeSelectAndAdd("insertSelect", $insertPartNumbers, 250, "createInsert", "Create Insert", "javascript:showAddInsert();");
	writeButton("addInsert", "Add Insert", "javascript:addInsertToList();");
        print("<select id = \"insertList\" size = \"$frmToolElementCount\" style=\"width:250\">\n");
        print("</select>");
        print("<br>");
        print("\t</td>");
      }
      print("\t</td>");
      print("\t</tr>\n");
    } 

    print("\t<tr>\n");
    print("\t<td>");
    writeSubmit("addTool", "Insert Tool");

   /* A hidden textbox to store the tools for posting */
    print("\t<input type = \"hidden\" id = \"insertStore\" name = \"insertStore\" />\n");