/*---------------------------------------------*/
/* Last update : 2011-12-01 Pascal St-Louis    */
/* - Ajout: noel.canoe.ca >> var allSitesCA    */
/* - Modif: chealth.canoe.ca >> UA-26086572-1  */
/*---------------------------------------------*/
/* Update : 2011-09-06 Andre Riverin           */
/* - Implantation du code GA spécifique aux    */
/*   sites classified                          */
/* - Fix: Ajouter un "." devant les domaines   */
/*   des sites d'exceptions                    */
/*---------------------------------------------*/
/* Update : 2011-06-21 Pascal St-Louis         */
/* - Retrait du code GA global                 */
/* - Implantation du code GA spécifique aux    */
/*   domaines canoe.ca et canoe.com            */
/*   source : http://canoe.ca/generix/ga.js    */
/*---------------------------------------------*/

/*
	Author: Andre Riverin - nurun.com, 2011-06-16
	Modify: Pascal St-Louis - nurun.com, 2011-06-21
		Andre Riverin - nurun.com, 2011-09-06
		Pascal St-Louis - nurun.com, 2011-12-01
*/

/***************************************************************************************
	=> [ Dynamic GA script ]
***************************************************************************************/

// Test to avoid this script to run twice in the same page
if (typeof _GA_actualSite == 'undefined') {

	// Retrieve the domain name
	var _GA_actualSite = window.location.hostname;

	// Initialisation
	var UA_code = "";
	var domainName = "";
	var accountName = "canoeGlobal";
	var accountCode = "23847165";

	// Remove useless prefix
	_GA_actualSite = _GA_actualSite.toLowerCase();
	if (_GA_actualSite.substring(0,4) == "www.")
		_GA_actualSite = _GA_actualSite.substring(4);
	else if (_GA_actualSite.substring(0,5) == "www2.")
		_GA_actualSite = _GA_actualSite.substring(5);
	
	_GA_subDomains = _GA_actualSite.split(".");
        _GA_actualDomain = _GA_subDomains[_GA_subDomains.length-2] + "." + _GA_subDomains[_GA_subDomains.length-1];
	
	// Associative array with all sites and their associated GA code
	var allSitesCA = {
		"canoe.ca"						: "UA-26089433-1",
		"fr.canoe.ca"					: "UA-26089433-1",
		"chealth.canoe.ca"				: "UA-26086572-1",
		"federales2011.canoe.ca"		: "UA-26089433-1",
		"noel.canoe.ca"					: "UA-26089433-1",
		"passeport.canoe.ca"			: "UA-26089433-1"
	};
	var allSitesCOM = {
		"canoe.com"						: "UA-23847151-1",
		"bulletins.canoe.com"			: "UA-23847151-1",
		"cartesvirtuelles.canoe.com"	: "UA-23847151-1",
		"horairetele.canoe.com"			: "UA-23847151-1",
		"passeport.canoe.com"			: "UA-23847151-1",
		"sante.canoe.com"				: "UA-23847151-1"
	};
	var exceptionSites = {
		"24hmontreal.canoe.ca"			: "UA-22839502-1",
		"elephant.canoe.ca"				: "UA-24507761-1"
	};
	var classifiedSites = {
		"vitevitevite.ca"				: "UA-24978529-1",
		"classifiedextra.ca"			: "UA-24979614-1",
		"shopping.canoe.ca"				: "UA-25450198-1"
	};

	// Validate if current domain is in the list
	if (allSitesCA[_GA_actualSite]) {
		// Set 'canoe.ca' UA code
		UA_code = allSitesCA[_GA_actualSite];
		domainName = '.canoe.ca';
	} else if (allSitesCOM[_GA_actualSite]) {
		// Set 'canoe.com' UA code
		UA_code = allSitesCOM[_GA_actualSite];
		domainName = '.canoe.com';
	} else if (exceptionSites[_GA_actualSite]) {
		// Set exception sites UA code
		UA_code = exceptionSites[_GA_actualSite];
		domainName = "." + _GA_actualSite;
	} else if (classifiedSites[_GA_actualDomain] || classifiedSites[_GA_actualSite]) {
		// Set shopping sites UA code
		UA_code = classifiedSites[_GA_actualDomain] ? classifiedSites[_GA_actualDomain] : classifiedSites[_GA_actualSite];
		domainName = "." + (classifiedSites[_GA_actualDomain] ? _GA_actualDomain : _GA_actualSite);
		// Overwrite canoeGlobal account
		accountName = "classifiedsGlobal";
		accountCode = "24978842";
	} else {
		// Not in the whitelist array, so using a generic UA code
		UA_code = "UA-24016064-1";
		domainName = 'none';
	}

	var _gaq = _gaq || [];
	// Part 1
	_gaq.push(['_setAccount', UA_code]);
	_gaq.push(['_setDomainName', domainName]);
	_gaq.push(['_addIgnoredRef', 'canoe']);
	_gaq.push(['_trackPageview']);
	_gaq.push(['_trackPageLoadTime']);

	//Part 2
	_gaq.push([accountName + '._setAccount', 'UA-' + accountCode + '-1']);
	_gaq.push([accountName + '._setDomainName', 'none']);
	_gaq.push([accountName + '._setAllowLinker', true]);
	_gaq.push([accountName + '._setAllowHash', false]);
	_gaq.push([accountName + '._setCookiePath', '/' + accountCode + '/']);
	_gaq.push([accountName + '._setSessionCookieTimeout',  1800000]); //Default 30mins in milliseconds
	_gaq.push([accountName + '._setCampaignCookieTimeout', 2592000000]); //30days in milliseconds
	_gaq.push([accountName + '._setVisitorCookieTimeout', 63072000000]); //Default 24months in milliseconds
	_gaq.push([accountName + '._trackPageview']);
	_gaq.push([accountName + '._trackPageLoadTime']); //Page Loading Time Tracking Code

	// Part 3
	_gaq.push(['masterGlobal._setAccount', 'UA-21910987-1']); // 1.0 (Phase I) Master Global
	_gaq.push(['masterGlobal._setDomainName', 'none']);
	_gaq.push(['masterGlobal._setAllowLinker', true]);
	_gaq.push(['masterGlobal._setAllowHash', false]);
	_gaq.push(['masterGlobal._setCookiePath', '/21910987/']);
	_gaq.push(['masterGlobal._setSessionCookieTimeout',  1800000]);
	_gaq.push(['masterGlobal._setCampaignCookieTimeout', 2592000000]);
	_gaq.push(['masterGlobal._setVisitorCookieTimeout', 63072000000]);
	_gaq.push(['masterGlobal._trackPageview']);
	_gaq.push(['masterGlobal._trackPageLoadTime']);

	(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/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();


	// Comscore begins
	var __cs_c1 = 2;
	var __cs_c2 = "3005667";
	var __cs_c3 = "3005667";
	var __cs_c4 = escape(window.location.href);
	var __cs_c5 = "";
	var __cs_c6 = "";
	var __cs_c15 = "";
	var __cs_params = ["c1=", __cs_c1, "&c2=", __cs_c2, "&c3=", __cs_c3, "&c4=", __cs_c4, "&c5=", __cs_c5, "&c6=", __cs_c6, "&c15=", __cs_c15].join('');
	document.write(unescape("%3Cscript src='" + (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js?" + __cs_params + "' %3E%3C/script%3E"));
	// Comscore ends
}


/*
STUBBING
Vieilles fonctions Omniture pouvant être appelées directement
dans les pages HTML (en dehors du fichier TagOmnitureEngine.js)
*/

function TrackPhotoAlbum(albumID,picID) {
// STUBBED
}
function ButtonClick(buttonName) {
// STUBBED
}

