﻿// JScript File

//Fonction qui retourne un paramètre decoder car les parametres sont encoder en UTF-8.
function ObtenirParametreDecode(unParam)
{
	var stringParam;
	var recherche = "";
	var arrayParam;

	stringParam = decodeURI(window.location.search);
	if (stringParam.indexOf("?") == 0)
	{
		stringParam = stringParam.substring(1);				
	}
	arrayParam = stringParam.split("&");

	if (arrayParam == null)	{}
	else 
	{
		for (var i = 0; i < arrayParam.length; i++)
		{
			if (arrayParam[i].toLowerCase().indexOf(unParam + "=") == 0)
			{
				recherche = arrayParam[i].substring(unParam.length + 1);	
			}
		}
	}	
	return recherche;	
}

//Fonction qui retourne le nom du host dans les www.
function NomHostSansWww(s)
{
    var unHost; 
    unHost = s.toLowerCase(); 
    if (unHost.indexOf("www.") == 0) 
	{
	    unHost = unHost.substring(4);    
	}
	return unHost;	
}

//Fonction qui retourne vrai pour la prod.
function estP(unDom)
{
	var retour = (unDom.toLowerCase().indexOf("dgdom.net") == -1) ? true : false ;
	return retour;
}

//Fonction qui retourne l'acc pour les stats.
function ObtenirAccMca(mca)
{
    if (mca == null) {return mca;}
    if (mca.toLowerCase() == 'p') {return 'lapersonnellecom';}
    if (mca.toLowerCase() == 'd') {return 'inscom';}
    if (mca.toLowerCase() == 'h') {return 'hbc';}
    else {return null;}
}

//Fonction qui retourne l'acc pour les stats.
function ObtenirAcc(mca)
{    
    var acc = ObtenirAccMca(mca);
    var suf = estP(window.location.host) ? 'prod' : 'dev';
    if (acc == null)
    {
        suf = 'dev';
        acc = 'lapersonnellecom';    
    }
    acc = 'dgag' + acc + suf;
    return acc;
}

//Fonction qui retourne la valeur du cookie formate pour les statistiques.
function ObtenirValeurStat(nomCookie, cleCookie)
{    
    var cookie = ObtenirCleCookie(nomCookie, cleCookie);
    if (cookie != null)
    {
        cookie = cookie.toLowerCase();
        cookie = cookie.replace(/_/g, '-');        
        return cookie;
    }
    else
    {        
        return '';
    }    
}

