﻿// This function calls the Web service method and
// passes the event callback function.

function UpdateUserRating(_UserRating, _UserId, _CommentObjId, _IsUnRegisterUserAllowed, _UserRatingUpdateAllowed, _LocalAlreadyRated, _LocalLoginToRate, AnonyKey) {
    DNNCentric.RatingAndComments.RatingController.UpdateRating(_UserRating, _UserId, _CommentObjId, _IsUnRegisterUserAllowed, _UserRatingUpdateAllowed, _LocalAlreadyRated, _LocalLoginToRate, AnonyKey, SucceededCallback, FailedCallback);
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs) {
    if (!window.jqsDCCRnC)
        jqsDCCRnC = jQuery;
    // Page element to display feedback.
    if ((result.AlreadyRated == null)) {
        jqsDCCRnC(document).ready(function() {
            idAvgRatingValue.html(result.AverageRating.toString().replace('.', strDecimalSeparator));
            if (result.RatingCount > 0) {
                idRatingCount.html(result.RatingCount);
                idYourRating.html(result.YourRating.toString().replace('.', strDecimalSeparator));
                idYourRating.format({ format: "#.#0", locale: strLocale });
                idYourRatingText.removeClass("prc_ratingtext2_hidden");
                idYourRatingText.addClass('prc_ratingtext2');
                idYourRatingValue.html(idYourRatingValue.html().replace('.', strDecimalSeparator));
                idYourRatingValue.removeClass('rating_other_text_hidden');
                idYourRatingValue.addClass('rating_other_text');
            }
        });
    }
    else {
        jqsDCCRnC(document).ready(function() {
            idMsg.html(result.AlreadyRated);
            if (result.YourRating > 0)
                idYourRating.html(result.YourRating);
            idYourRating.format({ format: "#.#0", locale: strLocale });
        });
    }
    jqsDCCRnC(document).ready(function() {
        jqsDCCRnC(idRater).empty().rating({ curvalue: result.AverageRating, maxvalue: 5, increment: 0.5 });
    });

}
// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error) {
    
    // Display the error.    
    /*var RsltElem = 
    document.getElementById("ResultId");
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();*/
    //alert("Failed: " +error.toString());
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName) {
    if (userContext == "XmlDocument") {
        GetWebServiceXMLResult(result);
    }

}

//this is to update the comment points
function UpdatePointResponse(_UserId, _CommentId, _UpOrDown) {

    DNNCentric.RatingAndComments.RatingController.UpdatePointResponse(_UserId, _CommentId, _UpOrDown, SucceededPointCallback, FailedCallback);
}
//succeeded callback for update comment points
function SucceededPointCallback(result, eventArgs) {
    if (!window.jqsDCCRnC)
        jqsDCCRnC = jQuery;
    // Page element to display feedback.
    if ((result != null)) {
        jqsDCCRnC(document).ready(function() {
            idCommentPointText.html(result);
            UpdatePointResponse.idCommentPointLinkDown.removeClass("prc_ratingbuttons1Link");
            UpdatePointResponse.idCommentPointLinkDown.addClass("prc_ratingbuttons1LinkDisabled");
            UpdatePointResponse.idCommentPointLinkUp.removeClass("prc_ratingbuttons1Link");
            UpdatePointResponse.idCommentPointLinkUp.addClass("prc_ratingbuttons1LinkDisabled");

            UpdatePointResponse.idCommentPointLinkDown.attr({ disabled: "disabled" });
            UpdatePointResponse.idCommentPointLinkUp.attr({ disabled: "disabled" });
            UpdatePointResponse.idCommentPointLinkDown.attr({ href: "" });
            UpdatePointResponse.idCommentPointLinkUp.attr({ href: "" });

        });
    }
    else {

    }
    function ReportComment(_PortalID, _TabID, _ModuleID, _iModuleID, _ModUserID, _OwnerUserID, _ThisUserID, _ReportedCommentID, _ReportedCommentByUserID, _ReportedCommentByUserName, _ReportedCommentByEmailID, _ReportedCommentText, _ReportedCommentSetting) {
        DNNCentric.RatingAndComments.RatingController.ReportComment(_PortalID, _TabID, _ModuleID, _iModuleID, _ModUserID, _OwnerUserID, _ThisUserID, _ReportedCommentID, _ReportedCommentByUserID, _ReportedCommentByUserName, _ReportedCommentByEmailID, _ReportedCommentText, _ReportedCommentSetting, SucceededReportCommentCallback, FailedCallback);
    }
    function SucceededReportCommentCallback(result, eventArgs) {

        // Page element to display feedback.
        if ((result != null)) {

            jQDCCRnC;
            jQDCCRnC(document).ready(function() {
                //the report comment link
                var idReportComment = jQDCCRnC('table#prc_maintable_' + result.ModuleID).find('a[id=prc_reportcomment_' + result.CommentID + ']');
                if (result.Reported == true) {
                    var temp = jQDCCRnC(idReportComment).parents('table[id=CommentItem_' + result.CommentID + ']').find('a.[id*=_lnkbttnAdminDelete]').length;
                    if ((result.ReportedCommentSetting.toLowerCase() == 'true') && (temp == 0)) {
                        jQDCCRnC(idReportComment).parents('table[id=CommentItem_' + result.CommentID + ']').find('td.prc_commenttextTD').hide("slow");
                    }

                    //hiding the reply, point buttons and the separator between the reply and report buttons
                    jQDCCRnC(idReportComment).parents('table[id=CommentItem_' + result.CommentID + ']').find('a[id=prc_replyto_' + result.CommentID + ']').parent('td').html('');
                    jQDCCRnC(idReportComment).parents('table[id=CommentItem_' + result.CommentID + ']').find('a.prc_ratingbuttons1Link').addClass("prc_ratingbuttons1LinkDisabled").attr("disabled", "disabled").removeAttr("href").removeClass("prc_ratingbuttons1Link");
                    jQDCCRnC(idReportComment).parents('table[id=CommentItem_' + result.CommentID + ']').find('td.prc_replyreportbuttonsSepTD').html('');

                    jQDCCRnC(idReportComment).parent('td').html('<span class="prc_reportedtxt" id="prc_reported_' + result.CommentID + '">Reported</span>');
                }
                else {
                }

            });
        }
        else {

        }
        jQDCCRnC;
        jQDCCRnC(document).ready(function() {

        });

    }
    //    jQuery;
    //    jQuery(document).ready(function()
    //    {
    //       
    //    });

}
//every external Javascript file that is being referenced from ScriptManager must have a call to Sys.Application.
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
