// ===============================================================
// CBkort version 2.x, copyright Carl Bro GIS&IT, 2006
// ===============================================================
// $Archive: /Products/CBKort2/development/2.6/standard/wwwroot/WEB-INF/config/modules/standard/spatialquery/js/leftbarsq.js $ 
// $Date: 25-03-11 18:31 $
// $Revision: 29 $ 
// $Author: Nsm $
// =============================================================== 



var leftbarsq_reportoption = true;

function leftbarsq_showQueryresult (queryurl, searchText, hidereportoptions, hidesearchimage)
{
    // Mulighed for at undlade rapportvisning
    if(hidereportoptions)
    {  leftbarsq_reportoption = false;
    }


    getElement('resutltab_content').innerHTML = leftbarsq_generateHTML_headergroup ('searchelement', leftbarsq_generateHTML_searchHeader(searchText,true) );
    leftbartabs_tabClickGo('leftbartabs_resultat');
    contentContainer_visible = false;
    leftbarsq_setContentContainer(true);

    spatialquery_currentQueryResult = spatialquery_getQueryResult (queryurl, searchText);
    if(spatialquery_currentQueryResult)
    {
        spatialquery_currentQueryResult.searchImgHide = hidesearchimage;
        getElement('resutltab_content').innerHTML = leftbarsq_generateHTML(spatialquery_currentQueryResult);
    }
    else
    {
        var h = leftbarsq_generateHTML_headergroup ('searchelement', leftbarsq_generateHTML_searchHeader(searchText) );
        getElement('resutltab_content').innerHTML = h;
    }
}


function leftbarsq_generateHTML(queryResult)
{
    var padding = 0;
    if(ie)
        padding += 17;
    var t = '';
    t = leftbarsq_generateHTML_searchHeader(queryResult.searchText);
    
    var resultHtml = '';
    resultHtml += leftbarsq_generateHTML_headergroup('heading',t);
    resultHtml += '<div class="resultlistheader">';
    var padding = 20;
    if(ie)
        padding += 17;
    resultHtml += '<table style="width:100%"><tr><td>' + cbInfo.getString('spatialquery.results') + ':</td><td style="width:5px;padding-right:2px;padding-right:'+padding+'px;"><a href="javascript:leftbarsq_showAll();" style="font-size:8pt;text-decoration: none;"><img class="resultinfoimg" onmouseover="showHint(event,\'' + cbInfo.getString("spatialquery.show_all_details")+ '\');" onmouseout="hideHint();" src="/modules/spatialquery/images/info.gif"/></a></td></tr></table>';
    resultHtml += '</div>';
    
    for(var i=0;i<queryResult.targets.length;i++)
    {
        var display = 'block';

        if(!queryResult.targets[i].expand)
        {  display = 'none';
        }
        
        var hitCountText = "";
        
        if (queryResult.targets[i].warning == 'queryerror')
        {  hitCountText = '(' + cbInfo.getString('standard.error.error') +  ')';
        }
        else if(queryResult.targets[i].warning == 'maxresulterror')
        {  
           hitCountText = '(' + queryResult.targets[i].n + '+)';
        }
        else
        {  
           hitCountText = '(' + queryResult.targets[i].n + ')';
        }
            
        var text = queryResult.targets[i].heading + ' <span class="themegrouplabel_count">' + hitCountText +  '</span>';
        var hint = queryResult.targets[i].heading + ' ' + hitCountText;
        resultHtml += leftbarsq_generateHTML_group(i,text,hint);
        resultHtml += '<div id="div_qresult'+i+'" style="display:'+display+';">';
        
        if (queryResult.targets[i].warning == 'queryerror')
        {
           resultHtml += "<i>'" + cbInfo.getString('spatialquery.error.theme_not_queried') + "'</i>";
        }
        else
        {
           for(var j=0;j<queryResult.targets[i].targetHits.length;j++)
           {
               var heading = queryResult.targets[i].targetHits[j].listHeading;
               var pcolid = queryResult.targets[i].targetHits[j].orgPcolid;
               var geometryType = queryResult.targets[i].targetHits[j].geometryType;
            
               resultHtml += leftbarsq_generateHTML_element(queryResult.targets[i].targetHits[j],i+'_'+j);
           }
           resultHtml += '</div>';
        }   
    }
    return resultHtml;
}


//********************************************//
//  Genererer indhold i overskriftselementet  //
//********************************************//
function leftbarsq_generateHTML_searchHeader(searchText,loading)
{
    var t = '';
    t += '  <div style="width:146px;">';
    t += '    <table style="width:100%">';
    t += '      <tr>';
    t += '        <td style="padding-right:0px;padding-left:0px;">';
    t += '          <div style="display:inline;">' + cbInfo.getString('spatialquery.you_have_queried_by') + ' ' + searchText + '</div>';
    t += '        </td>';
    t += '        <td style="width:5px;padding-right:2px;padding-left:2px;" class="themenametexttd">';
    if (loading) {
        t += '          <div style="display:inline" class="resultitem"><div class="resultitemloading"></div></div>';
    } else {
        t += '          <div style="display:inline" class="resultitem"><a href="javascript:spatialquery_showSearchElementInMap();leftbarsq_closeWin();" style="font-size:8pt;text-decoration: none;"><img onmouseover="showHint(event,\'' + cbInfo.getString("spatialquery.locate_in_map", searchText) + '\');" onmouseout="hideHint();" style="text-decoration: none;border:1px solid #C8C8C8;padding:1px;" src="/modules/spatialquery/images/visikort.gif"/></a></div>';
    }
    t += '        </td>';
    t += '      </tr>';
    t += '    </table>';
    t += '  </div>';
    return t;
}


//********************************************//
//  Genererer overskriftselementet            //
//********************************************//
function leftbarsq_generateHTML_headergroup(id,text)
{
    var h = '';
    h += '<div class="searchheadertext">';
    h += '  <span id="lbl_qresult'+id+'" style="position:relative;top:-1px;margin-left:0px;">'+text+'</span>';
    h += '</div>';
    return h;
}
//********************************************//
//  Genererer resultatgrupperne               //
//********************************************//
function leftbarsq_generateHTML_group(id,text,hint)
{
    var h = '';
    h += '<div class="themegroupname">';
    h += '  <span id="lbl_qresult'+id+'" class="themegrouplabel" onmouseover="themeGroupMouseEvent.mouseoverevent(event,this,\''+hint+'<br/>' + cbInfo.getString("spatialquery.fold_undfold_group") +'\');" onmouseout="themeGroupMouseEvent.mouseoutevent(this);" onclick="treeClick(this);">'+text+'</span>';
    h += '</div>';
    return h;
}


//********************************************//
//  Genererer listen af reslutater            //
//********************************************//
function leftbarsq_generateHTML_element(targetHit,id,text)
{
    var mouseoverText = '';
    var showmap = false;
    var showSearchElement = false;
    var geometrytype = '';
    var showinfo = false;
    var targetId;
    var targetHitId;
    var displaybuffer = '';
    var dynamiclayer = '';
    if(!targetHit)
    {
       showSearchElement = true;
    }
    else
    {
        showinfo = true;
        var prop = targetHit.getProperty('description');
        if(prop)
            mouseoverText = 'onmouseover="doMouseOverInfo(event,\''+prop+'\');" onmouseout="doMouseOutInfo();"';
        if(targetHit.orgPcolid)
        {
            showmap = targetHit.orgPcolid;
            geometrytype = targetHit.geometryType;
        }
        text = targetHit.listHeading || '-';
        var idsplit = id.split('_');
        targetId = idsplit[0];
        targetHitId = idsplit[1];

        prop = targetHit.getProperty('displaybuffer');
        if(prop)
            displaybuffer = prop;
    }
    
   
    if (showinfo || showmap)
    {  // Split first word if it is to long to prevent the icons from disapearing

       var maxWordLength = cbInfo.getParam("module.spatialquery.result.maxwordlength");
       
       if (maxWordLength!=null && maxWordLength!="")
       {
          var i = 0;
          var h = 0;
          while (text!=null && i<text.length)
          {  i++;
             h++;
             
             if (text.charAt(i)==' ')
             {  h = 0;
             }
             else
                if (h>maxWordLength)
                {  // Split
                   var s = text.substring (0, i-1);
                   s += "-<br/>";
                   s += text.substring(i-1);
                   text = s;
                   h=0;
                   i += 6;
                }
          }
       }   
    }    
    

    var padding = 10;
    if(ie)
        padding = 15;
    
    var h = '';
    h += '  <div class="themelayername" style="padding-right:'+padding+'px;width:151px;">';
    h += '    <table style="width:100%">';
    h += '      <tr>';
    h += '        <td style="padding-right:3px;padding-left:5px;" class="themenametexttd" '+mouseoverText+'>';
    h += '          <div style="display:inline;">'+text+'</div>';
    h += '        </td>';
    if(showSearchElement)
    {
        h += '        <td style="width:5px;padding-right:2px;padding-left:2px;" class="themenametexttd">';
        h += '          <div style="display:inline"><a href="javascript:spatialquery_showSearchElementInMap();leftbarsq_closeWin();" style="font-size:8pt;text-decoration: none;"><img class="resultkortimg" onmouseover="showHint(event,\'' + cbInfo.getString('spatialquery.locate_in_map_2') + '\');" onmouseout="hideHint();" src="/modules/spatialquery/images/visikort.gif"/></a></div>';
        h += '        </td>';
    }
    if(showinfo)
    {
        var func = 'leftbarsq_showDetail('+targetId+','+targetHitId+')';
        var prop = targetHit.getProperty('infourl');
        if(prop)
            func = 'leftbarsq_showDetailUrl(\''+prop+'\')';
        prop = targetHit.getProperty('nodetail_javascriptlink');
        if(prop)
            func = prop;
        h += '        <td style="width:5px;padding-right:2px;padding-left:2px;" class="themenametexttd">';
        h += '          <div style="display:inline"><a href="javascript:'+ func +';" style="font-size:8pt;text-decoration: none;"><img class="resultinfoimg" onmouseover="showHint(event,\'' + cbInfo.getString('spatialquery.show_more_info') + '\');" onmouseout="hideHint();" src="/modules/spatialquery/images/info.gif"/></a></div>';
        h += '        </td>';
    }
    if(showmap)
    {
        h += '        <td style="width:5px;padding-right:2px;padding-left:2px;" class="themenametexttd">';
        h += '          <div style="display:inline"><a href="javascript:spatialquery_showInMap(\''+showmap+'\',\''+displaybuffer+'\');leftbarsq_closeWin();" style="font-size:8pt;text-decoration: none;"><img class="resultkortimg" onmouseover="showHint(event,\'' + cbInfo.getString('spatialquery.locate_in_map_2') + '\');" onmouseout="hideHint();" src="/modules/spatialquery/images/visikort.gif"/></a></div>';
        h += '        </td>';
    }
    else
    {
        h += '        <td style="width:5px;padding-right:2px;padding-left:2px;" class="themenametexttd">';
        h += '          <div style="display:inline;visibility:hidden;"><img style="text-decoration: none;border:1px solid #C8C8C8;padding:1px;" src="/modules/spatialquery/images/visikort.gif"/></div>';
        h += '        </td>';
    }
    h += '      </tr>';
    h += '    </table>';
    h += '  </div>';

    return h;
}

//********************************************//
//  Vis all detaljer                          //
//********************************************//
function leftbarsq_showAll()
{
    var queryResult = spatialquery_currentQueryResult;
    var html = '';
    // Mulighed for at undlade rapportvisning
    if(leftbarsq_reportoption)
    {
        html+= '<div id="leftbarsq_show_report_div" class="queryresult_show_report">';
        html+= '  <table style="width:100%;">';
        html+= '    <tr align="left">';
        html+= '      <td class="spacertab"></td>';
        html+= '      <td class="buttontab"><div class="activetab" id="leftbarsq_overview_tab" onClick="leftbarsq_showListDiv();"><span id="leftbarsq_overview_tab_text">' + cbInfo.getString('spatialquery.overview') + '</span></div></td>';
        html+= '      <td class="spacertab"></td>';
        html+= '      <td class="buttontab"><div class="passivetab" id="leftbarsq_report_tab" onClick="leftbarsq_showReportDiv();"><span  id="leftbarsq_report_tab_text">' + cbInfo.getString('spatialquery.report') + '</span></div></td>';
        html+= '      <td class="endspacertab"></td>';
        html+= '    </tr>';
        html+= '  </table>';
        html+= '</div>';

        html+= '<div class="reportcontent_div" id="reportdiv" style="width:100%;display:none">';
        html+= '  <table style="width:100%">';
        html+= '    <tr>';
        html+= '      <td colspan="2">Format:</td>';

        html+= '    </tr>';
        html+= '    <tr>';
        html+= '      <td colspan="2">';
        html+= '        <select id="reportpage" name="reportpage">';
        html+= '          <option value="spatialquery-report-html" selected="selected">' + cbInfo.getString('spatialquery.report.chooseformat') + '</option>';
        html+= '          <option value="spatialquery-report-html">' + cbInfo.getString('spatialquery.report.htmlreport') + '</option>';
        html+= '          <option value="spatialquery-pdf-overview">' + cbInfo.getString('spatialquery.report.pdfoverviewreport') + '</option>';
        html+= '          <option value="spatialquery-pdf">' + cbInfo.getString('spatialquery.report.pdfdetailreport') + '</option>';
        html+= '          <option value="spatialquery-xls">' + cbInfo.getString('spatialquery.report.excelreport') + '</option>';
        html+= '        </select>';

        html+= '      </td>';
        html+= '    </tr>';
        html+= '    <tr>';
        html+= '      <td colspan="2"><input type="checkbox" name="leftbarsq_includeheader" id="leftbarsq_includeheader" value="includeheader_value" checked="true"/>' + cbInfo.getString('spatialquery.report.useheaderpage');
        html+= '      <button id="reportbutton" class="menubutton" style="margin-left:50px;" onclick="leftbarsq_printReport();">' + cbInfo.getString("spatialquery.report.button.showreport") + '</button></td>';
        html+= '    </tr>';

        html+= '    <tr>';
        html+= '      <td colspan="2">' + cbInfo.getString('spatialquery.content') + ':</td>';

        for(var a=0;a<queryResult.targets.length;a++)
        {
            html+= '    <tr>';
            html+= '      <td colspan="2">';
            html+= '        <input type="checkbox" id="leftbarsq_reportelement_targetnumber_'+ queryResult.targets[a].targetnumber + '" checked="checked"/>';
            html+= '        '+queryResult.targets[a].heading+' ('+queryResult.targets[a].targetHits.length+')';
            html+= '      </td>';
            html+= '    </tr>';
        }

        html+= '  </table>';
        html+= '</div>';

        html+= '<div class="reportcontent_div" id="helpdiv" style="width:100%;display:none">';
        html+= cbInfo.getString('spatialquery.all_reports_opens_in_a_new_window') + '</div>';
    }
    // Genererer html for de enkelte hits
    html+= '<div id="listdiv" style="width:100%;">';
    for(var a=0;a<queryResult.targets.length;a++)
    {
        if(queryResult.targets[a].targetHits.length > 0)
            html += '<span class="queryresult_detailgroup_header">'+queryResult.targets[a].heading+'</span>';
        for(var b=0;b<queryResult.targets[a].targetHits.length;b++)
        {
            html += leftbarsq_getHtml(a,b,true);
            html += '</br></br>';
        }
    }
    html+= '</div>';
    // Add html to contentContainer
    //contentContainer_showContent(html);
    leftbarsq_showWin (html);

    getReportselector(getElement('reportpage'));
    
    // set default tab
    if(leftbarsq_reportoption)
    {
    	leftbarsq_detailTabSetPassive(getElement("leftbarsq_report_tab"));
    	leftbarsq_detailTabSetPassive(getElement("leftbarsq_help_tab"));
    	leftbarsq_detailTabSetActive(getElement("leftbarsq_overview_tab"));
    }
    
    var totalcount = 0;
    var count = 0;
    for(var a=0;a<queryResult.targets.length;a++)
        totalcount += queryResult.targets[a].targetHits.length;
    // Danner og sætter billederne for de enkelte hits
    showWaitingBox( cbInfo.getString('standard.message.getting_data') + '...');
    queryResult.lasthit = false;
    
    var maxImages = parseInt(cbInfo.getParam('module.spatialquery.map.max'));
    if(!maxImages)
        maxImages = 1000;
        
    if(maxImages<totalcount)
        totalcount = maxImages;
    
    for(var a=0;a<queryResult.targets.length;a++)
    {
        for(var b=0;b<queryResult.targets[a].targetHits.length;b++)
        {
            count++;
            if(count<=maxImages)
                setTimeout("leftbarsq_showImages("+a+","+b+",true,"+count+","+totalcount+")",(b+1)*250);
        }
    }
    //hideWaitingBox();
}

//********************************************//
//  Vis detaljer for et hit                   //
//********************************************//
function leftbarsq_showDetail(targetId,targetHitId)
{
    var queryResult = spatialquery_currentQueryResult;
    var html = leftbarsq_getHtml(targetId,targetHitId,queryResult.searchImgHide);
//    contentContainer_showContent(html);
    leftbarsq_showWin (html);
    showWaitingBox(cbInfo.getString('standard.message.getting_data') + '...');
    setTimeout("leftbarsq_showImages("+targetId+","+targetHitId+","+queryResult.searchImgHide+")" ,1);
}

var leftbarsq_winactive = false;
var leftbarsq_win = null;
function leftbarsq_showWin (html) {
    if (leftbarsq_win == null) {
        leftbarsq_win = new OverlayWindow( {headertype: 'toolbar',layout:'map'} ); 
        var mytools = [ {label: cbInfo.getString('standard.misc.map'), onclick: leftbarsq_closeWin},
                        {label: cbInfo.getString('standard.misc.print'), onclick: leftbarsq_printDetail}];
        leftbarsq_win.loadToolbarButtons (mytools);
    }
    leftbarsq_winactive = true;
    leftbarsq_win.setContent('<div id="contentContainer_content" style="color:#000000;position:relative;left:5px;top:5px;right:5px;bottom:5px;">'+html+'</div>');
//    leftbarsq_win.setContent('<div style="padding:5px;"><div style="padding:0px;">'+html+'</div></div>');
//    leftbarsq_win.setContent(html);
}
function leftbarsq_closeWin () {
    leftbarsq_winactive = false;
    if (leftbarsq_win) {
        leftbarsq_win.hide ();
    }
}

//********************************************//
//  Vis detaljer for et hit (HTML)            //
//********************************************//
function leftbarsq_getHtml(targetId,targetHitId,hideSearchImg)
{
    var targetHit = spatialquery_getQueryResultTargetHit(targetId, targetHitId);
    var queryResult = spatialquery_currentQueryResult;
    var img = '<table class="detailed_view_table"><tr>';

    var showselectorimage = targetHit.getProperty('showselectorimage');
    showselectorimage = showselectorimage ? showselectorimage.toLowerCase() : 'true';

    if(showselectorimage=='true')
        img += '<td><img id="detailed_view_searchimg_'+targetId+'_'+targetHitId+'" style="border: 1px solid #000000;" src="/images/standard/1x1.gif"/></td>';

    var showdetailimage = targetHit.getProperty('showdetailimage');
    showdetailimage = showdetailimage ? showdetailimage.toLowerCase() : 'true';
    if(showdetailimage!='false')
    {
        if(targetHit.orgPcolid)
            img += '<td style="width:100%"><img id="detailed_view_hitimg'+targetId+targetHitId+'" style="border: 1px solid #000000;" src="/images/standard/1x1.gif"/></td>';
    }
    img += '</tr><tr>';
    if(showselectorimage=='true')
        img += '<td>' + queryResult.searchText + '</td>';
    if(!targetHit.hitImageLabel)
        targetHit.hitImageLabel = targetHit.detailHeading;
    if(showdetailimage!='false')
    {
        if(targetHit.orgPcolid)
            img += '<td>' + targetHit.hitImageLabel + '</td>';
    }
    img += '</tr></table>';

    var s = '<table class="detailed_view_table"><tr><td colspan="2" class="heading3td">'+targetHit.detailHeading+'</td></tr>';
    var link = '<table class="detailed_view_table">';
    var hitcount = 0;
    for(var r=0;r<targetHit.values.length;r++)
    {
        if(targetHit.values[r].format == 'hyperlink')
        {
            link += '<tr><td><a target="_blank" href="'+targetHit.values[r].value+'">'+targetHit.values[r].label+'</a></td></tr>';
        }
        else if(targetHit.values[r].format == 'javascriptlink')
        {
            link += '<tr><td><a href="javascript:'+targetHit.values[r].value+'">'+targetHit.values[r].label+'</a></td></tr>';
        }
        else if(targetHit.values[r].format == 'image')
        {
            link += '<tr><td colspan="2"><img src="'+targetHit.values[r].value+'" alt="'+targetHit.values[r].label+'" title="'+targetHit.values[r].label+'"/></td></tr>';
        }
        else
        {
            var tdclass = 'detailed_view_td_uneq';
            if(hitcount % 2)
                tdclass = 'detailed_view_td_eq';
            s += '<tr class="'+tdclass+'"><td>'+targetHit.values[r].label+'</td><td style="width:100%;border-left:3px solid #FFFFFF;">' +targetHit.values[r].value+'</td></tr>';
            
            hitcount++;
        }
    }
    
    s+='</table>';
    link+='</table>';

    return s+link+img;
}

//********************************************//
//  Vis detaljer for et hit (IMAGES)          //
//********************************************//
function leftbarsq_showImages (targetId, targetHitId, hideSearchImg, count, totalcount)
{
    var targetHit   = spatialquery_getQueryResultTargetHit (targetId, targetHitId);
    var queryResult = spatialquery_currentQueryResult;
    
    var request = new CBhttp();

    // Create new temp. cbmap session
    var sesPCol       = request.executeUrl (cbKort.getServletUrl() + "?page=spatialquery-create-session", false);   
    var tempSessionId = sesPCol.get(0).column("sessionid").getValue();

    var showselectorimage = 'true';

    if(!hideSearchImg)
    {
        showselectorimage = targetHit.getProperty('showdetailimage');
        showselectorimage = showselectorimage ? showselectorimage.toLowerCase() : 'true';
    }
    if(showselectorimage == 'true')
    {
        if(!queryResult.searchImgSmall)
        {
            var mapsize = cbInfo.getParam('module.spatialquery.map.size');
            mapsize = (mapsize != '' && mapsize != null ? mapsize : '250 250');
            var propmapsize = targetHit.getProperty('mapsize');
            mapsize = propmapsize ? propmapsize : mapsize;
            var displaybuffer = targetHit.getProperty('displaybuffer');
            displaybuffer = displaybuffer ? displaybuffer.toLowerCase() : cbInfo.getParam("cbinfo.map.displaybuffer");

            var url = cbKort.getServletUrl();
            url += "?page=spatialquery-get-map-from-pcol";
            url += "&sessionid=" + tempSessionId;
            url += "&profile=" + cbKort.getProfile();
            url += "&pcollectionid=" + targetHit.orgPcolid;
            url += "&geometrycolumn=selector_geo";
            url += "&dynamiclayer=smalluser*search";
            url += "&sourcesessionid=" + cbKort.getSessionId();
            url += "&map_size=" + mapsize;
            url += "&displaybuffer=" + displaybuffer;

            var pcol = request.executeUrl (url, false);   

            queryResult.searchImgSmall = pcol.get(0).getValue();
        }
        var searchimgURL = '/tmp/'+queryResult.searchImgSmall;
        var searchimg = getElement('detailed_view_searchimg_'+targetId+'_'+targetHitId);
        if(searchimg)
        {
            if(searchimg.src != searchimgURL)
            {   searchimg.src = searchimgURL;
            }
        }
    }
    var showdetailimage = targetHit.getProperty('showdetailimage');
    showdetailimage = showdetailimage ? showdetailimage.toLowerCase() : 'true';
    if(showdetailimage!='false')
    {
        if(targetHit.orgPcolid)
        {
            if(!targetHit.hitImage)
            {
                var showdetailimagewithselector = targetHit.getProperty('showdetailimagewithselector');
                showdetailimagewithselector = showdetailimagewithselector ? showdetailimagewithselector.toLowerCase() : 'true';

                if(showdetailimagewithselector == 'true')
                {
                    var url = cbKort.getServletUrl();
                    url += "?page=spatialquery-add-dynamiclayer-from-pcol";
                    url += "&sessionid=" + tempSessionId;
                    url += "&pcolid=" + targetHit.orgPcolid;
                    url += "&geometrycolumn=selector_geo";
                    url += "&dynamiclayer=smalluser*search";
                    url += "&sourcesessionid=" + cbKort.getSessionId();
                    url += "&savename=last_sq_result";
    
                    request.executeUrl (url, true);
                }
                else
                {
                    var url = cbKort.getServletUrl();
                    url += "?page=spatialquery-remove-dynlayers";
                    url += "&sessionid=" + tempSessionId;
                    url += "&dynamiclayer=smalluser*search";
    
                    request.executeUrl (url, true);
                }

                var mapsize = cbInfo.getParam('module.spatialquery.map.size');
                mapsize = (mapsize != '' ? mapsize : '250 250');
                var propmapsize = targetHit.getProperty('mapsize');
                mapsize = propmapsize ? propmapsize : mapsize;
                var displaybuffer = targetHit.getProperty('displaybuffer');
                displaybuffer = displaybuffer ? displaybuffer.toLowerCase() : cbInfo.getParam("cbinfo.map.displaybuffer");

                url =  cbKort.getServletUrl();
                url += "?page=spatialquery-get-map-from-pcol";
                url += "&sessionid=" + tempSessionId;
                url += "&profile=" + cbKort.getProfile();
                url += "&pcollectionid=" + targetHit.orgPcolid;
                url += "&geometrycolumn=shape_wkt";
                url += "&dynamiclayer=smalluser*found";
                url += "&sourcesessionid=" + cbKort.getSessionId();
                url += "&map_size=" + mapsize;
                url += "&displaybuffer=" + displaybuffer;
               
                var pcol = request.executeUrl (url, true);   

                targetHit.hitImage = pcol.get(0).getValue();
            }
             
            var hitimgURL = '/tmp/'+targetHit.hitImage;
            var hitimg = getElement('detailed_view_hitimg'+targetId+targetHitId);
            if(hitimg.src != hitimgURL)
            {    hitimg.src = hitimgURL;
            }
        }
    }
    
    // Remove new temp. cbmap session
    request.executeUrl (cbKort.getServletUrl() + "?page=spatialquery-remove-session&sessionid="+tempSessionId, false);   
    
    if(count == totalcount)
    {
        hideWaitingBox();
        queryResult.lasthit = true;
    }
    else if(count != null && totalcount != null && !queryResult.lasthit)
    {   showWaitingBox(cbInfo.getString('standard.message.getting_data') + '...' +'('+count+'/'+totalcount+')');
    }
}

//********************************************//
//  Vis den url, der er angivet i property    //
//********************************************//
function leftbarsq_showDetailUrl(url)
{
    contentContainer_showContentIframe(url);
}

function leftbarsq_detailTabSetActive(e)
{
    if(e)
        e.className = 'activetab';
}

function leftbarsq_detailTabSetPassive(e)
{
    if(e)
        e.className = 'passivetab';
}

function leftbarsq_showListDiv()
{
	leftbarsq_detailTabSetPassive(getElement("leftbarsq_report_tab"));
	leftbarsq_detailTabSetPassive(getElement("leftbarsq_help_tab"));
	leftbarsq_detailTabSetActive(getElement("leftbarsq_overview_tab"));
    
    getElement("reportdiv").style.display = "none";
    getElement("helpdiv").style.display = "none";
    getElement("listdiv").style.display = "block";
}

function leftbarsq_showReportDiv()
{
	leftbarsq_detailTabSetPassive(getElement("leftbarsq_overview_tab"));
	leftbarsq_detailTabSetPassive(getElement("leftbarsq_help_tab"));
	leftbarsq_detailTabSetActive(getElement("leftbarsq_report_tab"));
    
    getElement("listdiv").style.display = "none";
    getElement("helpdiv").style.display = "none";
    getElement("reportdiv").style.display = "block";
}

function leftbarsq_showHelpDiv()
{
	leftbarsq_detailTabSetPassive(getElement("leftbarsq_overview_tab"));
	leftbarsq_detailTabSetPassive(getElement("leftbarsq_report_tab"));
	leftbarsq_detailTabSetActive(getElement("leftbarsq_help_tab"));
    
    getElement("listdiv").style.display = "none";
    getElement("helpdiv").style.display = "block";
    getElement("reportdiv").style.display = "none";
}

function leftbarsq_tab_setMouseOver()
{
    this.style.fontWeight = 'bold';
}

function leftbarsq_tab_setMouseOut()
{
    this.style.fontWeight = 'normal';
}

//********************************************//
//  Aktivering/deaktivering af faneblad       //
//********************************************//
function leftbarsq_deActivateTabHandler()
{
    leftbarsq_setContentContainer(true);
}
function leftbarsq_activateTabHandler()
{
    if(spatialquery_showOnActivate)
        leftbarsq_setContentContainer(false);
}
function leftbarsq_setContentContainer(show)
{
    if (leftbarsq_win) {
        if(!show) {
            if (leftbarsq_winactive) {
                leftbarsq_win.show ();
            }
        } else {
            leftbarsq_win.hide ();
        }
    }
    spatialquery_showOnActivate = show;
}


//********************************************//
//  Udskriv indhold i detaljevinduet          //
//********************************************//
var contentContainer_contentType = '';
function leftbarsq_printDetail()
{
    if(contentContainer_contentType == 'iframe')
    {
        if(ie)
        {
            document.detailframe.focus();
            document.detailframe.print();
        }
        else
        {
            var e = getElement('detailframe');
            if(e)
            {
                var w = window.open(e.src,'print');
                try {
                    w.print();
                    w.close();
                } catch(e) {}
            }
            else
                alert(cbInfo.getString('standard.error.an_error_occurred'))
        }
    }
    else
    {
        var url = cbKort.getFormParamAsUrl();
        url = replaceUrlParam('page', 'print_current_centent', url);
        url = replaceUrlParam('contenthtml_handler', 'leftbarsq_printGetContent', url);
        url = replaceUrlParam('localposthandler', 'leftbarsq_printSetContentPrintable', url);
        window.open(url, 'Print', 'toolbar=no,location=no,directories=no,status=yes,menubar=yes,resizable=yes,scrollbars=yes,width=800,height=500,left=50,top=50');
    }
}

//  Henter indholdet til detaljeprint         //
function leftbarsq_printGetContent()
{
    var html = getElement('contentContainer_content').innerHTML;
    return html;
}

//  Behandler indholdet i printviduet efter   //
//  html'en er sat ind (lokan funktion)       //
function leftbarsq_printSetContentPrintable()
{
    var e = getElement('leftbarsq_show_report_div');
    if(e)
        e.style.display = 'none';
}


//********************************************//
//  Udskriv indhold i detaljevinduet          //
//********************************************//

function leftbarsq_printReport()
{
    var queryResult = spatialquery_currentQueryResult;
    var targetlist = ""; 
    
    for(var a=0;a<queryResult.targets.length;a++)
    {
        var targetnumber = queryResult.targets[a].targetnumber;
        
        var e=getElement('leftbarsq_reportelement_targetnumber_'+targetnumber);
        if (e.checked)
        {
           if (a>0)
           {  targetlist +=",";
           }
            
           targetlist += targetnumber;
        }    
    }
    var page=getElement('reportpage').value;
       
    var includeheader = getElement('leftbarsq_includeheader').checked;
        
    spatialquery_printReport (queryResult.searchURL, queryResult.searchText, page, targetlist, includeheader);
}
       
       

