// ===============================================================
// CBkort version 2.x, copyright Carl Bro GIS&IT, 2006
// ===============================================================
// $Archive: /Products/CBKort2/development/2.3/standard/wwwroot/WEB-INF/config/modules/standard/spatialquery/js/queryresult.js $ 
// $Date: 15-09-07 23:11 $
// $Revision: 14 $ 
// $Author: Nsm $
// =============================================================== 


// Søgninger
// [QueryResult].targets[x].targetHits[y].values[z]

/*
 *  QueryResult
 */


function QueryResult(searchText)
{
    this.searchText = searchText;
    this.searchURL = '';
    this.queryString = null;
    this.searchImgHide = false;
    this.searchImgSmall = null;
    this.targets = new Array();
    this.selectorPcolId = null;
    this.n = 0;
}

QueryResult.prototype.addTarget = function(targetname, targetnumber, header, expand, warning, errortext)
{
    var nTargets = this.targets.length;
    this.targets[nTargets] = new Target(targetname, targetnumber, header, expand, warning, errortext);
    this.n = nTargets+1;
    return this.targets[nTargets];
}

QueryResult.prototype.getTarget = function(targetId)
{
    return this.targets[targetId];
}
QueryResult.prototype.getTargetHit = function(targetId,targetHitId)
{
    return this.getTarget(targetId).getTargetHit(targetHitId);
}

/*
 * Target
 */

function Target(targetname, targetnumber, header, expand, warning, errortext)
{
    this.targetname    = targetname; 
    this.targetnumber  = targetnumber; 
    this.heading       = header;
    this.expand        = expand;
    this.warning       = warning || null;
    this.errortext     = errortext;
    this.targetHits    = new Array();
    this.n = 0;
}

Target.prototype.addTargetHit = function()
{
    var nHits = this.targetHits.length;
    this.targetHits[nHits] = new TargetHit();
    this.n = nHits+1;
    return this.targetHits[nHits];
}
Target.prototype.getTargetHit = function(targetHitId)
{
    return this.targetHits[targetId];
}

/*
 * Targethit
 */

function TargetHit()
{
    this.values = new Array();
    this.n = 0;
    this.orgPcolid = null;
    this.geometryType = 'GEOMETRY UNDEFINED';
    this.listHeading = '';
    this.detailHeading = '';
    this.hitImage = null;
    this.hitImageLabel = '';
    this.hitImageURl = '';
    this.properties = new Array();
}

TargetHit.prototype.addValue = function(values)
{
    if(values.format == 'org-pcolid')
    {
        this.orgPcolid = values.value;
        this.geometryType = values.label;
    }
    else if(values.format == 'heading')
    {
        this.listHeading = values.value;
        this.detailHeading = values.label;
    }
    else if(values.format == 'hitImage')
    {
        this.hitImage = values.value;
        this.hitImageLabel = values.label;
    }
    else if(values.format == 'hitImageURL')
    {
        this.hitImageURl = values.value;
    }
    else if(values.format == 'properties' || values.format == 'property')
    {
        this.properties[this.properties.length] = values;
        this.n = this.properties.length+1;
    }
    else
    {
        this.values[this.values.length] = values;
        this.n = this.values.length+1;
    }
}

TargetHit.prototype.getValueFromLabel = function(label)
{
    for(var i=0;i<this.values.length;i++)
    {
        if(this.values[i].label == label)
            return this.values[i].value;
    }
    return null;
}

TargetHit.prototype.getValueFromFormat = function(format)
{
    for(var i=0;i<this.values.length;i++)
    {
        if(this.values[i].format == format)
            return this.values[i].value;
    }
    return null;
}

TargetHit.prototype.getProperty = function(navn)
{
    for(var i=0;i<this.properties.length;i++)
    {
        if(this.properties[i].label == navn)
            return this.properties[i].value;
    }
    return null;
}