//Copyright Liwio SARL - Darel v0.6


var _gaq = _gaq || [];
(function () {
    var ga = document.createElement("script");
    ga.type = "text/javascript";
    ga.async = true;
    ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/u/ga_debug.js";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(ga, s);
})();



//Recapitulatif slot
// slot 1 : Key : Univers / Value : Infos Page - Level 2 pour LP
// slot 2 : Key : Univers / Value : Infos Page - Level 3
// slot 3 : 
// slot 4 : Key : online,offline / Value : Undefined ou Ville
// slot 5 : Key : client,prospect / Value : articles,prix
// setVar : Inscription Newsletter

/* Declaration des variables pouvant servir.*/
function Liwio () {}

/* Parametrage generaliste */
Liwio.prototype.ac = 'UA-4444741-1';
Liwio.prototype.a = '';	//PREFIXE DU TRACKER SI NECESSAIRE
Liwio.prototype.ae = '';	//domainname
Liwio.prototype.af = false;	//SetAllowHash, SetAllowLinker
Liwio.prototype.ag = '';	//Set Cookie PathFormat '/remi/'
Liwio.prototype.ab = '';	//TrackerID On stock le tracker sans point pour reutilisation dans getTrackerByName
Liwio.prototype.ad = '';	//Pageview
Liwio.prototype.ah = '';	//SplitGoogle. Donne le detail par extension Google pour les pays anglophones. Mettre lettres de la langue. fr/es/en/pt/etc...
Liwio.prototype.am = '';	//Site Search Keyword
Liwio.prototype.an = '';	//Site Search Category
Liwio.prototype.ao = true;	//False = No Results, True = Results
Liwio.prototype.at = false;	//Active ou non le time tracker.
Liwio.prototype.au = false;	//Set true if First visite
Liwio.prototype.av = false;	//Autotrack outbound links
Liwio.prototype.aw = false;	//Autotrack downloads
Liwio.prototype.ax = false;	//Treat referrer as new session
Liwio.prototype.ay = false;	//Treat referrer as same session. Pour modif a venir GA.
Liwio.prototype.az = '';	//hostname calcule par la fonction pour test sur outbound, downloads...
Liwio.prototype.ns = '';	//setnamespace, definit un name space si remplit

/* Parametrage specifique */
Liwio.prototype.ai = '';	//Univers
Liwio.prototype.aii = '';	//Sous-Categorie
Liwio.prototype.aiii = '';	//Nom du produit
Liwio.prototype.aj = '';	//PageType
Liwio.prototype.ak = '';	//Client type : Shopbot ou merchant
Liwio.prototype.al = '';	//Statut de membre ou non etc...
Liwio.prototype.ba = 'darel';	//RegEx de la marque du marchand ex: tw(?:e|i)nga
Liwio.prototype.bb = '';	//Url de redirection a utiliser lors de la redirection par jumper

Liwio.prototype.b1 = '';	//Filtre 1 utilise
Liwio.prototype.b2 = '';	//Filtre 2 utilise
Liwio.prototype.b3 = '';	//Filtre 3 utilise
Liwio.prototype.b4 = '';	//Filtre 4 utilise
Liwio.prototype.b5 = '';	//Filtre 5 utilise

Liwio.prototype.cv1 = '';	//Custom var 1
Liwio.prototype.cv2 = '';	//Custom var 2
Liwio.prototype.cv3 = '';	//Custom var 3
Liwio.prototype.cv4 = '';	//Custom var 4
Liwio.prototype.cv5 = '';	//Custom var 5

/* Parametrage ecommerce */
Liwio.prototype.eo = '';	//orderID
Liwio.prototype.ea = '';	//affiliation - store
Liwio.prototype.ep = '';	//total price
Liwio.prototype.et = '';	//taxes
Liwio.prototype.es = '';	//shipping

Liwio.prototype.er = [];	//Reference produit SKU
Liwio.prototype.en = [];	//Nom du produit
Liwio.prototype.ec = [];	//Categorie du produit
Liwio.prototype.eu = [];	//uniq price
Liwio.prototype.eq = [];	//quantity

/* Page de produit */
Liwio.prototype.photos = '';	//Nombre de photos
Liwio.prototype.desc = '';	//longueur de la description
Liwio.prototype.couleurs = '';	//Nombre de couleurs
Liwio.prototype.module = '';	//presence du module "Vous aimerez" oui/non

/* Page de look */
Liwio.prototype.produits = '';	//Nombre de produits proposés sur la page de look

/* Page de Categorie */
Liwio.prototype.nbcat = '';	//Nombre de categories proposées

/****************************************
*
*	Fonctions externes
*
*
*
******************************************/

Liwio.prototype.tpv = function ( uri ) {	
    if (uri) {
        _gaq.push( [ this.a + '_trackPageview' , uri ]);
    } else {
        _gaq.push( [ this.a + '_trackPageview' ] );
    }
};

Liwio.prototype.event = function (category, action, label, value) {
    if (category && action) {
        if (typeof label == "undefined") {
            var label = "";
        }
        if (typeof value == "undefined") {
            var value = 0;
        }
        _gaq.push( [ this.a + '_trackEvent', this.clean(category) , this.clean(action) , this.clean(label) , value ] );
    }
};

Liwio.prototype.cv = function (index, name, value, scope) {
    if (index && name && value) {
        _gaq.push([this.a + '_setCustomVar', index, name.replace(/\s/g, "_"), value.replace(/\s/g, "_"), scope]);
    }
};


/****************************************
*
*	Fonctions génériques
*	setCookie : void
*	getCookie : string
*	deleteCookie : void
*	getHostname : string
*	getUnixtime : int
*	isNumeric : boolean
*	isArray : boolean
*	clean : string. Reecrit this.ad = uri
*	getTimeDifference : string
*
******************************************/

Liwio.prototype.setCookie = function ( name , value , expiredays , cookiepath , setdomainname , secure )
{
	if(!expiredays) expiredays = 0;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	
	if(!cookiepath) cookiepath = '/';
	if(!setdomainname) setdomainname = this.getHostname();
	
	document.cookie = name + "=" + value +
	( ( expiredays ) ? ";expires=" + exdate.toUTCString() : "" ) +
	( ( cookiepath ) ? ";path=" + cookiepath : "" ) +
	( ( setdomainname ) ? ";domain=" + setdomainname : "" ) +
	( ( secure ) ? ";secure" : "" );
};

Liwio.prototype.getCookie = function ( name )
{
	if (document.cookie.length>0)
  	{
		var returnValue = "-";
		var reg = new RegExp("(?:^|;\\s)"+name+"=(.*?)(?:;|$)");
		var cookie = reg.exec(document.cookie);
		if (cookie)
		{
			if (cookie.length > 1)
			{
				returnValue = cookie[1];
			}
		}
		return returnValue;
  	}
};

Liwio.prototype.deleteCookie = function ( name , cookiepath , setdomainname )
{
	
	if(!cookiepath) cookiepath = '/';
	if(!setdomainname) setdomainname = this.getHostname();
	
	var cookie_date = new Date ( ); 
	cookie_date.setTime ( cookie_date.getTime() - 1 );
  	document.cookie = name + "=" +
		( ( cookiepath ) ? ";path=" + cookiepath : "") +
		( ( setdomainname ) ? ";domain=" + setdomainname : "" ) +
		";expires=" + cookie_date.toGMTString();
};

Liwio.prototype.getHostname = function()
{
	hn = document.location.hostname.split( '' ).reverse().join( '' );
	hn = hn.match(/(?:[a-z]{2,4}\.[a-z]{2,4}|[a-z]{2,4})\.[a-z0-9\-]+\./i);
	hn = hn[0].split( '' ).reverse().join( '' );
	
	return hn;
};

Liwio.prototype.getUnixtime = function()
{
	var foo = new Date;
	var unixtime_ms = foo.getTime();
	var unixtime = parseInt(unixtime_ms / 1000);
	
	return unixtime;
};

Liwio.prototype.isNumeric = function( sText )
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   /*var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}*/
	
   return IsNumber;
};

Liwio.prototype.isArray = function (array) {
    if (array) {
        if (array.constructor.toString().indexOf("Array") == -1) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
};

Liwio.prototype.clean = function( string )
{
	string = string.replace(/\s+|\+/g, '-');
	string = string.replace(/À|Á|Â|Ã|Ä|Å|Æ/gi, 'a');
	string = string.replace(/Ç/gi, 'c');
	string = string.replace(/È|É|Ê|Ë|é|è/gi, 'e');
	string = string.replace(/Ì|Í|Î|Ï/gi, 'i');
	string = string.replace(/Ñ/gi, 'n');
	string = string.replace(/Ò|Ó|Ô|Õ|Ö|Ø/gi, 'o');
	string = string.replace(/Ù|Ú|Û|Ü/gi, 'u');
	string = string.replace(/Ý|Y|ÿ/gi, 'y');
	string = string.replace(/ß/gi, 'ss');
	string = string.replace(/æ/gi, 'ae');
	string = string.toLowerCase();
	
	return string;
};

Liwio.prototype.hash = function()
{
	if ( document.location.hash )
    {
    	this.ad = this.ad + (this.ad.length ? "&" : "?") + document.location.hash.replace(/^#/, "");
    }
};

Liwio.prototype.getTimeDifference = function( begin , end )
{	
	if (begin && end)
	{
        begin = parseInt(begin);
        end = parseInt(end);
        var d = end - begin;
        
        if (d > 0)
        {            
            if( d < 60)
            {
            	return d + "s";
            }
            else if (d < 3600)
            {
            	d = Math.floor(d / 60);
            	return d + "m";
            }
            else if (d < 86400)
            {	
                d = Math.floor(d / 3600);
                return d + "h";
            }
            else
            {
               return Math.floor(d / 86400)+"j";
            }
        }
        else
        {
        	return "";
        }
    }
};


/****************************************
*
*	Fonctions liées aux cookies GA
*	getUtmz
*	getUtma
*	getUtmb
*	
*	
*
******************************************/

Liwio.prototype.getUtmz = function( info )
{
	var utmz = new Array();
	var gclid = '-';
	var source = '-';
	var medium = '-';
	var term = '-';
	var content = '-';
	var name = '-';
	
	utmz = this.getCookie("__utmz").toLowerCase();
	utmz = utmz.substr( utmz.indexOf('utm') , utmz.length );

	utmz = utmz.replace(/\(|\)/g, '');
	
	var utms = utmz.split('|');
    for (var i = 0; i < utms.length; i++)
    {
        var key = utms[i].substring(0, utms[i].indexOf('='));
        var val = decodeURIComponent(utms[i].substring(utms[i].indexOf('=')+1, utms[i].length));
        switch(key)
        {
            case 'utmcsr':
                source = val;
                break;
            case 'utmcmd':
                medium = val;
                break;
            case 'utmccn':
                name = val;
                break;
            case 'utmctr':
                term = val.substr(0, 61);
                break;
            case 'utmcct':
                content = val;
                break;
            case 'utmgclid':
                gclid = val;
                break;
         }
     }
        
        if ( gclid != '-' )
        {
        	source = 'google';
        	medium = 'cpc';
        }
        
        switch(info)
        {
            case 'source':
                return source;
                break;
            case 'medium':
                return medium;
                break;
            case 'name':
                return name;
                break;
            case 'term':
                return term.substr(0, 61);
                break;
            case 'content':
                return content;
                break;
            case 'gclid':
                return gclid;
                break;
        }

	    return {
            'source': source,
            'medium': medium,
            'name': name,
            'term': term,
            'content': content,
            'gclid': gclid
        };
};

//Permet de reecrire des parties du cookie utmz
Liwio.prototype.setUtmz = function( key , value )
{
	if ( key && value )
	{
		reg = "";
		switch(key)
        {
            case 'source':
                reg = /utmcsr=.*?(?:\||$)/i;
                reg2 = "utmcsr";
                break;
            case 'medium':
                reg = /utmcmd=.*?(?:\||$)/i;
                reg2 = "utmcmd";
                break;
            case 'name':
                reg = /utmccn=.*?(?:\||$)/i;
                reg2 = "utmccn";
                break;
            case 'term':
                reg = /utmctr=.*?(?:\||$)/i;
                reg2 = "utmctr";
                break;
            case 'content':
               reg = /utmcct=.*?(?:\||$)/i;
               reg2 = "utmcct";
                break;
            case 'gclid':
                reg = /utmcgclid=.*?(?:\||$)/i;
                reg2 = "utmcgclid";
                break;
        }

		if ( reg )
		{	
		
			utmz = this.getCookie('__utmz');
			utmz = utmz.replace( reg , reg2 + "=" + value + "|" );

			if ( utmz[utmz.length-1] == "|" )
			{
				utmz = utmz.substring( 0 , utmz.length-1 );
			}

			this.setCookie('__utmz' , utmz , 183 , this.ag , this.ae );
		}
	}
};

//Fonction qui renvoie les infos utma sous forme d'array ou sinon string si l'info demandee est specifiee
//@info = string
//Si @info definit return string
//Si @info non definit return array
Liwio.prototype.getUtma = function( info )
{
	var utma = new Array();
	
	utma = this.getCookie("__utma").split(".");
    
     switch(info)
     {
     	case 'dh':
        	return parseInt(utma[0]);
        break;      
        case 'uid':
            return parseInt(utma[1]);
        break;
        case 'fv':
            return parseInt(utma[2]);
        break;
        case 'lv':
            return parseInt(utma[3]);
        break;
        case 'cv':
            return parseInt(utma[4]);
        break;
        case 'nbv':
            return parseInt(utma[5]);
        break;
      }
      
      return {
    	'dh': parseInt(utma[0]),
        'uid': parseInt(utma[1]),
        'fv': parseInt(utma[2]),
        'lv': parseInt(utma[3]),
        'cv': parseInt(utma[4]),
        'nbv': parseInt(utma[5])
       };
};

Liwio.prototype.getUtmb = function( info )
{
	var utmb = new Array();
	
	utmb = this.getCookie("__utmb").split(".");
    
     switch(info)
     {
     	case 'dh':
        	return parseInt(utmb[0]);
        break;      
        case 'pageview':
            return parseInt(utmb[1]);
        break;
        case 'bucket':
            return parseInt(utmb[2]);
        break;
        case 'cv':
            return parseInt(utmb[3]);
        break;
      }
      
      return {
    	'dh': parseInt(utmb[0]),
        'pageview': parseInt(utmb[1]),
        'bucket': parseInt(utmb[2]),
        'cv': parseInt(utmb[3])
       };
};

/****************************************
*
*	Fonctions relatives à l'initailisation GA
*	initTracking
*	addOrganic
*	sessionBegin
*	
*
******************************************/
Liwio.prototype.initTracking = function()
{
	if ( this.a )
    {
		this.ab = this.a;
		this.a = this.a + ".";
    }
 	
	_gaq.push( [ '_gat._createTracker' , this.ac , this.ab ]);
    _gaq.push( [ this.a + '_setAllowAnchor' , true ] );
	
	if( this.ns )
	{
		//_gaq.push( [ this.a + '_setNamespace' , 'preprod' ] );
	}
	_gaq.push( [ this.a + '_setMaxCustomVariables' , 10 ] );
    
    if ( this.ae )
    {
    	_gaq.push( [ this.a + '_setDomainName' , this.ae ] );
    }
    
    if ( this.af )
    {
        _gaq.push( [ this.a + '_setAllowHash' , false ] );
        _gaq.push( [ this.a + '_setAllowLinker', true ] );
    }
    
    if ( this.ag )
    {
        _gaq.push( [ this.a + '_setCookiePath', this.ag ] );
    }
};

Liwio.prototype.addOrganic = function()
{

	_gaq.push( [ this.a + '_addOrganic' , 'lo.st' , 'x_query'] );
	_gaq.push( [ this.a + '_addOrganic' , 'google' , 'query'] );
	
	if ( this.ah )
	{
		switch( this.ah )
		{
			case 'en' :
				_gaq.push( [ this.a + '_addOrganic' , 'google.co.uk' , 'q', true ] ); 
				_gaq.push( [ this.a + '_addOrganic' , 'google.com' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.ie' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.au' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.co.in' , 'q', true ] ); 
				_gaq.push( [ this.a + '_addOrganic' , 'google.ca' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.co.nz' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.co.za' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.hk' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.sg' , 'q', true ] );
			break;
			
			case 'fr' :
				_gaq.push( [ this.a + '_addOrganic' , 'google.fr' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.ch' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.be' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.ca' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.co.ma' , 'q', true ] );
				
			break;
			
			case 'es' :
				_gaq.push( [ this.a + '_addOrganic' , 'google.es' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.mx' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.ar' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.co' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.pe' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.co.ve' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.cl' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.ec' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.co.cr' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.do' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.uy' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.gt' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.bo' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.pr' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.py' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.sv' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.hn' , 'q', true ] );
				_gaq.push( [ this.a + '_addOrganic' , 'google.com.ni' , 'q', true ] );
			break;
		}
	}

 	if ( this.getUtmz('medium') == 'organic' )
    {
		//Condition relative à la position du mot clé
		ref = new RegExp( /((?:&|\?)cd=([0-9]+))/ );
	    var match = ref.exec( document.referrer );
		if( match != null )
		{
			if ( match[2] )
			{
				this.setUtmz( 'name' , 'SEO' );
				this.setUtmz( 'content' , match[2] );
			}
		}
		else
		{	
			ref = new RegExp( /((\?|&)(start|b|first|ap)=[0-1](&|$))|^.(?!.*(\?|&)(start|b|first|ap)=)/ );
			var match = ref.exec( document.referrer );
			if ( match != null )
			{
				this.setUtmz( 'name' , 'SEO' );
				this.setUtmz( 'content' , 'Page-1' );
			}
			
			ref = new RegExp( /(\?|&)(start|b|first|ap)=(10|11|2)(&|$)/ );
			var match = ref.exec( document.referrer );
			if ( match != null )
			{
				this.setUtmz( 'name' , 'SEO' );
				this.setUtmz( 'content' , 'Page-2' );
			}
			
			ref = new RegExp( /(\?|&)(start|b|first|ap)=(20|21|3)(&|$)/ );
			var match = ref.exec( document.referrer );
			if ( match != null )
			{
				this.setUtmz( 'name' , 'SEO' );
				this.setUtmz( 'content' , 'Page-3' );
			}
			
			ref = new RegExp( /(\?|&)(start|b|first|ap)=(?![0-3](&|$))(?![1-2][0-1](&|$))/ );
			var match = ref.exec( document.referrer );
			if ( match != null )
			{
				this.setUtmz( 'name' , 'SEO' );
				this.setUtmz( 'content' , 'Page-4' );
			}
		}
    }
};

Liwio.prototype.remi = function()
{
	V = this.isNewSession();

	this.initTracking();
	this.uri();
	
	this.siteSearch();
	this.hash();
	
	_gaq.push( [ this.a + '_initData' ]);
	
	U = this;
	if ( this.sourceDirect() )
	{
		_gaq.push(function ()
		{
			if ( V )
			{
				U.addOrganic();
				U.socialMedia();
				U.webmail();
			}
     	});
     }
	
	//Conditions liées au tunnel de conversion !!!!!!!!!!!!!!!!!! Revoir dessous la page
	U.buy();
	
	_gaq.push(function ()
	{
		U.customvar1();
		U.customvar2();
		U.customvar3();
		U.customvar4();
		U.customvar5();
		U.customvar6();
		U.customvar7();
		U.customvar8();
		U.tpv(U.ad);
		U.trans();
     });
};

/****************************************
*
*	Fonctions relatives à GA
*	siteSearch : reecrit this.ad = uri
*	notoriete : boolean
*	cleanURI : string
*	
*	
*
******************************************/


Liwio.prototype.siteSearch = function()
{
	if( this.am )
	{
		this.ad = this.ad + (this.ad.match(/\?/) ? "&" : "?") + "LiwioKw=" + this.am;
	}
	
	if( this.an )
	{
		this.ad = this.ad + (this.ad.match(/\?/) ? "&" : "?") + "LiwioCat=" + this.an;
	}
	
	if( this.ao == false && this.am )
	{
		this.ad = this.ad + (this.ad.match(/\?/) ? "&" : "?") + "LiwioRes=no_results";
	}
	else if ( this.am )
	{
		this.ad = this.ad + (this.ad.match(/\?/) ? "&" : "?") + "LiwioRes=results";
	}
};

Liwio.prototype.notoriete = function ( )
{
	if( this.getUtmz('medium') == 'none' )
	{
		return true;
	}
	
	term = this.getUtmz('term');

	if ( this.ba && term )
	{
		reg = new RegExp( this.ba , "i" );

		if( term.match( reg ) )
		{
			return true;
		}
		else
		{
			return false;	
		}
	}
	else
	{
		return false;
	}
};

Liwio.prototype.cleanURI = function( URI )
{
	if (URI)
	{
		URI = decodeURI(URI);
		URI = URI.replace( /gclid=.*?(?:&|$)/i , "" );
		URI = URI.replace( /utm_source=.*?(?:&|$)/i , "" );
		URI = URI.replace( /utm_medium=.*?(?:&|$)/i , "" );
		URI = URI.replace( /utm_term=.*?(?:&|$)/i , "" );
		URI = URI.replace( /utm_content=.*?(?:&|$)/i , "" );
		URI = URI.replace( /utm_campaign=.*?(?:&|$)/i , "" );
		
		if ( URI[URI.length-1] == "?" || URI[URI.length-1] == "&" || URI[URI.length-1] == "#" )
		{
			URI = URI.substring( 0 , URI.length-1 );
		}
	}
	else
	{
		URI = "";
	}
	
	return URI;
};

Liwio.prototype.firstStepTunnel = function()
{	
	if ( this.ap )
	{
		reg = new RegExp( this.ap );
	
		if ( this.ad.match ( reg ) )
		{
			if ( document.cookie.indexOf("liwio-step1=") == -1 )
			{	
				this.setCookie( 'liwio-step1' , this.getUnixtime() , 0 , this.ag , this.ae );
			}
		}
	}
};

Liwio.prototype.getFirstStepTunnel = function()
{
	if ( document.cookie.indexOf("liwio-step1=") != -1 )
	{
		archive = this.getCookie( 'liwio-step1' );
		archive = parseInt(archive);
		return archive;
	}
	else
	{
		return 0;
	}
};

Liwio.prototype.isNewSession = function()
{
	if( document.cookie.indexOf('__utmb=') == -1 || document.cookie.indexOf('__utmc=') == -1 )
	{
		return true;
	}
	else
	{
		return false;
	}
};

Liwio.prototype.isNewVisitor = function()
{
	if( document.cookie.indexOf('__utma=') == -1 || this.getUtma('nbv') == 1 )
	{
		return true;
	}
	else
	{
		return false;
	}
};

Liwio.prototype.uri = function()
{
    /*if ( this.ai && !this.ad && this.ai != 'divers' )
    {
		this.ad = '/' + this.clean(this.ai);
		if( this.aii ) this.ad = this.ad + '/' + this.clean(this.aii);
		if( this.aiii ) this.ad = this.ad + '/' + this.clean(this.aiii);
    }
	else */if( !this.ad )
	{
		this.ad = document.location.pathname + document.location.search;
	}
};

/****************************************
*
*	Fonctions liées aux ecommerce GA
*	
******************************************/
Liwio.prototype.orderId = function( orderid )
{
	if ( orderid )
    {
    	orderid = orderid + "-" + this.getUtma('uid');
    }
	else
	{
		orderid = this.getUtma('uid');
	}
	
	orderid = orderid + "-" + this.getHostname();
	
	if ( this.conf )
	{
		orderid = this.conf + orderid;
	}
	
    return orderid;
};

Liwio.prototype.affiliation = function()
{
	affiliation = '-';
	
	return affiliation;
};

Liwio.prototype.price = function( number )
{	
	if ( number.length > 0 )
    {
		number = number.replace(/,/, ".");
    }
    else
    {
    	number = 0;
    }
    
    return number;
};

Liwio.prototype.taxe = function( number )
{	
	if ( number.length > 0 )
    {
		number = number.replace(/,/, ".");
    }
    else
    {
    	number = 0;
    }
    
    return number;
};

Liwio.prototype.shipping = function( number )
{	
	if ( number.length > 0 )
    {
		number = number.replace(/,/, ".");
    }
    else
    {
    	number = 0;
    }
    
    return number;
};

Liwio.prototype.sku = function( sku )
{    
    if ( sku )
    {
		sku = sku;
    }
    else
    {
    	sku = this.getUtmz('source') + '_' + this.getUtmz('medium') + '_' + ( ( this.notoriete() ) ? "notoriete" : "generic" );
    }
    
    if ( !sku )
    {
    	sku = Math.floor(Math.random() * 9999999);
    }
    
    return sku;
};

Liwio.prototype.name = function( name )
{
	return name;
};

Liwio.prototype.category = function( category )
{
	return category;
};

Liwio.prototype.uniq = function( number )
{	
	if ( number.length > 0 )
    {
		number = number.replace(/,/, ".");
    }
    else
    {
    	number = 0;
    }
    
    return number;
};

Liwio.prototype.quantity = function( quantity )
{
	quantity = parseInt(quantity);
	
	if( quantity > 0 )
	{
		quantity = quantity;
	}
	else
	{
		quantity = 1;
	}
	
	return quantity;
};

Liwio.prototype.trans = function()
{

	if( this.eo )
	{
		this.eo = this.orderId( this.eo );
		this.ea = this.affiliation( this.ea );
		this.ep = this.price( this.ep );
		this.et = this.taxe( this.et );
		this.es = this.shipping( this.es );
		
		if ( this.getCookie( this.eo ) == "-"  )
		{
			_gaq.push([ this.a + '_addTrans', this.eo , this.ea , this.ep , this.et , this.es , '' , '' , '' ]);
			this.setCookie( this.eo , "" );
		}
		
		if (this.isArray(this.en) == true)
		{
			for (i = 0; i < this.en.length; i++)
			{
				name = this.name(this.en[i]);
				sku = this.sku(this.er[i]);
				category = this.category(this.ec[i]);
				uniq = this.uniq(this.eu[i]);
				qy = this.quantity(this.eq[i]);
				
				reg = new RegExp("(?:^|\|)"+sku+"(?:\||$)");
				if ( this.getCookie(this.eo).match(reg) == null )
				{
					_gaq.push([ this.a + '_addItem', this.eo, sku, name, category, uniq, qy]);
					this.setCookie( this.eo , this.getCookie(this.eo) + "|" + sku );
				}
			}
		}
		else
		{
			name = this.name(this.en);
			sku = this.sku(this.er);
			category = this.category(this.ec);
			uniq = this.uniq(this.eu);
			qy = this.quantity(this.eq);
			
			reg = new RegExp("(?:^|\|)"+sku+"(?:\||$)");
			if ( this.getCookie(this.eo).match(reg) == null )
			{
				_gaq.push([ this.a + '_addItem', this.eo, sku, name, category, uniq, qy]);
				this.setCookie( this.eo , this.getCookie(this.eo) + "|" + sku );
			}
		}
    	_gaq.push([ this.a + '_trackTrans']);
    }
};

/****************************************
*
*	Fonctions liées aux sources de trafic
*	
*	
*	
*	
*	
*
******************************************/

//Si le cookie utmb est present mais pas le cookie utmc alors il s'agit d'une visite directe due au temps d'attente
Liwio.prototype.sourceDirect = function()
{
	if ( document.cookie.indexOf('__utmc=') >= 0 && document.cookie.indexOf('__utmb=') == -1 )
	{
		//this.setUtmz( 'medium' , '(go-on-visit)' );
		//this.setUtmz( 'source' , '(direct)' );
		//this.setUtmz( 'name' , '(direct)' );
		
		return false;
	}
	else
	{
		return true;
	}
};

//Transforme le medium des reseaux sociaux en "social-media" si pas CPC.
Liwio.prototype.socialMedia = function()
{
	sm = new Array();
	sm[0] = 'advogato\.org';
	sm[1] = 'amiestreet\.com';
	sm[2] = 'anobii\.com';
	sm[3] = 'asianave\.com';
	sm[4] = 'athlinks\.com';
	sm[5] = 'mubi\.com';
	sm[6] = 'avatarsuniqed\\.com';
	sm[7] = 'badoo\\.com';
	sm[8] = 'bebo\.com';
	sm[9] = 'bigadda\.com';
	sm[10] = 'bigtent\.com';
	sm[11] = 'biip\.no';
	sm[12] = 'blackplanet\.com';
	sm[13] = 'blogster\.com';
	sm[14] = 'buzznet\.com';
	sm[15] = 'cafemom\.com';
	sm[16] = 'cakefinancial\.com';
	sm[17] = 'care2\.com';
	sm[18] = 'caringbridge\.org';
	sm[19] = 'cellufun\.com';
	sm[20] = 'classmates\.com';
	sm[21] = 'cloob\.com';
	sm[22] = 'collegeblender\.com';
	sm[23] = 'couchsurfing\.org';
	sm[24] = 'cozycot\.com';
	sm[25] = 'crunchyroll\.com';
	sm[26] = 'nate\.com';
	sm[27] = 'dailybooth\.com';
	sm[28] = 'dailystrength\.org';
	sm[29] = 'decayenne\.com';
	sm[30] = 'delicious\.com';
	sm[31] = 'deviantart\.com';
	sm[32] = 'disaboom\.com';
	sm[33] = 'dol2day\.com';
	sm[34] = 'dontstayin\.com';
	sm[35] = 'draugiem\.lv';
	sm[36] = 'elftown\.com';
	sm[37] = 'epernicus\.com';
	sm[38] = 'eons\.com';
	sm[39] = 'esnips\.com';
	sm[40] = 'experienceproject\.com';
	sm[41] = 'exploroo\.com';
	sm[42] = 'facebook\.com';
	sm[43] = 'faceparty\.com';
	sm[44] = 'fetlife\.com';
	sm[45] = 'fillos\.org';
	sm[46] = 'profileheaven\.com';
	sm[47] = 'filmaffinity\.com';
	sm[48] = 'thefitfinder\.co\.uk';
	sm[49] = 'fledgewing\.com';
	sm[50] = 'flixster\.com';
	sm[51] = 'flickr\.com';
	sm[52] = 'folkdirect\.com';
	sm[53] = 'fotolog\.com';
	sm[54] = 'foursquare\.com';
	sm[55] = 'friendsreuniqed\.com';
	sm[56] = 'friendster\.com';
	sm[57] = 'fruehstueckstreff\.de';
	sm[58] = 'gaiaonline\.com';
	sm[59] = 'gamerdna\.com';
	sm[60] = 'gather\.com';
	sm[61] = 'gays\.com';
	sm[62] = 'geni\.com';
	sm[63] = 'gogoyoko\.com';
	sm[64] = 'goodreads\.com';
	sm[65] = 'gossipreport\.com';
	sm[66] = 'govloop\.com';
	sm[67] = 'grono\.net';
	sm[68] = 'hospitalityclub\.org';
	sm[69] = 'hi5\.com';
	sm[70] = 'thehotlist\.com';
	sm[71] = 'hubculture\.com';
	sm[72] = 'hyves\.nl';
	sm[73] = 'ibibo\.com';
	sm[74] = 'indabamusic\.com';
	sm[75] = 'irc-galleria\.net';
	sm[76] = 'italki\.com';
	sm[77] = 'internations\.org';
	sm[78] = 'itsmy\.com';
	sm[79] = 'iwiw\.hu';
	sm[80] = 'jaiku\.com';
	sm[81] = 'jammerdirect\.com';
	sm[82] = 'kaioo\.com';
	sm[83] = 'kaixin001\.com';
	sm[84] = 'kiwibox\.com';
	sm[85] = 'lafango\.com';
	sm[86] = 'lastfm\.fr';
	sm[87] = 'librarything\.com';
	sm[88] = 'lifeknot\.com';
	sm[89] = 'linkedin\.com';
	sm[90] = 'linkexpats\.com';
	sm[91] = 'listography\.com';
	sm[92] = 'livejournal\.com';
	sm[93] = 'livemocha\.com';
	sm[94] = 'ls8\.se';
	sm[95] = 'meetin\.org';
	sm[96] = 'meetup\.com';
	sm[97] = 'meettheboss\.tv';
	sm[98] = 'mixi\.jp';
	sm[99] = 'mocospace\.com';
	sm[100] = 'mog\.com';
	sm[101] = 'mouthshut\.com';
	sm[102] = 'multiply\.com';
	sm[103] = 'muxlim\.com';
	sm[104] = 'myanimelist\.net';
	sm[105] = 'mychurch\.org';
	sm[106] = 'myheritage\.fr';
	sm[107] = 'mylife\.com';
	sm[108] = 'my\.opera\.com';
	sm[109] = 'myspace\.com';
	sm[110] = 'myyearbook\.com';
	sm[111] = 'nk\.pl';
	sm[112] = 'netlog\.com';
	sm[113] = 'nettby\.no';
	sm[114] = 'nexopia\.com';
	sm[115] = 'ngopost\.org';
	sm[116] = 'ning\.com';
	sm[117] = 'odnoklassniki\.ru';
	sm[118] = 'oneclimate\.net';
	sm[119] = 'oneworld\.net';
	sm[120] = 'opendiary\.com';
	sm[121] = 'orkut\.com';
	sm[122] = 'outeverywhere\.com';
	sm[123] = 'partnerup\.com';
	sm[124] = 'passportstamp\.com';
	sm[125] = 'pingsta\.com';
	sm[126] = 'plaxo\.com';
	sm[127] = 'playahead\.se';
	sm[128] = 'plurk\.com';
	sm[129] = 'presently\.com';
	sm[130] = 'qapacity\.com';
	sm[131] = 'quechup\.com';
	sm[132] = 'qq\.com';
	sm[133] = 'raptr\.com';
	sm[134] = 'ravelry\.com';
	sm[135] = 'renren\.com';
	sm[136] = 'researchgate\.net';
	sm[137] = 'reverbnation\.com';
	sm[138] = 'ryze\.com';
	sm[139] = 'sciencestage\.com';
	sm[140] = 'scispace\.com';
	sm[141] = 'sharethemusic\.com';
	sm[142] = 'shelfari\.com';
	sm[143] = 'skyrock\.com';
	sm[144] = 'socialvibe\.com';
	sm[145] = 'somethingawful\.com';
	sm[146] = 'sonico\.com';
	sm[147] = 'stickam\.com';
	sm[148] = 'studivz\.net';
	sm[149] = 'stumbleupon\.com';
	sm[150] = 'tagged\.com';
	sm[151] = 'lafango\.com';
	sm[152] = 'talkbiznow\.com';
	sm[153] = 'taltopia\.com';
	sm[154] = 'taringa\.net';
	sm[155] = 'teachstreet\.com';
	sm[156] = 'travbuddy\.com';
	sm[157] = 'travellerspoint\.com';
	sm[158] = 'tribe\.net';
	sm[159] = 'trombi\.com';
	sm[160] = 'tuenti\.com';
	sm[161] = 'tumblr\.com';
	sm[162] = 'twitter\.com';
	sm[163] = 'vk\.com';
	sm[164] = 'vampirefreaks\.com';
	sm[165] = 'viadeo\.com';
	sm[166] = 'virb\.com';
	sm[167] = 'vox\.com';
	sm[168] = 'wakoopa\.com';
	sm[169] = 'wattpad\.com';
	sm[170] = 'wasabi\.com';
	sm[171] = 'wayn\.com';
	sm[172] = 'weeworld\.com';
	sm[173] = 'weourfamily\.com';
	sm[174] = 'wer-kennt-wen\.de';
	sm[175] = 'weread\.com';
	sm[176] = 'wiserearth\.org';
	sm[177] = 'xanga\.com';
	sm[178] = 'xing\.com';
	sm[179] = 'xt3\.com';
	sm[180] = 'yammer\.com';
	sm[181] = 'yelp\.com';
	sm[182] = 'zoo\.gr';
	sm[183] = 'zooppa\.com';
	sm[184] = 'argentinalife\.net';
	sm[185] = 'liwio\.com';
	
	reg = RegExp( "^(?:"+sm.join('|')+")" , "i" );
	
	if ( this.getUtmz('medium') == 'referral' && this.getUtmz('source').match(reg) )
	{
		this.setUtmz( 'medium' , '(social-media)' );
	}
};

Liwio.prototype.webmail = function()
{
	reg = RegExp( "(?:webmail|sfr-messagerie|mail.yahoo|imp.free.fr|mail.live|zimbra|mail[0-9].voila|mail.google)" , "i" );

	if ( this.getUtmz('source').match( reg ) )
	{
		this.setUtmz( 'source' , 'webmail' );
		this.setUtmz( 'medium' , 'email' );
	}
};


/****************************************
*
*	Fonctions liées aux sources de trafic
*
******************************************/
Liwio.prototype.customvar1 = function()
{
	if( this.aj ) { pagetype = this.clean(this.aj) }else { pagetype = '-' };
	if( this.isNumeric(this.photos) ) { photos = this.photos }else { photos = '-' };
	if( this.isNumeric(this.desc) ) { desc = this.desc }else { desc = '-' };
	if( this.isNumeric(this.eu) ) { prix = this.eu }else { prix = '-' };
	if( this.isNumeric(this.couleurs) ) { couleurs = this.couleurs }else { couleurs = '-' };	
	if( this.module == 'oui' ) { module = 1 }else { module = 0 };
	if( this.isNumeric(this.prixorigine) ) { prixorigine = this.prixorigine }else { prixorigine = '-' };
	if( this.isNumeric(this.promo) ) { promo = this.promo }else { promo = '-' };
	if( this.isNumeric(this.produits) ) { produits = this.produits }else { produits = '-' };
	if( this.isNumeric(this.nbcat) ) { nbcat = this.nbcat }else { nbcat = '-' };
	
	value = '0-' + pagetype + '_1-' + photos + '_2-' + desc + '_3-' + prix + '_4-' + couleurs + '_5-' + module + '_6-' + prixorigine + '_7-' + promo + '_8-' + produits + '_9-' + nbcat;
	
	_gaq.push( [ this.a + '_setCustomVar', 1 , this.clean(this.ai) , value , 2 ] );
	_gaq.push( [ this.a + '_setCustomVar', 2 , this.clean(this.ai) , value , 3 ] );
};

Liwio.prototype.customvar2 = function()
{
	//Cf customvar 1
};

Liwio.prototype.customvar3 = function()
{
	/*if ( this.getUtma('nbv') == 1 )
	{
        _gaq.push( ['_setCustomVar', 3, 'First-Source', this.getUtmz('source') + '_' + this.getUtmz('medium'), 1] );
    }*/
	
	position = '-';
	ref = new RegExp( /((?:&|\?)cd=([0-9]+))/ );
	var match = ref.exec( document.referrer );

	if( match != null )
	{
		if ( match[2] )
		{
			position = 'position-'+match[2];
		}
	}
	else
	{
		ref = new RegExp( /((\?|&)(start|b|first|ap)=[0-1](&|$))|^.(?!.*(\?|&)(start|b|first|ap)=)/ );
		var match = ref.exec( document.referrer );
		if ( match != null )
		{
			position = 'page-1';
		}
		
		ref = new RegExp( /(\?|&)(start|b|first|ap)=(10|11|2)(&|$)/ );
		var match = ref.exec( document.referrer );
		if ( match != null )
		{
			position = 'page-2';
		}
		
		ref = new RegExp( /(\?|&)(start|b|first|ap)=(20|21|3)(&|$)/ );
		var match = ref.exec( document.referrer );
		if ( match != null )
		{
			position = 'page-3';
		}
		
		ref = new RegExp( /(\?|&)(start|b|first|ap)=(?![0-3](&|$))(?![1-2][0-1](&|$))/ );
		var match = ref.exec( document.referrer );
		if ( match != null )
		{
			position = 'page-4';
		}
	}

	if ( position != '-' )
	{
		_gaq.push( [ this.a + '_setCustomVar', 3, 'SEO', position, 2] );
	}
};

Liwio.prototype.customvar4 = function()
{	
	//Key : online/offline
	//Value : undefined ou ville
	//Level 1
	var F = _gat._getTrackerByName(this.ab);
	if (F)
	{
		F._getVisitorCustomVar(4);
	}
	//Si pas de custom var on en créé une avec online undefined
	if ( !F._getVisitorCustomVar(4) )
	{
		_gaq.push( [ this.a + '_setCustomVar', 4 , 'online' , 'undefined' , 1 ] );
	}
	//Si page = /boutique et custom var = online on passe en offline
	if ( this.ad == '/fr/store-locator/' && ( !F._getVisitorCustomVar(4) || F._getVisitorCustomVar(4) == 'undefined' ) )
	{
		_gaq.push( [ this.a + '_setCustomVar', 4 , 'offline' , 'undefined' , 1 ] );
	}
	//Si referrer moteur de recherche contient un nom de ville on passe le nom de ville dans le offline
	ref = new RegExp( /(aix|angers|angouleme|anvers|avignon|besancon|bordeaux|boulogne|bourges|bruges|bruxelles|cannes|deauville|dijon|ferrand|grenoble|knooke|la defense|le havre|levallois|lille|limoges|londres|lyon|marseille|marylebone|metz|montpellier|nancy|nantes|neuilly|nice|orleans|parly 2|passy|pau|rennes|rome|rouen|saint etienne|saint tropez|sevres|strasbourg|toulouse|tours)/ );
	var match = ref.exec( this.getUtmz('term') );	
	if ( match != null )
	{
		_gaq.push( [ this.a + '_setCustomVar', 4 , 'offline' , this.clean(match[0]) , 1 ] );
	}
};

Liwio.prototype.customvar5 = function()
{
	//Key : Client/Prospect
	//Value : Montant panier
	//Level 1
	
	//Si page de recap panier
	//if ( this.ad.match('/v1/ShowBasket.php') )
	//{
	//	_gaq.push( [ this.a + '_setCustomVar', 5 , 'Prospect' , this.ep , 1 ] );
	//}
	//else if ( this.ad.match('/reinit.php/i') )
	//{
	//	_gaq.push( [ this.a + '_setCustomVar', 5 , 'Client' , this.ep , 1 ] );
	//}
	
	_gaq.push(function(){
		//Custom var ou inserer l'ID unique
		customVar = 5;

		var F = _gat._getTrackerByName();
		if (!F._getVisitorCustomVar(customVar))
		{
			var date = new Date();
			_gaq.push([ '_setCustomVar', customVar, 'ID', date.getTime()+Math.floor(Math.random()*100000), 1]);
		}
	});
};

Liwio.prototype.customvar6 = function()
{

};

Liwio.prototype.customvar7 = function()
{
	//date = new Date();
	//Jour de la semaine
	//_gaq.push( [ this.a + '_setCustomVar', 7 , 'Day' , date.getDay() , 2 ] );
};

Liwio.prototype.customvar8 = function()
{
	//Jour du mois
	//_gaq.push( [ this.a + '_setCustomVar', 8 , 'Date' , date.getDate() , 2 ] );
};

Liwio.prototype.setVar = function( string )
{
	reg = new RegExp( 'mail' );
	if( string )
	{
		_gaq.push( [ this.a + '_setVar', string ] );
	}
	else if ( !string && (getUtmz('medium').match(reg) || this.ad == '/newsletter.php') )
	{
		_gaq.push( [ this.a + '_setVar', 'Newsletter' ] );
	}
};

Liwio.prototype.buy = function()
{
	//Ce qu'il se passe juste avant la vente. Recup d'infos etc...
	if ( this.ad.match('/reinit.php/i') )
	{
		_gaq.push([ this.a + '_trackEvent' , 'Time-to-contract' , this.getTimeDifference( this.getUtma('cv') , this.getUnixtime() ) ]);
	}
	//U.firstStepTunnel();
};

loadPostMessage = function()
{
	/*
	$(document).ready(function(){
		var url = location.pathname;
		if (url.indexOf("fr/product/") > -1 )
		{
			//if (typeof console != "undefined") console.log("remi"); 
			//Code Facebook Like :
			$("div#b_add").replaceWith("<div id=\"b_add\">\n                            \n      <input class=\"button\" type=\"button\" name=\"b_addBag\" id=\"b_addBag\" value=\"AJOUTER AU PANIER\" accesskey=\"submit\" tabindex=\"1\" style=\"cursor: pointer; \" onclick=\"javascript:checkAction(&quot;MARO&quot;, this.form.sizeSelect.options[this.form.sizeSelect.selectedIndex].value, &quot;Sac \\&quot;24 heures\\&quot; points lacés Daim lavé Santa Fé&quot;, &quot;Couleur:0067 - Taille:&quot;+this.form.sizeSelect.options[this.form.sizeSelect.selectedIndex].text,&quot;MB798M4580067_&quot;,&quot;Sélectionnez une taille&quot;, &quot;true&quot;);\">\n      <br>\n                          \n            </div><BR><iframe src=\"http://www.facebook.com/plugins/like.php?app_id=212873172076392&amp;href="+encodeURIComponent(document.location)+encodeURIComponent("?utm_source=facebook.com&utm_medium=(social-media)&utm_campaign=like_campaign")+"&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:450px; height:80px;\" allowTransparency=\"true\"></iframe><meta property=\"og:title\" content=\"Gerard Darel\" />\n<meta property=\"og:type\" content=\"company\" />\n<meta property=\"og:url\" content=\"\" />\n<meta property=\"og:image\" content=\"\" />\n<meta property=\"og:site_name\" content=\"Gerard Darel\" />\n<meta property=\"fb:admins\" content=\"733310763\" /><BR>");
			$("div#prod-info-under").css({"top":220});
			$("div#assoc-prods").css({"top":200});
		}
	});
	*/
};

if (typeof jQuery == "undefined"){
	var e = document.createElement("script");
	var gaJsHost= (("https:" == document.location.protocol) ? "https://" : "http://"); 
	e.src = gaJsHost+"ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js";
	e.type = "text/javascript";
	var tmp = document.getElementsByTagName("head")[0].appendChild(e);
	
	e.onload = loadPostMessage;
}
else loadPostMessage();


