<div class="com-content">
<h2><?php echo sprintf(__('com.nb_com'),sizeof((array)v('tCommentaires'))); ?></h2>
<form method="post" class="com-form" action="<?php echo WWW_ROOT; ?>tabcommentaires/commatch/<?php echo v('MAT_CLE'); ?>" onsubmit="return false;">
	<textarea name="commentaire" class="com-zone-com"></textarea>
	<input type="submit" value="<?php echo __('com.action.ok'); ?>" />
</form>
<?php foreach((array)v('tCommentaires') as $cle=>$com) {?>
<div class="com-block">
	<span class="com-auteur"><?php echo zk_joueur($com['Auteur']); ?></span> - <span class="com-date"><?php echo date_fr($com['Date'],2); ?></span>
	<?php echo v('is_admin')==true? href(img('icons/cross.png'),array('controleur'=>'tabcommentaires','action'=>'supprimer','params'=>$cle,'class'=>'com-delete', 'onclick'=>'return false')):''; ?>
	<p><?php echo $com['Commentaire']; ?></p>
</div>
<?php } ?>


<script type="text/javascript">
$(".com-form").submit(function(){
	if ( $(this).children(".com-zone-com").val() == "" ){
		alert("Merci de saisir un commentaire");
		return false;
	}	
	$.ajax({
		type: "POST",
		url: $(this).attr("action"),
		data: "commentaire="+encodeURIComponent($(this).children(".com-zone-com").val()),
		success: function(data, text){
			//Rafraichir la tab
			$(".com-content").parent().load("<?php echo WWW_ROOT; ?>tabcommentaires/match/<?php echo v('MAT_CLE'); ?>");
		},
		error: function (request, status, error) {
	        alert("Erreur : "+request.responseText);
	    }
	});
	return false;
});

$(".com-delete").click(function(){
	$.ajax({
		type: "POST",
		url: this.href,
		success: function(data, text){
			//Rafraichir la tab
            $(".com-content").parent().load("<?php echo WWW_ROOT; ?>tabcommentaires/match/<?php echo v('MAT_CLE'); ?>");
		},
		error: function (request, status, error) {
	        alert("Erreur : "+request.responseText);
	    }
	});
	return false;
});

</script>
</div>