/**
 * fonctions ajax pour Indy-musics-V2.0
 * @author franckysolo
 * avec le framework mootools
 * 
 */
function setCssStyle(name)
{
	var myUrl = 'application/ajax/ajax.php?action=setCssStyle&id='+name;	
	var req = new Request({
				url : myUrl ,
				method :  "get"	,
				onComplete: function() {
					
				}
		});
	req.send();
}					
function harmonyTable()
{
	var div = $('scale');
	if(div != undefined)
	{
		var value = $('tonique').value;
		var myUrl = 'application/ajax/ajax.php?action=harmonyTable&tonique='+value;	
		var req = new Request({
					url : myUrl ,
					method :  "post"	,
					evalScripts: true,
					onComplete: function() {
						div.set('html', this.response.text);
					}
			});
		req.send('tonique='+value);
	}
}
function tableMode()
{
	var div = $('tableMode');
	if(div != undefined)
	{
		var link = $$('a.mode');
		var bg = $('bg');
		var value = 0;
		link.each(function(el){
			 value = el.get('rel');
			// alert(value);
		});
		var myUrl = 'application/ajax/ajax.php?action=tableMode&tonique='+value;	
		var req = new Request({
					url : myUrl ,
					method :  "get"	,
					evalScripts: true,
					onComplete: function() {
						div.set('html', this.response.text);
					}
			});
		req.send();
	}
}
function generatePassword()
{	
	var myUrl = 'application/ajax/ajax.php?action=generatePassword';	
	var req = new Request({
				url : myUrl ,
				method :  "get"	,
				onComplete: function() {
					$('passClear').set('html', 'Votre nouveau mot de passe : '+ this.response.text);
					$('passClear').setProperty('class','indexMsg');
					$('passClear').highlight('#cce');
					$('pass').value = this.response.text;
					$('passConfirm').value = this.response.text;
					analyseSecurityPass();
				}
		});
	req.send();	
}
function wrappComment()
{	
	var wrapper = $('wrapperCom');
	var txt = $('linkCom');
	var fx = new Fx.Slide(wrapper,  {
		mode:'vertical',
		open: false,
		wait: true,
		transition : Fx.Transitions.Quad.easeOut,
		onComplete : function(){
			
			if(fx.open == false)
			{
				txt.set('html','Afficher les commentaires');	
			}
			else
			{
				txt.set('html','Cacher les commentaires');
			}
		}
		
	});
	
	//alert(txt.get('html'));
//	if(txt.get('html') == 'Afficher le commentaire')
//	{
//		txt.set('html','Cacher le commentaire');	
//	}
//	else if(txt.get('html') == 'Afficher les commentaires')
//	{
//		txt.set('html','Cacher les commentaires');	
//	}
//	else if(txt.get('html') == 'Cacher le commentaire')
//	{
//		txt.set('html','Afficher le commentaire');	
//	}
//	else
//	{
//		txt.set('html','Afficher les commentaires');
//	}

	fx.toggle();
	
}
function getNewsComments(id)
{	
	var myUrl = 'application/ajax/ajax.php?action=getNewsComments&id='+id; 	
	var req = new Request({
		url : myUrl ,
		method :  "get"	,
		onComplete: function() {		
			$('contentNews').set('html', this.response.text);	
			sondageView();
		}
	}).send();		
}
function submitNewVote(ip, id)
{
	var myUrl = 'application/ajax/ajax.php?action=submitNewVote'; 
	var div = $('alertVotation');
	var req = new Request({
		url : myUrl ,
		method :  "post"	,
		onComplete: function() {		
			div.set('html', this.response.text);
			
			div.fade('in');
			timer = setTimeout( function(){
				div.fade('out');
				showMiniSondage();
				div.set('html', '');
			},3000);
			
		}
	}).send('id='+id+'&ip='+ip);	
}
function activeSondage(id)
{
	var div = $('activeSondage');
	var myUrl = 'application/ajax/ajax.php?action=activeSondage&id='+id;
	var fx = Fx.Slide(div);
	var timer = null;
	var req = new Request({
		url : myUrl ,
		method :  "get"	,
		onComplete: function() {
			div.set('html', '<p class="info_msg">Le sondage est activé.</p>');	
		}
	}).send();
	div.fade('in');
	timer = setTimeout(function(){
		div.fade('out');
	},1000);
}
function desactiveSondage(id)
{
	var div = $('activeSondage');
	var myUrl = 'application/ajax/ajax.php?action=desactiveSondage&id='+id;
	var fx = Fx.Slide(div);
	var timer = null;
	var req = new Request({
		url : myUrl ,
		method :  "get"	,
		onComplete: function() {
			div.set('html', '<p class="info_msg">Le sondage est désactivé.</p>');		
		}
	}).send();
	div.fade('in');
	timer = setTimeout(function(){
		div.fade('out');
	},1000);
}

function isPseudoFree()
{
	var div = $('ajax');
	var value = $('login').value;
	var myUrl = 'application/ajax/ajax.php?action=isPseudoFree&login='+value;
	var req = new Request({
		url : myUrl ,
		method :  "get"	,
		onComplete: function() {
			div.set('html',this.response.text);
		}
	});
	req.send();	
	
}

function isValidMail()
{
	var div = $('validMail');
	var value = $('email').value;
	var myUrl = 'application/ajax/ajax.php?action=isValidMail&email='+value;
	var req = new Request({
		url : myUrl ,
		method :  "get"	,
		onComplete: function() {
			div.set('html',this.response.text);
		}
	});
	req.send();	
}
function showMiniSondage()
{
	var div = $('homeSondage');
	if(div != undefined)
	{
		var myUrl = 'application/ajax/ajax.php?action=showMiniSondage';
		var req = new Request({
			url : myUrl ,
			method :  "post",
			evalScripts: true,
			onComplete: function() {
				div.set('html',this.response.text);
			}
		});
		req.send();	
	}
}
function voteArtiste(id)
{
	var timer = null;
	var div = $('vote');
	var message = " ";
	var myUrl = 'application/ajax/ajax.php?action=voteArtiste&id='+id;
	var req = new Request({
		url : myUrl ,
		method :  "get"	,
		onComplete: function() {
				div.set('html', this.response.text);
				div.fade('in');
				timer = setTimeout( function(){
					div.fade('out');
					div.set('html', '');
				},5000);
		}
	});
	req.send();	
}
function openImager(id)
{
	var timer = null;
	var div = $('vote');
	var message = " ";
	var myUrl = 'application/ajax/ajax.php?action=openImager&id='+id;
	var req = new Request({
		url : myUrl ,
		method :  "get"	,
		onComplete: function() {
				halfBox(this.response.text);			
		}
	});
	req.send();	
}
function percent(x)
{
	var txt = $('txt-percent').set('morph',{
		duration: 1000, 
		onComplete: function(){
			$('alert').fade('out');
			$('mB').fade('in');
		}
	});
	x++;
	if(x < 99)
	{
		txt.set('html',x+' % ');
	}
	else
	{
		txt.set('html',' 100% ');
		txt.morph({color: '#f00'});
	
	}
	
}
function progressBar()
{	
	var div = $('myUpload');
	var percent = $('percent');
	var timer = null;
	var i = j = 0;
	if(div != undefined)
	{
		$('progressBar').set('tween', {duration: 1000});
		$('alert').set('html','Veuillez patientez...');
		
		while(i < 100)
		{			
			i++;		
			timer = setTimeout('percent('+i+')',i * 10);
			$('progressBar').tween('width',[0, 4 * i]);
			
			
		}		
	}	
}


