/**
 * Classe permettant d'ouvrir une url en overlay grâce à une iframe
 * @update 02/07/2009 - Christophe Moine : Remise en place de la protection de vidéo
 * @update 03/07/2009 - Christophe Moine : Support surcharge du message de protection + support redimensionnement auto
 **/
var TF1Overlay = {
	
	box:null,	/* la boite qui contient la barre supérieure + l'iframe */
	iframe:null,
	node:null,	
	loadingPanel:null,
	
	browserIsIE : navigator.userAgent.indexOf("MSIE") != -1,
	browserIsIE6 : navigator.userAgent.indexOf("MSIE 6.0") != -1,
	browserIsIE7 : navigator.userAgent.indexOf("MSIE 7.0") != -1,
	browserIsIE8 : navigator.userAgent.indexOf("MSIE 8.0") != -1,
	browserIsChrome : navigator.userAgent.indexOf("Chrome") != -1,
	browserIsFirefox : navigator.userAgent.indexOf("Firefox") != -1,
	width:null,
	height:null,
	stayInsideOnTerminated:false,
	callbackOnTerminated:null,
	callbackOnLoad:null,
	displayIsAllowed:true,
	cancelLoading:false,
	savedFlashVisibility:{object:[],embed:[]},
	tsLastResize:0,
	flashsAreVisible:true,
	fallbackTitle:'',
	
	DEFAULT_WIDTH:800,
	DEFAULT_HEIGHT:600,
	
	trkType:null,
	trkRub:null,
	trkE:null,
	trkU:null,
		
	/**
	 * Ferme (masque) l'overlay. Peut-être appelé depuis l'intérieur de l'iframe
	 * 
	 **/	
	close : function(targetUrl) {
		
		if (this.loadingPanel == null) { //possible: l'overlay n'a pas été ouvert
			return;
		}
		this.loadingPanel.style.display = 'none';
		
		// Il faut impérativement détruire l'iframe sinon l'éventuelle vidéo qu'elle contient continue de tourner !
		document.body.removeChild(this.node);
		this.node = null;
		this.doOnAfterUsed();
		
		if (typeof targetUrl == 'undefined' || targetUrl == null || targetUrl.indexOf('emptyUrl') != -1) {
			if (typeof AccountBloc != 'undefined') {			
				AccountBloc.update();
			}			
			TF1Overlay.switchFlashsVisibility(true);
			return;
		}

		if (targetUrl == '') {
			window.location.reload();
			return;
		}
		
		if (targetUrl.indexOf('/') == 0) {
			targetUrl = 'http://' + window.location.hostname + targetUrl;			
		}
		window.location.href = targetUrl;
		
	},
	
	/**
	 * Traitement effectué lorsque la fenêtre ouverte dans l'overlay a terminé 
	 **/
	doOnTerminated : function(targetUrl) {
		
		this.cancelLoad = true;
		
		if (this.callbackOnTerminated != null) {
			this.callbackOnTerminated(targetUrl);
		} else {
			this.close(targetUrl);
		}
		
	},
	
	stayInside : function() {
		return this.stayInsideOnTerminated;
	},
	
	/**
	 * Set les attributs nécessaires à l'appel de trkUrl dans la fonction open
	 */
	trk : function(type,rub,e,u) {
		this.trkType = type;
		this.trkRub = rub;
		this.trkE = e;
		this.trkU = u;
	},

	/**
	 * Ouvre une url en overlay
	 * Si stayInsideOnTerminated vaut true, on reste dans l'overlay une fois les opérations mso terminées
	 **/
	open : function(url, width, height, stayInsideOnTerminated, overlayCallbackOnTerminated, overlayCallbackOnLoad) {

		// appel de trkUrl
		if(!isNaN(this.trkType)) {
			trkUrl(url, this.trkType, this.trkRub, this.trkE, this.trkU);
		}
		
		// largeur forcée
		this.width = !isNaN(width)?width:null;
		this.height = !isNaN(height)?height:null;
		
		if (typeof stayInsideOnTerminated != 'undefined') {
			this.stayInsideOnTerminated = stayInsideOnTerminated;
		}
		
		if (typeof overlayCallbackOnTerminated == 'function') {
			this.callbackOnTerminated = overlayCallbackOnTerminated;
		} else {
			this.callbackOnTerminated = null;
		}
		
		if (typeof overlayCallbackOnLoad == 'function') {
			this.callbackOnLoad = overlayCallbackOnLoad;
		} else {
			this.callbackOnLoad = null;
		}		
				
		this.doOnBeforeUsed();
		
		if (this.node == null) {
			var ifrStr = '<div id="TF1OverlayMask" onclick="TF1Overlay.doOnClickMask(event)"></div><div id="TF1OverlayBox"><div id="TF1OverlayBar"><div id="TF1OverlayTitle"></div><div id="TF1OverlayBoxClose" onclick="TF1Overlay.doOnClickClose()">Fermer</div></div><iframe id="TF1OverlayFrame" frameborder="0" onload="TF1Overlay.doOnLoad()"';
			/*if (this.width != null && this.height != null) {
				ifrStr+= ' width="' + this.width + '" height="' + this.height + '"';
			}*/
			ifrStr+= '></iframe></div>';			
		
			var node = document.createElement('div');
			node.id = 'TF1Overlay';
			node.style.display = 'none';
			node.innerHTML = ifrStr;
			document.body.appendChild(node);
			this.node = node;
			
			this.loadingPanel = document.createElement('div');
			this.loadingPanel.id = 'TF1OverlayLoading';			
			document.body.appendChild(this.loadingPanel);
					
			
			this.iframe = document.getElementById('TF1OverlayFrame');			
			this.box = document.getElementById('TF1OverlayBox');
			
		} else {
			/* Cette réinitialisation est nécessaire sinon l'iframe garde la hauteur du plus grand document précédement ouvert */		
			this.iframe.style.height = '0px';
		}
				
		var viewboxWidth = this.getViewboxWidth();
		var viewboxHeight = this.getViewboxHeight();
		var loadingPanel = this.loadingPanel;
		
		loadingPanel.style.display = 'block';		
		loadingPanel.style.left = ((viewboxWidth - this.loadingPanel.offsetWidth) / 2) + 'px';
		loadingPanel.style.top = document.documentElement.scrollTop + ((viewboxHeight - this.loadingPanel.offsetHeight) / 2) + 'px';		
		
		this.iframe.src = url;
		
	},
	
	/**
	 * Affiche ou masque les flash de la page pour qu'il ne se superposent pas à l'overlay
	 * Note: lorsqu'on réaffiche les flash, on essaie de remettre les propriétés visible dans l'état où on les a trouvées
	 **/	
	switchFlashsVisibility : function(makeVisible) {		
	
		if (!this.flashsAreVisible && !makeVisible) {
			// ils sont déjà masqués;
			return;
		}
		if (this.flashsAreVisible && makeVisible) {
			// ils sont déjà visibles;
			return;
		}
		
		if (!makeVisible) {			
			this.savedFlashVisibility = {object:[],embed:[]};
		}
		var objList = document.getElementsByTagName('object');
		var e = null;
		for (var i = 0; i < objList.length; i++) {
			var e = objList.item(i);
			if (makeVisible) {
				e.style.visibility = this.savedFlashVisibility.object[i];
			} else {
				this.savedFlashVisibility.object[i] = e.style.visibility;
				e.style.visibility = 'hidden';
			}			
		}
		var objList = document.getElementsByTagName('embed');

		for (var i = 0; i < objList.length; i++) {
			var e = objList.item(i);
			if (makeVisible) {
				e.style.visibility = this.savedFlashVisibility.embed[i];
			} else {
				this.savedFlashVisibility.embed[i] = e.style.visibility;
				e.style.visibility = 'hidden';
			}
		}
		this.flashsAreVisible = makeVisible;
		
	},
	
	/**
	 * Renvoie la largeur de la partie visible de la page
	 **/
	getViewboxWidth : function() {
		
		var viewboxWidth = document.documentElement.clientWidth;
		
		// 20090418 - cmoine : Cas particuliers des pages qui utilisent le doctype sans dtd
		if (this.browserIsIE && viewboxWidth == 0) { 
			viewboxWidth = document.documentElement.offsetWidth;
		}
		if (this.browserIsFirefox) { // le pb se pose uniquement avec le doctype sans dtd
			viewboxWidth = Math.min(document.documentElement.clientWidth, document.body.clientWidth);
		}
		
		return viewboxWidth;
		
	},

	/**
	 * Renvoie la hauteur de la partie visible de la page
	 **/
	getViewboxHeight : function() {
		
		var viewboxHeight = document.documentElement.clientHeight;
				
		// 20090418 - cmoine : Cas particuliers des pages qui utilisent le doctype sans dtd
		if (this.browserIsIE && viewboxHeight == 0) {
			viewboxHeight = document.documentElement.offsetHeight;
		}
		if (this.browserIsFirefox) { // le pb se pose uniquement avec le doctype sans dtd
			viewboxHeight = Math.min(document.documentElement.clientHeight, document.body.clientHeight);
		}
		
		return viewboxHeight;
		
	},	

	/**
	 * Traitement sur clic sur le masque. Le contenu de la page en arrière plan (les liens par ex) ne doivent pas réagir
	 **/
	doOnClickMask : function(evt) {
		
		if (!evt) {
			var evt = window.event;
		}
		if (evt.stopPropagation) {
			evt.stopPropagation();
		} else {
			evt.cancelBubble = true;
		}
		
	},
			
	/**
	 * Traitement sur clic sur le bouton de fermeture de l'overlay
	 **/
	doOnClickClose : function() {
		this.close(null);
	},
	
	/**
	 * Permet de surcharger le titre utilisé lorsque la communication interframe n'est pas possible
	 **/
	setFallbackTitle : function(title) {
		this.fallbackTitle = title;
	},
	
	doOnLoad : function() {		

		if (this.cancelLoad) {			
			this.cancelLoad = false;
			return;
		}

		if (this.callbackOnLoad != null) {
			this.callbackOnLoad();
		}

		var title = '';
		try {
			title = this.iframe.contentWindow.Mso.getTitle();
		} catch(e) {
			title = this.fallbackTitle;
		}
	 	document.getElementById('TF1OverlayTitle').innerHTML = title;

		if (this.displayIsAllowed) {
			this.show();
		}	
	},

	show : function() {

		this.loadingPanel.style.display = 'none';
		TF1Overlay.switchFlashsVisibility(false);
		this.node.style.display = 'block';
		this.resize();
		
	},

	setDisplayIsAllowed : function(allowed) {	
		this.displayIsAllowed = allowed;
	},
	
	/**
	 * Redimensionne les éléments de l'overlay en fonction de la place disponible
	 **/
	resize : function() {
		
		var now = (new Date).getTime();		
		if (this.browserIsIE8 && (now - this.tsLastResize < 250)) {
			// sous IE8, le resize de l'overlay déclenche le resize de la fenêtre ce qui enclenche une récursion
			this.tsLastResize = now;
			return;
		}
		this.tsLastResize = now;
		//gId('ibl120634').innerHTML+= 'i = ' + (now - this.tsLastResize) + '<br/>';
		
		var viewboxWidth = this.getViewboxWidth();
		var viewboxHeight = this.getViewboxHeight();
			
		var documentScrollHeight = document.documentElement.scrollHeight;
		var documentScrollTop = document.documentElement.scrollTop;

		if (this.browserIsChrome) {	
			/* document.documentElement.scrollHeight est incorrect sous Google Chrome lorsqu'il n'y a pas de scrollbars */
			documentScrollHeight = Math.max(documentScrollHeight, document.documentElement.clientHeight);			
		}
		
		var iframeDoc = null;
		try {
			var iframeDoc = this.iframe.contentWindow.document;
		} catch (e) {
			// L'iframe ouverte n'a probablement pas setté document.domain correctement (cf getMainDocDomain())	
		}
		
		var iframeContentHeight = null;
		var iframeContentWidth = null;
				
		if (iframeDoc != null && iframeDoc.body != null) {								
			
			// cette ligne posait pb sous FF3
			//var iframeContentHeight = iframeDoc.documentElement.scrollHeight;		
			iframeContentHeight = iframeDoc.body.scrollHeight;		
			iframeContentWidth = iframeDoc.body.scrollWidth;		
			
			if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 

				var ffversion=parseFloat(RegExp.$1)

				/* Sous FF3.0, body.scrollWidth et html.scrollWidth ne sont pas cohérents, on doit choisir le plus grand des 2 */
 				if (ffversion == 3) {
 					iframeContentWidth = Math.max(iframeContentWidth, iframeDoc.documentElement.scrollWidth); 					
 				}
			}			
			
			if (this.browserIsIE6 || this.browserIsIE7) {
				// 20090413 - utilité de ce hack confirmée
				iframeContentHeight+= 10;
				iframeContentWidth+= 10;
			}
		}

		if (this.height != null) {
			// si une hauteur est imposée, on la prend
			iframeContentHeight = this.height;
		} else if (iframeContentHeight == null) {
			// si la hauteur du contenu de l'iframe n'a pas pu être récupéree, on utilise la hauteur par défaut
			iframeContentHeight = this.DEFAULT_HEIGHT;
		}
		
		if (this.width != null) {
			// si une largeur est imposée, on la prend
			iframeContentWidth = this.width;
		} else if (iframeContentWidth == null) {
			// si la largeur du contenu de l'iframe n'a pas pu être récupéree, on utilise la largeur par défaut
			iframeContentWidth = this.DEFAULT_WIDTH;			
		}		
		
		/* On ne peut pas utiliser iframe.style.height=100%, ça ne donne pas la hauteur souhaitée */		
		this.iframe.style.height = iframeContentHeight + 'px';
		
		var overlayBar = document.getElementById('TF1OverlayBar');
		var newBoxHeight = iframeContentHeight + overlayBar.offsetHeight;		
		var newBoxWidth = iframeContentWidth;
		
		this.box.style.height = newBoxHeight + 'px';
		this.box.style.width = newBoxWidth + 'px';
		this.box.style.left = ((viewboxWidth - newBoxWidth) / 2) + 'px';
		//this.box.style.top = (documentScrollTop + (viewboxHeight - newBoxHeight) / 2) + 'px';	
		
		/* hauteur de l'espace entre l'overlay et les bords supérieurs et inférieurs de la page */
		var spacerHeight = (viewboxHeight - newBoxHeight) / 2;
		
		var newOverlayHeight = 0;
		if (spacerHeight < 0) {
			// pas assez de place pour afficher l'iframe centrée: on force une marge mini en haut et en bas
			spacerHeight = 100;
			newOverlayHeight = Math.max(newBoxHeight + spacerHeight * 2, documentScrollHeight);
						
		} else {			
			newOverlayHeight = documentScrollHeight;						
		}
		
		this.node.style.height = newOverlayHeight + 'px';
		
		if (this.browserIsIE6) {
			document.getElementById('TF1OverlayMask').style.height = newOverlayHeight + 'px';
			this.node.style.width = document.documentElement.clientWidth;
		}
			
		this.box.style.top = documentScrollTop + spacerHeight + 'px';
		
	},
	
	/**
	 * Permet de forcer la taille alors que l'overlay est déjà ouvert
	 **/
	setSize : function(width, height) {
		this.height = height;
		this.width = width;		
	},
	
	doOnWindowResize : function() {		
		TF1Overlay.resize();
	},

	/**
	 * Initialisations avant utilisation de l'overlay. 
	 **/
	doOnBeforeUsed : function() {
		if (!/(.xiti.com)|(.atinternet-solutions.com)/.test(document.domain)) {
			document.domain = getMainDocDomain();
		}
		addEvtListener(window, 'resize', this.doOnWindowResize);
	},

	/**
	 * Nettoyage après utilisation de l'overlay. 
	 **/	
	doOnAfterUsed : function() {		
		removeEvtListener(window, 'resize', this.doOnWindowResize);		
	}
}

/**
 * Classe Mso de front: permet d'ouvrir l'inscription en overlay
 **/
var MsoFront = {
	
	DEFAULT_POPUP_WIDTH : 800,
	DEFAULT_POPUP_HEIGHT : 600,
	
	// message par défaut
	protectedVideoMsg : 'Pour accéder au Live, vous devez avoir un compte TF1.fr<br/><a href="#" onclick="MsoFront.doOnClickWatVideoSubscribe(true);return false;">Identifiez-vous</a> ou <a href="#" onclick="MsoFront.doOnClickWatVideoSubscribe(false);return false;">inscrivez-vous</a> gratuitement.',
	
	serviceAvailable : true,


	/**
	 * Ouvre une page mso
	 * @param string pageName : identification|inscription|compte|...
	 * @param integer unvId : identifiant d'univers/inscription
	 * @param integer srvId : identifiant du service
	 * @param integer targetUrl : url à ouvrir en fin de parcours dans l'overlay
	 * @param integer overlayCallback : fonction appelée en fin de parcours de l'overlay
	 * @param integer popupParams : si non vide, l'url de fin sera ouverte dans une popup avec les caractéristiques données
     * @param string paramGet : parametre à transmettre dans l'ul si besoin
	 **/
	open : function(pageName, unvId, srvId, targetUrl, useOverlay, overlayCallbackOnTerminated, popupParams, overlayCallbackOnLoad, paramGet) {
		var url = this.getUrl(pageName, unvId, srvId, targetUrl, paramGet);
		this.openUrl(url, useOverlay, overlayCallbackOnTerminated, popupParams, overlayCallbackOnLoad);
	},
	
	/**
	 * Ouvre une url mso
	 * @param url : l'url à ouvrir
	 * @param useOverlay : si true l'url sera ouverte dans l'overlay
	 * @param overlayCallbackOnTerminated : fonction de callback appelée à la fin du traitement de l'overlay
	 * @param popupParams : null ou tableau associatif décrivant le popup dans lequel l'url doit s'ouvrir. 
	 * @param overlayCallbackOnLoad : fonction de callback appelée à la fin du chargement de l'overlay
	 * Note: overlayCallback ne sont pas compatibles l'un avec l'autre
	 **/
	openUrl : function(url, useOverlay, overlayCallbackOnTerminated, popupParams, overlayCallbackOnLoad) {
		if (typeof useOverlay == 'undefined') {
			useOverlay = true;
		}
		if (!useOverlay) {
			window.location.href = url;
			return;
		}
		var width = null;
		var height = null;
		if (typeof popupParams == 'undefined') {
			popupParams = null;
		}
		if (typeof overlayCallbackOnTerminated != 'function' && popupParams != null) {
			// Dans ce cas on construit une fonction de callback qui va gérer l'ouverture en popup
			overlayCallbackOnTerminated = function(url) {
				var width = (typeof popupParams.width != 'undefined')?popupParams.width:MsoFront.DEFAULT_POPUP_WIDTH;
				var height = (typeof popupParams.height != 'undefined')?popupParams.height:MsoFront.DEFAULT_POPUP_HEIGHT;
				var windowName = (typeof popupParams.windowName != 'undefined')?popupParams.windowName:'Popup';
				var features = 'width=' + width + ',height=' + height;
				window.open(url, windowName, features);
				TF1Overlay.close();
			}
		}
		TF1Overlay.open(url, width, height, false, overlayCallbackOnTerminated, overlayCallbackOnLoad);
	},

	
	/**
	 * Renvoie une url mso
     ** @param string paramGet : parametre à transmettre dans l'ul si besoin
     **/
	getUrl : function(pageName, unvId, srvId, targetUrl, paramGet) {
		
		if (typeof targetUrl == 'undefined' || targetUrl == '') {
			if (pageName == 'deconnexion' && window.location.href.indexOf('/mon-compte/') != -1) { 
				// le user se déconnecte d'une page protégée: on redirige sur la home pour ne pas tomber à nouveau sur la page d'identification
				targetUrl = 'http://' + window.location.hostname;
			} else {
				targetUrl = escape(window.location.href);			
			}
		}		
		if (targetUrl.indexOf('/') == 0) {
			targetUrl = 'http://' + window.location.hostname + targetUrl;
		}
		
		if (targetUrl == 'emptyUrl' && TF1Overlay.browserIsIE6) {
			// 20090804 - cmoine: cas de concernant IE6 uniquement. En tout dernier recours lorsqu'on n'arrive
			// pas à faire de la communication cross frame (malgré le bon réglage des noms de domaine),
			// on transmet l'url courante qu'IE doit suivre
			// Ne se produit que sur certains IE6
			targetUrl+= '_' + escape(top.location.href);
		}

        if (typeof paramGet == 'undefined' || paramGet == '') {
            paramGet = '';
        } else {
            paramGet += '&'+paramGet;
        }
		
		var url = 'http://' + LOGIN_HOSTNAME + '/src/' + pageName + '.php?unv_id=' + unvId + '&srv_id=' + srvId + '&referer=' + targetUrl+paramGet;
		return url;
		
	},
	
	/**
	 * Sur chargement d'une vidéo protégée
	 **/
	doOnLoadProtectedVideo : function() {			

		if (!MsoFront.userIsIdentified()) {
			MsoFront.showOverlayWatVideo();
			return;
		}
		MsoFront.checkUserSubscription(MsoFront.SRV_ID_VIDEO);
		
	},	
	
	
	getElementPosition : function(theElement) {
		
		var posX = 0;
		var posY = 0;
              
  		while(theElement != null){
    		posX += theElement.offsetLeft;
    		posY += theElement.offsetTop;
    		theElement = theElement.offsetParent;
  		}
                        		      
   		return {x:posX,y: posY};
   		
	},
	
	/**
	 * Permet de surcharcher le message par défaut
	 **/
	setProtectedVideoMsg : function(msg) {
		this.protectedVideoMsg = msg;
	},
	
	/**
	 * Ajoute un overlay sur le player wat "cliquez ici pour vous inscrire"	 
	 **/
	showOverlayWatVideo : function() {
		
		var flashPlayer = gId('FlashPlayer');
		var playerInstance = gId('WATPlayerInstance');
		//playerInstance.setAttribute('wmode', 'transparent');
		if (flashPlayer == null) {
			return;
		}
		
		flashPlayer.style.backgroundColor = '#000000';
						
		var frame = document.getElementById('watOverlayFrame');
		var panel = document.getElementById('watOverlayPanel');
		if (frame == null) {
			frame = document.createElement('iframe');
			frame.id = 'watOverlayFrame';
			flashPlayer.parentNode.appendChild(frame);
			
			panel = document.createElement('div');
			panel.id = 'watOverlayPanel';			
			
			panel.innerHTML = '<div id="watOverlaySpacer">&nbsp;</div>' + this.protectedVideoMsg;
			
			flashPlayer.parentNode.appendChild(panel);
		}		
		
		this.watDoOnResize();
		
		playerInstance.style.visibility = 'hidden';
		addEvtListener(window, 'resize', MsoFront.watDoOnResize);
		
	},
	
	/**
	 * Resize pour faire en sorte que le layer reste au-dessus du player.
	 * 20090703 - cmoine : A ce jour, ça ne marche pas.
	 **/
	watDoOnResize : function() {
		
		var flashPlayer = gId('FlashPlayer');		
		var playerHeight = flashPlayer.style.height;
		var panel = document.getElementById('watOverlayPanel');				
		var p = MsoFront.getElementPosition(flashPlayer);		
		var frame = gId('watOverlayFrame');
		frame.style.top = p.y + 'px';
		frame.style.left = p.x + 'px';
		frame.style.height = playerHeight;
		panel.style.top = p.y + 'px';
		panel.style.left = p.x + 'px';
		panel.style.height = playerHeight;
		
	},
	
	hideOverlayWatVideo : function() {
		
		var playerInstance = gId('WATPlayerInstance');
		var frame = document.getElementById('watOverlayFrame');
		var panel = document.getElementById('watOverlayPanel');
		
		if (playerInstance == null || frame == null || panel == null) {
			return;
		}
		removeEvtListener(window, 'resize', MsoFront.watDoOnResize);
		playerInstance.style.visibility = 'visible';
		
		var flashPlayer = gId('FlashPlayer');
		flashPlayer.parentNode.removeChild(frame);
		flashPlayer.parentNode.removeChild(panel);
		
	},
	
	/**
	 * Traitement sur click du lien affiché en overlay sur le player wat	 
	 **/
	doOnClickWatVideoSubscribe : function(ident) {
		
		var pageName = '';
		if (ident) {
			pageName = 'identification';
		} else {
			pageName = 'inscription';
		}

		this.open(pageName, unv_id, this.SRV_ID_VIDEO, 'emptyUrl', true, this.doOnLoadProtectedVideo);
		
	},
	
	
	/**
	 * Renvoie true si l'utilisateur est identifié
	 **/
	userIsIdentified : function() {
		
		var ticket = getCookie('_MSOTICKET_');
		var identified = (ticket != 'Undefined' && ticket.match(/[0-9]{30}/) != null);		
		return identified;
		
	},


    /**
     * Renvoie true si l'utilisateur est confirmé
     **/
    userIsConfirmed : function() {
        var usrConfirmed = getCookie('_MSOCONFIRMED_');
        var confirmed = (usrConfirmed != 'Undefined' && usrConfirmed == '0')? false : true;
        return confirmed;
    },
	
	userIsSubscribed : function(srvId) {
		
		var msoSrv = getCookie('_MSOSRV_');
		var srvList = [];
		if (msoSrv != 'Undefined' && msoSrv.match(/^[0-9;]+/) != null) {
			srvList = unescape(msoSrv).split(',');
		}		
		for (var i = 0, n = srvList.length; i < n; i++) {
			if (srvList[i] == srvId) {
				return true;
			}
		}
		return false;
		
	},
	
	/**
	 * Méthode appelée par le js qui construit le flash du player wat pour indiquer au player si la lecture peut commencer
	 **/
	userIsAllowedWatVideo : function(srvId) {
		
		this.SRV_ID_VIDEO = srvId;
		if (this.userIsIdentified() && this.userIsSubscribed(srvId)) {
			return "1"; // c'est un flashvars et le flash attend une chaine de caractère
		}
		return "0";
		
	},	
	
	/**
	 * Renvoie true si l'utilisateur est abonné au service donné
	 **/
	checkUserSubscription : function(srvId) {

		if (MsoFront.userIsSubscribed(srvId)) {
			MsoFront.doOnUserSubscriptionChecked();
			return;
		}		
		
		// Cet appel doit provoquer l'abonnement automatique
		this.open('identification', unv_id, srvId, 'emptyUrl', true, function () {MsoFront.checkUserSubscription(srvId)});
		
	},
	
	/**
	 * Fin des vérification
	 **/
	doOnUserSubscriptionChecked : function() {

		// note: la fermeture de l'overlay restore la valeur précédente de visibility des flashs
		TF1Overlay.close();
		
		MsoFront.hideOverlayWatVideo();
		
		if (typeof WATPlayer != 'undefined') {
			WATPlayer.userAuthorisationGranted();
		}
		
	},
	
	/**
	 * Renvoie le pseudo du user connecté, à partie des cookies
	 **/
	getUserPseudo : function() {
		var c = getCookie('_MSOPSEUDO_');
		return (c != 'Undefined')?c:'';
	},

    /**
     * Renvoie le mail du user connecté, à partir des cookies
     **/
    getUserMail : function() {
        var c = getCookie('_MSOMAIL_');
        return (c != 'Undefined')?c:'';
    },
	
	isServiceAvailable : function() {
		return this.serviceAvailable;
	},
	
	setServiceAvailable : function(status) {
		this.serviceAvailable = status;
	}
}

/*
// Note: onsole.log() est définie au moins sous FF3, chrome, et IE8
if (typeof console == 'undefined') {
	var console = {log:function() {}};
}*/

