
function formSearch(callerId)
{$j("input#"+callerId).css({backgroundImage:"url(/images/indicator.gif)",backgroundRepeat:"no-repeat",backgroundPosition:"right"});query=$j("input#"+callerId).attr("value");initSearch(query,function(data){$j("input#"+callerId).css('background','none');redirectSearch(data);});}
function quickSearch()
{$j("#location-search-preview #preview-results").hide();$j("#location-search-preview #status-indicator").show();if($j("#location-search-preview").css('display')=='none')
{$j("#location-search-preview").slideDown('normal');}
query=$j("#location-search input#search-input").attr("value");initSearch(query,previewSearch);}
function initSearch(query,callback)
{$j.getJSON('/ajax/initSearch.php',{search:encodeURI(query)},callback);}
function redirectSearch(data)
{window.location.assign('/search.php?search='+data.query);}
function previewSearch(data)
{$j("#location-search-preview #status-indicator").hide();if(data.perfect_match.length==1)
{var match=data.perfect_match[0];var gotoUrl=permalink(match)+'&search='+data.query;window.location.assign(gotoUrl);}
else
{if((data.perfect_match.length==0)&&(data.matches.length==0))
{$j("#location-search-preview #preview-results").html("Beklager, ingen treff.");}
else
{$j("#location-search-preview #preview-results").html("<ul></ul>");var displayed=0;$j.each(data.perfect_match,function(){if(displayed<5)
{var perma_link_segment=" <a href=\""+permalink(this)+"\">Permalenke</a>";var match_onclick="javascript:showMatch("+this.x+","+this.y+",'"+this.location+" "+this.location_id+this.location_sub_id.toLowerCase()+"');";var match_link_segment="<a class=\"hitlink\" href=\"#map-holder\" onclick=\""+
match_onclick+"\"><strong>"+
this.location+" "+this.location_id+this.location_sub_id.toLowerCase()+"</strong> &raquo; "+
this.type+"</a>"+"<a href=\"#map-holder\" onclick=\""+
match_onclick+"\">Vis i kart</a> | ";var priority_class='search-result-priority-one';$j("#location-search-preview #preview-results ul").append("<li class=\""+
priority_class+"\">"+
match_link_segment+
perma_link_segment+"</li>");displayed++;}});$j.each(data.matches,function(){if(displayed<5)
{if(this.type.length<1)
{this.type='Gate/vei';}
var perma_link_segment=" <a href=\""+permalink(this)+"\">Permalenke</a>";var match_onclick="javascript:showMatch("+this.x+","+this.y+",'"+this.location+" "+this.location_id+this.location_sub_id.toLowerCase()+"');";var match_link_segment="<a class=\"hitlink\" href=\"#map-holder\" onclick=\""+
match_onclick+"\">"+
this.location+" "+this.location_id+this.location_sub_id.toLowerCase()+" &raquo; "+
this.type+"</a>"+"<a href=\"#map-holder\" onclick=\""+
match_onclick+"\">Vis i kart</a> | ";var priority_class='search-result-priority-three';if(this.source=='place_search')priority_class='search-result-priority-two';$j("#location-search-preview #preview-results ul").append("<li class=\""+
priority_class+"\">"+
match_link_segment+
perma_link_segment+"</li>");displayed++;}});if(data.number_of_matches>displayed)
{$j("#location-search-preview #preview-results").append("<a href=\"/search.php?search="+data.query+"\">Se "+(data.number_of_matches-displayed)+" flere treff</a>");}}}
$j("#location-search-preview, #preview-results").show();}
function permalink(match)
{var retVal='/index.php'+'?x='+match.y+'&y='+match.x+'&markers='+match.y+','+match.x+'&zoom=4';return retVal;}
function showMatch(x,y,location)
{map.clearAnnotations();var coord=new Coordinate(y,x);map.centerAndZoom(coord,map.getZoomLevel());current_marker=map.addAnnotation(new Annotation(coord,"<strong>"+location+"</strong>",'','http://img.derdubor.no/img/hvor/map_ui/marker.gif',-17,-34,0,12));current_markers=x+','+y;}