--- trunk2/eurovoc/js/usage.js 2004/10/18 17:59:37 517 +++ trunk2/eurovoc/js/usage.js 2004/10/19 16:15:13 527 @@ -27,131 +27,115 @@ function go(f) { - var form = document.getElementById('search'); - var query = null; - if (document.form.elements['query']) query = document.form.elements['query'].value; - var index_name = document.form.elements['index_name'].options[document.form.elements['index_name'].selectedIndex].value; - - if(!query) - { - return false; - } - - if(query == null || query == "") - { - alert("No search terms entered!"); - return false; - } - - var parsed_string = query.replace(/\s/gi,"+"); - //var url=location.host+location.pathname+"?search="+parsed_string; - var url=location.pathname+"?"; - if (index_name) url += "index_name="+index_name+"&"; - url += "query="+parsed_string; - location = url; + var form = document.getElementById('search'); + var query = null; + if (document.form.elements['query']) query = document.form.elements['query'].value; + var index_name = document.form.elements['index_name'].options[document.form.elements['index_name'].selectedIndex].value; + + if(!query) + { + return false; + } + + if(query == null || query == "") + { + alert("No search terms entered!"); + return false; + } + + var parsed_string = query.replace(/\s/gi,"+"); + //var url=location.host+location.pathname+"?search="+parsed_string; + var url=location.pathname+"?"; + if (index_name) url += "index_name="+index_name+"&"; + url += "query="+parsed_string; + location = url; - 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; + return false; } // Function to find a specified "DIV" element by id function findDiv(id) { - return findDivHelper(document.body,id); + return document.getElementById(id); } // Print results to page function printResults(result) { - //clearTimeout(watchdog_id); - //debug("clearTimeout = "+watchdog_id); - debug("printResults("+result.length+")"); - - var d = findDiv("results"); - var header; - - // Null result output - if(result.length < 1) - { - header = (d.getElementsByTagName("h2"))[0].firstChild; - try { - header.replaceData(0, 14, "Nothing Found "); - } catch(e) {} - - if(search_err != "") - { - e = document.createElement("font"); - e.setAttribute("color","red"); - e.setAttribute("size","+1"); - e.appendChild(document.createTextNode(search_err)); - d.appendChild(e); - d.appendChild(document.createElement("br")); - } - - return; - } - - debug("sort results by title"); - results.sort(sortResults_title); - - // Add results to main document - for(var i=result.length-1; i>=0; i--) - { - var e = document.createElement("font"); - - e = document.createElement("a"); - e.setAttribute("href","hijerarhija.html?o="+result[i].link); - e.appendChild(document.createTextNode(result[i].title)); - d.appendChild(e); - d.appendChild(document.createTextNode(" ")); - - e = document.createElement("a"); - e.setAttribute("href","thes/"+result[i].link+".html"+location.search); - //e.setAttribute("target","popup"); - //e.onclick = function() { return popup(); }; - e.onclick = popup; - e.appendChild(document.createTextNode("\u00bb")); - d.appendChild(e); + //clearTimeout(watchdog_id); + //debug("clearTimeout = "+watchdog_id); + debug("printResults("+result.length+")"); + + var d = findDiv("results"); + var status = findDiv("status"); + + // Null result output + if(result.length < 1) + { + if (status) status.innerHTML = "Nije pronašen niti jedan rezultat."; + + if(search_err != "") + { + e = document.createElement("font"); + e.setAttribute("color","red"); + e.setAttribute("size","+1"); + e.appendChild(document.createTextNode(search_err)); + d.appendChild(e); + d.appendChild(document.createElement("br")); + } + + return; + } + + debug("sort results by title"); + results.sort(sortResults_title); + + // Add results to main document + for(var i=result.length-1; i>=0; i--) + { + var li = document.createElement("li"); + + var e = document.createElement("a"); + e.setAttribute("href","hijerarhija.html?o="+result[i].link); + var regex = new RegExp(/ *\* */); + if (results[i].title.match(regex)) { + e.appendChild(self.document.createTextNode(results[i].title.replace(regex,' '))); + var pic = self.document.createElement("img"); + pic.src = 'img/crovoc.png'; + pic.border = 0; + e.appendChild(pic); + } else { + e.appendChild(document.createTextNode(result[i].title)); + } + li.appendChild(e); + li.appendChild(document.createTextNode(" ")); + + e = document.createElement("a"); + e.setAttribute("href","thes/"+result[i].link+".html"+location.search); + //e.setAttribute("target","popup"); + //e.onclick = function() { return popup(); }; + e.onclick = popup; + var pic = self.document.createElement("img"); + pic.src = 'img/listic.png'; + pic.border = 0; + e.appendChild(pic); + li.appendChild(e); /* - e = document.createElement("font"); - e.setAttribute("color","gray"); - e.appendChild(document.createTextNode("["+result[i].frequency+"]")); - d.appendChild(e); + e = document.createElement("font"); + e.setAttribute("color","gray"); + e.appendChild(document.createTextNode("["+result[i].frequency+"]")); + li.appendChild(e); */ - d.appendChild(document.createElement("br")); - } - - // Change header - header = (d.getElementsByTagName("h2"))[0].firstChild; - - try { - header.replaceData(0, 14, "Search Results"); - } catch(e) {} + li.appendChild(document.createElement("br")); + d.appendChild(li); + } + + if (status) status.innerHTML = "Pronašeno je "+results.length+" rezultata."; } // override default sort by frequency and sort by headline function sortResults_title(a, b) { - 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); }