var IS_IE = (document.all) ? true : false;
var CLASS_NAME = (IS_IE) ? "className" : "class";

var regex = new RegExp("[A-Za-z0-9._-]{1,}@[A-Za-z0-9._-]{1,}[.][A-Za-z]{2,}", "gi"); 

// --------------------------------------------------------
//  NEWSBOX -> homepage
// --------------------------------------------------------
function showArticle(_idMot) {
	var t = new Date();
	var time1 = t.getTime();
	//jQuery("#box_newsbox").fadeOut("fast");  
	jQuery("#box_newsbox_wait").show();
	jQuery.get(
		"/fr/spip.php?page=ajax_newsbox" , 
		{ idMot: _idMot } , 
		function(data){ 	
			jQuery("#box_newsbox").html(data);  	     
			jQuery("#box_newsbox_wait").hide("fast");		
		}
	);       
	
}

function confirmBox(_content, _titre, _mod, _darg) { 
	new Boxy(_content, {title: _titre, modal: _mod, closeable:true, closeText:'Sluiten', clone:false, draggable:_darg});    
}

// --------------------------------------------------------
//  NEWSBOX -> homepage FUN
// --------------------------------------------------------
function showArticleFun(_idMot) {
	var t = new Date();
	var time1 = t.getTime();
	//jQuery("#box_newsbox").fadeOut("fast");  
	jQuery("#box_newsbox_wait").show();
	jQuery.get(
		"/fr/spip.php?page=ajax_newsbox_fun" , 
		{ idMot: _idMot } , 
		function(data){     
			jQuery("#box_newsbox").html(data);           
			jQuery("#box_newsbox_wait").hide("fast");        
		}
	);       
	
}

// --------------------------------------------------------
// champs email colonne droite
// --------------------------------------------------------
function champEmail() {
  
}

// --------------------------------------------------------
//  Show loginbox
// --------------------------------------------------------
var ouvert = 0;
function openLogin() {
  //alert('ok');
  if (ouvert == 0) {
    jQuery('#btn_connexion').removeClass('btn- connexion float-left');
    jQuery('#btn_connexion').addClass('connexion_hover');
    jQuery('#btn_connexion').css('color', '#FFFFFF', 'text-decoration', 'none');
	  jQuery('#LoginBox').fadeIn('slow');
	  ouvert = 1;
	}
	else {
    jQuery('#btn_connexion').removeClass('connexion_hover');
    jQuery('#btn_connexion').addClass('btn- connexion float-left');
	  jQuery('#LoginBox').fadeOut('slow');
	  ouvert = 0;
	}
	 
}


// --------------------------------------------------------
//  Show loginbox
// --------------------------------------------------------
var ouvertBox = 0;
function openBox(_div) {
  if (ouvertBox == 0) {
	  jQuery('#'+_div).fadeIn('slow');
	  ouvertBox = 1;
	}
	else {
	   jQuery('#'+_div).fadeOut('slow');
	  ouvertBox = 0;
	}
	 
}

// --------------------------------------------------------
//  Fermer un objet
// --------------------------------------------------------
function fermer(_div) {
	jQuery("#"+_div).fadeOut('fast');	
}

// --------------------------------------------------------
//  Fermer un objet
// --------------------------------------------------------
function fermer_slide(_div) {
	jQuery("#"+_div).slideUp('fast');	
}

// --------------------------------------------------------
// Envoyer article à un ami
// --------------------------------------------------------
function envoie_ami(_idArticle) {
	var t = new Date();
	
	jQuery("#envoi_ami").fadeIn("fast").html("Envoi en cours ...");
	
	jQuery.get(
		"/fr/envoi_ami.php" , 
		{ idArticle: _idArticle, t: t.getTime()} , 
		function(data){ jQuery("#envoi_ami").fadeIn("fast").html(data); }
	);	
}

// --------------------------------------------------------
// Poster article
// --------------------------------------------------------
function post_ami(_idArticle) {
	
	var _nom = escape(document.inviter.nom.value);
	var _email = escape(document.inviter.email.value);
	var _email1 = escape(document.inviter.email1.value);
	var _email2 = escape(document.inviter.email2.value);
	var _email3 = escape(document.inviter.email3.value);
	var _url = escape(document.inviter.urlPage.value);
	
	jQuery("#envoi_ami").show("fast").html("Envoi en cours ...");
	
	var t = new Date();
	jQuery.post(
		"/fr/ajax_envoi_ami_multi.php" , 
		{ envoiAmi: 1,url : _url, idArticle: _idArticle, nom: _nom, email: _email, email1: _email1, email2: _email2, email3: _email3, t: t.getTime()} , 
		function(data){ 
      jQuery("#envoi_ami").show("fast").html(data); 
      window.setTimeout("fermer('envoi_ami');",3000);
    }
	);	
}


// --------------------------------------------------------
// Envoie d'un commentaire sur un article
// --------------------------------------------------------
function envoiComment() {
	
	_idArticle = document.commentaire.idArticle.value;
	_message = document.commentaire.message.value;
	
	if (_idArticle > 0 && _message != '')
		document.commentaire.submit("sdfdsfdsfds"); 
	else
	{
		if (_message == '') document.getElementById('message').style.background = "#CCCFFF";
	}
}


// --------------------------------------------------------
// Sondages : Voter
// --------------------------------------------------------
function sondagesVoter(_poll_id) {
	var _option_id = '';
	_option_id = jQuery("#sondages input:checked").val();

	jQuery("#chargeSondage").fadeIn("fast").html('<center><img src="http://www.baby.be/fr/images/loading.gif"></center>');
	
	jQuery.post(
	"ajax.php" , 
	{poll_ident : _poll_id, action : "vote", option_id : _option_id} , 
	function(data){ 
		jQuery("#ajaxSondage").html(data).fadeIn("fast"); 
		jQuery("#chargeSondage").fadeOut("fast");  
	}
	);		
}

// --------------------------------------------------------
// Sondages : Voir les resultats
// --------------------------------------------------------
function sondagesResults(_poll_id) {
	jQuery("#chargeSondage").fadeIn("fast").html('<center><img src="http://www.baby.be/fr/images/loading.gif"></center>');
	
	jQuery.post(
	"ajax.php" , 
	{poll_ident : _poll_id, action : "voir"} , 
	function(data){ 
		jQuery("#ajaxSondage").html(data).fadeIn("fast"); 
		jQuery("#chargeSondage").fadeOut("fast"); 
	}
	);		
}

// --------------------------------------------------------
// Sondages : Retour
// --------------------------------------------------------
function sondagesRetour(_poll_id) {
	jQuery("#chargeSondage").fadeIn("fast").html('<center><img src="http://www.baby.be/fr/images/loading.gif"></center>');
					 
	jQuery.post(
	"ajax.php" , 
	{poll_ident : _poll_id, action : "autre"} , 
	function(data){   
		jQuery("#ajaxSondage").html(data).fadeIn("fast"); 
		jQuery("#chargeSondage").fadeOut("fast");
	}
	);		
}

// --------------------------------------------------------
// Form commentaire
// --------------------------------------------------------
function formComment(_action, _id, _template) {
	jQuery("#chargeSondage").fadeIn("fast").html('<center><img src="http://www.baby.be/fr/images/loading.gif"></center>');
	
	jQuery.post(
	"./ajax.php" , 
	{formComment: 1, id : _id, action : "send"} , 
	function(data){ 
		jQuery("#ajaxSondage").html(data); 
		jQuery("#chargeSondage").fadeOut("fast");  
	}
	);		
}

// --------------------------------------------------------
// LOGIN babyclub
// --------------------------------------------------------
function loginBabyclub() {
	_login = jQuery("#login").val();
	_pass = jQuery("#pass").val();
	if (_login != '' && _pass != '') {
	  jQuery("#wait_connect").html('<img src="http://www.babyfrance.com/images/attente_mini.gif">');
  	jQuery.post(
  	"login.php" , 
  	{connexion : 1, login: _login, pass:_pass} , 
  	function(data){ 
  	
  		if (data == 'ok_org') {
	        jQuery("#erreur_login").html("<center>Bienvenue !</center>");   
	        document.location.href="http://www.famidoo.be/clientspace/fr/client/index.php"; 
      	}       	
  		if (data == 'ok') {
	        jQuery("#erreur_login").html("<center>Bienvenue !</center>");   
	        document.formConnexion.submit(); 
      	}
 	
  		else jQuery("#erreur_login").html("Votre identifiant ou mot de passe n'est pas correct!");  		
  		jQuery("#wait_connect").html('');
  	});	
  	
	} else {
    jQuery("#erreur_login").html("Veuillez introduire vos identifiant et mot de passe!");
  }
}

// --------------------------------------------------------
// LOGIN babyclub
// --------------------------------------------------------
function loginBabyclubPop() {
	_login = jQuery("#identifiant").val();
	_pass = jQuery("#motdepasse").val();
	_idC = jQuery("#idC").val();	
	
	//alert(_idC);
	
	if (_login != '' && _pass != '') {
	  jQuery("#confirmLogin").html('<img src="http://www.babyfrance.com/images/attente_mini.gif">');
  	jQuery.post(
  	"login.php" , 
  	{connexion : 1, login: _login, pass:_pass, idC:_idC} , 
  	function(data){ 
  		if (data == 'ok_org') {
	        jQuery("#erreur_login").html("<center>Bienvenue !</center>");   
	        document.location.href="http://www.famidoo.be/clientspace/fr/client/index.php"; 
      	}        	
  	
  		if (data == 'ok') {
        jQuery("#confirmLogin").html("<center>Bienvenue !</center>");   
        document.formConnexion.submit(); 
      }     
      
  		else jQuery("#confirmLogin").html("<div style='border:#d20b46 1px solid; padding:3px'>Votre identifiant ou mot de passe n'est pas correct!</div>");  		
  		//jQuery("#confirmLogin").html('');
  	});	
  	
	} else {
    jQuery("#confirmLogin").html("<div style='border:#d20b46 1px solid; padding:3px'>Veuillez introduire vos identifiant et mot de passe!</div>");
  }
}

// --------------------------------------------------------
// Form oublié mon mot de passe
// --------------------------------------------------------
function formOublie(_fichier, _div) {
	if (_div == null) _div = 'login_centre';
	jQuery("#"+_div).html('<center><img src="images/loading.gif"></center>').fadeIn("fast");
	jQuery.get(
	""+_fichier+"" , 
	{formOubie : 1, fichier : _fichier, div : _div} , 
	function(data){ 
		jQuery("#"+_div).html(data).fadeIn("fast"); 
	});
}

// --------------------------------------------------------
// Envoie Form oublié mon mot de passe
// --------------------------------------------------------
function envoiFormOublie(_fichier, _div) {
	if (_div == null) _div = 'login_centre';  
	_email = jQuery("#emailOublie").val();
	if (_email.search(regex) != -1) {
		jQuery("#"+_div).html('<center><img src="images/loading.gif"></center>').fadeIn("fast");  
		jQuery.post(
		""+_fichier+"" , 
		{envoiFormOublie : 1, email:_email, div : _div} , 
		function(data){ 
			jQuery("#"+_div).html(data).fadeIn("fast"); 
		}
		);
	}
	else
		document.getElementById('emailOublie').style.background = "#ffcccc";
}


/*function envoiForm(formulaire) {
	_nom = jQuery("#nom").val();
	_email = jQuery("#email").val();
	_societe = jQuery("#societe").val();
	_fonction = jQuery("#fonction").val();
	_telephone = jQuery("#telephone").val();
	_message = jQuery("#message").val();
	_type = jQuery("#type").val();
	_objet = jQuery("#objet").val();
	
	jQuery("#formulaire").html("<br><br><center><b>Envoi en cours ...</b></center>"); 
	
	jQuery.post(
		"./ajax.php" , 
		{ nom: _nom, email: _email, societe: _societe, fonction: _fonction, telephone: _telephone, message: _message, type: _type, objet:_objet } , 
		function(data){ jQuery("#formulaire").html(data); }
	);    
}   */

function envoiForm(formulaire) {
	_nom = $("#nom").val();
	_email = $("#email").val();
	_societe = $("#societe").val();
	_fonction = $("#fonction").val();
	_telephone = $("#telephone").val();
	_message = $("#message").val();
	_type = $("#type").val();
	_objet = $("#objet").val();
	
	if (_telephone != '' && _email != '' && _message != '' && _nom != '') {
		
		$("#formulaire").html("<br><br><center><b>Envoi en cours ...</b></center>"); 
		
		$.post(
			"./ajax.php" , 
			{ nom: _nom, email: _email, societe: _societe, fonction: _fonction, telephone: _telephone, message: _message, type: _type, objet:_objet } , 
			function(data){ 
	      $("#formulaire").html(data); 
	    });  
		
	}  else {
		alert('Tous les champs sont nécessaires pour envoyer votre message!');
	}
}   

function formCommentSondages(_id, _titre) {    
	var _t = jQuery("#titreSondage").html();
	if (_t == null)
		_t = _titre;
	jQuery("#tiers3").html('<br><br><br><br><center><img src="images/loading.gif"> Formulaire en chargement ...</center>').fadeIn("fast");    
	jQuery.get(
		"./ajax.php" , 
		{ formSondages: 1, id:_id, titre:_t} , 
		function(data){ jQuery("#tiers3").html(data).fadeIn("fast"); }
	);    
}

function envoiFormCommentSondages(_id, _titre) {
	_message = jQuery("#messageSondage").val();
	
	var erreur = 0;
	if (_message == '') {
		document.getElementById('messageSondage').style.background = "#ffcccc";
		erreur++;
	}
	else
		document.getElementById('messageSondage').style.background = ""; 
	
	if (erreur == 0) {
		jQuery("#formOnDenonce").html('<img src="images/loading.gif"> Envoi en cours ...').fadeIn("fast"); 
		jQuery.post(
			"./ajax.php" , 
			{envoiFormCommentSondages:1, message: _message, id:_id, titre:_titre } , 
			function(data){ jQuery("#tiers3").html(data); }
		);  
	}
}


function apercu() {
	_texte = jQuery("#texte").val();
	if(_texte != '') {
		jQuery.post(
			"/fr/babyclub/forum/ajax_apercu.php" , 
			{ texte: _texte} , 
			function(data){ jQuery("#apercu").html(data); }
		);
	}
	else
		jQuery("#apercu").hide();
}

var actualUser = 0;

function infoBullUser(_idCompte, _pseudo) {
	
	if (actualUser > 0)
		jQuery("#userProfil_"+actualUser).fadeOut('fast');

	jQuery("#userProfil_"+_idCompte).fadeIn("fast");
	//jQuery("#bullPseudo_"+_idCompte).html(_pseudo);
	
	actualUser = _idCompte;  
	
	jQuery.ajax({
	  type: "GET",
	  url: "/fr/ajax.php",
	  cache: true,
	  data: "INFOBULLUSER&idCompte="+_idCompte,
	  success: function(data){
		jQuery("#userProfil_"+_idCompte).html(data);
	  }
	});    

}

function masquer(_div1, _div2) {
	jQuery("#"+_div2).html('<a href="javascript:afficher(\''+_div1+'\', \''+_div2+'\')">réafficher</a>');
	jQuery("#"+_div1).slideUp("slow");    
}

function afficher(_div1, _div2) {
	jQuery("#"+_div2).html('<a href="javascript:masquer(\''+_div1+'\', \''+_div2+'\')">Masquer</a>');
	jQuery("#"+_div1).slideDown("slow");
}

function showDashBoard(_idCompte, _page) {
	jQuery.get(
		"dashboard.php" , 
		{ idCompte: _idCompte, page: _page} , 
		function(data){ jQuery("#dashBoardList").html(data); }
	);  
}

// --------------------------------------------------------
// Add to NOD list
// --------------------------------------------------------
function addToNodList(_date, _div) {
	jQuery("#"+_div).html('<img src="http://www.baby.be/fr/images/loading.gif">').fadeIn("fast");
	jQuery.get(
	"/fr/ajax.php" , 
	{addToNodList : 1, date : _date} , 
	function(data){ 
		jQuery("#"+_div).html(data).fadeIn("fast"); 
		//showNodList(_date, _div);
	}
	);
}

// --------------------------------------------------------
// Show NOD list
// --------------------------------------------------------
function showNodList(_date, _div) {
	jQuery("#"+_div).html('<img src="http://www.baby.be/fr/images/loading.gif">').fadeIn("fast");
	jQuery.get(
	"/fr/ajax.php" , 
	{showNodlist : 1} , 
	function(data){ 
		jQuery("#"+_div).html(data).fadeIn("fast"); 
	}
	);
}

//-----------------------------------------------------------------------
// Système de vote par points  (RANK)
//-----------------------------------------------------------------------

var NOMBRE_ETOILES = 5;

//------------------------------------------------------------------------
// Initialisation des points
//------------------------------------------------------------------------
function init_votes()
{
	var ratings = document.getElementsByTagName('div');
	for (var i = 0; i < ratings.length; i++)
	{
		if (ratings[i].className != 'rating')
			continue;

		var rating = ratings[i].firstChild.nodeValue;
		ratings[i].removeChild(ratings[i].firstChild);
		if (rating > NOMBRE_ETOILES || rating < 0)
			continue;

		// On cherche les étoiles :-)
		for (var j = 0; j < NOMBRE_ETOILES; j++)
		{
			var etoile = document.createElement('img');
			if (rating >= 1)
			{
				etoile.setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_on.png');
				etoile.className = 'on';
				rating--;
			}
			else if(rating == 0.5)
			{
				etoile.setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_half.png');
				etoile.className = 'half';
				rating = 0;
			}
			else
			{
				etoile.setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_off.png');
				etoile.className = 'off';
			}
			var widgetId = ratings[i].getAttribute('id').substr(7);
			etoile.setAttribute('id', 'star_'+widgetId+'_'+j);
			etoile.onmouseover = new Function("evt", "displayHover("+widgetId+", "+j+");");
			etoile.onmouseout = new Function("evt", "displayNormal("+widgetId+", "+j+");");
			ratings[i].appendChild(etoile);
		}
	}
}

// --------------------------------------------------------
// Mettre à jour l'affichage du vote
// --------------------------------------------------------
function resultatVote(_div) {

	var ratings = document.getElementById(_div);

		var rating = ratings.firstChild.nodeValue;
		ratings.removeChild(ratings.firstChild);

		for (var j = 0; j < NOMBRE_ETOILES; j++)
		{
			var etoile = document.createElement('img');
			if (rating >= 1)
			{
				etoile.setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_on.png');
				etoile.className = 'on';
				rating--;
			}
			else if(rating == 0.5)
			{
				etoile.setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_half.png');
				etoile.className = 'half';
				rating = 0;
			}
			else
			{
				etoile.setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_off.png');
				etoile.className = 'off';
			}
			var widgetId = ratings.getAttribute('id').substr(7);
			etoile.setAttribute('id', 'star_'+widgetId+'_'+j);
			etoile.onmouseover = new Function("evt", "displayHover("+widgetId+", "+j+");");
			etoile.onmouseout = new Function("evt", "displayNormal("+widgetId+", "+j+");");
			ratings.appendChild(etoile);
		}

}

// --------------------------------------------------------
// Afficher le hover des étoiles
// --------------------------------------------------------
function displayHover(ratingId, etoile)
{
	for (var i = 0; i <= etoile; i++)
	{
		document.getElementById('star_'+ratingId+'_'+i).setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_over.png');
	}
}

// --------------------------------------------------------
// Afficher normalement les étoiles
// --------------------------------------------------------
function displayNormal(ratingId, etoile)
{
	for (var i = 0; i <= etoile; i++)
	{
		var status = document.getElementById('star_'+ratingId+'_'+i).className;
		document.getElementById('star_'+ratingId+'_'+i).setAttribute('src', 'http://www.famidoo.be/fr/images/stars/rating_'+status+'.png');
	}
}

// --------------------------------------------------------
// Voter
// --------------------------------------------------------
function vote(evt) {
	var tmp = evt.target.getAttribute('id').substr(5);
	var _id = tmp.substr(0, tmp.indexOf('_'));
	var etoileNbr = tmp.substr(tmp.indexOf('_')+1);

	jQuery("#resultat_"+_id).html("Attendez SVP ...");

	// AJAX --> mise à jour des données
	jQuery.get(
		  "./ajax.php" ,
		  { action: 'vote' , ID: _id , points: parseInt(etoileNbr)+1 } ,
		  function(data){ jQuery("#resultat_"+_id).show("fast").html(data); }
		 );

	// Mise à jour du vote
	jQuery("#rating_"+_id).show("fast").html(parseInt(etoileNbr)+1);
	resultatVote("rating_"+_id);
}

// --------------------------------------------------------
// Changerle rank d'une image
// --------------------------------------------------------
function changeRank(_idi,_nidi) {

	jQuery("#reting_"+_idi).html(_nidi);

	init_votes();
}

// --------------------------------------------------------
// Initialiser l'affichage des étoiles
// --------------------------------------------------------
function init() {
	init_votes();
	jQuery('div.rating img').click(vote);
}


function showDivs() {
	jQuery('#ad').hide(); 
	jQuery('#container').show(); 
	jQuery('#footer_wrapper').show();    
}

function hideDivs() {
	jQuery('#container').hide();
	jQuery('#footer_wrapper').hide(); 
}


function envoie_ami_multi(_id, _idf) {
	jQuery("#envoi_ami_multi").slideDown('fast').html("Sending ...");
	_nom = jQuery("#prenom").val();
    
	_nom1 = jQuery("#nom1").val();
	_nom2 = jQuery("#nom2").val();  
	_nom3 = jQuery("#nom3").val();  
	_nom4 = jQuery("#nom4").val();  
  	
	_email1 = jQuery("#email1").val();
	_email2 = jQuery("#email2").val();  
	_email3 = jQuery("#email3").val();  
	_email4 = jQuery("#email4").val();  
	
	var t = new Date();
	jQuery.post(
		"./ajax_envoi_ami_multi.php" , 
		{ id: _id, idf: _idf, t: t.getTime(),nom: _nom, nom1: _nom1, nom2: _nom3, nom3: _nom3, nom4: _nom4, email1: _email1, email2: _email2, email3: _email3, email4: _email4 } , 
		function(data){ jQuery("#envoi_ami_multi").slideDown('fast').html(data); }
	);    
}

var ouvert = 0;
jQuery(document).ready(function(){
    jQuery('#sendFormComment').click(function(){
      if (ouvert == 0) {
        jQuery('#formComment').slideDown('fast');
        ouvert = 1;
      }
      else {
        jQuery('#formComment').slideUp('fast');
        ouvert = 0;
      }
    });
    
    jQuery('#sendFormComment2').click(function(){
      if (ouvert == 0) {
        jQuery('#formComment').slideDown('fast');
        ouvert = 1;
      }
      else {
        jQuery('#formComment').slideUp('fast');
        ouvert = 0;
      }
    });    
});

function search_dico() {
  if (jQuery('#dico_key').val() != '' && jQuery('#dico_key').val() != 'Rechercher un mot, une expression') {
    jQuery('#search_results').slideDown('fast');
    jQuery('#search_results').html('<img src="images/loading2.gif" style="margin-left:260px; margin-top:120px">');
    jQuery('#search_results').load('./spip.php?page=dico_search&recherche='+jQuery('#dico_key').val());
  }
  else 
    alert('Veuillez indiquer un mot SVP!');
}

function AjouterMotDico() {
  var _mot = jQuery('#mot_txt').val();
  if (_mot != '') {
  	jQuery.get(
  	"ajax.php" , 
  	{checkMot : 1, mot : _mot} , 
  	function(data){   
  		if (data == 'ok') {
         jQuery("#champMot").css({'padding':'3px','border':'1px solid #add211','background':'#c7f23e'});
         jQuery("#champMotMsg").html('<br>Ce mot existe déjà dans la liste, vous pouvez y ajouter un article!');
         jQuery("#formAjoutDico").slideDown('fast');
        }
      else{
         jQuery("#champMot").css({'padding':'3px','border':'1px solid #ff8b00','background':'#ffbf73'});
         jQuery("#champMotMsg").html('<br>Ce mot n\'existe pas encore dans le dico, vous pouvez l\'ajouter');
         jQuery("#formAjoutDico").slideDown('fast');
        }
  	}
  	);
	}
}

function loadSousCat(_data) {
  if (_data > 0) {
  	jQuery.get(
  	"ajax.php" , 
  	{loadSousCatRecettes : 1, id_rubrique : _data} , 
  	function(data){   
      jQuery('#sousCats').html(data);
  	}
  	);
	}
}

initMp = 0;

// --------------------------------------------------------
// Lire un mp recu
// --------------------------------------------------------
/*function lireMp(_id) {
	//alert(_id);
	jQuery("#lireMp").fadeOut("fast");  
	document.getElementById('mp_'+_id).style.background = '#F6F6F6';
	jQuery.get(
		"../ajax.php" , 
		{ id: _id, LIREMP: 1 } , 
		function(data){ jQuery("#leMp_"+_id).html(data).fadeIn('fast'); }
	);
	
	if (initMp > 0) 
		document.getElementById('mp_'+initMp).style.background = '#FFFFFF';
		
	initMp = _id;       
}*/

function lireMp(_id) {
	//alert(_id);
	jQuery("#lireMp").fadeOut("fast");  
	jQuery("#mp_"+_id).removeClass('box-messages-lu');
	jQuery("#mp_"+_id).addClass('box-messages-current');
	jQuery.get(
		"../ajax.php" , 
		{ id: _id, LIREMP: 1 } , 
		function(data){ jQuery("#leMp").html(data).fadeIn('fast'); }
	);
	
	if (initMp > 0) { 
			jQuery("#mp_"+initMp).removeClass('box-messages-current');  
	    jQuery("#mp_"+initMp).addClass('box-messages-lu');
	}
		
	initMp = _id;       
}

// --------------------------------------------------------
// Lire un mp recu
// --------------------------------------------------------
function supprimerMp(_id) {
	if(confirm('Êtes-vous sûr de vouloir supprimer ce MP?')) { 
		jQuery.post(
			"../ajax.php" , 
			{ id: _id, SUPPRIMERMP: 1 } , 
			function(data){ 
        jQuery("#leMp").html(data).fadeIn('fast'); 
        jQuery('#mp_'+_id).fadeOut('slow');
      }
		);     
	}       
}

// --------------------------------------------------------
// Lire un mp envoyé
// --------------------------------------------------------
function lireMpEnvoye(_id) {
	
	jQuery("#lireMp").fadeOut("fast");
	document.getElementById('mp_'+_id).style.background = '#F6F6F6';
	jQuery.get(
		"../ajax.php" , 
		{ id: _id, LIREMPENVOYE: 1 } , 
		function(data){ jQuery("#leMp_"+_id).html(data).fadeIn('fast'); }
	);
	
	if (initMp > 0) 
		document.getElementById('mp_'+initMp).style.background = '#FFFFFF';
		
	initMp = _id;
} 

// --------------------------------------------------------
// Afficher les mp reçus
// --------------------------------------------------------
function mpRecus(_idCompte) {
	
	jQuery("#allMp").html('Chargement des MP ...');

	jQuery("#fondMpRecus").removeClass('onglet1');  
	jQuery("#fondMpRecus").addClass('onglet1_current'); 
	jQuery("#fondMpEnvoyes").removeClass('onglet2_current');  
	jQuery("#fondMpEnvoyes").addClass('onglet2'); 
	
	jQuery.get(
		"../ajax.php" , 
		{ idCompte: _idCompte, MPENVOYES: 1 } , 
		function(data){ jQuery("#allMp").html(data).slideDown('fast'); }
	);

}

// --------------------------------------------------------
// Afficher les mp envoyé
// --------------------------------------------------------
function mpEnvoyes(_page, _total) {
	initMp = 0;

	jQuery("#fondMpRecus").removeClass('onglet1_current');  
	jQuery("#fondMpRecus").addClass('onglet1'); 
	jQuery("#fondMpEnvoyes").removeClass('onglet2'); 
	jQuery("#fondMpEnvoyes").addClass('onglet2_current'); 
	
	jQuery("#allMp").fadeOut("fast");
	
	jQuery.get(
		"../ajax.php" , 
		{ MPENVOYES: 1, page:_page, total:_total } , 
		function(data){ jQuery("#allMp").html(data).fadeIn('fast'); }
	);
}

function allMp(_page, _total) {
	jQuery("#allMp").fadeOut("fast"); 
	jQuery("#fondMpRecus").removeClass('onglet1');  
	jQuery("#fondMpRecus").addClass('onglet1_current'); 
	jQuery("#fondMpEnvoyes").removeClass('onglet2_current');  
	jQuery("#fondMpEnvoyes").addClass('onglet2');
	
	jQuery.get(
		"../ajax.php" , 
		{ ALLMP: 1, page:_page, total:_total } , 
		function(data){ jQuery("#allMp").html(data).fadeIn('fast'); }
	);
}

// --------------------------------------------------------
// Envoyer mp  via courrier
// --------------------------------------------------------
function envoyerCourrier(_idCompte, _idMp) {  
	_texte = $("#mpTexte"+_idCompte).val();  
	if (_texte != '') {
  	$("#leMp").html('<img src="images/attente.gif"> Envoi en cours ...'); 
  	$.post(
  		  "../ajax.php" ,
  		  { envoyerCourrier: 1 , idCompte: _idCompte, texte: _texte, idMp: _idMp} ,
  		  function(data){ $("#leMp").html(data); }
  		 );  
	}
	else alert("Veuillez écrire un message SVP!");
}

// --------------------------------------------------------
// Envoyer mp  via courrier
// --------------------------------------------------------
function envoyerMP(_idCompte, _idMp) {  
	_texte = $("#mpTexte"+_idCompte).val();  
	if (_texte != '') {
  	$("#reponse"+_idCompte).html('<img src="http://www.famidoo.be/fr/images/attente.gif"> Envoi en cours ...'); 
  	$.post(
  		  "login.php" ,
  		  { envoyerCourrier: 1 , idCompte: _idCompte, texte: _texte, idMp: _idMp} ,
  		  function(data){ $("#reponse"+_idCompte).html(data); }
  		 );  
	}
	else alert("Veuillez écrire un message SVP!");
}

function formMp(_id) {
  jQuery("#mp").fadeIn("slow");
}

// --------------------------------------------------------
// Ajouter un ami
// --------------------------------------------------------
function ajouterAmie(_idCompte) {  
  if (confirm('Êtes-vous sûre de l\'ajouter à votre liste d\amis?') == true) {
  	$("#ajouterAmie"+_idCompte).fadeIn('fast');   
  	$("#ajouterAmieReponse"+_idCompte).html('<img src="./images/tourne.gif">');
  	$.post(
  		  "login.php" ,
  		  { ajoutAmie: 1 , idCompte: _idCompte} ,
  		  function(data){ $("#ajouterAmieReponse"+_idCompte).html(data); }
  		 );  
  }
}

function chater(_id) {
  alert('Le chat sera très bientôt disponible!');
}

// --------------------------------------------------------
// Ajouter un ami
// --------------------------------------------------------
function ajouterAmieProfile(_idCompte) {  
  if (confirm('Êtes-vous sûre de l\'ajouter à votre liste d\amis?') == true) {
  	$("#ajouterAmie"+_idCompte).fadeIn('fast');   
  	$("#ajouterAmieReponse"+_idCompte).html('<img src="./images/tourne.gif">');
  	$.post(
  		  "http://www.famidoo.be/fr/ajax.php" ,
  		  { ajoutAmie: 1 , idCompte: _idCompte} ,
  		  function(data){ $("#ajouterAmieReponse"+_idCompte).html(data); }
  		 );  
  }
}

function init_profile(_id, _case) {
  jQuery('.section_'+_case).html('<center><img src="../images/loading.gif" style="margin-top:30px; margin-bottom:30px"></center>');
  jQuery('.section_'+_case).load('ajax_profile.php?id='+_id+'&section='+_case);
}

// --------------------------------------------------------
// Voter pour un commentaire
// --------------------------------------------------------
function voterComment(_idComment, _point) {

	jQuery("#result_"+_idComment).fadeIn("fast").html('<img src="http://www.babyfrance.com/images/attente_mini.gif">');
	
	jQuery.get(
	"ajax.php" , 
	{voterComment:1, idComment : _idComment, point: _point} , 
	function(data){ 
		jQuery("#result_"+_idComment).html(data).fadeIn("fast");
	}
	);		
}

// --------------------------------------------------------
//  les evenements sur la page d'accueil
// --------------------------------------------------------
var last_date = '';
var last_nb = 1;
function getEvents(_date, _nb) {
  
  jQuery('#date_'+_date).removeClass('agenda-jour');
  jQuery('#date_'+_date).addClass('agenda-jour-current');
  
  jQuery('#date_'+last_date).removeClass('agenda-jour-current');
  jQuery('#date_'+last_date).addClass('agenda-jour');  

  jQuery('#groupEvents').removeClass('box-agenda-col-liste-jour0'+last_nb);
  jQuery('#groupEvents').addClass('box-agenda-col-liste-jour0'+_nb);    
  
  jQuery('#listeEvents').fadeIn("fast").html('<center><img src="images/loading.gif" style="margin-top:30px; margin-bottom:30px"></center>');
  
	jQuery.get(
		"ajax.php" , 
		{ showEvents: 1, date:_date } , 
		function(data){ 	
			jQuery("#listeEvents").html(data);
		}
	);       
	last_date = _date;
	last_nb = _nb;
}

var last_onglet = 'agenda';
function dashboard(_action) {
  jQuery('#onglet_'+_action).removeClass('nav-onglet');
  jQuery('#onglet_'+_action).addClass('nav-onglet-current');
  
  if (last_onglet != _action) {
    jQuery('#onglet_'+last_onglet).removeClass('nav-onglet-current');
    jQuery('#onglet_'+last_onglet).addClass('nav-onglet');  
  }
  jQuery('#dashboard').fadeIn("fast").html('<center><img src="../images/loading.gif" style="margin-top:30px; margin-bottom:30px"></center>');
  
  jQuery('#dashboard').load('ajax_dashboard.php?action='+_action);
  
  last_onglet = _action;
  
}

function deleteDashBoard(_action, _id) {
  if (confirm("Êtes-vous sûr de vouloir supprimer cet élément?")) {
    jQuery("#liste_"+_id).fadeOut("slow");
  }
}

function popupUser(_id) {
    $('#user_'+_id).qtip({
       content: {url: 'login.php?profile', data: { id: _id }, method: 'get'},
       style: { 
          width: 200,
          padding: 5,
          background: '#FFF',
          color: 'black',
          border: {
             width: 7,
             radius: 5,
             color: '#d20b46'
          },
          tip: 'topLeft',
          name: 'dark'
       },

       show: 'click',
       hide: { when: { event: 'unfocus' } }
    });
}
