// Comment alert event

$(document).ready(function() {
	$("img.comment-alert").click(function() {

		if(confirm('Weet je zeker dat je melding wilt maken van een ongepaste reactie? De redactie zal op de hoogte worden gebracht en de reactie controleren. \n\nLet op, misbruik wordt bestraft met een IP-Ban.')) {

			var comment_id = $(this).attr('comment_id');
			var weblog_id = $(this).attr('weblog_id');
			var entry_id = $(this).attr('entry_id');

			$.ajax({
				type: "POST",
				cache: false,
				url: "/index/ajax/comment-alert",
				data: "comment_id="+comment_id+"&weblog_id="+weblog_id+"&entry_id="+entry_id+"&client_ip="+client_ip,
				success: function(msg){
					if(msg == "ok") { alert("Melding succesvol verzonden.\n\nLet op: Misbruik wordt direct bestraft met een IP-Ban"); }
				}
			});
		}				
	});
});

// comment warning event

$(document).ready(function() {

$("a#test").click(function() {
	alert('test');
	return false;
});

        $("a#comment_warning").click(function() {


                if(confirm('Waarschuwing versturen?')) {

                        var comment_id = $(this).attr('comment_id');
                        var comment  = $(this).attr('comment');
                        var entry_id = $(this).attr('entry_id');
			var author =  $(this).attr('author');
			var email = $(this).attr('email');

			alert(comment_id+"\n"+comment+"\n"+entry_id+"\n"+email+"\n"+author);

                        $.ajax({
                                type: "POST",
                                cache: false,
                                url: "/index/ajax/comment-warning",
                                data: "comment_id="+comment_id+"&comment="+comment+"&entry_id="+entry_id+"&email="+email+"&author="+author,
                                success: function(msg){
                                        if(msg == "ok") { alert("Melding succesvol verzonden."); }
                                }
                        }); 
                }

	

		return false;
        });
});


// switch comment status from closed to open
// admin function only

$("a#comment_close").click(function() {
	var comment_id = $(this).attr('comment_id');

        $.ajax({
        	type: "POST",
                cache: false,
                data: "comment_id="+comment_id,
                url: "/index/ajax/comment-update-status",
                success: function(data){
                	if(data == "c") $(".comment_close_"+comment_id).html("closed");
                        else if(data == "o") $(".comment_close_"+comment_id).html("open"); 
			else alert(data);
                }
	 });
});


// reply form

$(function(){
// Find all the "reply to" links and bind to the click event
$('a[href^=/index/comment-form/]').click(function() {

  var url_array = $(this)    // The anchor object
	.attr('href')    // Fetch the value of the href attribute
	.split("/");    // Divide into chunks, using / as the divider
  var id = url_array[4];    // We want the fourth chunk


  // Change the value of weever-parent-id
  $('#weever-parent-id').val(id);

  // Now we'll move the form
  
  $('form#comment_form')
	.insertAfter(    // Insert the comment form after div.entry
	  $(this)
	  .parent()    // The containing p tag
	  .parent()    // div.entry
	  );

  return false;
});
});

