<% local form, viewlibrary, page_info = ... 
require("htmlviewfunctions")
html = require("acf.html")
%>

<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"></script>
<script type="text/javascript">
	$(function(){
		$('input, select').first().focus();
		$('input, select').keydown(function(e){
			if (e.keyCode == 13) {
				$(this).parents('form').find('input.submit').click();
				return false;
			}
		});
	});
</script>

<% if form.value.values then %>
<H1>Device</H1>
	<DL>
<% if form.errtxt then io.write("<P CLASS='error'>" .. string.gsub(html.html_escape(form.errtxt), "\n", "<BR>") .. "</P>\n") end %>
	<DT>Device ID</DT><DD><input class="text" type="text" value="<%= html.html_escape(form.value.result.value[1].device_id) %>" readonly="true"></DD>
<H2>Parameter Values</H2>
<%
	require("session")
	val = session.serialize("values", form.value.values.value)
	val = string.gsub(val, "[^\n]*%{%}\n", "")
	print("<pre>"..val.."</pre>")
	form.value.values = nil
elseif form.value.result then
	local func = haserl.loadfile(page_info.viewfile:gsub("searchdevices", "listdevices"))
	func(form.value.result, viewlibrary, page_info, session)
%>
	</DL>
<% end %>

<H1><%= html.html_escape(form.label) %></H1>
<%
	form.value.result = nil
	htmlviewfunctions.displayform(form, nil, nil, page_info, 2)
%>
