@model Nop.Web.Models.Catalog.ProductReviewHelpfulnessModel
<div class="product-review-helpfulness">
    @T("Reviews.Helpfulness.WasHelpful?")
    <span id="vote-yes-@(Model.ProductReviewId)" class="vote">@T("Common.Yes")</span>&nbsp;<span id="vote-no-@(Model.ProductReviewId)" class="vote">@T("Common.No")</span>
    (<span id="helpfulness-vote-yes-@(Model.ProductReviewId)">@(Model.HelpfulYesTotal)</span>/<span id="helpfulness-vote-no-@(Model.ProductReviewId)">@(Model.HelpfulNoTotal)</span>)
    <div id="helpfulness-vote-result-@(Model.ProductReviewId)"></div>

    
    <script type="text/javascript">
        $(document).ready(function () {
            $('#vote-yes-@(Model.ProductReviewId)').click(function () {
                setProductReviewHelpfulness@(Model.ProductReviewId)('true');
            });
            $('#vote-no-@(Model.ProductReviewId)').click(function () {
                setProductReviewHelpfulness@(Model.ProductReviewId)('false');
            });
        });

        function setProductReviewHelpfulness@(Model.ProductReviewId)(wasHelpful){
                $.ajax({
                    cache:false,
                    type: "POST",
                    url: "@(Url.Action("SetProductReviewHelpfulness", "Catalog"))",
                    data: "productReviewId=" + @(Model.ProductReviewId) + "&washelpful=" + wasHelpful,
                    success: function (data) {
                         $("#helpfulness-vote-yes-@(Model.ProductReviewId)").html(data.TotalYes);
                         $("#helpfulness-vote-no-@(Model.ProductReviewId)").html(data.TotalNo);
                         $("#helpfulness-vote-result-@(Model.ProductReviewId)").html(data.Result);
                                                  
                         $('#helpfulness-vote-result-@(Model.ProductReviewId)').fadeIn("slow").delay(1000).fadeOut("slow");
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to vote. Please refresh the page and try one more time.')
                    }  
                });
        }
    </script>
</div>
