function ajouter_livreor(){var a="#commentaire_area";add_commentaire("ajax/bio/add","bbcode="+$(a).val().replace(/&/g, "%26").replace(/#/g, "%23"));$(a).val("");}
function ajouter_com_news(s){var a="#commentaire_area";add_commentaire("ajax/news/"+s+"/add","bbcode="+$(a).val().replace(/&/g, "%26").replace(/#/g, "%23"));$(a).val("");}
function ajouter_com_mix(s){var a="#commentaire_area";add_commentaire("ajax/mix/"+s+"/add","bbcode="+$(a).val().replace(/&/g, "%26").replace(/#/g, "%23"));$(a).val("");}

function preview(z,id){
	var t = z.value;
	t = t.replace(/\n/gi, "<br />");
	t = t.replace(/\r/gi, "");
	t = t.replace(/\[b\](.+?)\[\/b]/gi, "<b>$1</b>");
	t = t.replace(/\[i\](.+?)\[\/i]/gi, "<i>$1</i>");
	t = t.replace(/\[u\](.+?)\[\/u]/gi, "<u>$1</u>");
	t = t.replace(/\[quote\](.+?)\[\/quote]/gi, '<div class="quoting"><div class="yellow">Citation :</div><div class="pad10p">$1</div></div>');
	t = t.replace(/\[url=(.+?)\](.+?)\[\/url]/i, '<a href="$1" target="_blank" rel="nofollow" class="pt underlined orange">$2</a>');

	$("#"+id).empty();
	$("#"+id).append(t);
}

function preview_inverse(t){
	t = t.replace(/\<b\>(.+?)\<\/b>/gi, "[b]$1[/b]");
	t = t.replace(/\<i\>(.+?)\<\/i>/gi, "[i]$1[/i]");
	t = t.replace(/\<u\>(.+?)\<\/u>/gi, "[u]$1[/u]");
	t = t.replace(/\<br \/>/gi, "\r\n");
	t = t.replace(/\<br\/>/gi, "\r\n");
	t = t.replace(/\<br>/gi, "\r\n");
	t = t.replace(/\<a href="(.+?)" title="(.+?)"\>(.+?)<\/a\>/i, "[url=$1]$3[/url]");
	t = t.replace(/\<div class="quoting"><div class="yellow">Citation :<\/div><div class="pad10p">(.+?)<\/div><\/div>/gi, "[quote]$1[/quote]");
	return t;
}

function bbcodeCommentaire(){
	$(function(){$('textarea[name=bbcode]').bbcodeeditor({
		bold:$('.bold'),italic:$('.italic'),underline:$('.underline'),link:$('.link'),quote:$('.quote'),
		back:$('.back'),forward:$('.forward'),back_disable:'btn_com back_disable',forward_disable:'btn_com forward_disable',
		exit_warning:false,preview:$('#preview')
	});});
}

function ajouterCommentaire(s){if($("#"+s).css("display")=="none"){ouvrirCommentaire(s);}else{fermerCommentaire(s);}}
function ouvrirCommentaire(id){$("#ajouter_bouton").hide("fast");$("#"+id).show("normal",function(){resizeMe();});}
function fermerCommentaire(id){$("#ajouter_bouton").show("fast");$("#"+id).hide("normal",function(){resizeMe();});}

function quoter_commentaire(el){
	var comment = preview_inverse($(el).parent().parent().parent().children(".un_commentaire").html());
	$('#commentaire_area').val($('#commentaire_area').val()+'[quote]'+comment+'[/quote]');
	ouvrirCommentaire('ajouter_commentaire_cacher');
}

