// ===============================================================
// CBkort version 2.x, copyright Carl Bro GIS&IT, 2006
// ===============================================================
// $Archive: /Products/CBKort2/development/2.4/standard/wwwroot/js/standard/cbinfo.js $ 
// $Date: 21-01-08 14:24 $
// $Revision: 7 $ 
// $Author: Nsm $
// =============================================================== 

function CBInfo()
{
    this.params = {};
    this.isParamsLoaded = false; 
    this.texts = {};
}

CBInfo.prototype.getParam = function(paramname)
{
    if(! this.isParamsLoaded)
    {  this.loadParams();
       this.isParamsLoaded = true;
    }
    
    var value = this.params[paramname.toLowerCase()];
    
    if (value==null)
    {  value = "";
    }  
    
    return value;
}

CBInfo.prototype.loadParams = function()
{
    var url = cbKort.getServletUrl();
    url += "?page=get-cbinfo-parameters";
    url += "&sessionid=" + cbKort.getSessionId();
    
    var dom = cbhttp_getRequestDom(url);
    var cols = dom.getElementsByTagName('col');
    
    for(var ncols=0;ncols<cols.length;ncols++)
    {  this.params [cols[ncols].getAttribute("name").toLowerCase()] = cbhttp_getNodeValue(cols[ncols]);
    }
}

CBInfo.prototype.getString = function(key, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
{
    var parms = "";

    key = key.toLowerCase();
    
    if (p1!=null) parms += "&p1=" + p1;
    if (p2!=null) parms += "&p2=" + p2;
    if (p3!=null) parms += "&p3=" + p3;
    if (p4!=null) parms += "&p4=" + p4;
    if (p5!=null) parms += "&p5=" + p5;
    if (p6!=null) parms += "&p6=" + p6;
    if (p7!=null) parms += "&p7=" + p7;
    if (p8!=null) parms += "&p8=" + p8;
    if (p9!=null) parms += "&p9=" + p9;
    if (p10!=null) parms += "&p10=" + p10;
    
    if (parms==null || parms=="")
    {   // check the hashtable first (the cache)
        var value = this.texts[key];
        if (value!=null)
        {  // Found - just return the value 
           return value; 
        } 
    }
       
    var url = cbKort.getBaseUrl();
    url+= "&page=get-string";
    url+= "&key=" + key;
    
   
    if (parms!=null && parms!="")
    {
       url += parms;
    }
    
    url+= "&sessionid=" + cbKort.getSessionId();
    url+="&jdaf.error.xslt=";
    url+="&jdaf.error.contenttype=text/xml";
 
    var request = new CBhttp ();
           
    pcol = request.executeUrl(url, false);

    var result = key;           
    if (pcol!=null && pcol.get(0)!=null && pcol.get(0).getValue()!=null)
    {
        result = pcol.get(0).getValue();
    }
    
    if (parms==null || parms=="")
    {
       // No parms - store the value in the cache
       this.texts[key] = result;
    }
    
    return result;
}


var cbInfo = new CBInfo();
