function xmlhttpPost() {
var searchform = document.forms['searchform'];
search(searchform.query.value);
}
// static variables
var start = new Date();
var query = "";
var searchresult;
var totalResults = 0;
var filetypes;
var topics;
var script = "";
function search(search) {
query = search;
start = new Date();
var self = this;
if (window.XMLHttpRequest) { // Mozilla/Safari
self.xmlHttpReq = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('GET', "yacysearch.json?verify=false&resource=local&maximumRecords=1000&nav=all&query=" + query, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
preparepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(null);
}
function navget(list, name) {
for (var i = 0; i < list.length; i++) {
if (list[i].facetname == name) return list[i];
}
}
function preparepage(str) {
var raw = document.getElementById("raw");
if (raw != null) raw.innerHTML = str;
var rsp = eval("("+str+")");
var firstChannel = rsp.channels[0];
searchresult = firstChannel.items;
totalResults = firstChannel.totalResults.replace(/[,.]/,"");
// var startIndex = firstChannel.startIndex;
// var itemsPerPage = firstChannel.itemsPerPage;
topics = navget(firstChannel.navigation, "topics");
filetypes = {};
script = "";
document.getElementById("searchresults").innerHTML = resultList();
document.getElementById("searchnavigation").innerHTML = resultStart();
hideDownloadScript();
}
function makeDownloadScript() {
document.getElementById("downloadscript").innerHTML = "
" + script + "
";
document.getElementById("downloadbutton").innerHTML = "";
}
function hideDownloadScript() {
document.getElementById("downloadscript").innerHTML = "";
var dlb = document.getElementById("downloadbutton");
if (dlb) dlb.innerHTML = "";
}
function resultStart() {
var html = "";
if (totalResults > 0) {
html += "";
} else {
if (query == "") {
html += "please enter some search words";
} else {
html += "no results";
}
}
html += "";
// add extension navigation
var extnav = "";
for (var key in filetypes) {
if (filetypes[key] > 0) {
extnav += "" + key + "(" + filetypes[key] + ") ";
}
}
if (extnav.length > 0) {
html += "apply a filter by filetype: " + extnav + "";
} else {
// check if there is a filetype constraint and offer a removal
if (query.length >= 13 && query.substring(query.length - 13, query.length - 3) == " filetype:") {
html += "remote the filter '" + query.substring(query.length - 12) + "'";
}
}
// add topic navigation
/*
if (topics && topics.length > 0) {
var topwords = "";
for (var i = 0; i < topics.elements.length; i++) {
topwords += "" + topics.elements[i].name + " ";
if (i > 10) break;
}
html += " topwords: " + topwords;
}
*/
return html;
}
function resultList() {
var html = "";
if (searchresult.length > 0) {
var item;
html += "
";
html += "
";
html += "
Protocol
";
html += "
Host
";
html += "
Path
";
html += "
Name
";
html += "
Size
";
//html += "
Description
";
html += "
Date
";
for (var i = 0; i < searchresult.length; i++) {
var item = searchresult[i];
html += resultLine(item);
}
html += "
";
}
return html;
}
function resultLine(item) {
var html = "";
p = item.link.indexOf("//");
protocol = "";
host = "";
path = item.link;
if (p > 0) {
q = item.link.indexOf("/", p + 2);
protocol = item.link.substring(0, p - 1);
host = item.link.substring(p + 2, q);
path = item.link.substring(q + 1);
}
if (path.length >= 40) path = path.substring(0, 18) + "..." + path.substring(path.length - 19);
html += "
";
title = item.title;
if (title == "") title = path;
if (title.length >= 60) title = title.substring(0, 28) + "..." + title.substring(title.length - 29);
html += "