27 |
|
|
28 |
function go(f) |
function go(f) |
29 |
{ |
{ |
30 |
var form = document.getElementById('search'); |
var form = document.getElementById('search'); |
31 |
var query = document.form.elements['query'].value; |
var query = null; |
32 |
var index_name = document.form.elements['index_name'].options[document.form.elements['index_name'].selectedIndex].value; |
if (form) query = form.elements['query'].value; |
33 |
|
|
34 |
if(!query) |
if(!query) |
35 |
{ |
{ |
36 |
return false; |
return false; |
37 |
} |
} |
38 |
|
|
39 |
if(query == null || query == "") |
if(query == null || query == "") |
40 |
{ |
{ |
41 |
alert("No search terms entered!"); |
alert("No search terms entered!"); |
42 |
return false; |
return false; |
43 |
} |
} |
44 |
|
|
45 |
var parsed_string = query.replace(/\s/gi,"+"); |
var parsed_string = query.replace(/\s/gi,"+"); |
46 |
//var url=location.host+location.pathname+"?search="+parsed_string; |
//var url=location.host+location.pathname+"?search="+parsed_string; |
47 |
var url=location.pathname+"?"; |
var url=location.pathname+"?"; |
48 |
if (index_name) url += "index_name="+index_name+"&"; |
if (index_name) url += "index_name="+index_name+"&"; |
49 |
url += "query="+parsed_string; |
url += "query="+parsed_string; |
50 |
location = url; |
location = url; |
51 |
|
|
52 |
return false; |
return false; |
|
} |
|
|
|
|
|
// Function to help find a "DIV" element |
|
|
function findDivHelper(n, id) |
|
|
{ |
|
|
for(var m=n.firstChild; m != null; m=m.nextSibling) |
|
|
{ |
|
|
if((m.nodeType == 1) && |
|
|
(m.tagName.toLowerCase() == "div") && |
|
|
m.getAttribute("id") && |
|
|
(m.getAttribute("id").toLowerCase() == id.toLowerCase() )) |
|
|
{ |
|
|
return m; |
|
|
} |
|
|
else |
|
|
{ |
|
|
var r=findDivHelper(m, id); |
|
|
if(r) return r; |
|
|
} |
|
|
} |
|
|
return null; |
|
53 |
} |
} |
54 |
|
|
55 |
// Function to find a specified "DIV" element by id |
// Function to find a specified "DIV" element by id |
56 |
function findDiv(id) |
function findDiv(id) |
57 |
{ |
{ |
58 |
return findDivHelper(document.body,id); |
return document.getElementById(id); |
59 |
} |
} |
60 |
|
|
61 |
// Print results to page |
// Print results to page |
62 |
function printResults(result) |
function printResults(result) |
63 |
{ |
{ |
64 |
//clearTimeout(watchdog_id); |
//clearTimeout(watchdog_id); |
65 |
//debug("clearTimeout = "+watchdog_id); |
//debug("clearTimeout = "+watchdog_id); |
66 |
debug("printResults("+result.length+")"); |
debug("printResults("+result.length+")"); |
67 |
|
|
68 |
var d = findDiv("results"); |
var d = findDiv("results"); |
69 |
var header; |
var status = findDiv("status"); |
70 |
|
|
71 |
// Null result output |
// Null result output |
72 |
if(result.length < 1) |
if(result.length < 1) |
73 |
{ |
{ |
74 |
header = (d.getElementsByTagName("h2"))[0].firstChild; |
if (status) status.innerHTML = "Nije pronašen niti jedan rezultat."; |
75 |
try { |
|
76 |
header.replaceData(0, 14, "Nothing Found "); |
if(search_err != "") |
77 |
} catch(e) {} |
{ |
78 |
|
e = document.createElement("font"); |
79 |
if(search_err != "") |
e.setAttribute("color","red"); |
80 |
{ |
e.setAttribute("size","+1"); |
81 |
e = document.createElement("font"); |
e.appendChild(document.createTextNode(search_err)); |
82 |
e.setAttribute("color","red"); |
d.appendChild(e); |
83 |
e.setAttribute("size","+1"); |
d.appendChild(document.createElement("br")); |
84 |
e.appendChild(document.createTextNode(search_err)); |
} |
85 |
d.appendChild(e); |
|
86 |
d.appendChild(document.createElement("br")); |
return; |
87 |
} |
} |
88 |
|
|
89 |
return; |
debug("sort results by title"); |
90 |
} |
results.sort(sortResults_title); |
91 |
|
|
92 |
debug("sort results by title"); |
// Add results to main document |
93 |
results.sort(sortResults_title); |
for(var i=result.length-1; i>=0; i--) |
94 |
|
{ |
95 |
// Add results to main document |
var li = document.createElement("li"); |
96 |
for(var i=result.length-1; i>=0; i--) |
|
97 |
{ |
var e = document.createElement("a"); |
98 |
var e = document.createElement("font"); |
e.setAttribute("href","hijerarhija.html?o="+result[i].link); |
99 |
|
var regex = new RegExp(/ *#C# */); |
100 |
e = document.createElement("a"); |
if (results[i].title.match(regex)) { |
101 |
e.setAttribute("href","hijerarhija.html?o="+result[i].link); |
e.appendChild(self.document.createTextNode(results[i].title.replace(regex,' '))); |
102 |
e.appendChild(document.createTextNode(result[i].title)); |
var pic = self.document.createElement("img"); |
103 |
d.appendChild(e); |
pic.src = 'img/crovoc.png'; |
104 |
d.appendChild(document.createTextNode(" ")); |
pic.border = 0; |
105 |
|
e.appendChild(pic); |
106 |
e = document.createElement("a"); |
} else { |
107 |
e.setAttribute("href","thes/"+result[i].link+".html"+location.search); |
e.appendChild(document.createTextNode(result[i].title)); |
108 |
//e.setAttribute("target","popup"); |
} |
109 |
//e.onclick = function() { return popup(); }; |
li.appendChild(e); |
110 |
e.onclick = popup; |
li.appendChild(document.createTextNode(" ")); |
111 |
e.appendChild(document.createTextNode("\u00bb")); |
|
112 |
d.appendChild(e); |
e = document.createElement("a"); |
113 |
|
e.setAttribute("href","thes/"+result[i].link+".html"+location.search); |
114 |
|
//e.setAttribute("target","popup"); |
115 |
|
//e.onclick = function() { return popup(); }; |
116 |
|
e.onclick = popup; |
117 |
|
var pic = self.document.createElement("img"); |
118 |
|
pic.src = 'img/listic.png'; |
119 |
|
pic.border = 0; |
120 |
|
e.appendChild(pic); |
121 |
|
li.appendChild(e); |
122 |
/* |
/* |
123 |
e = document.createElement("font"); |
e = document.createElement("font"); |
124 |
e.setAttribute("color","gray"); |
e.setAttribute("color","gray"); |
125 |
e.appendChild(document.createTextNode("["+result[i].frequency+"]")); |
e.appendChild(document.createTextNode("["+result[i].frequency+"]")); |
126 |
d.appendChild(e); |
li.appendChild(e); |
127 |
*/ |
*/ |
128 |
d.appendChild(document.createElement("br")); |
li.appendChild(document.createElement("br")); |
129 |
} |
d.appendChild(li); |
130 |
|
} |
131 |
// Change header |
|
132 |
header = (d.getElementsByTagName("h2"))[0].firstChild; |
if (status) status.innerHTML = "Pronašeno je "+results.length+" rezultata."; |
|
|
|
|
try { |
|
|
header.replaceData(0, 14, "Search Results"); |
|
|
} catch(e) {} |
|
133 |
|
|
134 |
} |
} |
135 |
|
|
136 |
// override default sort by frequency and sort by headline |
// override default sort by frequency and sort by headline |
137 |
function sortResults_title(a, b) |
function sortResults_title(a, b) |
138 |
{ |
{ |
139 |
return a.title.toLowerCase() == b.title.toLowerCase() ? 0 : ( a.title.toLowerCase() > b.title.toLowerCase() ? -1 : 1); |
return a.title.toLowerCase() == b.title.toLowerCase() ? 0 : ( a.title.toLowerCase() > b.title.toLowerCase() ? -1 : 1); |
140 |
} |
} |