﻿// 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)
{
    
    // Page element to display feedback.
    if ((result.AlreadyRated==null))
    {
        
        jQuery.noConflict();
        jQuery(document).ready(function()
        {
            idAvgRatingValue.html(result.AverageRating);
            if(result.RatingCount>0)
            {
                idRatingCount.html(result.RatingCount);
                idYourRating.html(result.YourRating);
				idYourRating.format({format:"#.#0", locale:"us"}); 
				
				           
			    idYourRatingText.removeClass("prc_ratingtext2_hidden");
                idYourRatingText.addClass('prc_ratingtext2');
                idYourRatingValue.removeClass('rating_other_text_hidden');
                idYourRatingValue.addClass('rating_other_text');
            }
            
        });
    }
    else    
    {
        jQuery.noConflict();
        jQuery(document).ready(function()
        {
            idMsg.html(result.AlreadyRated);
            if(result.YourRating>0)
                idYourRating.html(result.YourRating);
				idYourRating.format({format:"#.#0", locale:"us"}); 
        });
    }
    jQuery.noConflict();
    jQuery(document).ready(function()
    {
        jQuery(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)
{
    
    // Page element to display feedback.
    if ((result!=null))
    {
        
        jQuery.noConflict();
        jQuery(document).ready(function()
        {
           idCommentPointText.html(result);
           idCommentPointLinkDown.removeClass("prc_ratingbuttons1Link");
           idCommentPointLinkDown.addClass("prc_ratingbuttons1LinkDisabled");
           idCommentPointLinkUp.removeClass("prc_ratingbuttons1Link");
           idCommentPointLinkUp.addClass("prc_ratingbuttons1LinkDisabled");
           
           idCommentPointLinkDown.attr({disabled: "disabled"});
           idCommentPointLinkUp.attr({disabled: "disabled"});
            idCommentPointLinkDown.attr({href: ""});
           idCommentPointLinkUp.attr({href: ""});
           
        });
    }
    else    
    {
        
    }
    jQuery.noConflict();
    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();
