var RESULT_COLUMNS = 3; var REQUEST_COUNTER = 0; var timer = 0; function dynamicSearch () { clearTimeout(timer); timer = setTimeout('execDynamicSearch()', 500); } function execDynamicSearch() { if($( "search_string" )){ var el = $( "search_string" ); var text = el.value; var statusMonitor = $( "statusMonitor" ); } if($( "search_language" )){ var lang = $( "search_language" ); lang = lang.value //if(lang == 'NB') { //var pageTrackerSrc = _gat._getTracker("UA-4865559-1"); //pageTrackerSrc._trackPageview('http://medinor.no/wsp/medinor2/frontend.cgi?func=search.ajax_search&input=' + text); //} } var container = $( 'top-group' ); if ( container == undefined ) { return; } var monitor = $( 'ajax_monitor' ); if ( monitor == undefined ) { // this is the first call to the search monitor = new Element( 'div',{id:'ajax_monitor'} ); container.insert({'after':monitor}); } if ( text.length < 1 || text=='Søg efter produkt her') { // first call when page loaded return; } else if ( text.length < MIN_SEARCH_CHAR ) { // clear the result panel if the search string is too short clear( monitor ); // kill any ongoing request if any ++REQUEST_COUNTER; // reset the background color of the input el.style.backgroundColor='#ffffff'; statusMonitor.innerHTML = ''; return; } else { statusMonitor.innerHTML = 'Søger efter '+ text +', Venligst vent...'; } var thisCounter = ++REQUEST_COUNTER; var handler = function( hreq ) { if ( REQUEST_COUNTER != thisCounter ) { return; } var json = hreq.responseText.split( '__boundary__' );// This is a hack to remove the comments added by $wo in the response var data = eval("(" + json[1] + ")"); clear( monitor ); if ( data[0] == undefined ) { // nothing found el.style.backgroundColor='#ff9999'; statusMonitor.innerHTML = 'Søg efter '+ text +' gav ingen resultater.'; return; } else { el.style.backgroundColor='#ffffff'; } var bc_path = document.createElement('p'); bc_path.className = 'path'; bc_path.appendChild( document.createTextNode( "Du er her > Søgeresultat > '"+text+"'" ) ); monitor.appendChild( bc_path ); var title = document.createElement( 'h1' ); title.className = 'result_title'; title.appendChild( document.createTextNode( 'Søgeresultat' ) ); monitor.appendChild( title ); var t = document.createElement( 'table' ); monitor.appendChild( t ); monitor.appendChild( document.createElement('br') ); var colNumber = RESULT_COLUMNS; if ( colNumber > data.length ) { // don't make more columns that it is needed colNumber = data.length; } displaySearchResult( statusMonitor, text, data, t, colNumber ); // make the home page banner smaller var banner = $('top_menu'); if ( undefined != banner ) { banner.className = 'top_menu'; } } var url = URL_BASE + 'func=search.ajax_search&input='+ text; new Ajax.Request( url, { onSuccess: handler } ); } function displaySearchResult ( statusMonitor, text, data, table, columns ) { // Build a table containing the search results addHeaders( table, columns ); var totalHits = 0; var tr; for ( var i=0; data[i] != undefined; ++i ) { var row = data[i]; if ( i % columns == 0 ) { tr = table.insertRow(-1); } var a = document.createElement( 'a' ); a.innerHTML = row.TXT; a.href = URL_SEARCH + '&input='+ text +'&category='+ row.CATEGORYNU +'&categoryname='+ row.TXT +'#'+ PROD_LISTING; var catCell = tr.insertCell(-1); catCell.className = 'category'; catCell.appendChild( a ); var numCell = tr.insertCell(-1); numCell.className = 'number'; numCell.appendChild( document.createTextNode('('+ row.COUNT +')') ); totalHits += parseInt(row.COUNT); } if ( (i % columns) != 0 ) { // we need to complete the last row with empty cells var emptyCells = columns - (i % columns); for ( var ii=0; ii < emptyCells; ++ii ) { var dummy1 = tr.insertCell(-1); dummy1.className = 'category'; var dummy2 = tr.insertCell(-1); dummy2.className = 'number'; } } statusMonitor.innerHTML = totalHits +' produkter matcher '+ text +''; var prodListContainer = $(PROD_LISTING); if ( undefined != prodListContainer && undefined != prodListContainer.firstChild) { // so that we get to the #prod_listing only when there actually are products document.location = document.location; } } function addHeaders ( table, columns ) { var tr = table.insertRow(-1); for ( var i=0; i'; }