-if( count($errors) > 0 ) {
- plc_errors ($errors);
-}
-
-$self = $_SERVER['PHP_SELF'];
-if (!empty($_SERVER['QUERY_STRING'])) {
- $self .= "?" . $_SERVER['QUERY_STRING'];
-}
-
-?>
-
-<form name="fm" method="post" action="<?php echo $self; ?>">
-<input type="hidden" name="submitted" value="1">
-
-<h3>Node Details</h3>
-
-
-<input type="hidden" name="submitted" value="1">
-
-<table width="100%" cellspacing="0" cellpadding="4" border="0">
-
-<tr>
-<td width=250>Hostname:</td>
-<td><input type="text" name="hostname"
-value="<?php print($hostname); ?>" size="40" maxlength="256"></td>
-</tr>
-
-<tr>
-<td>Model:</td>
-<td><input type="text" name="model"
-value="<?php print($model); ?>" size="40" maxlength="256"></td>
-</tr>
-
-</table>
-
-
-<h3>Interface Settings</h3>
-
-<table width="100%" cellspacing="0" cellpadding="4" border="0">
-
-<tr>
-<td valign='top' width="250">Addressing method</td>
-<td>
-<input type="radio" name="method" value="dhcp" onChange='updateStaticFields()'
-<?php if($method == 'dhcp') { echo "checked"; } ?>>DHCP
-<input type="radio" name="method" value="static" onChange='updateStaticFields()'
-<?php if($method == 'static') { echo "checked"; } ?>>Static
-</td>
-</tr>
-
-<tr>
-<td valign='top'>IP address</td>
-<td><input type="text" name="ip" value="<?php print($ip); ?>"></td>
-</tr>
-
-<tr>
-<td valign='top'>Netmask</font></td>
-<td><input type="text" name="netmask" value="<?php print($netmask); ?>"></td>
-</tr>
-
-<tr>
-<td valign='top'>Network address</td>
-<td><input type="text" name="network" value="<?php print($network); ?>">
-</td>
-</tr>
-
-<tr>
-<td valign='top'>Gateway address</td>
-<td><input type="text" name="gateway" value="<?php print($gateway); ?>"></td>
-</tr>
-
-<tr>
-<td valign='top'>Broadcast address</td>
-<td><input type="text" name="broadcast" value="<?php print($broadcast); ?>">
-</td>
-</tr>
-
-<tr>
-<td valign='top'>Primary DNS</td>
-<td><input type="text" name="dns1" value="<?php print($dns1); ?>">
-</td>
-</tr>
-
-<tr>
-<td valign='top'>Secondary DNS (optional)</td>
-<td><input type="text" name="dns2" value="<?php print($dns2); ?>">
-</td>
-</tr>
-
-<tr>
-<td></td>
-<td><input type="submit" name="Submit" value="Add"></td>
-</tr>
-
-</table>
-</form>
-
-<?php
-
-}
-
+$toggle = new PlekitToggle ('add-node',"Add Node",
+ array('bubble'=>'Add a node - does not enforce PCU - for admins only !',
+ 'visible'=>get_arg('show_details',true)));
+$toggle->start();
+
+$details=new PlekitDetails($has_privileges);
+
+// xxx hardwire network type for now
+$form_variables = array('type'=>"ipv4");
+//$form=$details->form_start(l_actions(),$form_variables);
+$form=$details->form_start('/db/nodes/node_add.php',$form_variables,
+ array('onSubmit'=>'return interfaceSubmit()'));
+
+$details->start();
+
+$site_columns=array( "site_id", "name", "login_base" );
+$local_sites= $api->GetSites( array("peer_id"=>NULL, '-SORT'=>'name'), $site_columns );
+function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
+$site_selector = array_map ("site_selector",$local_sites);
+$site_select = $form->select_html("site_id", $site_selector, array('id'=>'site_id'));
+$details->th_td("Site",
+ $site_select,
+ "site_id",
+ array('input_type'=>'select','value'=>$interface['site_id']));
+
+$details->th_td("Hostname",$hostname,"hostname");
+$details->th_td("Model",$model,"model");
+$node_type_select = $form->select_html ("node_type",
+ node_type_selectors($api,$node_type),
+ array('id'=>'node_type'));
+$details->th_td("Reservation",$node_type_select,"node_type",
+ array('input_type'=>'select','value'=>$node_type));
+$method_select = $form->select_html ("method",
+ interface_method_selectors($api,$method,true),
+ array('id'=>'method',
+ 'onChange'=>'updateMethodFields()'));
+$details->th_td("Method",$method_select,"method",
+ array('input_type'=>'select','value'=>$interface['method']));
+
+// dont display the 'type' selector as it contains only ipv4
+//>>> GetNetworkTypes()
+//[u'ipv4']
+
+$details->th_td("IP address",$ip,"ip",array('width'=>15,
+ 'onKeyup'=>'networkHelper()',
+ 'onChange'=>'networkHelper()'));
+$details->th_td("Netmask",$netmask,"netmask",array('width'=>15,
+ 'onKeyup'=>'networkHelper()',
+ 'onChange'=>'networkHelper()'));
+$details->th_td("Network",$network,"network",array('width'=>15));
+$details->th_td("Broadcast",$broadcast,"broadcast",array('width'=>15));
+$details->th_td("Gateway",$gateway,"gateway",array('width'=>15,
+ 'onChange'=>'subnetChecker("gateway",false)'));
+$details->th_td("DNS 1",$dns1,"dns1",array('width'=>15,
+ 'onChange'=>'subnetChecker("dns1",false)'));
+$details->th_td("DNS 2",$dns2,"dns2",array('width'=>15,
+ 'onChange'=>'subnetChecker("dns2",true)'));
+$details->space();
+$details->th_td("BW limit (bps)",$bwlimit,"bwlimit",array('width'=>11));
+
+// the buttons
+$add_button = $form->submit_html ("add-node","Add New Node");
+$details->tr($add_button,"right");
+
+$form->end();
+$details->end();
+$toggle->end();