/*********************************************************************************************************************************/
//onClic du champ rechercher effacer la valeur
function Focus(that, defaultval){
	if(that.value == defaultval) that.value = "";
}
function Blur(that, defaultval){
	if(that.value == "") that.value = defaultval;
}





/*********************************************************************************************************************************/
//Affichage de la date

Date.prototype.getDateString = function(str)
{
  /*var dnames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
      'Thursday', 'Friday', 'Saturday', 'Sunday'];*/

  var mnames = ['janvier', 'février', 'mars', 'avril',
      'mai', 'juin', 'juillet', 'Août', 'septembre',
      'octobre', 'novembre', 'décembre'];

 /* str = str.replace('%day', dnames[this.getDay()]);*/
  str = str.replace('%date', this.getDate());
  str = str.replace('%ordinal', this.getDateOrdinal());
  str = str.replace('%month', mnames[this.getMonth()]);
  str = str.replace('%year', this.getFullYear());

  return str;
};

Date.prototype.getDateOrdinal = function()
{
  var n = this.getDate();

  var ord = '';

  if (n==1)
  {
    ord = 'er';
  }
  return ord;
};

Date.prototype.getISODate = function()
{
  var mth = this.getMonth() + 1;
  mth = (mth < 10 ? '0' : '') + mth;

  var date = this.getDate();
  date = (date < 10 ? '0' : '') + date;

  return  date + mth + this.getFullYear();
};

var today = new Date();
var sentence = today.getDateString(
    '%date%ordinal %month %year');


$(document).ready(
				function() {

var dateDiv = document.getElementById('date');
if (!dateDiv) {return;}
dateDiv.innerHTML = sentence;

							}
						
				);


/*********************************************************************************************************************************/
//Affichage du flv dans coeur de page


function launchVideo() {
		if (!document.getElementById('swfVideo')) {return;}
		var so = new SWFObject('swf/video.swf', 'website', '335', '255', '8.0.0.0', '#ffffff');
		so.addParam('wmode', 'opaque');
		so.write('swfVideo');
}

$(document).ready(launchVideo);

/*********************************************************************************************************************************/
//Affichage des listes de liens pathologies, médicaments, sites du groupe

if (PF === undefined){var PF ={};}

PF.displayLinks = {

	checkLists : function(){
		if(document.getElementById){document.documentElement.className='js';}	
		if ($('ul.linksList').length)
		{
		    $('ul.linksList').click(PF.displayLinks.click);
		};
		if($('.interactive').length){
			$('.contenu').css('display','none');
            $('#defaultz').css('display','block');
			$('#themeQuestion li li a').click(
				function(){
					$('#themeQuestion li li').removeClass('current');
					$(this).parent().addClass('current');
					PF.displayLinks.displayContact($(this));
					PF.displayLinks.close($('#themeQuestion'));
					return false;				
				}
			)
		}
	},
	
	click: function(e) {
		var t = e.target,
			p = t.parentNode;
		if(p && $(p).hasClass('first')) {
			if($(this).hasClass('open')) {
				PF.displayLinks.close(this);
				return false;
			} else {
				PF.displayLinks.open(this);
				return false;
			}
		}
	},
	
	open: function(arg){
		$(arg).addClass('open');
		if($(arg).height()>315){
			$(arg).css({'height':'315px'});
			$(arg).addClass('scroll');
		}
		$(document).bind('mousedown.dropDown', function(e) {
			var t = e.target;
			while(t.parentNode && !$(t).hasClass('linksList')) {
				t = t.parentNode;
			}
			if(!t || (t && t != arg)) {PF.displayLinks.close(arg);$('#interactive').removeClass('on');}
		});
		
		if($(arg).hasClass('up')){
			$(arg).css({'position':'relative','background':'#fff'});
			$(arg).css('top', -$(arg).height() +'px');
			$($(arg).children()[0]).css({'position': 'absolute', 'bottom': '-15px','background':'#FFFFFF url(/Portals/0/PfizerResources/img/selectArrow.gif) no-repeat 100% 0'});
		}
	},
	
	close: function(arg){
		$(arg).removeClass('open');
		$(arg).removeClass('scroll');
		$(document).unbind('mousedown.dropDown');
		$(arg).css({'height':'auto'});
		
		if($(arg).hasClass('up')){
			$(arg).css({'position': 'relative', 'top': '0'});
			$($(arg).children()[0]).css('position','static');
		}
	},
	
	displayContact: function(oAnchor){
		$('.contenu').css('display','none');
		$('.contenu').removeClass('selected');
		var oContactBlockId = oAnchor.attr('href').split('#')[1];
		$('#'+oContactBlockId).css('display','block');
		$('#'+oContactBlockId).addClass('selected')
		$(".scroll-pane").jScrollPane();

	    $('.selected .popinContact').click(function(){
	        PF.Contact.showForm();
	    });		
	}
	
};

$(document).ready(PF.displayLinks.checkLists);


/*********************************************************************************************************************************/
//gestion des cookies pour agrandissement et r?duction du texte

/*Agrandir le texte de la page */
function checkSizeTxt(){
	
	var SizeType = ReadCookie('SizeType');
	
	if(SizeType == 0){modifyTxt('100%');}
	else if(SizeType == 1){modifyTxt('120%');}
	else if(SizeType == 2){modifyTxt('140%');}
	else{modifyTxt('100%');}
	
	var plusSwitcherEl = $('#tools li')[0];	
	var minusSwitcherEl = $('#tools li')[1];
	
	plusSwitcherEl.onclick = function(){
		SizeType = SizeType +1;
		
		if(SizeType >= 2){SizeType=2;WriteCookie('SizeType', 2);}		
		else{WriteCookie('SizeType', SizeType);}
		
		if(SizeType == 0){modifyTxt('100%');}
		else if(SizeType == 1){modifyTxt('120%');}
		else if(SizeType == 2){modifyTxt('140%');}
		else{modifyTxt('100%');}
		
		return false;
	};
	
	minusSwitcherEl.onclick = function(){
		SizeType = SizeType -1;
		
		if(SizeType <= 0){SizeType=0;WriteCookie('SizeType', 0);}		
		else{WriteCookie('SizeType', SizeType);}
		
		if(SizeType == 0){modifyTxt('100%');}
		else if(SizeType == 1){modifyTxt('120%');}
		else if(SizeType == 2){modifyTxt('140%');}
		else{modifyTxt('100%');}
		
		return false;
	};
}

/*Modifie le texte de la page */
function modifyTxt(newSize) {
	
	var contentEl = document.getElementById('content');	
	contentEl.style.fontSize = newSize;

	
	if(contentEl.getElementsByTagName('h1')[0]){
		var h1El = contentEl.getElementsByTagName('h1')[0];
		h1El.style.fontSize = newSize;
	}
	
	if(contentEl.getElementsByTagName('h2')[0]){
		var h2El = contentEl.getElementsByTagName('h2')[0];
		h2El.style.fontSize = newSize;
	}	

	// on recalcule la zone à scroller si on change la taille du texte
		var isPaneNeccessary = document.getElementById('content');
				// Barre de scroll
		if (isPaneNeccessary.offsetHeight > 317) {
			var $pane1 = $('#pane1');
			if ($pane1) {
				//console.log('modifyTxt Scroll sans ancres');
				jQuery(".scroll-pane").jScrollPane();
			}
			var $pane2 = $('#pane2');
			if ($pane2) {
				//console.log('modifyTxt Scroll avec ancres');
				$pane2.jScrollPane({
					animateTo: true
				});
				$('a.scroll-to-element-demo').bind('click', function(){
					var targetElementSelectorString = $(this).attr('rel');
					$pane2[0].scrollTo(targetElementSelectorString);
					return false;
				});
			}
			
			
		}
	
}




function printThis(){
	var printEl = $('#tools li')[3];
	
	printEl.onclick = function() {
		document.getElementById('content').className = 'print';

		/*
		var pngs = $('#content .png');
		for(var i=0;i<pngs.length;i++){
			var alts = document.createTextNode(pngs[i].alt);
			pngs[i].parentNode.replaceChild(alts,pngs[i]);
		}	
		*/
		window.print();
		return false;
		}	
}


$(document).ready(
				function() {
							if (!document.getElementById('tools')){return;}
							checkSizeTxt();
							printThis();
							}						
				);





//Gestion des cookies
function WriteCookie(nom, valeur){
	var argv = WriteCookie.arguments;
	var argc = WriteCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = nom+'='+escape(valeur)+((expires==null) ? '' : ('; expires='+expires.toGMTString()))+((path==null) ? "" : ("; path="+path))+((domain==null) ? "" : ("; domain="+domain))+((secure==true) ? "; secure" : "");
}

function getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function ReadCookie(nom){
	var arg = nom + '=';
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i<clen){
		var j = i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

var me;
function getID( swfID ){
	  me = document[swfID];
}

function pausePagePlayer(){
	getID("PLAYER");
	me.onPause();
}

/*********************************************************************************************************************************/
//initialisation des variables du faux-select et de la barre de scroll

if (PF === undefined){var PF ={};}
	
	$(document).ready(function() {
		
		PF.fauxSelect = FauxFields.Manager({
			field: 'select',
			maxHeight: 200
		});
		
		/* hack medicament tahor */
		$('.exc').parent().css({'height':'294px', 'margin-top':'5px'});
		$('.exc p').css({'margin':'9px 16px 9px 18px'});
		$('.exc p:first-child').css({'margin':'4px 16px 9px 18px'});
		$('.exc p:last-child').css({'margin':'4px 16px 0px 18px'});
		$('.exc').next('.jScrollPaneTrack').children().css({'top':'-10px'});

		/*PF.fauxRadio = FauxFields.Manager({
			field: 'radio'
		});		*/
		
	
	});


/*********************************************************************************************************************************/
// gestion du popin send to a friend

if (PF === undefined){var PF ={};}

PF.sendToAFriend = {
	
	init: function(){
		var elTools = document.getElementById('tools');
		
		if (!elTools) return;
		
		var elSend = elTools.getElementsByTagName('a')[2];
		elSend.onclick=function(){PF.sendToAFriend.showForm()}
	},
	
	showForm: function(){
		var masque = document.createElement('div');
		masque.id = "mask";
				
		document.body.appendChild(masque);
		masque.style.height = document.documentElement.scrollHeight +'px';
		
		var popupContainer = document.createElement('div');
		popupContainer.id = 'popupContainer';
		document.body.appendChild(popupContainer);
		
	    var toolsTabUrl=document.getElementById('toolsTabUrl');
	    var sendToAFriendUrl=document.getElementById('sendToAFriendUrl');
	    var title=document.title;
	    if (toolsTabUrl)
		    $('#popupContainer').load(sendToAFriendUrl.value, {tabTitle: title, tabUrl : toolsTabUrl.value}, null);
		
		/* 
		var btnFermer = document.getElementById('fermer');
		if(!btnFermer) return;
		btnFermer.onclick = function(){
			PF.sendToAFriend.fermer()
			}
		*/
		PNGKiller();
	},
	
	fermer: function(){
		var btnFermer = document.getElementById('fermer');
		if(!btnFermer) return;
		
		var masque = document.getElementById('mask');
		var popupContainer = document.getElementById('popupContainer');
		
		document.body.removeChild(masque);
		document.body.removeChild(popupContainer);
		alert('toto');
		//masque.style.display = 'none';
		//popupContainer.style.display = 'none';
		
	}
	
	
}

$(document).ready(function(){
	PF.sendToAFriend.init();
})
	
/*********************************************************************************************************************************/
// gestion du popin video

PF.launchPopinVideo = {
    
    init:function(){
        $('.videoPopin').click(function(){
            PF.launchPopinVideo.displayMask();
            PF.launchPopinVideo.getAjax($(this));
			pausePagePlayer();
            return false;
        })
    },
    
    displayMask: function(){
        var masque = document.createElement('div');
		masque.id = "mask";
		var bodyHeight = document.documentElement.offsetHeight;
		
		$(masque).css('height',bodyHeight+'px');
		$('body').append(masque);
    },
    
    getAjax: function(datas){
        var popinUrl = datas.attr('href');
		if(datas.attr('href').indexOf('large') != -1){
			var format = 'large';
		}
		else{
			var format = 'normal';
		}
		$.ajax({
            type: 'GET',
            url:  popinUrl,
            success: function(data){PF.launchPopinVideo.displayResponse(data,format)}
        })
        
    },
    
    displayResponse: function(data,format){

        //var popinTmp = document.createElement('div');
        //popinTmp.innerHTML = data;
        //console.log(data.split('<body>')[1].replace('</body>', '').replace('</html>', ''))
        var popinTmp = data.split('<body>')[1].replace('</body>', '').replace('</html>', '');
		if(format == 'large'){
			popinTmp = popinTmp.replace('player_FLV.swf','player_169.swf').replace('445','330').replace('captions.xml','captions_169.xml');
		}
        $('body').append(popinTmp);
        //console.log(document.getElementById('popInSend'));
        
        $('#fermer').click(function(){
            PF.launchPopinVideo.closePopinVideo($(this))
        })
    },
    
    closePopinVideo: function(btn){
        btn.parent().parent().remove();
        $('#mask').remove();
        
    }
    
}



$(document).ready(function(){
	PF.launchPopinVideo.init();
})

/*********************************************************************************************************************************/
// gestion du bandeau aléatoire

PF.shuffleBandeau = {
	
	init:function(){
					if(!document.getElementById('home')){return};
					var randomImageIndex = Math.round( Math.random( ) * 4 )+1;
					var headerBg = document.getElementById('headerWrapper');
					headerBg.style.backgroundImage = 'url(/Portals/0/PfizerResources/img/bandeau0'+ randomImageIndex +'.jpg)';
					}
}

$(document).ready(function(){
	PF.shuffleBandeau.init();
})	
