/******************************************************************************
 * @title Statistics functions
 * @author DENIS ROUSSEAU
 * @version 1.4.1.0.6
 /******************************************************************************
 * Global variables
 */
/* Required by GA */
var _gaq = _gaq || [];
/*****************************************************************************
 * Condition object: current state of statistics
 *****************************************************************************/
stat_condition = 
{
    _undef : 'undefined',
	_func : 'function',
	_done: false,
    _prepared: false,
    _excluded: false,
    _gaOn: false,
    _gaSrc: '',
    _defpage: '',
    _objURL: null,
    _path: window.location.pathname,
    _preview: false,
    _async: true,
    _checked: false,
    _error: false,
    _isPageSet: false,
    _method: 
    {
        async: true,
        preview: false
    },
    _xitisrc: 
    {
        sync: '',
        async: '',
        clicks: ''
    },
    _pathRemover: 
    {
        common: '',
        next: false,
		enabled: false
    },
    /***************************************
     * Initial conditions check & completion 
     ***************************************/
    Checked: function()
    {
        /* Check configuration-stat.js */
        if (!stat_condition._checked) 
        {
			/* Required by XITI */
			xtnv = document; /* parent.document or top.document or document */
			xw = window;
			if (typeof xtdmc == stat_condition._undef) xtdmc = '';
			if (typeof xtprm == stat_condition._undef) xtprm = '';
			if (typeof xtclzone == stat_condition._undef) xtclzone = (xw.scriptOnClickZone != null) ? xw.scriptOnClickZone : 0;
			if (typeof xtsd == stat_condition._undef) xtsd = '';
			if (typeof xtsite == stat_condition._undef) xtsite = ''
			if (typeof xnt2 == stat_condition._undef) xnt2 = '';
			if (typeof xtpage == stat_condition._undef) xtpage = '';
			if (typeof xtdi == stat_condition._undef) xtdi = 0;
			if (typeof gasiteID == stat_condition._undef) gasiteID = '';
			
            stat_condition._checked = true;
            if (typeof STAT_Method == 'object' && typeof STAT_XitiSrc == 'object' && typeof STAT_PathRemover == 'object') 
            {
                stat_condition._method.async = STAT_Method.Async;
                stat_condition._xitisrc.sync = STAT_XitiSrc.Sync;
                stat_condition._xitisrc.async = STAT_XitiSrc.Async;
                stat_condition._xitisrc.clicks = STAT_XitiSrc.Clicks;
                stat_condition._pathRemover.common = STAT_PathRemover.Common;
                stat_condition._pathRemover.next = STAT_PathRemover.Next;
                
                if (typeof isCustomPreview == stat_condition._func) 
                {
                    stat_condition._method.preview = isCustomPreview();
                }
                else 
                {
                    stat_condition._method.preview = STAT_Method.Preview;
                }
                if (typeof doCustomCheck == stat_condition._func) 
                {
                    stat_condition._error = !doCustomCheck();
                }
            }
            else if (typeof _STAT == 'object' && typeof _GA == 'object' && typeof _XITISRC == 'object') 
            {
                stat_condition._method.async = _STAT.Async;
                gasiteID = _GA.SiteID;
                stat_condition._xitisrc.sync = _XITISRC.Sync;
                stat_condition._xitisrc.async = _XITISRC.Async;
                stat_condition._xitisrc.clicks = _XITISRC.Clicks;
                if (typeof STAT_PathRemover == 'object') 
                {
                    stat_condition._pathRemover.common = STAT_PathRemover.Common;
                    stat_condition._pathRemover.next = STAT_PathRemover.Next;
                }
                if (typeof isCustomPreview == stat_condition._func) 
                {
                    stat_condition._method.preview = isCustomPreview();
                }
            }
            else 
            {
                if (typeof doCustomAlert == stat_condition._func) 
                {
                    doCustomAlert('configuration-stat.js');
                }
                stat_condition._error = true;
            }
        }
        return !stat_condition._error;
    }
};
/*****************************************************************************
 * Settings object: compute statistics settings from a given page path
 *****************************************************************************/
stat_settings = 
{
    _xtsd: '',
    _xtsite: '',
    _xtn2: '',
    _xtpage: '',
    _gasiteID: '',
    
    Collect: function(sp, p_xtpage, sl)
    {
        if (!stat_condition.Checked()) 
        {
            return;
        }
        
        var rest = sp;
        var isEqual = false;
        var isSite = false;
        
        stat_condition._isPageSet = false;
        stat_settings._xtpage = '';
        /*------------------------------------------------------------ XITI */
        for (var i = 0; i < sl.length; i++) 
        {
            if (isCustomEqualPath(sp.substring(0, sl[i][0].length), sl[i][0]) || (i == (sl.length - 1) && sl[i][0] == '*')) 
            {
                if (sp.length == sl[i][0].length) 
                {
                    isEqual = true;
                }
                else if (sl[i][0] != '*') 
                {
                    rest = sp.substring(sl[i][0].length);
                }
                var l = sl[i].length;
                if (l > 1) 
                {
                    if (sl[i][1].length > 0) 
                        stat_settings._gasiteID = sl[i][1];
                    if (l > 2) 
                    {
                        if (sl[i][2].length > 0) 
                            stat_settings._xtsd = sl[i][2];
                        if (l > 3) 
                        {
                            if (sl[i][3].length > 0) 
                            {
                                stat_settings._xtsite = sl[i][3];
                                isSite = true;
                            }
                            if (l > 4) 
                            {
                                if (sl[i][4].length > 0) 
                                    stat_settings._xtn2 = sl[i][4];
                                if (l > 5) 
                                {
                                    if (sl[i][5].length > 0) 
                                    {
                                        stat_settings._xtpage = sl[i][5];
                                        stat_condition._isPageSet = (stat_settings._xtpage.length > 0);
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
        /* Settings adjustments */
        if (stat_settings._xtn2.length == 0) 
        {
            stat_settings._xtn2 = '0';
        }
        if (stat_settings._xtn2 == '0') 
        {
            rest = sp;
        }
        if (rest.length > 0 || isEqual) 
        {
            if (isEqual) 
            {
                var abp = sp.split("/");
                rest = '' + abp[abp.length - 1];
            }
            if (rest.charAt(0) === '/') 
            {
                rest = rest.substr(1);
            }
            var isRoot = (stat_settings._xtpage.length > 2 && stat_settings._xtpage.substr(stat_settings._xtpage.length - 2, 2) == "::");
            if (isRoot && isEqual) 
            {
                stat_settings._xtpage = stat_settings._xtpage.substr(0, stat_settings._xtpage.length - 2);
            }
            else if (stat_settings._xtpage.length == 0 || isRoot) 
            {
                stat_settings._xtpage += trimString(rest.split("/").join("::"));
            }
        }
        /* Forced page name (keep chapters) */
        if (stat_condition._defpage.length > 0) 
        {
            stat_settings._xtpage = updateXtPageName(stat_settings._xtpage, stat_condition._defpage);
        }
        /* Forced whole page name (including chapters) */
        if (p_xtpage !== undefined && p_xtpage !== null && p_xtpage.length > 0) 
        {
            stat_settings._xtpage = p_xtpage;
        }
        /* Still no page name, or page name not set and current value existing  : use it */
        else if (stat_settings._xtpage.length == 0 || (!stat_condition._isPageSet && xtpage.length > 0)) 
        {
            stat_settings._xtpage = xtpage;
        }
        /* Remove forbidden characters */
        stat_settings._xtpage = filterXtPageName(stat_settings._xtpage);
        
        /*------------------------------------------------------------ Turn to preview settings */
        if (isSite && stat_condition._method.preview && stat_settings._xtsite.length > 0) 
        {
            var pm = getStatPreviewMap();
            var pxtsite = false, pxtsd = false, pga = false;
            for (var j = 0; j < pm.length; j++) 
            {
                if (pm[j][0] == stat_settings._xtsite || (j == (pm.length - 1) && pm[j][0] == '*')) 
                {
                    var lm = pm[j].length;
                    if (lm > 1 && pm[j][1].length > 0 && !pxtsite) 
                    {
                        stat_settings._xtsite = pm[j][1];
                        pxtsite = true;
                    }
                    if (lm > 2 && pm[j][2].length > 0 && !pxtsd) 
                    {
                        stat_settings._xtsd = pm[j][2];
                        pxtsd = true;
                    }
                    if (lm > 3 && !pga) 
                    {
                        gasiteID = pm[j][3];
                        pga = true;
                    }
                    /* missing one entry: jump to default (if any) */
                    if ((!pxtsite || !pxtsd || !pga) && (j < (pm.length - 2))) 
                    {
                        j = pm.length - 2;
                    }
                    break;
                }
            }
        }
        /*------------------------------------------------------------ Switch on secured server */
        if ('https:' == document.location.protocol && stat_settings._xtsd.indexOf(document.location.protocol) < 0) 
        {
            var pm = getStatSecuredServerMap();
            var pxtsd = false;
            for (var j = 0; j < pm.length; j++) 
            {
                if (pm[j][0] == stat_settings._xtsd || (j == (pm.length - 1) && pm[j][0] == '*')) 
                {
                    if (pm[j].length > 1 && pm[j][1].length > 0 && !pxtsd) 
                    {
                        stat_settings._xtsd = pm[j][1];
                        pxtsd = true;
                    }
                    /* missing entry: jump to default (if any) */
                    if (!pxtsd && (j < (pm.length - 2))) 
                    {
                        j = pm.length - 2;
                    }
                    break;
                }
            }
        }
    },
    /******************************************************************************
     * Settings preparation
     ******************************************************************************/
    Prepare: function(p_xtpage)
    {
        if (!stat_condition.Checked()) 
        {
            return;
        }
        var sp = getPageStatPath(stat_condition._path);
        /*------------------------------------------------------------ XITI */
        stat_settings.Collect(sp, p_xtpage, getStatGlobalMap());
        /* Substitute new values to defaults */
        if (stat_settings._xtsd.length > 0) 
        {
            xtsd = stat_settings._xtsd;
        }
        if (stat_settings._xtsite.length > 0) 
        {
            xtsite = stat_settings._xtsite;
        }
        if (stat_settings._gasiteID.length > 0) 
        {
            gasiteID = stat_settings._gasiteID;
        }
        /* Once global accounts done, modify path if needed  */
        if (typeof getCustomPath == stat_condition._func) 
        {
            sp = getCustomPath(sp, false);
        }
        stat_settings._xtn2 = xtn2;
        stat_settings._xtpage = xtpage;
        stat_settings.Collect(sp, p_xtpage, getStatSettingsMap());
        if (stat_settings._xtsd.length > 0) 
        {
            xtsd = stat_settings._xtsd;
        }
        if (stat_settings._xtsite.length > 0) 
        {
            xtsite = stat_settings._xtsite;
        }
        if (stat_settings._gasiteID.length > 0) 
        {
            gasiteID = stat_settings._gasiteID;
        }
        xtn2 = stat_settings._xtn2;
        xtpage = stat_settings._xtpage;
        
        stat_condition._excluded = (xtsd == "" || xtsd == "!" || xtsite == "" || xtsite == "!" || xtpage == "!");
        if (!stat_condition._excluded && typeof isCustomExcluded == stat_condition._func) 
        {
            stat_condition._excluded = isCustomExcluded(sp);
        }
        // Custom variables
        if (typeof setCustomXt == stat_condition._func) 
        {
            setCustomXt(sp);
        }
        /*------------------------------------------------------------ GA */
        /* GA is activated only if Xiti is activated and an ID provided  */
        stat_condition._gaOn = (!stat_condition._excluded && gasiteID.length > 1);
        if (stat_condition._gaOn) 
        {
            stat_condition._gaSrc = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            if (stat_condition._method.async) 
            {
                _gaq.push(['_setAccount', gasiteID]);
                _gaq.push(['_setDomainName', getDomainCookie()]);
                if (typeof setCustomGA == stat_condition._func) 
                {
                    setCustomGA(_gaq);
                }
                _gaq.push(['_trackPageview']);
            }
        }
        stat_condition._prepared = true;
    }
};

/*****************************************************************************
 * Events listeners
 */
function addPageEvent(node, type, fn, tn)
{
	if (node.addEventListener) 
	{
		node.addEventListener(type, function(){fn(this);}, false);		
	}
	else if (node.attachEvent) 
	{
		node.attachEvent('on' + type, function()
		{
			var eventNode = window.event.srcElement ;
			if (tn != undefined && eventNode.tagName != tn)
			{
				eventNode = eventNode.parentNode ;
			}
			fn(eventNode);
		});
	}
}
function addPageEventLink(node, fn)
{
	addPageEvent(node, 'click', fn, 'A');
}
function addPageEventLoad(node, fn)
{
	addPageEvent(node, 'load', fn);
}

/*****************************************************************************/
stat_link =
{
	_aExt : [],
	
	getLinkName: function(target)
	{
		var lpage = xtpage ;
	    if (typeof getCustomLinkName == stat_condition._func)
		{
			lpage = getCustomLinkName(target) ;
		}
		else
		{
		    /* title is only the file name */
		    var urlname = target ;
		    var aPath = target.split("/");
		    if (aPath.length > 0) 
		    {
		        urlname = aPath[aPath.length - 1];
		    }
		    lpage = (lpage !== "") ? (lpage + '::' + urlname) : urlname;	
		}
		return lpage ;
	},
	
	getLinkNodeName: function(node)	
	{
		return (typeof getCustomLinkNodeName == stat_condition._func)? getCustomLinkNodeName(node) : stat_link.getLinkName(node.href) ;
	},
	
	getParentNodes: function(selector)
	{
		var nodes = [] ;
		/* No node specification : all document links will be checked */
		if (selector == null || selector.length == 0)
		{
			nodes.push(document) ;
		}
		else
		{
			var an = selector.split(':');
			if (an.length > 0)
			{
				/* Node specified by id */
				if (an.length == 1)
				{
					var node = document.getElementById(an[0]) ;
					if (node)
					{
						nodes.push(node) ;
					}
				}
				/* Node specified by TagName:className */
				else
				{
					var an2 = document.getElementsByTagName(an[0]) ;
					for (var j = 0; j < an2.length; j++)
					{
				        if (an2[j].className == an[1]) 
						{
							nodes.push(an2[j]) ;
						}
					}
				}
			}
		}
		return nodes ;
	},
	
	modifySelection: function(nodes, extList, modifyFn, listenerFn)
	{
		for (var n = 0; n < nodes.length ; n++) 
		{
			var ia = nodes[n].getElementsByTagName('A');
			for (var j = 0; j < ia.length; j++) 
			{
				/* if not handled by javascript */
				if (ia[j].href.indexOf('javascript:') < 0)
				{
					/* No extension specified : link is handled */
					if (extList == null || extList.length == 0)
					{
						modifyFn(ia[j], listenerFn)
					}
					/* Check if link matches one of specified extension */
					else
					{
						for (var k = 0; k < extList.length; k++) 
						{
							if (ia[j].href.indexOf(extList[k]) > 0) 
							{
								/* Extension matches: link is handled */
								modifyFn(ia[j], listenerFn)
								break;
							}
						}
					}
				}
			}
		}
	},
	
	addMapEvent: function(pm, fn, obj)
	{
	    if (! obj || !obj._aExt)
		{
			obj = stat_link ;
		}
		for (var i = 0; i < pm.length; i++) 
	    {
			/* if current path is in map */
	        if (comparePath(stat_condition._path, pm[i][0]) || (i == (pm.length - 1) && pm[i][0] == '*')) 
	        {
				if (pm[i].length > 1)
				{
					/* Retrieve selected parent nodes */
					var nodes = stat_link.getParentNodes(pm[i][1]) ;
					/* Retrieve selected extensions */
					if (pm[i].length > 2 && pm[i][2].length > 0)
					{
						obj._aExt = pm[i][2].split('|');
					}
					/* Modify corresponding child links by adding an onclick listener */
					stat_link.modifySelection(nodes, obj._aExt, addPageEventLink, fn) ;
				}
	            break;
	        }
	    }
	}
} ;

/*****************************************************************************/
stat_download =
{
	_aExt : [],
	
    /* raise click marker */
	raiseDownloadClickTag: function(lpage)
	{
	    xt_med('C', xtn2, lpage, 'T');
	},	

	relayDownloadClickTag: function(node)
	{
		stat_download.raiseDownloadClickTag(stat_link.getLinkNodeName(node)) ;
	},	

	addDownloadClickTags: function()
	{
	    if ((typeof getStatDownloadMap == stat_condition._func))
		{
			stat_link.addMapEvent(getStatDownloadMap(), stat_download.relayDownloadClickTag, stat_download) ;
		}
	},

	hookDownloadLink: function()
	{
	    if (typeof setCustomDownloadHook == stat_condition._func) 
	    {
	        setCustomDownloadHook();
	    }
		/* Hook direct window.open call */
        if (typeof STAT_windowOpen != stat_condition._func)
		{
 			STAT_windowOpen = window.open ;
		}
		window.open = function(sUrl, sName, sFeatures, bReplace)
		{
			if (sName == '_blank')
			{
				for (var i = 0; i < stat_download._aExt.length; i++) 
				{
					if (sUrl.indexOf(stat_download._aExt[i]) > 0) 
					{
						stat_download.raiseDownloadClickTag(stat_link.getLinkName(sUrl)) ;
						break ;
					}
				}
			}
			STAT_windowOpen(sUrl, sName, sFeatures, bReplace) ;
		} ;
	},

	activate: function()	
	{
		stat_download.addDownloadClickTags() ;
		addPageEventLoad(window, stat_download.hookDownloadLink) ;
	}
} ;

/******************************************************************************
 * Retrieve domain from URL (could be already defined)
 */
if (typeof getDomainCookie != stat_condition._func) 
{
    window.getDomainCookie = function()
    {
        return window.location.host.replace(/^[a-z-A-Z]+[0-9]*/, "").replace(/:[0-9]*/, "");
    };
}

/******************************************************************************
 * Compare Path strictly (default is case sensitive)
 */
function isCustomEqualPath(p1, p2)
{
	return (p1 == p2) ;	
}

/******************************************************************************
 * Compare page path to Xiti filter
 */
function comparePath(url, filter)
{
    var filter_str = "" + filter;
    var url_str = "" + url;
    var filter_t = filter_str.split("/");
    var url_t = url_str.split("/");
    var u_i = 0;
    var f_i = 0;
    if (filter_t[0] === "") 
    {
        f_i++;
    }
    if (url_t[0] === "") 
    {
        u_i++;
    }
    while (u_i < url_t.length) 
    {
        if (f_i >= filter_t.length) 
        {
            return false;
        }
        if (url_t[u_i] != filter_t[f_i]) 
        {
            if (filter_t[f_i] == '*') 
            {
                while (filter_t[f_i] == '*' && f_i < filter_t.length) 
                {
                    f_i++;
                }
                if (f_i >= filter_t.length) 
                {
                    return true;
                }
                var loop_in = true;
                while (u_i < url_t.length - 1 && loop_in) 
                {
                    if (url_t[u_i] == filter_t[f_i] && url_t[u_i + 1] != filter_t[f_i]) 
                    {
                        loop_in = false;
                    }
                    else 
                    {
                        u_i++;
                    }
                }
            }
            else 
            {
                return false;
            }
        }
        else 
        {
            u_i++;
            f_i++;
        }
    }
    return true;
}

/******************************************************************************
 * Retrieve parameter parser in given URL
 */
function getUrlParser(surl)
{
	var osurl = new Object();
	surl.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"), function(b, a, d, c)
	{
		osurl[a] = c
	});
	return osurl ;	
}

/******************************************************************************
 * Retrieve parameter in current URL
 */
function getPageParam(p)
{
    if (stat_condition._objURL === null) 
    {
        stat_condition._objURL = getUrlParser(window.location.search) ;
    }
    return stat_condition._objURL[p];
}

/******************************************************************************
 * Deduct  StatPath from path name
 * (Note : StatPath is the formal path requested by pageStat)
 */
function getPageStatPath(pu)
{
    var sp = pu;
    /* Remove common path and possibly next folder (when required)*/
    if (stat_condition._pathRemover.enabled && stat_condition._pathRemover.common.length > 0) 
    {
		sp = sp.replace(new RegExp(stat_condition._pathRemover.common + '?', 'g'), '')
	    if (stat_condition._pathRemover.next)
		{
			sp = sp.replace(new RegExp('^/[^/]+/', 'g'), '');
		}
    }
    /* Remove last slash (if exists) and file extension (if any) */
    sp = sp.replace(/\/$/, '');
    var r2 = /\.(\w+($|\b\?))/.exec(sp);
    if (r2 != null) 
    {
        sp = sp.replace(r2[0], '');
    }
    if (typeof getCustomPath == stat_condition._func) 
    {
        sp = getCustomPath(sp, true);
    }
    return sp;
}

/******************************************************************************
 * Retrieve content of a meta tag
 */
function getPageMetaContent(n)
{
    var m = document.getElementsByTagName('meta');
    for (var i = 0; i < m.length; i++) 
    {
        if (m[i].name == n) 
        {
            return m[i].content;
        }
    }
}

/******************************************************************************
 * Retrieve last tag value used in current page
 */
function getPageLastTag(tagName)
{
    var t = document.getElementsByTagName(tagName);
    return (t !== undefined && t.length > 0) ? t[t.length - 1].innerHTML : "";
}

/******************************************************************************
 * Remove string spaces
 */
function trimString(a)
{
    return (a.replace(/(^\s*)/g, "").replace(/(\s*$)/g, ""));
}

/******************************************************************************
 * Retrieve page name into a p parameter
 */
function getXtPageName(p)
{
    var up = unescape(p);
    var pos = up.lastIndexOf('::');
    return (pos >= 0) ? up.substr(pos + 2) : up;
}

/******************************************************************************
 * Change page name into a p parameter
 */
function updateXtPageName(p, newPageName)
{
    return p.replace(getXtPageName(p), newPageName);
}

/******************************************************************************
 * Apply some filter on XITI string to avoid forbidden characters
 */
function filterXtPageName(p)
{
    p = trimString(p);
    p = encodeURIComponent(p);
    var name = getXtPageName(p);
    var r = /!|=|,|;|:|§|!|µ|%|@|£|²|°|'|<|>|\"|&|#|{|}|\$|\[|\]|\*|\?|\+|\~|}|{|\^|\\|\|/g;
    return updateXtPageName(p, name.replace(r, "-").replace(/\s/g, "_"));
}

/******************************************************************************
 * Retrieve domain from URL
 */
function getPageDomain()
{
    return window.location.host.replace(/^[a-z-A-Z]+[0-9]*/, "").replace(/:[0-9]*/, "");
}
if (typeof getDomainCookie != stat_condition._func) 
{
    window.getDomainCookie = function()
    {
        return getPageDomain();
    }
}

/*******************************************************************
 * Retrieve XiTi domain
 */
function getXtdomain()
{
    return (xtsd == '' ? xtsd : (xtsd + ".xiti.com"));
}

/******************************************************************************
 * Raise navigation or download click tag with or without executing the link (in the same window)
 * (compared to xt_med, page doesn't need to be marked before, it just needs to be prepared with pageStatPrepare)
 */
function clickStat(page, clickType, target, newWindow)
{
    var done = false;
    if (xtsite !== '') 
    {
        var xt_img = new Image();
        var imgDate = new Date();
        var imgSrc = getXtdomain() + '/hit.xiti?s=' + xtsite + '&s2=' + xtn2 + '&p=' + page + '&clic=' + clickType + '&hl=' + imgDate.getHours() + 'x' + imgDate.getMinutes() + 'x' + imgDate.getSeconds();
        if (parseFloat(navigator.appVersion) >= 4) 
        {
            imgSrc += '&r=' + screen.width + 'x' + screen.height + 'x' + screen.pixelDepth + 'x' + screen.colorDepth;
        }
        done = true;
        xt_img.src = imgSrc;
        xt_img.onload = function()
        {
            xt_img.onload = null;
        };
    }
    if ((target !== null) && (target !== undefined) && target !== '') 
    {
        if ((newWindow == '') || (newWindow == null) || (newWindow == undefined)) 
        {
        	document.location = target;
        }
        else 
        {
            var f = window.open(target, 'xfen', '');
            f.focus();
        }
   }
    else 
    {
        return done;
    }
}

/******************************************************************************
 * Raise navigation or download click when xtcore.js is still unloaded
 */
function xt_med(type, section, page, clickType, target, newWindow)
{
    if (type === "C") 
    {
        xtn2 = section;
        clickStat(page, clickType, target, newWindow);
    }
}

/******************************************************************************
 * Raise navigation or download click tag (Xiti)
 */
function linkStat(type, pageFrom, urlTo, x1, target)
{
    /* no tags on javascript calls or empty "page from"*/
    if (urlTo.indexOf('javascript:') === 0 || pageFrom === undefined || pageFrom === '') 
    {
        return;
    }
    var section = xtn2;
    var lpage = "";
    
    /* if url starts with a protocol and is not on the same domain : link out */
    if (urlTo.indexOf('://') >= 0 && urlTo.indexOf(getPageDomain()) === -1) 
    {
        /* title is complete url, without protocol */
        lpage = urlTo.substr(urlTo.indexOf('://') + 3);
    }
    /* otherwise : link in */
    else 
    {
        section = xtn2;
        lpage = xtpage;
        /* title is only the page name */
        var title = urlTo;
        var url_tags = urlTo.split("/");
        if (url_tags.length > 0) 
        {
            title = url_tags[url_tags.length - 1];
        }
        lpage = (lpage !== "") ? (lpage + '::' + title) : title;
    }
    /* raise click marker */
    xt_med('C', section, lpage, x1);
}

/******************************************************************************
 * Add synchronous script inclusion in DOM
 */
function setSyncScript(ss)
{
    document.write(unescape("%3Cscript src='" + ss + "' type='text/javascript'%3E%3C/script%3E"));
}

/******************************************************************************
 * Add asynchronous script inclusion in DOM
 */
function setAsyncScript(ss)
{
    var ns = document.createElement('script');
    var s = document.getElementsByTagName('script')[0];
    ns.type = 'text/javascript';
    ns.async = true;
    ns.src = ss;
    s.parentNode.insertBefore(ns, s);
}

/******************************************************************************
 * Raise GA content marker (asynchronous method)
 */
function raiseAsyncMarkerGA()
{
    setAsyncScript(stat_condition._gaSrc);
}

/******************************************************************************
 * Raise GA content marker (synchronous method)
 */
function raiseSyncMarkerGA()
{
    setSyncScript(stat_condition._gaSrc);
    try 
    {
        var pageTracker = _gat._getTracker(gasiteID);
        pageTracker._setDomainName(getDomainCookie());
        if (typeof setCustomGA == stat_condition._func) 
        {
            setCustomGA(pageTracker);
        }
        pageTracker._trackPageview();
    } 
    catch (err) 
    {
    }
}

/******************************************************************************
 * Raise Xiti content marker (asynchronous method)
 */
function raiseAsyncMarker()
{
    if (stat_condition.Checked()) 
    {
        setAsyncScript(stat_condition._xitisrc.async);
        if (stat_condition._gaOn) 
        {
            raiseAsyncMarkerGA();
        }
    }
}

/******************************************************************************
 * Raise Xiti content marker (synchronous method)
 */
function raiseSyncMarker()
{
    if (stat_condition.Checked()) 
    {
        setSyncScript(stat_condition._xitisrc.sync);
        if (stat_condition._gaOn) 
        {
            raiseSyncMarkerGA();
        }
    }
}

/******************************************************************************
 * Prepare all Xiti parameters
 */
function pageStatPrepare(p_xtpage)
{
    if (!stat_condition._prepared) 
    {
        stat_settings.Prepare(p_xtpage);
    }
    return !stat_condition._excluded;
}

/******************************************************************************
 * Prepare parameters and raise content marker (asynchronous method)
 */
function pageStatAsync(p_xtpage)
{
    var todo = pageStatPrepare(p_xtpage);
    if (todo) 
    {
        raiseAsyncMarker();
    }
    return todo;
}

/******************************************************************************
 * Prepare parameters and raise content marker (synchronous method)
 */
function pageStatSync(p_xtpage)
{
    var todo = pageStatPrepare(p_xtpage);
    if (todo) 
    {
        raiseSyncMarker();
    }
    return todo;
}

/******************************************************************************
 * Prepare content marker by initializing page name (it doesn't change chapters)
 * (to be used by generic pages like news, press releases, ...)
 */
function pageStatSub(p_defpage)
{
    stat_condition._defpage = p_defpage;
}

/******************************************************************************
 * Prepare parameters and raise content marker (method depending on global choice)
 */
function pageStat(p_uri, p_preview, p_xtpage)
{
    var done = false;
    if (!stat_condition._done && stat_condition.Checked()) 
    {
        stat_condition._path = p_uri;
        stat_condition._preview = p_preview;
        stat_condition._done = done = (stat_condition._method.async && xtclzone === 0) ? pageStatAsync(p_xtpage) : pageStatSync(p_xtpage);
    }
    if (typeof doCustomMarker == stat_condition._func) 
    {
        doCustomMarker();
    }
    return done;
}

/******************************************************************************
 * Same as previous
 */
function pageStatInjection(p_xtpage)
{
    stat_condition._pathRemover.enabled = true ;
	pageStat(stat_condition._path, stat_condition._preview, p_xtpage);
}



