
/**
 * @title Statistics customization for Partner Locator
 * @author DENIS ROUSSEAU
 * @version 1.4.2.1.0
 */
/*****************************************************************************
 * Globals declarations (if not done in configuration-stat.js)
 *****************************************************************************/
if (typeof STAT_PathRemover != 'object') 
{
    xtsd = getXtsd();
    xtsite = '';
    xtn2 = '';
    xtpage = '';
    xtdi = '0';
    xt_multc = '';
    gasiteID = '';
    
    STAT_PathRemover = 
    {
        Common: '/sites',
        Next: true
    };
}
var stat_custom = 
{
    _path: '',
    _running: false,
    _error: false
};

/*****************************************************************************
 * Settings maps
 ******************************************************************************/
/* Retrieve only site accounts */
function getStatGlobalMap()
{
    var sm = [];
    var pm = getXtsiteByLang();
    for (var i = 0; i < pm.length; i++) 
    {
        sm.push([pm[i][0], '', getXtsd(), pm[i][1]]);
    }
    /*----------------------------------------------------------------------------------*/
    return sm;
}
/* Retrieve all settings, or only level 2 and pages */
function getStatSettingsMap()
{
    var sm = [];
    var pm = getLevel2SiteForSite();
    for (var i = 0; i < pm.length; i++) 
    {
        sm.push([pm[i][0], '', '', '', pm[i][1]]);
    }
    /*----------------------------------------------------------------------------------*/
    return sm;
}
function getStatPreviewMap()
{
    var pm = [];
    pm.push(['*', getXtsitePreview(), getXtsdPreview()]); // default
    return pm;
}
/**************************************************************
 * Allow any specific marking (like other marking systems)
 * Called after standard content marker
 */
function doCustomMarker()
{
    //------------------------------------------ Change Activity
    if (typeof ChangeActivity == 'function') 
    {
        PL_ChangeActivity = window.ChangeActivity;
        window.ChangeActivity = function()
        {
            var activity = $("#activity :selected").text();
            if (activity != undefined && activity != null) 
            {
                clickStat('Activity::' + trimString(activity).replace(/ /g, "_"), 'N');
            }
            PL_ChangeActivity();
        };
    }
    //------------------------------------------ Open Layer
    if (typeof AfficheRevendeur == 'function') 
    {
        PL_AfficheRevendeur = window.AfficheRevendeur;
        window.AfficheRevendeur = function(id_selected, ancre)
        {
            if (!ancre) 
            {
                var node = document.getElementById('item_' + id_selected);
                if (node != null) 
                {
                    var dn = node.getElementsByTagName('div')[0].innerHTML;
                    var ln = dn.substr(dn.indexOf('&nbsp;') + 6);
                    clickStat('OpenLayer::' + trimString(ln).replace(/ /g, "_"), 'N');
                }
            }
            PL_AfficheRevendeur(id_selected, ancre);
        };
    }
    //------------------------------------------ EMail
    if (typeof doPartnerEmail == 'function') 
    {
        PL_doPartnerEmail = window.doPartnerEmail;
        window.doPartnerEmail = function(partnerName)
        {
            clickStat('EMail::' + trimString(partnerName).replace(/@/g, "-"), 'N');
            PL_doPartnerEmail(partnerName);
        };
    }
    
    //------------------------------------------ Select Certifications
    if (typeof selectCertification == 'function') 
    {
        PL_selectCertification = window.selectCertification;
        window.selectCertification = function()
        {
            clickStat('SelectCertification::' + "ActionCounter", 'N');
            PL_selectCertification();
        };
    }
}
/******************************************************************************
 * Standard function override for Partner Locator :
 * Deduct PageBase from url : remove domain, parameters and page extension
 * Result is prefixed by language folder ('en')
 * (Note : PageBase is the formal path requested by pageStat)
 */
function getXtPageBasePL(pu)
{
    return 'en/' + pu.match(new RegExp("^([^?]+)"))[0].replace(new RegExp("^http://[^/]+(/v2)?/[^/]+/", "g"), "").replace(".asp", "");
}
/******************************************************************************
 * Raise content marker for Partner Locator, name deducted from path or forced with p_defxtpage
 */
function pageStatInjection(p_defxtpage)
{
    // Hook pageStatPrepare to replace xtn2 default value by country value
    if (typeof pageStatPrepare == 'function') 
    {
        PL_pageStatPrepare = window.pageStatPrepare;
        window.pageStatPrepare = function(p_uri, p_xiti_preview, p_defxtpage)
        {
            var todo = PL_pageStatPrepare(p_uri, p_xiti_preview, p_defxtpage);
            var l = getPageParam('country');
            // Control value before replacing default
            if (l != undefined && l > 13 && l < 42 && l != 17) 
            {
                xtn2 = l;
            }
            return todo;
        };
    }
    // Raise content marker and call HookStat
    pageStat(getXtPageBasePL(window.location.href), "false", p_defxtpage);
}

