// 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 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");
   });
}

// 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';
	}
}
