13 // Query and result management
14 // ======================================================
16 function check_query_start()
20 if (!args['status'] || args['status'] != 'searching')
26 function start_search()
28 var url = "search.pz2?session=" + session +
30 "&query=" + args['query'];
31 SendXmlHttpObject(xsearch = GetXmlHttpObject(), url, search_started);
34 function search_started()
36 if (xsearch.readyState != 4)
38 var xml = xsearch.responseXML;
39 var error = xml.getElementsByTagName("error");
42 var msg = error[0].childNodes[0].nodeValue;
46 location = "?" + searchstring + "&status=searching";
49 function check_search()
51 clearTimeout(asearch);
52 var url = "search.pz2?" +
54 "&start=" + args['start'] +
55 "&session=" + session +
57 SendXmlHttpObject(xshow = GetXmlHttpObject(), url, show_records);
60 function show_records()
62 if (xshow.readyState != 4)
65 var xml = xshow.responseXML;
66 var body = document.getElementById("body");
67 var hits = xml.getElementsByTagName("hit");
68 if (!hits[0]) // We should never get here with blocking operations
70 body.innerHTML = "No records yet";
71 asearch = setTimeout(check_search, 250);
76 var total = Number(xml.getElementsByTagName('total')[0].childNodes[0].nodeValue);
77 var merged = Number(xml.getElementsByTagName('merged')[0].childNodes[0].nodeValue);
78 var start = Number(xml.getElementsByTagName('start')[0].childNodes[0].nodeValue);
79 var num = Number(xml.getElementsByTagName('num')[0].childNodes[0].nodeValue);
80 body.innerHTML = '<b>Records : ';
81 body.innerHTML += (start + 1) + ' to ' + (start + num) +
82 ' of ' + merged + ' (total hits: ' + total + ')</b>';
85 if (start + num < merged)
86 body.innerHTML += ' <a href="" ' +
87 'onclick="startrec=' + (start + 20) +
88 ';check_search(); return false;">Next</a>';
91 body.innerHTML += ' <a href="" ' +
92 'onclick="startrec=' + (start - 20) +
93 ';check_search(); return false;">Previous</a>';
96 body.innerHTML += '<br/>';
97 for (i = 0; i < hits.length; i++)
99 body.innerHTML += '<p>';
100 body.innerHTML += (i + start + 1) + ': ';
101 var mk = hits[i].getElementsByTagName("title");
103 body.innerHTML += mk[0].childNodes[0].nodeValue;
104 body.innerHTML += '</p>';
108 asearch = setTimeout(check_search, 1000);
110 asearch = setTimeout(check_search, 2000);
115 // Session management
116 // ======================================================
118 function session_started()
120 if (xinitSession.readyState != 4)
122 var xml = xinitSession.responseXML;
123 var sesid = xml.getElementsByTagName("session")[0].childNodes[0].nodeValue;
124 location = '?session=' + sesid;
127 function start_session()
129 var url="search.pz2?command=init";
130 SendXmlHttpObject(xinitSession = GetXmlHttpObject(), url, session_started);
133 function ping_session()
137 var url = "search.pz2?command=ping&session=" + session;
138 SendXmlHttpObject(xpingSession = GetXmlHttpObject(), url, session_pinged);
141 function session_pinged()
143 if (xpingSession.readyState != 4)
145 var xml = xpingSession.responseXML;
146 var error = xml.getElementsByTagName("error");
149 var msg = error[0].childNodes[0].nodeValue;
154 setTimeout(ping_session, 50000);
160 if (!args['session'])
164 session = args['session'];
165 document.getElementById("status").innerHTML = "Live";
166 document.searchform.elements['session'].value = session;
169 setTimeout(ping_session, 50000);
173 // ======================================================
177 searchstring = location.search.substring(1);
178 var list = searchstring.split('&');
182 var listparms = list[l].split('=');
183 args[listparms[0]] = listparms[1];
187 function GetXmlHttpObject()
190 if (window.XMLHttpRequest)
191 objXMLHttp=new XMLHttpRequest()
192 else if (window.ActiveXObject)
193 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
197 function SendXmlHttpObject(obj, url, handler)
199 obj.onreadystatechange=handler;
200 obj.open("GET", url);
207 <body onload="start();">
209 <table width="100%" border="1" cellpadding="5">
211 <td width="250" height="100" align="center">
212 <font size="+2"><b>MasterKey mk II</b></font>
216 <form name="searchform">
217 <b>Search:</b> <input name="query" type="text" size="50"/>
218 <input type="submit" value="Go"/>
219 <input type="hidden" name="session" value=""/>
226 <td valign="top" id="termlist"> </td>
228 <td valign="top" id="body">
229 Funky search prototype.<br><br><br><br>
239 Status: <span id="status">Initializing</span> <span id="targetstatus"></span><br/><span id="stat"></span>