function showAddDialog(productID)
        {
            $("#defradio").attr("checked", "checked");
            $("#commenttext").val('');
            $("#comment-dialog").attr('title', 'Add review');
            $("#comment-dialog").dialog({
            buttons: {
                    "Add review": function(){
                        if ($('#commentForm').valid())
                        {
                           mark = $(":radio[name=mark]").filter(":checked").val();
                           text = escape($("#commenttext").val());
                           name = $("#userName").val();
                           AddComment(productID, text, mark, name);
                           $(this).dialog("destroy")
                        }
            },
                    "Cancel": function(){
                           $(this).dialog("destroy")
                    }
            },
            modal: true,
            draggable : false
            }).dialog("open");
        }

function AddComment(productID, text, mark, name){
    $("#comment-loading").attr('title', 'Adding review...');
	$("#comment-loading").dialog({
		modal:true,
		draggable:false,
		beforeclose:function() {
			return false;
		}
	}).dialog("open");

	$.ajax({type: "GET",
			url : "/comment/add/",
			data : "productID="+productID+"&text="+text+"&mark="+mark+"&userName="+name,
			success: handleAddCommentAJAXResponse
			});
}

function handleAddCommentAJAXResponse(msg){
 	var response = eval("("+msg+")");
    $("#comment-loading").dialog("destroy");
	$("#commentblock").html(response["comments"]);
    $("#topcomcount").html(response["count"]);
    $("#bottomcomcount").html(response["count"]);
 }

function showConfirmCommentDelete(comID, prodID)
        {
            $("#confirm-comment-dialog").dialog({
            buttons: {
                    "Yes": function(){
                           DeleteComment(comID, prodID);
                           $(this).dialog("destroy")
            },
                    "No": function(){
                           $(this).dialog("destroy")
                    }
            },
            modal: true,
            draggable : false
            }).dialog("open");
        }


function DeleteComment(comID, prodID){
    $("#comment-loading").attr('title', 'Removing review...');
	$("#comment-loading").dialog({
		modal:true,
		draggable:false,
		beforeclose:function() {
			return false;
		}
	}).dialog("open");

	$.ajax({type: "GET",
			url : "/comment/delete/",
			data : "comID="+comID+"&prodID="+prodID,
			success: handleDeleteCommentAJAXResponse
			});
}

function handleDeleteCommentAJAXResponse(msg){
 	var response = eval("("+msg+")");
    $("#comment-loading").dialog("destroy");
	$("#commentblock").html(response["comments"]);
    $("#topcomcount").html(response["count"]);
    $("#bottomcomcount").html(response["count"]);
 }


function showEditDialog(commentID, productID)
        {
            var thisMark = $("#mark"+commentID+productID).text();
            var thisTextComment = $("#text"+commentID+productID).text();
            var thisName = $("#name"+commentID+productID).text();
            $(":radio[value="+thisMark+"]").attr("checked", "checked");
            $("#commenttext").val(thisTextComment);
            $("#userName").val(thisName);
            $("#comment-dialog").attr('title', 'Edit review');
            $("#comment-dialog").dialog({
            buttons: {
                    "Add review": function(){
                           var mark = $(":radio[name=mark]").filter(":checked").val();
                           var text = escape($("#commenttext").val());
                           var name = $("#userName").val();
                           EditComment(productID,commentID, text, mark, name);
                           $(this).dialog("destroy")
            },
                    "Cancel": function(){
                           $(this).dialog("destroy")
                    }
            },
            modal: true,
            draggable : false
            }).dialog("open");
        }



function EditComment(productID, commentID, text, mark, userName){
    $("#comment-loading").attr('title', 'Updating review...');
	$("#comment-loading").dialog({
		modal:true,
		draggable:false,
		beforeclose:function() {
			return false;
		}
	}).dialog("open");

	$.ajax({type: "GET",
			url : "/comment/edit/",
			data : "productID="+productID+"&commentID="+commentID+"&text="+text+"&mark="+mark+"&userName="+userName,
			success: handleEditCommentAJAXResponse
			});
}

function handleEditCommentAJAXResponse(msg){
 	var response = eval("("+msg+")");
    $("#comment-loading").dialog("destroy");
	$("#commentblock").html(response["comments"]);
    $("#topcomcount").html(response["count"]);
    $("#bottomcomcount").html(response["count"]);
 }