function afficheMessage(id, texte) {
	$(id).innerHTML = texte;
	$(id).style.display = "block";
	
	var myFx = new Fx.Slide(id);
	
	myFx.hide();
	myFx.toggle();
}

function trim(aString) {
	var regExpBeginning = /^\s+/;
	var regExpEnd = /\s+$/;
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

function isEmpty( inputStr ) { if ( "" == trim(inputStr) ) { return true; } return false; }

function voteSondage(sondage) {
	form = document.forms['form_sondage'];
	//sondage = form.sondage.value;
	vote = false;
	
	for(i=0; i<form.vote.length; i++){
		if ( form.vote[i].checked ) vote = form.vote[i].value;
	}
	if ( !vote ) {
		$('sondage_erreur').innerHTML = "Aucun choix sélectionné";
		$('sondage_erreur').style.display = "block";
		var myFx = new Fx.Slide('sondage_erreur').hide();
		var myFx = new Fx.Slide('sondage_erreur').toggle();
		return 0;
	}

	$('sondage').innerHTML = '<img src="images/ajax_noir.gif" alt="Chargement" />';

	var options = {url: "ajax.php", method : 'post' , update: $('sondage'), evalScripts: true};
    var monObjetAjax= new Request.HTML(options);
    monObjetAjax.send('action=sondage&sondage='+sondage+'&vote='+vote);
	
	return false;
}


function afficher(id) {
	if( $(id).style.display != "block" ) {
		$(id).style.display = "block";
	}
	else {
		$(id).style.display = "none";
	}
}

function toggle(id) {
	if ($(id).style.display != 'block') {
		$(id).style.display = 'block';
		var myFx = new Fx.Slide(id).hide();
	}
	var newFx = new Fx.Slide(id).toggle();
}

function cacherFlash(id) {
	var myFx = new Fx.Slide('flash_'+id).toggle();
	
	var options = {url: "ajax.php", method : 'post', evalScripts: true};
    var monObjetAjax= new Request.HTML(options);
    monObjetAjax.send('action=profil&fonction=cacherFlash&id='+id);
}

function etreAmi(choix, id) {
	var myFx = new Fx.Slide('ami_'+id).toggle();
	
	var options = {url: "ajax.php", method : 'post', evalScripts: true};
    var monObjetAjax= new Request.HTML(options);
    monObjetAjax.send('action=profil&fonction=etreAmi&choix='+choix+'&id='+id);
}

function flash_recu() {
	$('flash_recu').style.display = "block";
	$('flash_recu').fade(0);
}

function confirmMessage(texte, lien, type) {
	if (texte == 'supprimer') texte = 'Etes-vous sur de vouloir supprimer cet élément ?';
	
	var infoSplash = new Array();
	infoSplash['type'] = type;
	infoSplash['texte'] = texte;
	infoSplash['function'] = lien;
	
	splash(infoSplash);
}

function cacherMessage() {
	var myFx = new Fx.Slide('message').toggle();
	
	var options = {url: "ajax.php", method : 'post', evalScripts: true};
    var monObjetAjax= new Request.HTML(options);
    monObjetAjax.send('action=profil&fonction=cacherMessage');
}

	
function addSmiley(code) {
	$('texte').value += ' '+code+' ';
	return false;
}
	
function init() {
	new FormCheck('recherche');
	
	$$('a.submit').each(function(item){
		item.addEvents({
			'click': function(e){
				if (typeof(myCheck) != 'undefined') {
					if (typeof(myCheck.onSubmit()) != 'undefined') return false;
				}
				item.getParent("form").submit();
				return false;
		    }
		});
	});
	
	$$('a.flasher').each(function(item){
		var splitId = item.id.split('_');
		var idFlash = splitId[1];
		var membreId = splitId[2];
		var membrePseudo = item.name;
		
		item.addEvents({
			'click': function(e){
				var infoSplash = new Array();
				infoSplash['type'] = 'fonction';
				infoSplash['texte'] = 'Voulez-vous vraiment flasher <strong>'+membrePseudo+'</strong> ?';
				infoSplash['function'] = 'actionMessage(\'flasher\', \''+membreId+'\');cacherFlash('+idFlash+');';
				splash(infoSplash);
				return false;
		    }
		});
	});
	
	$$('a.cacherFlash').each(function(item){		
		item.addEvents({
			'click': function(e){
				cacherFlash(item.id.split('_')[1]);
				return false;
		    }
		});
	});
	
	/**
	$('bloc_meteo').addEvents({
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.set('tween', {
				duration: 1000,
				transition: Fx.Transitions.Bounce.easeOut // This could have been also 'bounce:out'
			}).tween('height', '355px');
		},
		'mouseleave': function(){
			// Resets the tween and changes the element back to its original size
			this.set('tween', {}).tween('height', '72px');
		}
	});
	
	
	var options = {url: "ajax.php", method : 'post', update : 'bloc_meteo', evalScripts: true};
    var monObjetAjax= new Request.HTML(options);
    monObjetAjax.send('action=meteo');
    **/
}

function actionMessage(type, id){
	if (type == 'flasher') fonction = 'flasher';
	else if (type == 'ami') fonction = 'demandeAmi';
	else if (type == 'voter') fonction = 'voter';
	
	var myRequest = new Request({url:'ajax.php',
        method: 'post',
        evalResponse: true,
        data: { 'action':'profil', 'fonction':fonction, 'id':id }, 
        onSuccess : function(response){
			var infoSplash = new Array();
			infoSplash['type'] = 'message';
			infoSplash['texte'] = 'Action effectuée';
			splash(infoSplash);
        }
    }).send();
}

function demanderPage(adresse){
	var page = prompt('Allez à la page :', '');
	
	if (page !== null && !isNaN(page) && page > 0)
	{
		document.location.href = url + adresse + 'page-' + page;
	} 
}
function demanderPageAjax(fonction){
	var page = prompt('Allez à la page :', '');
	
	if (page !== null && !isNaN(page) && page > 0)
	{
		eval(fonction + '('+page+')');
	} 
}
window.addEvent('domready', init);

var ajax_html = '<div style="text-align:center"><img src="images/ajax_gris.gif" alt="Chargement" /></div>';
