function postComment (id) {
	FCKeditorAPI.GetInstance('texts' + id).UpdateLinkedField();
	
	var chaine = 'xmlhttp=1&post=' + id + '&texts=' + $('texts' + id).value + '&pseudo=' + $('pseudo' + id).value + '&code=' + $('input_crypto' + id).value + '&hyperlien=' + $('hyperlien' + id).value;

	var myAjax = new Ajax ('scripts/php/postcomment.php', {method: 'post'
														, onSuccess: function(responseText, responseXML) {
																		if (responseText == 1) {
																			$('pseudo' + id).value = '';
																			$('input_crypto' + id).value = '';
																			FCKeditorAPI.GetInstance('texts' + id).Commands.GetCommand('NewPage').Execute();
																			document.images.cryptogram.src = 'scripts/php/crypt/cryptographp.php?cfg=0&&' + Math.round(Math.random(0)*1000) + 1;
																			showComments(id);
																		}
																		else {
																			alert (responseText);
																		}
																	}
														, wait: false
														, data: chaine
														, evalScripts: true
														}).request();
}

function showComments(id) {
	if ($("comments" + id).style.display == "none") {
		$("commenter" + id).style.display = "none";
		$("comments" + id).style.display = "block";
		$("viewcomments" + id).innerHTML = "Cacher les blablas";
		$("viewcommenter" + id).innerHTML = "Blablatez ici";
		
		var chaine = 'xmlhttp=1&post=' + id;
		
		var myAjax = new Ajax ('scripts/php/showcomments.php', {method: 'post'
															, update: $('commentaires' + id)
															, wait: false
															, data: chaine
															, evalScripts: true
															}).request();
	}
	else {
		var chaine = 'xmlhttp=1&post=' + id + '&numrows=1';
		
		var myAjax = new Ajax ('scripts/php/showcomments.php', {method: 'post'
															, onSuccess: function(responseText, responseXML) {
																			switch (responseText) {
																				case '0' :
																					$("viewcomments" + id).innerHTML = "No blabla.";
																					break;
																				case '1' :
																					$("viewcomments" + id).innerHTML = "Le blabla...";
																					break;
																				default:
																					$("viewcomments" + id).innerHTML = "Les " + test + " blablas...";
																					break;
																			}
																			
																			$("comments" + id).style.display = "none";
																		}
															, wait: false
															, data: chaine
															, evalScripts: true
															}).request();
		
	}
}

function showCommenter(id) {
	if ($("commenter" + id).style.display == "none") {
		if ($("comments" + id).style.display != "none") {
			showComments(id);
		}
		$("commenter" + id).style.display = "block";
		$("viewcommenter" + id).innerHTML = "En fait non.";
		showCrypto(id);
		if (!$('texts' + id + '___Config')) {
			setTimeout(function(){showCommenter(id);}, 100);
			setTimeout(function(){showCommenter(id);}, 200);
			setFCKeditor('texts' + id);
		}
	}
	else {
		$("commenter" + id).style.display = "none";
		$("viewcommenter" + id).innerHTML = "Blablatez ici";
	}

}

function showCrypto(id) {
	$("crypto").style.display = "block";
	$("crypto" + id).appendChild($("crypto"));
}

function setFCKeditor (textarea) {
	var oFCKeditor = new FCKeditor(textarea);
	oFCKeditor.BasePath = "scripts/js/fckeditor/";
	oFCKeditor.ToolbarSet = "Snas_comment";
    oFCKeditor.ReplaceTextarea() ;
}
