function getCss()
{
	var timer = null;
	$$('a.css').addEvent('click', function(){
		var name = this.get('rel');
		var src = $('css');
		var cookie = Cookie.write('css',name,365);
		$('cssalert').set('html','Css modifié, le changement sera effectif<br /> au prochain chargement de page');
		$('cssalert').fade('in');
		timer = setTimeout(function(){
			$('cssalert').fade('out');
		}, 3000);
	});
}
function closeSubmenu(el)
{
	return el.start({
		overflow: 'hidden',
		visibility: 'hidden',
		opacity: [1, 0],
		zIndex: 1
	});
}
function hideMenu(el)
{
	return el.setStyle('display','none');
}
function initFooter()
{	
	var scroll = $('main').getScroll() ;
	$('footer').setStyles({
		zIndex: '999',
		position: 'fixed',
		left:25,
		bottom: scroll.y ,
		margin: 'auto'
	});
}
function tips()
{
	$$('.tips').each(function(element, index) {
		if (element.get('title').split(' :: ') != null) {
			var content = element.get('title').split(' :: ');
			element.store('tip:title', content[0]);
			element.store('tip:text', (content[1] == '') ? '' : content[1]);
			element.setStyle('z-index', 99999);
		}
	});

	var tips = new Tips('.tips', {
		className : 'tips',
		fixed : false,
		hideDelay : 300,
		showDelay : 300
	});
	tips.addEvent('show', function(tip, el){
	    tip.fade('in');
	});
	tips.addEvent('hide', function(tip, el){
	    tip.fade('out');
	});
}
function accordion()
{
	var myAccordion = new Accordion($('accordion'), 'div.toggler', 'div.element', {
		opacity: false
	});
}
/**
 * Menu dépliant
 * @return void
 */

function dropMenu()
{
	var headLink = $$('li.submenu');
	//etat du menu: open | close
	var state = false;
	//etat du sous-menu: open | close
	var open = false;
	//sous menu
	var submenu = $('tree');
	//effet de transitions du sous menu
	var fx = new Fx.Morph(submenu, {duration: 500, transition: 'circ:out', wait: false});
	//Indicateur d'ouverture du sous-menu
	var el = new Element('span', {marginRight: '10px'});
	el.set('html','&nbsp;&raquo');
	//Lien du sous menu
	var sublink = $('guit');
	var subtree = $('subtree');	
	if(headLink != undefined)
	{
		headLink.each(function(header, i){			
			//menu
			var menu = header.getElement('ul.sub');
			//On applique un effet slide au menu
			menu.set('slide', {duration: 800, transition: 'circ:out', open: false});
			header.addEvents({	
				'domready': function() {
					//On cache le menu 
					menu.slide('hide');
					//et le sous menu
					submenu.setStyle('display','none');
				},			
				'mouseenter': function() {				
					menu.slide('in');		
					subtree.addEvents({
						'mouseenter': function(e){
							open = true;
							el.injectInside(sublink);	
							var x = menu.getSize().x.toInt();
							fx.start({			
								position: 'absolute',
								left:x,
								top: 30,
								display: 'block',
								overflow: 'visible',
								visibility: 'visible',
								opacity: [0, 1],
								zIndex: 5000
							});
							sublink.addClass('menu-hover');
						},
						'mouseleave': function() {
							el.dispose();
							sublink.addClass('menu-hover');
							sublink.addClass('menu-leave');
							closeSubmenu(fx);
							open = false;
						}
					});	
				},
				'mouseleave': function() {
					if(!open)
						menu.slide('out');			
				}
			});	
		});
	}
}
/**
 * Menu nav gauche
 * @return void
 */
function createNavLeft()
{
	var sl1 = new Fx.Slide('member-options', {
		mode : 'vertical',
		wait : false,
		duration : 1000,
		open: true,
		transition : Fx.Transitions.Quad.easeOut
	});
	$('member').addEvents( {

		'domready' : function() {
			sl1.hide();
		},
		'mouseenter' : function() {		
			sl1.slideIn();
		}
	});
	$('member-options').addEvents( {

		'mouseleave' : function() {
			//sl1.start({ duration : 'long'});
			sl1.slideOut();
		}
	});
	var sl2 = new Fx.Slide('visitor-options', {
		mode : 'vertical',
		wait : true,
		duration : 1000,
		open: -1,
		transition : Fx.Transitions.Quad.easeOut
	});
	$('visitor').addEvents( {

		'domready' : function() {
			sl2.hide();
		},
		'mouseenter' : function() {		
			sl2.slideIn();
		}
	});
	$('visitor-options').addEvents( {
		'mouseleave' : function() {			
			sl2.slideOut();
		}
	});
	var sl3 = new Fx.Slide('space-options', {
		mode : 'vertical',
		wait : true,
		duration : 1000,
		open: -1,
		transition : Fx.Transitions.Quad.easeOut
	});
	$('space').addEvents( {

		'domready' : function() {
			sl3.hide();
		},
		'mouseenter' : function() {		
			sl3.slideIn();
		}
	});
	$('space-options').addEvents( {

		'mouseleave' : function() {	
			sl3.slideOut();
		}
	});
}
/**
 * @author Franck Matherat
 * @copyright: franckysolo.productions
 * ok!!!
 */
function myLightBox() 
{	
	
	$$('a.fkyBox').addEvent('click',function(e){
		//On définis nos variables
		e = new Event(e).stop();
		//On recuppere l'id du conteneur à afficher
		var name = this.get('href');
		var array = name.split('#');
		var id = array[1];//nom de l'id
		
		//Pour simplifier l'ecriture
		var div = $(id);// div id= celle cliquée
		var bg = $('bg');//div bg

		//les effets mootools
		var container = new Fx.Morph(id,{transition: Fx.Transitions.Circ.easeOut, duration: 1000});
		var bgFx = new Fx.Morph('bg',{transition: Fx.Transitions.Quad, duration: 500});
		
		//centrage du conteneur 
		var w = 650;//largeur par défaut
		var h = 350;//hauteur par défaut
		
		var width = window.getSize().x.toInt();//largeur de la fenêtre
		var centerx = width / 2;//origine x de la fenetre
		
		var height = window.getSize().y.toInt();//hauteur de la fenêtre
		var centery = height / 2;
		//la position du haut de page si on scroll
		var scroll = window.getScrollTop();
		
		var maxLeft =  (width - w) / 2;
		var maxTop = ((height - h) / 2 ) + scroll;
		
		//Pour fermer notre conteneur
		var close = new Element('close',{
					'styles': {
						float: 'right',
						'font-weight': 'bold',
						cursor: 'help'
					},
					'html' : 'Pour fermer cliquez sur le fond noir',
					'class': 'labelDown'
		});
	
		//On insère le lien de fermeture dans la div
		div.adopt(close);
		div.setStyles({
			'background-color':'#FFF',
			opacity: 'inherit',
			border: '1px solid #000',
			width: 300,
			height: 400		
		});		
		//Conteneur: idem  
		container.start({
				display : 'block',
				opacity: 1,
				height: [50, h],
				width: [50, w],
				margin: '2%',
				left: [centerx, maxLeft],
				top: [centery + scroll, maxTop],
				zIndex: 9999
		});	
		//Background: on démarre l'effet
		bgFx.start({
			'background-color': '#000',
			opacity: [0,0.7],
			height: [0,height],
			width: [0,width],
			top: [0,scroll],
			zIndex: 9998,
			cursor: 'pointer'
			
		});
		//Si on scroll le conteneur, le background doit suivre
		window.addEvent('scroll',function(){
			$(bg).setStyle('top',window.getScrollTop());			
		});
		bg.addEvent('click', function(e) {
			e = new Event(e);
			e.stop();
			div.setStyle('display','none');
			bgFx.start({
				//'background-color': [0,'transparent'],
				opacity: [0.7,0],
				height: [height,0],
				width: [width,0],
				top: [scroll,0]
				
			});
			close.dispose();
		});	
	});		
}

/**
 * Menu du bas de page "infos utiles"
 * @return void
 */
function dropFooterMenu()
{
	var el = $('help');
	if(el != undefined)
	{
		var box = el.getElement('ul');
		var scroll = $(document.body).getScroll();
		var footer = $('footer');
		var b = parseInt(box.getStyle('height'));
		var c = parseInt(footer.getStyle('height')) - 10;
		var h = b + c;
		box.setStyles({
			position: 'relative',
			bottom:0,
			left: 0,
			padding: 0,
			display: 'none'		
		});
		var fx = new Fx.Morph(box, {duration: 800, transition: Fx.Transitions.Circ.easeOut});
		var link = $('help-box');
		el.addEvents({
			'click': function() {
				fx.start({
					zIndex: -1,
					bottom: h,
					left: 0,
					height:[0,b],
					overflow: 'hidden',
					opacity: [0, 1],
					display: 'block'
				});	
			},
			'mouseleave': function() {
				fx.start({
					bottom: [h,0],
					height: [b,0],
					overflow: 'hidden',
					opacity: [1, 0]			
				});
			}
		});
	}
}
/**
 * Ma tool Bar :) 
 * Affichage de l'Horloge,
 * Chat et Amis en ligne
 * @return void
 */

function clock()
{
	var timer = null;
	var clock = $('clock');
	var linkC = clock.getPrevious('a');
	var fxC = new Fx.Morph(clock, {duration: 800, transition: Fx.Transitions.linear});
	linkC.addEvents({
		'click': function() {	
			clearTimeout(timer);			
			fxC.start({
					position: 'absolute',
					bottom: [0,30],
					left: 0,
					opacity: [0,1],
					display: 'block'
			});
			timer = setTimeout(function(){
				fxC.start({
					bottom: [30,0],
					opacity: [1,0]
				});				
			}, 3000);			
		}
	});	
}
function closeBox(fx)
{
	return 0;
}
function toolBar()
{	
	var closeChat = $('closeChat');
	var closeLine = $('closeLine');	
	var online = $('online');
	var linkOnline = online.getPrevious('a');
	var fxOnline = new Fx.Morph(online, {duration: 800, transition: Fx.Transitions.linear});
	//Online
	if(linkOnline != undefined)
	{
		linkOnline.addEvent('click', function(){
			
			fxOnline.start({
					position: 'fixed',
					right: 60,
					bottom: 37,
					opacity: [0,1],
					display: 'block',
					zIndex: -1
			});	
		});
		
		closeLine.addEvent('click', function(){
			fxOnline.start({			
				opacity: [1,0]
			});
		});
	}
	//CHAT
	var chat = $('chat'); 
	var linkH = $$('a.connectChat');
	var hid = $('hide');
	if(hid != undefined)
	{
		var fxChat = new Fx.Morph(chat, {duration: 800, transition: Fx.Transitions.linear});
		var fxHide = new Fx.Morph(hid, {duration: 800, transition: Fx.Transitions.linear}); 
		linkH.each(function(link, i){		
			link.addEvent('click', function(){			 
				fxChat.start({
						position: 'absolute',
						bottom: 38,
						right: 238,
						opacity: [0,1],
						display: 'block'					
				});
				var span = hid.getElement('span');
				span.set('html',link.get('html'));
				fxHide.start({
					position: 'relative',
					left: 136,
					top: -22,
					opacity: [0,1],
					display: 'block'			
				});				
				 var myFx = new Fx.Morph('hide', { duration: 800});
				 myFx.start({opacity: [1,0], backgroundColor : '#f00'}).chain(
				     function(){ this.start({opacity: [0,1], backgroundColor : '#000'}); },
				     function(){ this.start({opacity: [1,0], backgroundColor : '#f00'}); },
				     function(){ this.start({opacity: [0,1], backgroundColor : '#000'}); }
				 );
			});
		});
		closeChat.addEvent('click', function(){
			fxChat.start({			
				opacity: [1,0]
			});
			hid.setStyle('visibility','hidden');
			var span = hid.getElement('span');
			span.set('html','');		
		});	
	}
}

function infosBox()
{
	var link = $('imgInfos');
	var box = $('uploadInfos');	
	if(link != undefined && box != undefined)
	{	
		var fx = new Fx.Slide(box, {
			mode:'vertical',
			open: false,
			wait: false,
			transition : Fx.Transitions.Quad.easeOut
		});
		fx.toggle();
	}
}
function avatarBox()
{
	var link = $('avatar');
	var box = $('avatarBox');
	
	if(link != undefined && box != undefined)
	{	
		var fx = new Fx.Slide(box, {
			mode:'vertical',
			open: false,
			wait: true,
			transition : Fx.Transitions.Quad.easeOut
		});
		fx.toggle();
	}	
}
function signatureBox()	
{
	var link = $('signature');
	var box = $('signatureBox');
	
	if(link != undefined && box != undefined)
	{	
		var fx = new Fx.Slide(box, {
			mode:'vertical',
			open: false,
			wait: true,
			transition : Fx.Transitions.Quad.easeOut
		});
		fx.toggle();
	}
}
function sondageView()
{
	var bool = false;
	var div = $$('.voteResult');
	var link = $('voteLink');	
	div.each(function(myDiv){
		if(link != undefined)
		{
			var fx = new Fx.Slide(myDiv, {
				mode:'vertical',
				open: false,
				wait: true,
				transition : Fx.Transitions.Quad.easeOut,
				onComplete: function(){
					if(fx.open == false)
					{
						link.setProperty('title','Afficher les résultats');
					}
					else
					{
						link.setProperty('title','Cacher les résultats');
					}
				}
			});
			fx.toggle();			
		}
	});
	
}
function imageTips()
{
	var hide = true;
	var width = window.getSize().x.toInt();//largeur de la fenêtre
	var centerx = width / 2;//origine x de la fenetre	
	var height = window.getSize().y.toInt();//hauteur de la fenêtre
	var centery = height / 2;
	var tips = $$('.imgTips');
	tips.setStyles({
		'text-decoration': 'none',
		color: 'white'		
	});
	tips.each(function(tip){
		
		var span = tip.getChildren('div');	
		span.setStyles({
			display: 'none', 
			position: 'absolute',
			left: centerx / 1.5,
			top: centery / 1.5,
			background: 'url(public/images/bubble.png) repeat',
			padding: 5,
			zIndex: 500		
		});
		span.each(function(sp){
			var fx = new Fx.Morph(sp, {
				duration: 'short',
				transition: Fx.Transitions.Sine.easeOut
			});		
			tip.addEvents({		
				'click': function(){
					if(hide)
					{
						fx.start({					
							display: 'block',
							opacity: [0,1]
							
						});
						hide = false;
					}
				},
				'mouseleave': function(){
					if(!hide)
					{
						fx.start({
							display: 'none',
							opacity: [1,0]
						});
						hide = true;
					}
				}
			});
		});
	});
}

function soundInfoBox()
{
	var link = $('attention');
	var div = $('infoSound');
	if(link != undefined && div != undefined)
	{
		link.addEvents({
			
			'domready': function() {
				div.slide('hide');
			},
			'click' : function(){
				div.slide('toggle');
			}
		});
	}
}
function sliderLevel()
{
	var el = $('levelMember');
	var input = $('level');
	var img = $('imgLevel');
	var levels = ['bannis','visiteur','membre','modo','admin'];	
	if(img != undefined)
	{
		img.src = 'public/images/bt-bannis.gif';
		new Slider(el, el.getElement('.knob'), {
			wheel: true,
			steps: 4,	
			range: [0,4],
			onChange: function(value){
				input.value = value;
				img.src = 'public/images/bt-'+levels[value]+'.gif';
			}
		});
	}
}
function alertButton()
{
	var img = $('alertButton');
	if(img != undefined)
	{
		img.setProperty('src', 'url(../../public/images/bta-alerton.png'); 
		 var myFx = new Fx.Morph('alertButton', { duration: 500});
		 myFx.start({opacity: [1,0.3]}).chain(
		     function(){ this.start({opacity: [0.3,1]}); },
		     function(){ this.start({opacity: [1,0.3]}); },
		     function(){ this.start({opacity: [0.3,1]}); }
		     
		 );
	}
}

function analyseSecurityPass()
{
	var div = $('securityTest');
	var value = $('pass').value;
	var fx = new Fx.Morph(div, {duration: 500, transition: Fx.Transitions.Circ.easeIn});
	div.setStyles({
		margin: 'auto',
		fontSize: 'small',
		color : 'white',
		fontWeight : 'bold',
		padding : '1%',
		textAlign : 'center'
	});
	var lgt = value.length;
	if(lgt >= 0 && lgt < 10)
	{
		fx.start({
			width : 50,
			height : 10,
			'background-color': '#F00'
			
		});
		div.set('html', 'Sécurité faible');
	}
	else if(lgt >= 10 && lgt < 20)
	{
		fx.start({
			width : 130,
			height :10,
			'background-color': '#F60'
		});
		div.set('html', 'Sécurité moyenne');
	}
	else
	{
		fx.start({
			width : 250,
			height : 10,
			'background-color': '#363'
		});
		div.set('html', 'Sécurité excellente');
	}
}

function sendId(id)
{
	var input = $('id');
	input.value = id;
}
function sendChoice(txt)
{
	var input = $('text');
	
	input.value = txt;
}
function sendInfosToForm(name, level)
{
	var txt = 'Modifier le niveau de '+name;
	$('legend').set('html', txt);
	$('level').value = level;
}
function hideBox()
{
	if($('accessBox') != undefined)
	{
		var div = $('accessBox');
		var timer = null;
		timer = setTimeout( function(){
			div.fade('out').slide('out');
		},3000);
	}
}
function fadeBox()
{
	var timer = null;
	var div = $('simpleFade');
	if(div != undefined)
	{
		timer = setTimeout( function(){
			div.fade('out');
		},3000);
	}
}
function lfadeBox()
{
	var div = $('longFade');
	var timer = null;
	if( div != undefined)
	{
		if(div.get('html') != '')
		{
			div.fade('in');
		}
		timer = setTimeout( function(){
			div.fade('out');
			div.set('html', '');
		},5000);
	}	
}
function showHelpRecord()
{
	var span = $('helpRecord');
		span.set('html','Vérification');
		span.addClass('helperRecord');
		span.fade('in');
}

function confirmPass()
{
	var pass = $('pass').value;
	var passConfirm = $('passConfirm').value;
	var span = $('helperPass');
	if(pass != '' && passConfirm != '')
	{
		if(pass == passConfirm)
		{
			span.removeClass('rouge');
			span.set('html','Confirmation ok!');
			span.addClass('vert');
		}
		else
		{
			span.removeClass('vert');
			span.set('html','Confirmation inexacte!!!');
			span.addClass('rouge');
		}
		span.fade('in');
	}
}
function closeHalfBox()
{
	var scroll = window.getScrollTop();
	var close = $('close');
	var div = $('wrapper');	
	var fx = new Fx.Morph(div,{transition: Fx.Transitions.Quad, duration: 800});
	fx.start({	
		opacity: [1,0],
		width: [240,0],
		top: [scroll,0],
		left: 0,
		zIndex: -1	
	});
	div.set('html','');
}
function halfBox(value)
{
	var scroll = window.getScrollTop();
	var close = $('close');
	var div = $('wrapper');	
	div.addClass('imager');
	var fx = new Fx.Morph(div,{transition: Fx.Transitions.Quad, duration: 800});
	div.set('html',value);
	fx.start({
		'background-color': '#000',
		opacity: [0,1],
		width: [0,240],
		top: [0,scroll],
		left: 0,
		zIndex: 10,
		verticalAlign : 'top',
		border: '4px solid #ccc',
		color: '#fff',
		padding: '1%'
	});
}
function setSearch(id) {
	var list = $('link-' + id);
	var searchId = $('searchId');
	for ( var i = 1; i <= 3; i++) {
		if (i == id) {
			list.addClass('selected');
			searchId.value = id;
		} else {
			$('link-' + i).removeClass('selected');
		}
	}
}
function champ_obligatoire() {
	var txt = "";
	var timer = null;
	txt = "Les champs pr&eacute;c&eacute;d&eacute;s d'un * sont obligatoires";
	$('champ').set('html', txt);
	$('champ').fade('in');
	timer = setTimeout(function(){
		$('champ').fade('out');
	}, 3000);
}
function affiche_txt() {
	var txt = "";
	var timer = null;
	txt = 'Vous avez eu un coup de coeur pour cet artiste ou ce groupe votez pour lui';
	$('vote').set('html',txt);
	$('vote').fade('in');
	timer = setTimeout(function(){
		$('vote').fade('out');
	}, 3000);
}
function affiche_out() {
	var txt = "";
	$('vote').set('html',txt);
}

function closeSuppMessage(id)
{
	$(id).setStyle('display','none');
	$('bg').setStyle('opacity','0');
}
function sendImageLink(name)
{
	$('texte').value += '[img]'+name+'[/img]';
}
function refresh() {
	$('captcha').src = 'captcha.php?' + Math.floor((new Date()).getTime() / 1000);
}
//horloge dynamique
function timer() {
	// initialisation des variables
	var time = new Date();
	var jour = time.getDate();
	var mois = time.getMonth() + 1;
	var annee = time.getFullYear();
	var heure = time.getHours();
	var minute = time.getMinutes();
	var seconde = time.getSeconds();
	if (jour < 10) {
		jour = "0" + jour;
	}
	if (mois < 10) {
		mois = "0" + mois;
	}
	if (heure < 10) {
		heure = "0" + heure;
	}
	if (minute < 10) {
		minute = "0" + minute;
	}
	if (seconde < 10) {
		seconde = "0" + seconde;
	}
	$("clock").innerHTML = jour + "/" + mois + "/"
			+ annee + "<br />" + heure + ":" + minute + ":" + seconde;
	// pour réactualiser la page toutes les secondes
	var timer = setTimeout("timer", 1000);
}
function display() {
	var str = '<span id="clock"></span>';
	// on affiche l'heure
	document.write(str);
	// l'appel à la fonction réactualise la page toutes les secondes
	timer();
}
/**
 * coche et décoche les checkbox en un click
 * 
 * @uses: pour la suppression multiple
 * @return mixed
 */
function checkAll() {
	var coche = document.myMp.coche;
	coche.style.cursor = 'pointer';
	var check = document.myMp.elements["mps[]"];
	if (check != null) {
		if (coche.checked == true) {
			for ( var i = 0; i < check.length; i++) {
				check[i].checked = true;
				var tmp = 1;
			}
		} else {
			for ( var i = 0; i < check.length; i++) {
				check[i].checked = false;
				var tmp = 1;
			}
		}
	} else {
		return false;
	}
}
/**
 * change le title du checkbox
 * 
 * @return void
 */
function getAllSelect() {
	if (document.myMp.coche.checked == true) {

		document.myMp.coche.title = "Tout décocher";

	} else {
		document.myMp.coche.title = "Tout cocher";
	}
}

function popup(page, name, option) {
	window.open(page, name, option);
}
function closePopup() {
	window.close();
}
