// JavaScript Document

// faire apparaitre ou non un div sans effet
function ouvreDiv(name,ouvre) {
	if (ouvre == '1') {
		document.getElementById(name).style.display = 'block';
	} else {
		document.getElementById(name).style.display = 'none'; 
	}
}

// faire apparaitre ou non un div avec effet "slide" (haut en bas)
function slideDiv(name,ouvre) {
	if (ouvre == 1) {
		$('#'+name).slideDown("normal");
	} else {
		$('#'+name).slideUp("normal");
	}
}


// faire apparaitre ou non un div dans une liste de div
function ouvreDivList(name,cmpt,ouvre) {
	if (ouvre == '1') {
		document.getElementById(name+cmpt).style.display = 'block';
		document.getElementById('aff_'+cmpt).style.visibility = 'hidden';
		document.getElementById('cach_'+cmpt).style.visibility = 'visible';
	} else {
		document.getElementById(name+cmpt).style.display = 'none';
		document.getElementById('cach_'+cmpt).style.visibility = 'hidden';
		document.getElementById('aff_'+cmpt).style.visibility = 'visible';
	}
}

// ouvrir une pop-up
function popup(url) {
	//window.open(url,'height=500px,width=800px,top=150px,left=150px,resible=yes');
	 window.open(url, "boncommande", "toolbar=no, location=no, directories=no, status=yes, scrollbars=yes, resizable=no, copyhistory=no, width=780, height=500, left=150, top=150");
}

// gérer le formulaire de pagination
function changePage(formu,cible) {
	document.forms[formu].action = cible;
	document.forms[formu].submit();
}

// pour intégrer des flash avec flashVars
function RunFlash(swf, hauteur, largeur, couleur, window_mode, nom, vars) {
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\""+hauteur+"\" height=\""+largeur+"\" id=\""+nom+"\" align=\"middle\">\n");
	document.write("<param name=\"allowScriptAccess\" value=\"always\" />\n");
	document.write("<param name='movie' value='"+swf+"' /> \n");
	document.write("<param name='quality' value='high' /> \n");
	document.write("<param name='bgcolor' value='"+couleur+"' /> \n");
	document.write("<param name='menu' value='true' /> \n");
	document.write("<param name='flashvars' value='"+vars+"' /> \n");
	if(window_mode=="transparent"||window_mode=="opaque"){
		document.write("<param name='wmode' value='"+window_mode+"' /> \n");
		document.write("<embed src='"+swf+"' menu='true' quality='high' wmode='"+window_mode+"' bgcolor='"+couleur+"' width='"+hauteur+"' height='"+largeur+"' name='"+nom+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='"+vars+"' />\n");
		}
	else{
		document.write("<embed src='"+swf+"' menu='true' quality='high' bgcolor='"+couleur+"' width='"+hauteur+"' height='"+largeur+"' name='"+nom+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='"+vars+"' />\n");
		}
	document.write("</object>\n");
	}

// pour le lecteur vidéo
function playerLite(myWidth,myHeight,myVideo,myImg,myDiv,baseUrl) {
	var flashvars = {
	  vidWidth: myWidth,
	  vidHeight: myHeight,
	  vidPath: myVideo,
	  thumbPath: myImg,
	  autoPlay: "false",
	  autoLoop: "true",
	  watermark: "hide",
	  watermarkURL: "http://www.flvplayerlite.com",
	  seekbar: "show",
	  showControls: "true",
	  vidAspectRatio: "fit"
	};
	var params = {
	  menu: "true",
	  allowfullscreen: "true",
	  allowscriptaccess: "always"
	};
	var attributes = {
	  id: myDiv,
	  name: myDiv
	};
	
	swfobject.embedSWF(baseUrl+"js/swf/playerLite.swf", myDiv, flashvars.vidWidth, flashvars.vidHeight, "9.0.0", baseUrl+"js/lib/expressInstall.swf", flashvars, params, attributes);
}

// pour le jCoverFlip
function iniCoverFlip(idaff) {
	$('#flip').jcoverflip({
	  current: idaff,
	  beforeCss: function( el, container, offset ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 120 - 80*offset )+'px', bottom: 0 }, { } ),
		  $.jcoverflip.animationElement( el.find( 'img' ), { opacity: 0.4, width: '65px' }, {} )
		];
	  },
	  afterCss: function( el, container, offset ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 55 + 80*offset )+'px', bottom: 0 }, { } ),
		  $.jcoverflip.animationElement( el.find('img'), { opacity: 0.4, width: '65px' }, {} )
		];
	  },
	  currentCss: function( el, container ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 40 )+'px', bottom: 0 }, { } ),
		  $.jcoverflip.animationElement( el.find( 'img' ), { opacity: 1, width: '80px' }, { } )
		];
	  }
	});	
	$('#prevflip').click(function() {
		$('#flip').jcoverflip('previous');
	});
	$('#nextflip').click(function() {
		$('#flip').jcoverflip('next');
	});
}

// pour le jCoverFlip Découvrez la Revue
function iniCoverFlipLaRevue(idaff) {
	$('#flip').jcoverflip({
	  current: idaff,
	  beforeCss: function( el, container, offset ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 250 - 160*offset )+'px', bottom: 0 }, { } ),
		  $.jcoverflip.animationElement( el.find( 'img' ), { opacity: 0.2, width: '160px' }, {} )
		];
	  },
	  afterCss: function( el, container, offset ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 90 + 160*offset )+'px', bottom: 0 }, { } ),
		  $.jcoverflip.animationElement( el.find('img'), { opacity: 0.2, width: '160px' }, {} )
		];
	  },
	  currentCss: function( el, container ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 80 )+'px', bottom: 0 }, { } ),
		  $.jcoverflip.animationElement( el.find( 'img' ), { opacity: 1, width: '160px' }, { } )
		];
	  }
	});	
	$('#prevflip').click(function() {
		$('#flip').jcoverflip('previous');
	});
	$('#nextflip').click(function() {
		$('#flip').jcoverflip('next');
	});
}

// pour le défilment auto des logos partenaires
function slideSwitch() {
    var $active = $('#slideparts IMG.active');

    if ( $active.length == 0 ) $active = $('#slideparts IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideparts IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 3500 );
});
/*
// fonction pour menu déroulant
function navDeroulant() {
	$("ul#navigate-menu div").each(function(){
	   $(this).click(function(){
		 $(this).children("ul").slideDown("fast");
			 //if($.browser.msie) { var hauteur = $(this).width(); $(this).children("ul").css({marginLeft:"-"+hauteur+"px"});   }
			 $(this).prev().children("ul").fadeOut("fast");
		 $(this).siblings().children("ul").fadeOut("fast");
	   });
	});
   $("ul#navigate-menu div ul").bind("mouseleave",function(){
	 $("ul#navigate-menu div ul").fadeOut("fast");
   });
}
*/
// fonction pour menu déroulant
function navDeroulant() {
	$("li#nav-revue div").bind("mouseover",function(){
		 $(this).children("ul").slideDown("fast"),
		 $("li#nav-actu div ul").fadeOut("fast"),
		 $("li#nav-libre div ul").fadeOut("fast"),
		 $("li#nav-emploi div ul").fadeOut("fast"),
		 $("li#nav-formation div ul").fadeOut("fast"),
		 $("li#nav-boutique div ul").fadeOut("fast");
   });
	$("li#nav-actu div").bind("mouseover",function(){
		 $(this).children("ul").slideDown("fast"),
		 $("li#nav-revue div ul").fadeOut("fast"),
		 $("li#nav-libre div ul").fadeOut("fast"),
		 $("li#nav-emploi div ul").fadeOut("fast"),
		 $("li#nav-formation div ul").fadeOut("fast"),
		 $("li#nav-boutique div ul").fadeOut("fast");
   });
	$("li#nav-libre div").bind("mouseover",function(){
		 $(this).children("ul").slideDown("fast"),
		 $("li#nav-revue div ul").fadeOut("fast"),
		 $("li#nav-actu div ul").fadeOut("fast"),
		 $("li#nav-emploi div ul").fadeOut("fast"),
		 $("li#nav-formation div ul").fadeOut("fast"),
		 $("li#nav-boutique div ul").fadeOut("fast");
   });
	$("li#nav-emploi div").bind("mouseover",function(){
		 $(this).children("ul").slideDown("fast"),
		 $("li#nav-revue div ul").fadeOut("fast"),
		 $("li#nav-actu div ul").fadeOut("fast"),
		 $("li#nav-libre div ul").fadeOut("fast"),
		 $("li#nav-formation div ul").fadeOut("fast"),
		 $("li#nav-boutique div ul").fadeOut("fast");
   });
	$("li#nav-formation div").bind("mouseover",function(){
		 $(this).children("ul").slideDown("fast"),
		 $("li#nav-revue div ul").fadeOut("fast"),
		 $("li#nav-actu div ul").fadeOut("fast"),
		 $("li#nav-libre div ul").fadeOut("fast"),
		 $("li#nav-emploi div ul").fadeOut("fast"),
		 $("li#nav-boutique div ul").fadeOut("fast");
   });
	$("li#nav-boutique div").bind("mouseover",function(){
		 $(this).children("ul").slideDown("fast"),
		 $("li#nav-revue div ul").fadeOut("fast"),
		 $("li#nav-actu div ul").fadeOut("fast"),
		 $("li#nav-libre div ul").fadeOut("fast"),
		 $("li#nav-emploi div ul").fadeOut("fast"),
		 $("li#nav-formation div ul").fadeOut("fast");
   });
	
   $("ul#navigate-menu").bind("mouseleave",function(){
	 $("ul#navigate-menu div ul").fadeOut("fast");
   });
}

// cacher/apparaitre des champs du formulaire d'inscription
function affFormChamp(valeur) {
	if (valeur != "0" && valeur != "7") {
		//alert('Pharmacien');
		if (valeur == "6") {
			document.getElementById('rppsPharma').style.display = 'none';
			document.getElementById('autreFonction').style.display = 'block';
		} else {
			document.getElementById('rppsPharma').style.display = 'block';
			document.getElementById('autreFonction').style.display = 'none';
		}
		if (valeur == "1" || valeur == "2" || valeur == "3") {
			document.getElementById('cipPharma').style.display = 'block';
		} else {
			document.getElementById('cipPharma').style.display = 'none';
		}
		if (valeur == "4") {
			document.getElementById('filierePharma').style.display = 'block';
			document.getElementById('anneePharma').style.display = 'block';
		} else {
			document.getElementById('filierePharma').style.display = 'none';
			document.getElementById('anneePharma').style.display = 'none';
		}
		$('#numPharma').slideDown("normal");
		//document.getElementById(name).style.display = 'block';
	} else {
		//alert('Autre');
		$('#numPharma').slideUp("normal");
		//document.getElementById(name).style.display = 'none';
	}
}

// sélecteur pour le choix d'offre d'un abonnement
function chooseAbonnement(optvaleur) {
	// on récupère les valeurs envoyées
	var tablo = optvaleur.split('µµµ');
	var position = tablo[0];
	var price = tablo[1];
	var pricehtml = tablo[2];
	var gesmag = tablo[3];
	// on met à jour les valeurs du formulaire
	document.getElementById('rprix_'+position).value = price;
	document.getElementById('rgesmag_'+position).value = gesmag;
	// on met à jour le prix de l'offre
	$("#prix_"+position).empty();
	$("#prix_"+position).append(pricehtml);
}

// carroussel pour les dates Agenda
function filtreAgenda(nombre,debut) {
	if (nombre == "") { nombre = 1; }
	if (debut == "") { debut = 0; }
	$("#agenda-caroussel").jCarouselLite({
		btnNext: "#agenda-next",
		btnPrev: "#agenda-prev",
		visible: nombre,
		vertical: true,
		start: debut
	});
}

// carroussel pour les archives de Revues
function archiveRevue(nombre,debut) {
	if (nombre == "") { nombre = 1; }
	if (debut == "") { debut = 0; }
	$("#archive-caroussel").jCarouselLite({
		btnNext: "#archive-next",
		btnPrev: "#archive-prev",
		visible: nombre,
		vertical: true,
		start: debut
	});
}

// pour changer les valeurs du template email du suivi de commande dans l'administration
function adminComMail(idcom) {
	idsuivi = document.comsuivi.suivi.options[document.comsuivi.suivi.selectedIndex].value;
	$.ajax({
		type: "POST",
		url: "/admin/getcomail.php",
		data: 'idcom='+idcom+'&idsuivi='+idsuivi,
		success: function(monecho){
			if (monecho != ''){
				// récupère les nouvelles valeurs dans le tableau
				montableau=monecho.split('_cc_');
				// met à jour les champs du formulaire concerné
				$("#msend").val(montableau[0]);
				$("#msujet").val(montableau[1]);
				CKEDITOR.instances.texte.setData(montableau[2]);
			}
		}
	});
	return false;
}
