+function update_action (new_action) {
+ document.search.action_type.value = new_action;
+}
+
+
+function make_pager (hits, offset, max) {
+ var html = '';
+ var off;
+ var start_offset = offset - page_window * max;
+ var div_elem = document.createElement('div');
+
+ div_elem.className = 'pages';
+
+ if (start_offset < 0) {
+ start_offset = 0;
+ }
+
+ for (off = start_offset;
+ off < hits && off < (start_offset + 2 * page_window * max);
+ off += max) {
+
+ var p = off / max + 1;
+ var page_elem = create_element('a', p);
+ var newline_node = document.createTextNode(' ');
+
+ if ((offset >= off) && (offset < (off + max))) {
+ page_elem.className = 'select';
+ }
+
+ page_elem.setAttribute('off', off);
+ page_elem.style.cursor = 'pointer';
+ page_elem.onclick = function () {
+ update_offset(this.getAttribute('off'));
+ };
+
+ div_elem.appendChild(page_elem);
+ div_elem.appendChild(newline_node);
+ }
+
+ return div_elem;
+}
+
+
+function update_offset (offset) {
+ clearTimeout(searchtimer);
+ document.search.startrec.value = offset;
+ update_action('page');
+ check_search();
+ update_history();
+ return false;
+}
+
+
+function create_element (name, cdata) {
+ var elem_node = document.createElement(name);
+ var text_node = document.createTextNode(cdata);
+ elem_node.appendChild(text_node);
+
+ return elem_node;
+}
+
+
+function clear_cell (cell) {
+ while (cell.hasChildNodes())
+ cell.removeChild(cell.firstChild);
+}
+
+
+function append_text(cell, text) {
+ text_node = document.createTextNode(text);
+ cell.appendChild(text_node);
+}
+
+
+function assign_text (cell, text) {
+ clear_cell(cell);
+ append_text(cell, text);
+}
+
+function set_sort_opt(n, opt, str)
+{
+ var txt = document.createTextNode(str);
+ if (opt == cur_sort)
+ n.appendChild(txt);
+ else
+ {
+ var a = document.createElement('a');
+ a.appendChild(txt);
+ a.setAttribute('href', "");
+ a.setAttribute('onclick', "set_sort('" + opt + "'); return false");
+ n.appendChild(a);
+ }
+}
+
+function set_sort(sort)
+{
+ if (sort && sort != cur_sort)
+ {
+ cur_sort = sort;
+ if (searched)
+ check_search();
+ }
+
+ var t = document.getElementById("sortselect");
+ clear_cell(t);
+ t.appendChild(document.createTextNode("Sort results by: "));
+ set_sort_opt(t, 'relevance', 'Relevance');
+ t.appendChild(document.createTextNode(" or "));
+ set_sort_opt(t, 'title:1', 'Title');
+}
+
+function displayname(name)
+{
+ if (name == 'md-author')
+ return 'Author';
+ else if (name == 'md-subject')
+ return 'Subject';
+ else if (name == 'md-date')
+ return 'Date';
+ else if (name == 'md-isbn')
+ return 'ISBN';
+ else if (name == 'md-publisher')
+ return 'Publisher';
+ else
+ return name;
+}
+
+function paint_details_tr(name, dn)
+{
+ //emit a table row
+ var dname = displayname(name);
+ var ln = create_element('b', dname);
+ var tln = document.createElement('td');
+ tln.setAttribute('width', 70);
+ tln.setAttribute('valign', 'top');
+ tln.appendChild(ln);
+ var tr = document.createElement('tr');
+ tr.appendChild(tln);
+ tr.appendChild(dn);
+ return tr;
+}
+
+function paint_details(body, xml)