//Autocomplete
function checkSendAll(){
	if(document.getElementById('send_all_members').style.display = 'block'){
		document.getElementById('send_all_members').style.display = 'none';
		}
}
function unCheckSendAll(){
	if(document.getElementById('send_all_members').style.display = 'none'){
		document.getElementById('send_all_members').style.display = 'block';
		}
}

function reloadMessages(conversation) {
	divId = 'to_refresh'; 
	url = '/mp/reload.php?conversation='+conversation; 
	ecache = false;
	Fajaxreplace(divId, url, ecache);
}
function afficherResultats(obj) {
	document.getElementById('resultats').style.display = 'block';
	document.getElementById('resultats').innerHTML = obj.responseText;
}

// Déclaration de la fonction qui lance la recherche
function loadData() {
	var XHR = new XHRConnection();
	XHR.appendData("pseudo", document.getElementById('pseudo').value);
	XHR.sendAndLoad("/ajax/autocompleteMp.php", "POST", afficherResultats);
}

function autocomplete(chaine){
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("chaine", chaine);
	XHR.sendAndLoad("/ajax/autocompleteMp.php", "POST", retour_autocomplete);
}
function retour_autocomplete(obj){
	retour = obj.responseText;
	document.getElementById('resultats').style.display = 'block';
	document.getElementById('resultats').innerHTML = retour;
}
function show_autocomplete(){
	document.getElementById('resultats').style.display='block';
}
function hide_autocomplete(){
	document.getElementById('resultats').style.display='none';
}

function write_into_div(id,text,width,height,id_user){
	var tab_data = text.split('$');
	document.getElementById(id).innerHTML = '<span class="orange">Destinataire:&nbsp;&nbsp;</span><img width="'+width+'" height="'+height+'" src="' + tab_data[0] + '" />&nbsp;&nbsp;<strong>'+tab_data[1]+"</strong>";
	document.getElementById('pseudo').disabled = "true";
	document.getElementById('modify').innerHTML = "<a href='javascript:void(0)' onclick='reset_initial(\"picture_name\")'>Modifier le destinataire</a>";
	document.getElementById('id_user').value = id_user;
}
function reset_initial(id){
	document.getElementById('pseudo').disabled = "";
	document.getElementById(id).innerHTML = "";
	document.getElementById('modify').innerHTML = "";
	document.getElementById('pseudo').value = "";
	document.getElementById('id_user').value = "";
}
function cocher(nb_lignes) {
	for (i = 0; i < nb_lignes; i++)
		document.getElementById('select' + i).checked = true;
		
}
function decocher(nb_lignes) {
	for (i = 0; i < nb_lignes; i++)
		document.getElementById('select' + i).checked = false;
}
//Pseudo
function checkDisponibility(pseudo,submit,id_user){
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("pseudo", pseudo);
	XHR.appendData("submit", submit);
	XHR.appendData("id_user", id_user);
	XHR.sendAndLoad("/ajax/check_dispo.php", "POST", retour_checkDisponibility);
}
function retour_checkDisponibility(obj){
	retour = obj.responseText;
	document.getElementById('checkPseudo').innerHTML = "";
	document.getElementById('checkPseudo').innerHTML = retour;
	}
function remplir_pseudo(value){
	document.getElementById('pseudo').value = "";
	document.getElementById('pseudo').value = value;
}
//#### UPLOAD ###
function delete_avatar(id){
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("id", id);
	XHR.sendAndLoad("/ajax/delete_avatar.php", "POST", retour_delete_avatar);
}

function retour_delete_avatar(obj){
retour = obj.responseText;
document.getElementById('avatarProfil').innerHTML = '';
document.getElementById('avatarProfil').innerHTML = retour;
document.getElementById('retourUpload').innerHTML = "Avatar supprimé"; 
}

function getImageLoading(){
	if(document.getElementById('photo').value != ''){
		document.getElementById('retourUpload').innerHTML = '<img src="/img/icons/loading.gif" width="32" height="32" border="0" align="center"/>';
	}else{
		document.getElementById('retourUpload').innerHTML = 'Merci de choisir un fichier...';
	}
}
function show_div_mail_notif(){
	document.getElementById('champ_mail_notif').style.display = '';
}
function hide_div_mail_notif(){
	document.getElementById('champ_mail_notif').style.display = 'none';
}
//####### FORUM ########
function forum_citer(idMessage){
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("idMessage", idMessage);
	XHR.sendAndLoad("/ajax/forum_citer.php", "POST", retour_forum_citer);
}
function retour_forum_citer(obj) {
	textarea = document.getElementById('answer');
	retour = obj.responseText;
	tabRetour = retour.split('$');
	auteur = tabRetour[0];
	contenu = tabRetour[1];
	chaine = '[citation]' + '[auteur]' + auteur + ' a &eacute;crit:[/auteur]' + contenu + '[/citation]';
	textarea.value += chaine;
	textarea.focus();
	
}
function signalerAbus(idMessage,idUser,ip){
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("idMessage", idMessage);
	XHR.appendData("idUser", idUser);
	XHR.appendData("ip", ip);
	XHR.sendAndLoad("/ajax/signalerAbus.php", "POST", retour_signaler_abus);
}
function retour_signaler_abus(obj) {
	retour = obj.responseText;
	tab = retour.split('-');
	idMessage = tab[1];
	text = tab[0];
	document.getElementById('signalerAbus'+idMessage).innerHTML = text;
}

//####### NOTES ########

//Astuces
function noter(id_astuce) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("id_astuce", id_astuce);
	XHR.sendAndLoad("/ajax/noter_astuce.php", "POST", retour_note_astuce);
}
function retour_note_astuce(obj) {
	retour = obj.responseText;
	tab_retour = retour.split("-");
	message = tab_retour[0];
	note = tab_retour[1];
	document.getElementById('lien_noter').style.display = 'none';
	document.getElementById('note_retour').innerHTML = message;
	document.getElementById('new_note').innerHTML = '(' + note + ')';

}
//Fin astuces

//Tutoriels
function noter_tutoriel(id_tuto) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("id_tuto", id_tuto);
	XHR.sendAndLoad("/ajax/noter_tutoriel.php", "POST", retour_note_tutoriel);
}
function retour_note_tutoriel(obj) {
	retour = obj.responseText;
	tab_retour = retour.split("-");
	message = tab_retour[0];
	note = tab_retour[1];
	document.getElementById('lien_noter').style.display = 'none';
	document.getElementById('note_retour').innerHTML = message;
	document.getElementById('new_note').innerHTML = '(' + note + ')';

}
//fin Tutoriels

//Saviez vous
function noter_saviez_vous(id_saviez_vous) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("id_saviez_vous", id_saviez_vous);
	XHR.sendAndLoad("/ajax/noter_saviez_vous.php", "POST", retour_note_saviez_vous);
}
function retour_note_saviez_vous(obj) {
	retour = obj.responseText;
	tab_retour = retour.split("-");
	message = tab_retour[0];
	note = tab_retour[1];
	document.getElementById('lien_noter').style.display = 'none';
	document.getElementById('note_retour').innerHTML = message;
	document.getElementById('new_note').innerHTML = '(' + note + ')';

}
//Fin saviez-vous
//Videos
function noter_video(id_video) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("id_video", id_video);
	XHR.sendAndLoad("/ajax/noter_video.php", "POST", retour_note_video);
}
function retour_note_video(obj) {
	retour = obj.responseText;
	tab_retour = retour.split("-");
	message = tab_retour[0];
	note = tab_retour[1];
	document.getElementById('lien_noter').style.display = 'none';
	document.getElementById('note_retour').innerHTML = message;
	document.getElementById('new_note').innerHTML = '(' + note + ')';

}
// Fin saviez-vous

//####### PARTENAIRES ########
//Visites Partenaires
function add_visite(partenaire) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("partenaire", partenaire);
	XHR.sendAndLoad("/ajax/add_visite_partenaire.php", "POST", retour_visite_partenaire);
}
function retour_visite_partenaire(obj) {
	retour = obj.responseText;

}
//Fin Visites Partenaires
function voter_partenaire(partenaire)
{
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("partenaire", partenaire);
	XHR.sendAndLoad("/ajax/voter_partenaire.php", "POST", retour_vote_partenaire);
}
function retour_vote_partenaire(obj) {
	retour = obj.responseText;
	tab_retour = retour.split("-");
	message = tab_retour[0];
	note = tab_retour[1];
	document.getElementById('lien_voter').style.display = 'none';
	document.getElementById('retour_partenaire').innerHTML = message;
	document.getElementById('vote').innerHTML = note; 

}

// ####### NEWS ########
function next(id_news)
{
 	var XHR = new XHRConnection();
    XHR.appendData("ajax", "1");
    XHR.appendData("id_news", id_news);
  	XHR.sendAndLoad("/ajax/changer_news.php", "POST",retour_news);
 }
 function retour_news(obj)
  {
   	document.getElementById('la_news').style.display='none';
  	document.getElementById('retour_news').style.display='block';
    document.getElementById('retour_news').innerHTML=obj.responseText;
  }
 function precedent(id_news)
{
 	var XHR = new XHRConnection();
    XHR.appendData("ajax", "1");
    XHR.appendData("id_news", id_news);
  	XHR.sendAndLoad("/ajax/prec_news.php", "POST",retour_news2);
 }
 function retour_news2(obj)
  {
   	document.getElementById('la_news').style.display='none';
  	document.getElementById('retour_news').style.display='block';
    document.getElementById('retour_news').innerHTML=obj.responseText;
  }
 
// ####### RSS ########
function abonner(id) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("id_rss", id);
	XHR.sendAndLoad("/ajax/abonner_rss.php", "POST", retour_rss);
}

function retour_rss(obj) {
	retour = obj.responseText;
	// id = document.getElementById('rss['+tab_retour[0]+']');
	// document.getElementById('message').style.display='block';
	document.getElementById('mes_flux').style.display = 'none';
	document.getElementById('retour_abonnement').innerHTML = retour;
	
}
function desabonner(id) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("id_rss", id);
	XHR.sendAndLoad("/ajax/desabonner_rss.php", "POST", desabonner_retour_rss);
}
function desabonner_retour_rss(obj) {
	retour = obj.responseText;
	// id = document.getElementById('rss['+tab_retour[0]+']');
	// document.getElementById('message').style.display='block';
	document.getElementById('mes_flux').style.display = 'none';
	document.getElementById('retour_abonnement').innerHTML = retour;
	
}

//####### CONNEXION ########
function connexion(login, pass) {
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("login", login);
	XHR.appendData("pass", pass);
	XHR.sendAndLoad("/ajax/verif_connexion.php", "POST", retour_connexion);
}

function connexion_page(login, pass){
	var XHR = new XHRConnection();
	XHR.appendData("ajax", "1");
	XHR.appendData("login", login);
	XHR.appendData("pass", pass);
	XHR.sendAndLoad("/ajax/verif_connexion.php", "POST", retour_connexion_page);
}
function retour_connexion(obj) {
	retour = obj.responseText;
	if (retour.length > 1) {
		document.getElementById('message_erreur').innerHTML = retour;
		
	} else {
		location.reload();
	}
}
function retour_connexion_page(obj) {
	retour = obj.responseText;
	if (retour.length > 1) {
		document.getElementById('message_erreur2').innerHTML = retour;	
	} else {
		location.reload();
	}
}

// ######### COMMENTAIRES ################
function montrer_formulaire()
{
	//On efface le message de retour 
	document.getElementById('messageComment').innerHTML='';
	//On vide le textarea
	document.getElementById('messageComment').value='';
	//On affiche le formulaire
	document.getElementById('champ_commentaire').style.visibility='visible';
	document.getElementById('bouton_commentaire').style.visibility='visible';
}
function montrer_formulaire_actualite()
{
	//On efface le message de retour 
	document.getElementById('messageActualite').innerHTML='';
	//On vide le textarea
	document.getElementById('commentaire').value='';
	//On affiche le formulaire
	document.getElementById('champ_commentaire').style.visibility='visible';
	document.getElementById('bouton_commentaire').style.visibility='visible';
}
function gestion_commentaire(id_tuto,valeur)
{
	var XHR = new XHRConnection();
    XHR.appendData("ajax", "1");
    XHR.appendData("id_tuto", id_tuto);
    XHR.appendData("valeur", valeur);
  	XHR.sendAndLoad("/ajax/gestion_commentaire.php", "POST",retour_message_commentaire);

}
function gestion_commentaire_astuce(id_astuce,valeur)
{
	var XHR = new XHRConnection();
    XHR.appendData("ajax", "1");
    XHR.appendData("id_astuce", id_astuce);
    XHR.appendData("valeur", valeur);
  	XHR.sendAndLoad("/ajax/gestion_commentaire_astuce.php", "POST",retour_message_commentaire);

}
function retour_message_commentaire(obj)
  {
  	document.getElementById('messageComment').style.display='block';
    document.getElementById('messageComment').innerHTML=obj.responseText;
    contenu_div = document.getElementById('messageComment').innerHTML;
    if(contenu_div.length > 58){
    document.getElementById('champ_commentaire').style.visibility='hidden';
	document.getElementById('bouton_commentaire').style.visibility='hidden';
    }
  }
function gestion_commentaire_saviez(id_saviez,valeur)
{
	var XHR = new XHRConnection();
    XHR.appendData("ajax", "1");
    XHR.appendData("id_saviez", id_saviez);
    XHR.appendData("valeur", valeur);
  	XHR.sendAndLoad("/ajax/gestion_commentaire_saviez.php", "POST",retour_message_commentaire_saviez);

}
function retour_message_commentaire_saviez(obj)
  {
  	document.getElementById('messageComment').style.display='block';
    document.getElementById('messageComment').innerHTML=obj.responseText;
    contenu_div = document.getElementById('messageComment').innerHTML;
    if(contenu_div.length > 58){
    document.getElementById('champ_commentaire').style.visibility='hidden';
	document.getElementById('bouton_commentaire').style.visibility='hidden';
    }
  }  
  
  function gestion_commentaire_video(id_video,valeur)
{
	var XHR = new XHRConnection();
    XHR.appendData("ajax", "1");
    XHR.appendData("id_video", id_video);
    XHR.appendData("valeur", valeur);
  	XHR.sendAndLoad("/ajax/gestion_commentaire_video.php", "POST",retour_message_commentaire_video);

}
function retour_message_commentaire_video(obj)
  {
  	document.getElementById('messageComment').style.display='block';
    document.getElementById('messageComment').innerHTML=obj.responseText;
    contenu_div = document.getElementById('messageComment').innerHTML;
    if(contenu_div.length > 58){
    document.getElementById('champ_commentaire').style.visibility='hidden';
	document.getElementById('bouton_commentaire').style.visibility='hidden';
    }
  }  
  function gestion_commentaire_actualite(id_actualite,valeur)
{
	var XHR = new XHRConnection();
    XHR.appendData("ajax", "1");
    XHR.appendData("id_actualite", id_actualite);
    XHR.appendData("valeur", valeur);
  	XHR.sendAndLoad("/ajax/gestion_commentaire_actualite.php", "POST",retour_message_commentaire_actualite);

}
function retour_message_commentaire_actualite(obj)
  {
  	document.getElementById('messageActualite').style.display='block';
    document.getElementById('messageActualite').innerHTML=obj.responseText;
    contenu_div = document.getElementById('messageActualite').innerHTML;
    if(contenu_div.length > 58){
    document.getElementById('champ_commentaire').style.visibility='hidden';
	document.getElementById('bouton_commentaire').style.visibility='hidden';
    }
  }  

