<% /*
    $Revision$
    $Id$

    File:           shared/xd.inc

    Description:    Common functions for XD (crossdomain) pages
    Parameters:
    Context:

    Notes:          Sets a few globals to be used by anyone who includes this
*/

%>
<%
// Splits de oude url: variant in een apiurl en deeplinkurl
function _xdparseUrl(domains)
{
    for (var cid in domains)
    {
        var dom = domains[cid];
        dom.apiurl = dom.apiurl || dom.url;
        dom.deeplinkurl = dom.deeplinkurl || dom.url;
        delete dom["url"];
    }
    return domains;
}

xd = {
    // Globals

    // de setting heeft format
    //{ "uwva":{"name": "UWV", "url": "http://uwva.sgf12/facilitor5iwork/"},
    //  "ivet":{"name": "Intervet", "url": "http://ivet.sgf12/facilitor5iwork/"}

    SecundaryDomains: _xdparseUrl(S("xd_secundarydomains")),

    enabled :
        function ()
        {
            if (S("xd_secundarydomains")&& user.prs_perslid_apikey()) return true; else return false
        },

    // Formatting functions
    fnCustName:
        function (oRs)
        {
            return "<span class='xdcustname'>" + safe.html(xd.SecundaryDomains[oRs.Fields("custid").Value].name + "-"+ oRs.Fields("name").Value) + "</span>";
        },

    fnPlaatsaanduiding:
        function (l,g,v,r)
        {
            var res = '';
            if (l) res += l.name;
            if (g) res += (l ? '-' : '') + g.name;
            if (v) res += '-' + v.name;
            if (r) res += '-' + r.name;
            return res;
        },

    fnRowData:
        function(oRs)
        {
            var data = { custid: oRs.Fields("custid").Value };
            return JSON.stringify(data);
        },

    fnrowClass:
        function (oRs)
        {
            var rowclass = "";
            return rowclass;
        },

    fncolFlags:
        function (oRs)
        {
          var mldkey = oRs.Fields("id").Value;
          var flagkey = oRs.Fields("flag").Value || 0;
          var ttl = L("lcl_mld_flag" + flagkey);
          var displ = flagkey||"";
          
	        if (outputmode == 1 || outputmode == 5)  // print
	        {
	            if (flagkey != 0) displ = safe.html(ttl);  // else blijft-ie gewoon leeg
	        }
	        else if (outputmode == 2 || outputmode == 6)  // Excel dan gewoon maar de code, handig groeperen
	        {
	            displ = flagkey||"";
	        }          
					else
          {
            if (flagkey == 0)
                var flagimg = "<i id='mldflagimg"+mldkey+"' flagkey='0' class='fa fa-circle-o mldflag"+flagkey+"'>";
            else
                var flagimg = "<i id='mldflagimg"+mldkey+"' flagkey='"+flagkey+"' class='fa fa-circle mldflag"+flagkey+"'>";
            // Met hidden flagkey voor sortering. 999 zorgt dat bij 1 keer sorteren de gevlagde direct bovenaan staan
            displ = "<div " +" title='" + safe.htmlattr(ttl)+"'>"
                  + flagimg
                  + "<span style='display:none'>" + (flagkey || 999) + "</span></div>";
          }
          return displ;
        }  
}

%>