var info_alerte	 = "TRUE STORIES ALERTE INFO !";
var info_confirm = "TRUE STORIES CONFIRMATION INFO !";
var msg_stories  = "<div id='ts-noresults'>Désolé, mais il n'y a aucun résultat correspondant à votre recherche</div>";
var msg_loading = "<center><img src='http://www.truestories.fr/img/ajax-loader.gif'> chargement...</center>"
var popupStatus = 0;  
var oldPopupHeight = 0;  

$(document).ready(function()
{
	$("#ts_pu_close").click(function(){ close_ts_pu(); });
	$(document).keypress(function(e){ if(e.keyCode==27 && popupStatus == 1) close_ts_pu(); });
	$("#connexion").click(function(){	logIn(); });
	$("#ts-prendre-contact, #ts-prendre-contact-about").click(function(){ $.post('getPU.php',{ place:"contact" },function success(data) { load_ts_pu( data, 585, null ); });	});
	$("#page_" + $("#currentPage").val()).addClass("active");
	$("#ts_header_fst_menu").click(function() { $("#ts_header_fst_menu_cont").toggle(); });
	$("#ts_header_scd_menu").click(function() { $("#ts_header_scd_menu_cont").toggle(); });
	$("#ts-search-box-btn").click(function() { if(isEmpty($("#ts-search-box-txt").val()) || $("#ts-search-box-txt").val() == "Rechercher...") jAlert('Heu ? Il <b>manque</b> quelque chose non ?', info_alerte); else $('#cse-search-box').submit(); });	
	$(window).scroll(function () { if ($(this).scrollTop() != 0) { $('#backtotop').fadeIn(); } else { $('#backtotop').fadeOut(); } });  
    $('#backtotop').click(function () {  goToTop(); });
	$('#ts_header_logo').click(function () { location.href = $("#page_index").attr("href"); });
	toggle_ts_toolbar();
	ts_tooltip();
});

function logIn() { $.post('getPU.php',{ place:"login" },function success(data) { load_ts_pu( data, null, 160 ); }); }

function toggle_ts_toolbar()
{
	$(".ts-pm-btn").click(function()
	{						
		id_toolbar = $(this).attr("id").split("_")[1];
		id_barre = "#ts-toolbar-row_"+parseInt(id_toolbar)+"_";
		current_id_row = parseInt($(this).attr("id").split("_")[2]);
		next_id_row = current_id_row + 1;
		
		if($(id_barre+next_id_row).css("display") == "none") 
		{
			$(id_barre+next_id_row).slideDown();
			$(this).addClass("ts-pm-btn-b");
		}
		else
		{
			if(next_id_row - 1 == 1)
			{
				i = next_id_row;
				while($(id_barre+i).length)
				{
					$(id_barre+i).slideUp();
					i++;
				}
				$("#ts-toolbar_"+id_toolbar+" .ts-pm-btn").removeClass("ts-pm-btn-b");
			}
			else 
			{
				$(id_barre+next_id_row).slideUp();
				$(this).removeClass("ts-pm-btn-b");
			}
		}
	});
}


function close_ts_pu() 
{
	if(popupStatus == 1)
	{
		$("#ts_pu_cont").height(oldPopupHeight);
		$('#ts_pu_data').html("&nbsp");
		$("#ts_pu_overlay").css('display', 'none');
		$('#ts_pu_cont').toggle('slow', function() {
			popupStatus = 0; 
		});
	}
}

function get_ts_pu(data,w,h) 
{
	if(popupStatus == 0)
	{
		center_ts_pu(w,h);
		$("#ts_pu_overlay").css('display', 'block');
		oldPopupHeight = $("#ts_pu_cont").height();
		$("#ts_pu_cont").height('auto');
		$("#ts_pu_cont").css('display', 'block');
		$("#ts_pu_data").html(data);
		popupStatus = 1;  
	}
}

function center_ts_pu(w,h)
{  	
	if(w != null) $("#ts_pu_cont").width(w);
	if(h != null) $("#ts_pu_cont").height(h);
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#ts_pu_cont").height();  
	var popupWidth = $("#ts_pu_cont").width();  
	$("#ts_pu_cont").css({  "top": windowHeight/2-popupHeight/2,  "left": windowWidth/2-popupWidth/2  });  
} 

function change_css(nomcss) 
{
	$('link[rel=stylesheet]:eq(2)').attr('disabled',true).attr('href','/img/theme/'+nomcss+'/theme.css').attr('disabled',false);
};

function racineSite(){
	var locarray = location.href.split("/");
	delete locarray[(locarray.length-1)];
	var racine = locarray.join("/");
	return racine;
}

function trim(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 

function ts_tooltip() {         
		xOffset = 20; yOffset = 20;
        $(".ts-tooltip").hover( function(e) { $("body").append("<p id='ts-tooltip'>"+ $(this).attr("info") +"</p>"); 
											  $("#ts-tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");},
								function() 	{ $("#ts-tooltip").remove(); }); 
        $(".ts-tooltip").mousemove(function(e){ $("#ts-tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px"); });                    
}

function lookup(inputString) {
    if(inputString.length == 0) {
        $("#suggestions").hide();
    } else {
        $.get("traitement_ajax.php", {membres: ""+inputString+""}, function(data){
            if(data != 0) {
                $("#suggestions").show();
                $("#autoSuggestionsList").html(data);
            }
			else $("#suggestions").hide();
			
        });
    }
} 

function flux_rss(le_flux)
{
	
	$("#div_flux").html(msg_loading);
	$.get(
		'traitement_ajax.php', 
		{ flux_rss: le_flux},
		function success(data)
		{
			$("#div_flux").fadeOut('slow', function() {

				$("#div_flux").html(data).fadeIn('slow');

				});
		}
	);
}

function isEmpty(value)
{
	return (value.replace(/^\s+/g,'').replace(/\s+$/g,'') =='') ? true : false;
}
 
//////////////////////////////////////////

function jAlertSwitch(info)
{
	switch(info)
		{
		case "droits" :
			jAlert('Vous n\'avez pas les droits nécessaire pour accéder à cette page.', info_alerte);
			break;	
		case "bloquer" :
			jAlert('Vous ne pouvez pas effectuer cette action car l\'un de vous deux a <b><u>bloqué</u></b> l\'autre.', info_alerte);
			break;				
		default :
			jAlert('Une erreur est survenue.', info_alerte);
		} 
}

function suppressions(quoi, var1, var2)
{
	if(quoi == "wall")
	{
		jConfirm('Voulez vous vraiment effacer ce message de votre profil ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ wall: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("truelives", "life]::[null]::["+var2,20);
					else
					jAlertSwitch("droits");
				});	
		});	
	}
	
	if(quoi == "recap")
	{
		jConfirm('Voulez vous vraiment effacer ce message ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ wall: var1},function success(data){
					if(data == 1)
						initPaginationGlobal("recap", var2, 10);
					else
						jAlertSwitch("droits");
				});	
		});	

	}	

	if(quoi == "broken_link")
	{
		jConfirm('Avez vous vraiment corrigé ce lien mort ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ broken_link: var1},function success(data){
					if(data == 1)
					location.reload();
					else
					jAlertSwitch("droits");
				});	
		});	
		
	}
	
	if(quoi == "post_it")
	{
		jConfirm('Voulez vous vraiment décoller ce post-it ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ post_it: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("postit", "null", 8);
					else
					jAlertSwitch("droits");
				});	
		});		
	}
	
	if(quoi == "suggestions")
	{
		jConfirm('Voulez vous vraiment supprimer cette suggestion ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ suggestions: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("suggestions", "null", 8);
					else
					jAlertSwitch("droits");
				});	
		});		
	}	
	
	if(quoi == "artiste")
	{
		jConfirm('Voulez vous vraiment supprimer cet artiste ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ artiste: var1},function success(data){
					if(data == 1)
					location.href = "artistes";
					else
					jAlertSwitch("droits");
				});	
		});			
	}
		
	if(quoi == "avis")
	{
		jConfirm('Voulez vous vraiment supprimer cet avis ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ avis: var1},function success(data){
					if(data == 1)
					location.reload();
					else
					jAlertSwitch("droits");
				});	
		});				
	}	
		
	if(quoi == "quotes")
	{
		jConfirm('Voulez vous vraiment supprimer cette citation ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ citation: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("quotes", "null", 20);	
					else
					jAlertSwitch("droits");
				});	
		});		
	}
		
	if(quoi == "membre")
	{
		jConfirm('Voulez vous vraiment supprimer ce membre ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ membre: var1},function success(data){
					if(data == 1)
					{
						if(var2 == "membres")
						initPaginationGlobal(var2, "null", 10);
						if(var2 == "profil")
						location.href = racineSite();
					}
					else
					jAlertSwitch("droits");
				});	
		});			
	}
	
	if(quoi == "img")
	{
		jConfirm('Voulez vous vraiment supprimer cette image ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ img: var1, img_mini: var2},function success(data){
					if(data == 1)
					initPaginationGlobal("img", "null", 25);	
					else
					jAlertSwitch("droits");
				});	
		});			
	}

	if(quoi == "tribune")
	{
		jConfirm('Voulez vous vraiment supprimer ce message ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ msgt: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("truelives", "null", 30);
					else
					jAlertSwitch("droits");
				});	
		});					
	}
	
	if(quoi == "story")
	{
		jConfirm('Voulez vous vraiment supprimer cette story ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ story: var1},function success(data){
					if(data == 1)
					location.href = racineSite();
					else
					jAlertSwitch("droits");
				});	
		});				
	}
	
	if(quoi == "commentaire")
	{
		jConfirm('Voulez vous vraiment supprimer ce commentaire ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ commentaire: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("commentaires", var2, 20);	
					else
					jAlertSwitch("droits");
				});	
		});			
	}
	
	if(quoi == "proposition_sup")
	{
		jConfirm('Voulez vous vraiment supprimer cette proposition ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ story: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("propositions", "null", 20);	
					else
					jAlertSwitch("droits");
				});	
		});		
	}
	
	if(quoi == "proposition_val")
	{		
		jConfirm('Voulez vous vraiment valider cette proposition ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_ajax.php',{ proposition: var1},function success(data){
					if(data == 1)
					initPaginationGlobal("propositions", "null", 20);	
					else
					jAlertSwitch("droits");
				});	
		});			
	}
	
	if(quoi == "forums_message")
	{		
		jConfirm('Voulez vous vraiment supprimer ce message ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ forums: var1, message: 1337 },function success(data){
					if(data == 1)
						initPaginationGlobal("forums", "messages]::["+var2, 20);	
					else
						jAlertSwitch("droits");
				});	
		});			
	}
	
	if(quoi == "forums_topic")
	{		
		jConfirm('Voulez vous vraiment supprimer ce sujet ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ forums: var1, topic: 1337 },function success(data){
					if(data == 1)
						location.href="forum-"+var2;	
					else
						jAlertSwitch("droits");
				});	
		});			
	}
	
	if(quoi == "forums_section")
	{		
		jConfirm('Voulez vous vraiment supprimer cette section ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_sup.php',{ forums: var1, section: 1337 },function success(data){
					if(data == 1)
						location.reload();	
					else
						jAlertSwitch("droits");
				});	
		});			
	}
}
function verifications(quoi, n)
{
	if(quoi == "son_moment")
	{
		if (document.son_moment.nom.value =='')
		{jAlert('Merci de saisir le nom l\'auteur !', info_alerte);return false ;}
		if (document.son_moment.titre.value =='')
		{jAlert('Merci de saisir le titre du son !', info_alerte);return false ;}
		if (document.son_moment.music.value =='')
		{jAlert('Merci de choisir le fichier !', info_alerte);return false ;}
		return true;
	}
	
	if(quoi == "evenement")
	{
		if (document.evenement.url.value =='')
		{jAlert('Merci de saisir l\'url de la story !', info_alerte);return false ;}
		if (document.evenement.image.value =='')
		{jAlert('Merci de choisir l\'image !', info_alerte);return false ;}	
		return true;
	}	
	
	if(quoi == "tribune")
	{
		if ($('#message').val() =='')
		{jAlert('Merci de saisir votre message !', info_alerte);return false ;}
		return true;
	}
	
	if(quoi == "post_it")
	{
		if ($("#msg").val() =='')
		{jAlert('Merci de saisir votre message !', info_alerte);return false ;}
		return true;
	}
	
	if(quoi == "recherche")
	{
		if ($('#recherche').val() =='' || $('#recherche').val() =='Rechercher...')
		{jAlert('Merci de saisir votre recherche !', info_alerte);return false ;}
		return true;
	}	
	
	if(quoi == "suggestion")
	{
		if (document.suggestion.suggestion.value =='')
		{jAlert('Merci de saisir une suggestion !', info_alerte);return false ;}
		return true;
	}
	
	if(quoi == "quotes")
	{
		if (document.ajout.citation.value =="")
		{jAlert("Merci de saisir la citation !", info_alerte);return false ;}
		if (document.ajout.auteur.value =="")
		{if(confirm('Etes vous sur de ne pas connaitre l\'auteur ?')){return true;}
		else{return false;}}
		return true;
	}
	
	if(quoi == "avatar")
	{
		if (document.avatar.new_avatar.value =='')
		{jAlert('Merci de choisir une image (de format gif ou jpg) !', info_alerte);return false ;}
		return true;
	}
	
	if(quoi == "artiste")
	{
		if (document.ajout.nom_artiste.value =='')
		{jAlert('Merci de saisir l\'alias de l\'artiste !', info_alerte);return false ;}
		if (document.ajout.nom.value =='')
		{jAlert('Merci de saisir le nom de l\'artiste !', info_alerte);return false ;}
		if (document.ajout.pays.value =='')
		{jAlert('Merci de saisir la nationalité de l\'artiste !', info_alerte);return false ;}
		if (document.ajout.genre.value =='')
		{jAlert('Merci de saisir le genre ou les genres de l\'artiste !', info_alerte);return false ;}	
		if (document.ajout.story.value =='')
		{jAlert('Merci de saisir une petite bio pour cet artiste !', info_alerte);return false ;}			
		return true;
	}
	
	if(quoi == "img")
	{
		if (document.form_img.image.value =='')
		{jAlert('Merci de choisir une image (de format gif ou jpg) !', info_alerte);return false ;}
		return true;
	}
	
	if(quoi == "profileMdp")
	{
			if ($("#oldmdp").val() != n)
			{jAlert("Merci de saisir votre <b>bon</b> ancien mot de passe !", info_alerte);return false ;}
			if ($("#lemdp").val() == "")
			{jAlert("Merci de saisir votre mot de passe !", info_alerte);return false ;}
			if ($("#mdp2").val() == "")
			{jAlert("Merci de confirmer votre mot de passe !", info_alerte);return false ;}
			if ($("#lemdp").val() != $("#mdp2").val())
			{jAlert("Attention, les deux mots de passe saisis sont différents ! Merci de les saisir à nouveau.", info_alerte);return false ;}
			
		return true;
	}
	
	if(quoi == "profileEmail")
	{
		var verif 	= new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,4}$");
		if (verif.exec($("#email").val()) == null)
		{jAlert("Votre adresse E-mail n'est pas correcte !", info_alerte);return false ;}
		return true;		
	}
	
	if(quoi == "wall")
	{
		if ($("#content").val() =='')
		{jAlert('Merci de saisir votre message !', info_alerte);return false ;}
		return true;
	}
	
	if(quoi == "repondreWall")
	{
		if ($('#wall'+n).val() == '')
		{jAlert('Merci de saisir votre message !', info_alerte);return false ;}
		return true;
	}	
	
	if(quoi == "avis")
	{
		if (document.envoyercom.avis.value =='')
		{jAlert('Merci de saisir un avis !', info_alerte);return false ;}
		return true;
	}	
	
	if(quoi == "proposer_story")
	{
		if (document.proposer.titre.value =="")
		{jAlert("Merci de saisir le titre de la Story !", info_alerte);return false ;}

		if (document.proposer.story.value =="")
		{jAlert("Merci de saisir la Story !", info_alerte);return false ;}
		
		return true;
	}	
	
	if(quoi == "story")
	{
		if (document.ajout.titre.value =="")
		{jAlert("Merci de saisir le titre de la Story !", info_alerte);return false ;}

		if (document.ajout.story.value =="")
		{jAlert("Merci de saisir la Story !", info_alerte);return false ;}

		if(document.ajout.moment.checked == true)
		{
				if (document.ajout.description_story.value =="")
				{jAlert("Merci de saisir la description !", info_alerte);return false ;}
			
				if(n == "add") // Si c'est une modif on est pas obligé d'upload une image :D
				{
				if (document.ajout.img_moment.value =="")
				{jAlert("Merci d'uploader une image !", info_alerte);return false ;}
				}
		}
		
		return true;
	}
		
	if(quoi == "commentaire")
	{
		if (isEmpty($('#content').val()))
		{jAlert('Merci de saisir un commentaire !', info_alerte);return false ;}
		return true;
	}		
	
	if(quoi == "message")
	{
		if (isEmpty($('#content').val()))
		{jAlert("Merci de saisir le contenu de votre message !", info_alerte);return false ;}
		return true;
	}

	if(quoi == "topic")
	{
		if (isEmpty($('#content').val()))
		{jAlert("Merci de saisir le contenu de votre sujet !", info_alerte);return false ;}
		if (isEmpty($('#titre').val()))
		{jAlert("Merci de saisir le titre de votre sujet !", info_alerte);return false ;}				
		return true;
	}	

	if(quoi == "section")
	{
		if (isEmpty($('#content').val()))
		{jAlert("Merci de saisir le résumé de la section !", info_alerte);return false ;}
		if (isEmpty($('#section-titre').val()))
		{jAlert("Merci de saisir le titre de la section !", info_alerte);return false ;}		
		return true;
	}	
	
	if(quoi == "contact")
	{
		if (isEmpty($('#content').val()))
		{jAlert("Merci de saisir le contenu de votre message !", info_alerte);return false ;}
		if (isEmpty($('#contact-name').val()))
		{jAlert("Merci de saisir un nom !", info_alerte);return false ;}
		if (isEmpty($('#contact-email').val()))
		{jAlert("Merci de saisir une adresse e-mail !", info_alerte);return false ;}			
		return true;
	}		
}

function limite(zone,max) 
{ 
	if(zone.value.length > max) zone.value=zone.value.substring(0,max); 
}

function cbFunctions()
{
	ts_tooltip();
}

function pCGlobal(page_index, jq)
{
	$(".ts-pagination").css("display", "none");
	$("#"+_tab).html(msg_loading);
	$.get('chargement_'+_tab+'.php',{ p : page_index, nbItem : _nbItem, filtre: _filtre, tab: _tab },function success(data)
	{
			$("#"+_tab).fadeOut('slow', function() {
					if(data != 0) $("#"+_tab).html(data).fadeIn('slow'); else $("#"+_tab).html(msg_stories).fadeIn('slow');
					if(num_entries > _nbItem ) $(".ts-pagination").css("display", "block");
					cbFunctions();
			});	
	});	
	return false;
}
    
function initPaginationGlobal(tab, filtre, nbItem) 
{
	_tab = tab;
	_nbItem = nbItem;
	_filtre = filtre;
	$(".ts-pagination").css("display", "none");
	$.get('chargement_'+_tab+'.php',{ nbRows: "1337", filtre: _filtre, tab: _tab},function success(data)
	{
		num_entries = data;
		$("#Pagination").pagination(num_entries, { num_edge_entries: 2, num_display_entries: 8, callback: pCGlobal, items_per_page:_nbItem });		
	});
 }
  
function trueUpdate()
{
	$.get('traitement_ajax.php', { whosOnline: "1854" }, function success(data) { $("#whosOnline").html(data); });
	window.setTimeout('trueUpdate()',30000);
}

function goToTop()
{
	$('html,body').animate({ scrollTop: 0 }, "slow");
}

function goToBottom(div)
{
	$('html, body').animate({ scrollTop: $('#'+div).offset().top }, "slow");
}

function openSlide(elem) { 
	if($('#'+elem).is(":visible")) $('#'+elem).slideUp("slow"); else $('#'+elem).slideDown("slow");
}

function openSlideState(elem)
{
	openSlide(elem);
	if($("#"+elem+"_state").html() == "-") $("#"+elem+"_state").html("+"); else $("#"+elem+"_state").html("-");
}

function only_members()
{
	jAlert("Oups, ce service est réservé aux membres. <br />Si vous n'êtes pas encore membre du site, <a href='sign'>inscrivez-vous</a>, c'est gratuit !  ", info_alerte);
}

function bientot_disponible()
{
	jAlert("Service bientôt disponible.", info_alerte);
}

function true_friends(action, to, from, profil)
{
	if(action == "block")
	{
		jConfirm('Voulez vous vraiment <b>bloquer</b> cette personne ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_ajax.php',{ friend: action, to: to},function success(data){
					if(data == 1)
					{
						if(from == "membres")
						{
							if(profil != 0)
							initPaginationGlobal(from, "friends]::["+profil+"]::[1", 10);
							else
							initPaginationGlobal(from, "null", 10);
						}
						if(from == "profil")
						location.reload();
					}
					else
					jAlertSwitch("droits");
				});	
		});			
	}
	if(action == "remove")
	{
		jConfirm('Voulez vous vraiment vous <b>débarasser</b> de cette "<b>ami(e)</b>" ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_ajax.php',{ friend: action, to: to},function success(data){
					if(data == 1)
					{
						if(from == "membres")
						{
							if(profil != 0)
							initPaginationGlobal(from, "friends]::["+profil+"]::[1", 10);
							else
							initPaginationGlobal(from, "null", 10);
						}
						if(from == "profil")
						location.reload();
					}
					else
					jAlertSwitch("droits");
				});	
		});			
	}
	if(action == "accept")
	{
		jConfirm('Voulez vous vraiment <b>accepter</b> cette <b>demande d\'amitié</b> ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_ajax.php',{ friend: action, to: to},function success(data){
					if(data == 1)
					{
						if(from == "membres")
						{
							if(profil != 0)
							initPaginationGlobal(from, "friends]::["+profil+"]::[1", 10);
							else
							initPaginationGlobal(from, "null", 10);
						}
						if(from == "profil")
						location.reload();
					}
					else
					jAlertSwitch("droits");
				});	
		});			
	}
	if(action == "deblock")
	{
		jConfirm('Voulez vous vraiment <b>débloquer</b> cette personne ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_ajax.php',{ friend: action, to: to},function success(data){
					if(data == 1)
					{
						if(from == "membres")
						{
							if(profil != 0)
							initPaginationGlobal(from, "friends]::["+profil+"]::[1", 10);
							else
							initPaginationGlobal(from, "null", 10);
						}
						if(from == "profil")
						location.reload();
					}
					else
					jAlertSwitch("droits");
				});	
		});			
	}	
	if(action == "add")
	{
		jConfirm('Voulez vous vraiment ajouter cette personne à vos "<b>amis</b>" ?', info_confirm, function(r) {
				if(r)
				$.get('traitement_ajax.php',{ friend: action, to: to},function success(data){
					if(data == 1)
					{
						if(from == "membres")
						{
							if(profil != 0)
							initPaginationGlobal(from, "friends]::["+profil+"]::[1", 10);
							else
							initPaginationGlobal(from, "null", 10);
						}
						if(from == "profil")
						location.reload();
					}
					else
					jAlertSwitch("droits");
				});	
		});			
	}
	if(action == "message")
	{
		$.post('getPU.php',{ place:"message", member: to, from: from },function success(data) { load_ts_pu( data, 585, null ); });	
	}	
	if(action == "request")
	{
		jAlert("Vous ne pouvez pas effectuer cette action tant que vous serez <b>en attente</b> d'acceptation.", info_alerte);
	}		
	if(action == "unwanted")
	{
		jAlert("Vous ne pouvez pas effectuer cette action car cette personne <b>vous a bloquée</b> !", info_alerte);
	}
	if(action == "unblock")
	{
		jAlert("Vous ne pouvez pas effectuer cette action car <b>vous avez bloqué cette personne</b> !", info_alerte);
	}	
}

function true_sharer(where) 
{
	u=location.href;
	t=document.title;
	
	if(where == "facebook")
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'True Sharer','toolbar=0,status=0,width=626,height=436');
	
	if(where == "twitter")
	window.open('http://twitter.com/home?status=Check out at '+encodeURIComponent(u),'True Sharer','toolbar=0,status=0,width=800,height=436');
	
	if(where == "myspace")
	window.open('http://www.myspace.com/index.cfm?fuseaction=postto&t='+encodeURIComponent(t)+'&u='+encodeURIComponent(u)+'&l=3','True Sharer','toolbar=0,status=0,width=626,height=436');
	
	if(where == "wikio")
	window.open('http://www.wikio.fr/vote?url='+encodeURIComponent(u),'True Sharer','toolbar=0,status=0,width=626,height=436');
	
	return false;
}

function getZikPlayer(r,t,n)
{
	if(t == "Deezer"){
	player = "<embed src='http://www.deezer.com/embed/player?rid="+r+"&ap=1&ln=fr' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' wmode='transparent' allownetworking='internal' width='450' height='375'></embed>"; 
	$("#zikPlayerTitle").html("La radio ( "+n+" ) "+t);
	}
	if(t == "Playlist"){ 
	player = "<embed src='http://www.deezer.com/embed/player?pid="+r+"&ap=1&ln=fr' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' wmode='transparent' allownetworking='internal' width='450' height='375'></embed> <br /><br /><b>Permalien :</b> <input type='text' class='permalien bradius' style='width:240px;' readonly='readonly' value='http://www.truestories.fr/p-"+n+"' onclick='this.select()' />"; 
	$("#zikPlayerTitle").html("La playlist de <a href='m-"+n+"'>"+n+"</a>");
	}
	if(t == "FM"){ 
	player = "<embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/mediaplayer/' SRC='"+r+"' width='280' height='50' autostart='1' wmode='transparent' showcontrols='1' showpositioncontrols='0' showstatusbar='1' volume='-200' wmode='transparent'></embed>";
	$("#zikPlayerTitle").html("La radio "+n);
	}
	$("#zikPlayer").html(player);
}


function TSCODE(tag,obj)
{
	textarea = document.getElementById(obj);
	tag1 = "["+tag+"]";
	tag2 = "[/"+tag+"]";

	if (document.selection) 
	{
		textarea.focus();
		sel = document.selection.createRange();
		if(tag == "list" || tag == "list=1")
		{
			list = sel.text.split('\n');
			for(i=0;i<list.length;i++) 
			{
				list[i] = '[*]' + list[i];
			}
			tag1 = (tag == "list=1") ? "[list=1]" : tag1;
			tag2 = (tag == "list=1") ? "[/list]" : tag2;			
			sel.text = tag1 + '\n' + list.join("\n") + '\n' + tag2;				
		}
		else
			sel.text = tag1 + sel.text + tag2;
	}
   else 
    {  
	    start = textarea.selectionStart;
		end = textarea.selectionEnd;		
		scrollTop = textarea.scrollTop;
		scrollLeft = textarea.scrollLeft;
        sel = textarea.value.substring(start, end);
		
		if(tag == "list" || tag == "list=1")
		{
			list = sel.split('\n');
			for(i=0;i<list.length;i++) 
			{
				list[i] = '[*]' + list[i];
			}
			tag1 = (tag == "list=1") ? "[list=1]" : tag1;
			tag2 = (tag == "list=1") ? "[/list]" : tag2;					
			rep = tag1 + '\n' + list.join("\n") + '\n' +tag2;		
		}
		else
			rep = tag1 + sel + tag2;	
		
        textarea.value =  textarea.value.substring(0,start) + rep + textarea.value.substring(end,textarea.value.length);
		textarea.scrollTop = scrollTop;
		textarea.scrollLeft = scrollLeft;
	}
}

function load_ts_pu(x,y,z)
{
	get_ts_pu( x, y, z );
	toggle_ts_toolbar();
	ts_tooltip();
}

