﻿/// <reference path="../API/Agility.js" />
/// <reference path="../API/Agility.UGC.API.js" />
/// <reference path="../Utils.js" />
/// <reference path="../ContextUtil.js" />

//Initialize YouTube Event Listener To catch player events
function onYouTubePlayerReady(playerId) {
    var VideoPlayer = document.getElementById("VideoDetailsPlayer");
    VideoPlayer.addEventListener("onStateChange", "Doritos.Modules.VideoDetails.YouTubeVideoStateChanged");
    Doritos.Modules.VideoDetails.LoadVideoEmbed();
}


var VideoDetails_RatingSum = 0;
var totalRatings = 0;
var ShareTracking = new Array();
var addthis_config =
{
    data_track_linkback: false
}

var addthis_share =
{
    templates: {
        twitter: 'check out {{url}} (from @DoritosViralocity.ca)'
    }
}


Agility.RegisterNamespace("Doritos.Modules.VideoDetails");

(function(VideoDetails) {

    var YouTubeVideoID = null;
    var SubmissionID = -1;
    var NilMessageIndex = 0;
    var VideoHasNotPlayedYet = true;
    var BitlyLink = null;
    var VideoTitle = null;
    var ReportAbuseDialog = null;
    var FavCallInProgress = false;



    VideoDetails.Init = function(youTubeVideoID) {



        YouTubeVideoID = youTubeVideoID;

        if (YouTubeVideoID != "NIL") {



            SubmissionID = Doritos.Utils.GetQueryString("v")

            VideoDetails.LoadVideo(YouTubeVideoID);
            setTimeout("Doritos.Modules.VideoDetails.LoadVideoStats()", 1);
            setTimeout("Doritos.Modules.VideoDetails.LoadVideoViralocity()", 1);
            setTimeout("Doritos.Modules.VideoDetails.LoadStarRating()", 500);
            setTimeout("Doritos.Modules.VideoDetails.LoadFavCount()", 600);
            setTimeout("Doritos.Modules.VideoDetails.LoadFacebookButton()", 1);
            setTimeout("Doritos.Modules.VideoDetails.LoadComments()", 100);

            setTimeout("Doritos.Modules.VideoDetails.CheckBitlyUrl()", 1000);

            VideoDetails.GetNextPrevVideoLinks();

            VideoTitle = $("#VideoTitle").html().replace(/^\s+|\s+$/g, ""); ;

        }
        else {
            Doritos.Modules.VideoDetails.LoadNILVideo();
            setTimeout("Doritos.Modules.VideoDetails.LoadVideoViralocity()", 10);

        }
    }

    VideoDetails.GetNextPrevVideoLinks = function() {
        return;

        var searchArg = {
            RecordTypeName: "VideoSubmission",
            PageSize: 1,
            RecordOffset: 0,
            SortedField: "ID",
            SortDirection: Agility.UGC.API.SortDirection.DESC,
            Search: "ID > " + SubmissionID
        }


        Agility.UGC.API.SearchRecords(searchArg, function(data) {
            if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
                alert(data.Message);
            } else {

                if (data.ResponseData.Records.length > 0) {


                    $("#NextVideo").attr("href", Agility.ResolveUrl("~/Gallery/VideoDetails.aspx?v=" + data.ResponseData.Records[0].ID));

                }
            }
        });

        var searchArg = {
            RecordTypeName: "VideoSubmission",
            PageSize: 2,
            RecordOffset: 0,
            SortedField: "ID",
            SortDirection: Agility.UGC.API.SortDirection.DESC,
            Search: "ID < " + SubmissionID
        }


        Agility.UGC.API.SearchRecords(searchArg, function(data) {
            if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
                ErrorOccured = true;
            } else {
                if (data.ResponseData.Records.length > 0) {


                    $("#PreviousVideo").attr("href", Agility.ResolveUrl("~/Gallery/VideoDetails.aspx?v=" + data.ResponseData.Records[0].ID));

                }
            }
        });
    }

    VideoDetails.LoadNILVideo = function() {
        $("#VideoPlayer").addClass("NilVideo");

        $("#VideoPlayer").html("<div id='NilMessage' class='NilMessageText'></div>");




        var params = { allowScriptAccess: "always", wmode: "transparent" };

        var atts = { id: "VideoDetailsPlayer" };
        swfobject.embedSWF("http://www.youtube.com/v/" + nilVideo + "?enablejsapi=1&playerapiid=ytplayer&showsearch=0&showinfo=0&rel=0", "VideoPlayer", "958", "502", "8", null, null, params, atts);


        // VideoDetails.AdvanceNilMessage();
    }

    VideoDetails.AdvanceNilMessage = function() {
        $("#NilMessage").html(nilMessage[NilMessageIndex]);

        NilMessageIndex++;
        if (NilMessageIndex < 4) {
            setTimeout("Doritos.Modules.VideoDetails.AdvanceNilMessage()", 3500);
        }
    }


    VideoDetails.LoadVideoViralocity = function() {
        var totalPoints = $("#VideoDetails_Viralocity").html();


        $("#VideoDetails_Viralocity").html(VideoDetails.GetPointImageString(totalPoints));
        $("#VideoDetails_Viralocity").show();
    }

    VideoDetails.LoadAddThis = function() {


        addthis_share.title = $("#VideoTitle").html().replace(/^\s\s*/, '').replace(/\s\s*$/, '');

        //        var path = location.href.substring(0, location.href.toLowerCase().indexOf("/home.aspx") + 10);
        //        var options = { ui_click: true };
        //        var param = { url: path, title: VideoTitle };

        $(".ShareButtons").children("a").each(function() {

            var classname = $(this).attr("class");
            var serviceName = classname.substring(classname.indexOf("addthis_button") + 15);

            $(this).bind("click", serviceName, function() {
                Doritos.Modules.VideoDetails.LogSharingEvent(serviceName);
            });

            //            if ($(this).attr("class").index("addthis_button") >= 0) {
            //                alert("found");
            //            }
            //            else {
            //                alert($(this).html());
            //            }
        });
        $(".addthis_button_expanded").bind("click", function() {

            setTimeout('Doritos.Modules.VideoDetails.LoadMoreShareBindings()', 1500);
        });

    }

    VideoDetails.LoadMoreShareBindings = function() {

        $(".at_item").each(function() {
            var classname = $(this).attr("id");
            var serviceName = classname.substring(classname.indexOf("at15t_") + 5);
            $(this).bind("click", serviceName, function() {
                Doritos.Modules.VideoDetails.LogSharingEvent(serviceName);
            });
        });

    }

    VideoDetails.LogSharingEvent = function(service) {

        var key = SubmissionID + "_" + service;
        var date = new Date();


        var currentTicks = parseInt(date.getTime());


        if (ShareTracking[key] == undefined || ShareTracking[key] == null || ShareTracking[key] <= currentTicks) {

            $.ajax({
                type: "POST",
                url: AgilityData_WebserviceUrl + '/LogShareEvent',
                data: "{'submissionID': " + SubmissionID + ", 'shareService': '" + service + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function(result) {
                    if (result.d != undefined && result.d != null) {
                        if (result.d) {

                            var shareDate = new Date();

                            ShareTracking[key] = parseInt(shareDate.getTime()) + 30000;
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {

                }
            });
        }
        else {

            ShareTracking[key] = parseInt(shareDate.getTime()) + 30000;
        }



    }

    VideoDetails.LoadVideo = function(VideoID) {

        var params = { allowScriptAccess: "always", wmode: "transparent" };

        var atts = { id: "VideoDetailsPlayer" };
        swfobject.embedSWF("http://www.youtube.com/v/" + YouTubeVideoID + "?enablejsapi=1&playerapiid=ytplayer&showsearch=0&showinfo=0&rel=0", "VideoPlayer", "958", "502", "8", null, null, params, atts);
        VideoDetails.LoadAddThis();



    }




    VideoDetails.YouTubeVideoStateChanged = function(newState) {

        if (newState == 1 && VideoHasNotPlayedYet) {
            if (Doritos.ContextUtil.IsAuthenticated()) {

                VideoHasNotPlayedYet = false;
                var record = {
                    ID: -1,
                    RecordTypeName: "VideoPlayingTracking",
                    SubmissionID: SubmissionID,
                    ProfileID: Doritos.ContextUtil.GetCurrentUserID()
                };

                Agility.UGC.API.SaveRecord(record, function(data) {
                    if (data.ResponseType != 0) {

                    }
                    else {

                    }
                });


            }
        }
    }



    VideoDetails.LoadVideoStats = function() {
        var flashvars = new Object();

        var langChanger = "";
        if (lang == "fr-ca") {
            langChanger = "_fr";
        }


        flashvars.xmlpath = Agility.ResolveUrl("~/xml/shell" + langChanger + ".xml");
        flashvars.isopath = Agility.ResolveUrl("~/xml/iso" + langChanger + ".xml");
        flashvars.statspath = Agility.ResolveUrl("~/HTTPHandlers/StatsXMLHandler.ashx?ID=" + SubmissionID);
        flashvars.swfpath = Agility.ResolveUrl("~/swf/shell.swf");
        flashvars.imgpath = Agility.ResolveUrl("~/swf/img/");


        var params = { wmode: "transparent" };


        var attributes = {};



        swfobject.embedSWF(Agility.ResolveUrl("~/SWF/loader.swf"), "VideoStats", "937", "379", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

    }



    VideoDetails.LoadStarRating = function() {



        $stars = $("#StarRating");

        //$stars.children().not("select").hide();



        $stars.stars({
            inputType: "select",
            captionEl: $("#StarDescription"),
            callback: function(ui, type, value) {
                VideoDetails.SaveRating(value);
            },
            cancelClass: 'ui-crystal-cancel',
            starClass: 'ui-crystal-star',
            starOnClass: 'ui-crystal-star-on',
            starHoverClass: 'ui-crystal-star-hover',
            cancelHoverClass: 'ui-crystal-cancel-hover',
            cancelShow: false
        });

        setTimeout("Doritos.Modules.VideoDetails.GetStarRating(true)", 10);

        $("#StarRating").bind("mouseover", function() {
            $("#StarRatingTotal").hide();
            $("#StarDescription").show();

        });
        $("#StarRating").bind("mouseout", function() {
            $("#StarDescription").hide();
            $("#StarRatingTotal").show();
        });
        //VideoDetails.GetStarRating

    }

    VideoDetails.GetStarRating = function(SetStars) {
        $.ajax({
            type: "POST",
            url: AgilityData_WebserviceUrl + '/GetVideoRating',
            data: "{'submissionID': " + SubmissionID + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(result) {

                if (result.d != undefined && result.d != null) {
                    var data = result.d;



                    var serviceURL = "http://gdata.youtube.com/feeds/api/videos/" + YouTubeVideoID + "?alt=json-in-script&callback=?";

                    $.getJSON(serviceURL,
                        function(youTubeData) {
                            var youTubeAverage = 0;
                            var youTubeTotal = 0;
                            var Average = 0;
                            var TotalRatings = 0;

                            if (youTubeData.entry != null) {
                                if (youTubeData.entry.gd$rating != null && youTubeData.entry.gd$rating != undefined) {
                                    youTubeAverage = youTubeData.entry.gd$rating.average;
                                    youTubeTotal = youTubeData.entry.gd$rating.numRaters;

                                }
                            }
                            if (youTubeTotal > 0) {

                                var temp = (data.AverageRating + youTubeAverage) / 2;

                                Average = Math.round(temp);
                                TotalRatings = data.TotalRatings + youTubeTotal;

                            }
                            else {
                                Average = data.AverageRating;
                                TotalRatings = data.TotalRatings;
                            }


                            if (SetStars) {
                                $("#StarRating").stars('select', Average);
                            }
                            $("#RatingTotal").html(TotalRatings);

                        });

                }
            },
            complete: function(XMLHttpRequest, textStatus) {
                //alert(XMLHttpRequest.status + ' ' + textStatus);
                //alert(XMLHttpRequest.responseText);
            }
        });
    }





    VideoDetails.SaveRating = function(value) {
        if (CurrentContestPhase >= 4) {
            return;
        }
        var LockKey = "SaveRating";

        Edentity.ClickLock.PerformAction(LockKey, function(unlockKey) {
            if (Doritos.ContextUtil.IsAuthenticated() || Doritos.ContextUtil.JustOneTimeAuthenticated()) {

                var searchString = "ProfileID = " + Doritos.ContextUtil.GetCurrentUserID() + " && SubmissionID = " + SubmissionID;

                if (Doritos.ContextUtil.GetJustOneTimeUserID().length > 0) {
                    searchString += " && JustOneTimeUser = '" + Doritos.ContextUtil.GetJustOneTimeUserID() + "'";
                }


                var searchArg = {
                    RecordTypeName: "VideoRatingTracking",
                    PageSize: 1,
                    RecordOffset: 0,
                    Search: searchString
                }

                Agility.UGC.API.SearchRecords(searchArg, function(data) {
                    if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
                        Edentity.ClickLock.ActionComplete(unlockKey);
                    } else {

                        var id = -1;

                        if (data.ResponseData.Records.length > 0) {
                            //do not allow a user to change thier rating

                            if (lang == "fr-ca") {
                                alert("Vous avez déjà évalué cette vidéo");
                            }
                            else {
                                alert("You have already rated this video.");
                            }
                            Edentity.ClickLock.ActionComplete(unlockKey);
                            VideoDetails.LoadStarRating();


                            return;
                            //id = data.ResponseData.Records[0].ID;
                        }



                        var ratingRecord = {
                            RecordTypeName: "VideoRatingTracking",
                            ID: id,
                            ProfileID: Doritos.ContextUtil.GetCurrentUserID(),
                            SubmissionID: SubmissionID,
                            Rating: value,
                            JustOneTimeUser: Doritos.ContextUtil.GetJustOneTimeUserID()
                        }

                        Agility.UGC.API.SaveRecord(ratingRecord, function(actSaveData) {
                            if (actSaveData.ResponseType != Agility.UGC.API.ResponseType.OK) {



                                Edentity.ClickLock.ActionComplete(unlockKey);
                                //alert(actSaveData.Message);
                                return;
                            } else {
                                try {
                                    Doritos.InvalidateCache.Remove("rating", SubmissionID);
                                }
                                catch (err) { }

                                Doritos.FacebookUtil.PublishRatingToWall(VideoTitle, BitlyLink, null);
                                VideoDetails.GetStarRating(false);
                                Edentity.ClickLock.ActionComplete(unlockKey);
                            }
                        });


                    }
                });


            }
            else {
                Edentity.ClickLock.ActionComplete(unlockKey);
                Doritos.Controls.Login.OpenDialog();

            }
        });

    }

    VideoDetails.AddToFavourites = function() {
        if (CurrentContestPhase >= 4) {
            return;
        }

        var LockKey = "AddToFavourites";


        Edentity.ClickLock.PerformAction(LockKey, function(unlockKey) {
            if (Doritos.ContextUtil.IsAuthenticated() || Doritos.ContextUtil.JustOneTimeAuthenticated()) {

                var searchString = "ProfileID = " + Doritos.ContextUtil.GetCurrentUserID() + " && SubmissionID = " + SubmissionID;

                if (Doritos.ContextUtil.GetJustOneTimeUserID().length > 0) {
                    searchString += " && JustOneTimeUser = '" + Doritos.ContextUtil.GetJustOneTimeUserID() + "'";
                }

                var searchArg = {
                    RecordTypeName: "VideoFavourites",
                    PageSize: 1,
                    RecordOffset: 0,
                    Search: searchString
                }


                Agility.UGC.API.SearchRecords(searchArg, function(data) {
                    if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
                        Edentity.ClickLock.ActionComplete(unlockKey);
                    } else {

                        if (data.ResponseData.Records.length == 0) {

                            var favRecord = {
                                RecordTypeName: "VideoFavourites",
                                ProfileID: Doritos.ContextUtil.GetCurrentUserID(),
                                SubmissionID: SubmissionID,
                                JustOneTimeUser: Doritos.ContextUtil.GetJustOneTimeUserID()
                            }

                            Agility.UGC.API.SaveRecord(favRecord, function(actSaveData) {
                                if (actSaveData.ResponseType != Agility.UGC.API.ResponseType.OK) {
                                    Edentity.ClickLock.ActionComplete(unlockKey);
                                    return;
                                } else {


                                    Doritos.FacebookUtil.PublishFaveToWall(VideoTitle, BitlyLink, null);
                                    VideoDetails.LoadFavCount();
                                    Edentity.ClickLock.ActionComplete(unlockKey);
                                }
                            });

                        }
                    }
                });


            }
            else {
                Doritos.Controls.Login.OpenDialog();
                FavCallInProgress = false;
            }
        });


    }
    VideoDetails.LoadFavCount = function() {



        var searchArg = {
            RecordTypeName: "VideoFavourites",
            PageSize: 1,
            RecordOffset: 0,
            Search: "SubmissionID = " + SubmissionID
        }


        Agility.UGC.API.SearchRecords(searchArg, function(data) {
            $("#FavCount").html(data.ResponseData.TotalRecords);
        });

        if (Doritos.ContextUtil.IsAuthenticated() || Doritos.ContextUtil.JustOneTimeAuthenticated()) {

            var searchString = "SubmissionID = " + SubmissionID + " && ProfileID = " + Doritos.ContextUtil.GetCurrentUserID();

            if (Doritos.ContextUtil.GetJustOneTimeUserID().length > 0) {
                searchString += " && JustOneTimeUser = '" + Doritos.ContextUtil.GetJustOneTimeUserID() + "'";
            }

            var searchArg = {
                RecordTypeName: "VideoFavourites",
                PageSize: 1,
                RecordOffset: 0,
                Search: searchString
            }


            Agility.UGC.API.SearchRecords(searchArg, function(data) {
                if (data.ResponseData.TotalRecords > 0) {
                    var favbutton = $("#FavButton");
                    favbutton.attr("src", Agility.ResolveUrl(UnFavButton));
                    favbutton.unbind("click");
                    favbutton.bind("click", function() {
                        Doritos.Modules.VideoDetails.UnFav();
                    });
                }
                else {
                    var favbutton = $("#FavButton");

                    favbutton.unbind("click");
                    favbutton.bind("click", function() {
                        Doritos.Modules.VideoDetails.AddToFavourites();
                    });
                }
            });
        }
        else {
            var favbutton = $("#FavButton");

            favbutton.unbind("click");
            favbutton.bind("click", function() {
                Doritos.Modules.VideoDetails.AddToFavourites();
            });
        }
    }

    VideoDetails.UnFav = function() {
        if (CurrentContestPhase >= 4) {
            return;
        }
        if (Doritos.ContextUtil.IsAuthenticated() || Doritos.ContextUtil.JustOneTimeAuthenticated()) {
            var searchString = "SubmissionID = " + SubmissionID + " && ProfileID = " + Doritos.ContextUtil.GetCurrentUserID();

            if (Doritos.ContextUtil.GetJustOneTimeUserID().length > 0) {
                searchString += " && JustOneTimeUser = '" + Doritos.ContextUtil.GetJustOneTimeUserID() + "'";
            }

            var searchArg = {
                RecordTypeName: "VideoFavourites",
                PageSize: 1,
                RecordOffset: 0,
                Search: searchString
            }



            Agility.UGC.API.SearchRecords(searchArg, function(data) {

                if (data.ResponseData.TotalRecords > 0) {
                    var id = data.ResponseData.Records[0].ID;

                    Agility.UGC.API.DeleteRecord(id, function(data) {

                        if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
                            alert(data.Message);
                        } else {
                            var favbutton = $("#FavButton");
                            favbutton.unbind("click");
                            favbutton.attr("src", Agility.ResolveUrl(FavButton));

                            favbutton.bind("click", function() {
                                Doritos.Modules.VideoDetails.AddToFavourites();
                            });

                            Doritos.Modules.VideoDetails.LoadFavCount();
                        }
                    });
                }
            });
        }
    }

    VideoDetails.LoadVideoEmbed = function() {
        var player = ytplayer = document.getElementById("VideoDetailsPlayer");

        try {
            $("#txtEmbedCode").val(player.getVideoEmbedCode());
        }
        catch (e) { }
    }

    VideoDetails.CheckBitlyUrl = function() {


        var bitlyUrl = $("#txtBitlyUrl").val();




        if (bitlyUrl == null || bitlyUrl.length == 0) {
            //no bitlyUrl available... try to get it.
            var url = "http://www.doritosviralocity.ca/gallery/videodetails.aspx?v=" + SubmissionID;

            BitlyClient.shorten(url, 'Doritos.Modules.VideoDetails.SaveBitlyURL');
        }
        else {
            BitlyLink = bitlyUrl;
        }


    }

    VideoDetails.SaveBitlyURL = function(data) {

        var first_result;
        // Results are keyed by longUrl, so we need to grab the first one.
        for (var r in data.results) {
            first_result = data.results[r]; break;
        }

        var bitlyUrl = first_result["shortUrl"];

        var title = $("#VideoTitle").html().replace(/^\s+|\s+$/g, "");


        BitlyLink = bitlyUrl;
        $("#txtBitlyUrl").val(bitlyUrl);

    }

    VideoDetails.LoadFacebookButton = function() {
        $(".fb_share_no_count").removeClass("fb_share_no_count");
        var div = $(".fb_share_count_nub_top");
        div.addClass("FacebookNub");
    }


    VideoDetails.LoadComments = function() {
        if (CurrentContestPhase >= 4) {
            return;
        }



        $.ajax({
            type: "POST",
            url: AgilityData_WebserviceUrl + '/GetSubmissionComments',
            data: "{'submissionID': " + SubmissionID + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",

            success: function(result) {
                if (result.d.length > 0) {
                    VideoDetails.RenderComments(result.d);

                }
            },
            complete: function(XMLHttpRequest, textStatus) {
                //alert(XMLHttpRequest.status + ' ' + textStatus);
                //alert(XMLHttpRequest.responseText);
            }
        });


    }

    VideoDetails.RenderComments = function(data) {
        if (CurrentContestPhase >= 4) {
            return;
        }
        var CommentArea = $("#CommentArea");


        var templateUrl = Agility.ResolveUrl("~/ClientTemplates/VideoComment.htm");
        CommentArea.setTemplateURL(templateUrl);
        CommentArea.setParam("ReportAbuse", "Report Abuse");
        CommentArea.processTemplate(data);
    }

    VideoDetails.FlagComment = function(CommentID) {
        if (CurrentContestPhase >= 4) {
            return;
        }
        ReportAbuseDialog = $("#ReportAbuseDialog").dialog({
            autoOpen: false,
            modal: true,
            closeText: 'hide',
            dialogClass: 'ReportAbuseDialog',

            resizable: false
        });

        ReportAbuseDialog.dialog("open");

        $("#ReportAbuseButton").unbind("click");
        $("#ReportAbuseButton").bind("click", function() {
            Doritos.Modules.VideoDetails.ReportAbuse(CommentID);
        });

    }

    VideoDetails.ReportAbuse = function(CommentID) {
        if (CurrentContestPhase >= 4) {
            return;
        }
        var reason = $("#ReportAbuseDialog select").val();


        Agility.UGC.API.SetRecordFlag(CommentID, Agility.UGC.API.RecordFlag.Abuse, reason, function(data) {


            ReportAbuseDialog.dialog("close");

            if (lang == "fr-ca") {
                alert("Merci");
            }
            else {
                alert("Thank you");
            }

        });

    }

    VideoDetails.SubmitComment = function() {
        
        if (CurrentContestPhase >= 4) {
            return;
        }

        if (Doritos.ContextUtil.IsAuthenticated() || Doritos.ContextUtil.JustOneTimeAuthenticated()) {

            var username = Doritos.ContextUtil.GetCurrentDisplayName();
            var userid = Doritos.ContextUtil.GetCurrentUserID();
            var comment = $("#txtComment").val();
            var videoID = SubmissionID;
            if (comment.length == 0) {
                return;
            }


            if (Doritos.ContextUtil.JustOneTimeAuthenticated()) {
                username = Doritos.ContextUtil.GetJustOneTimeUserDisplayName();
            }



            var commentRecord = {
                RecordTypeName: "SubmissionComment",
                SubmissionID: videoID,
                Username: username,
                Comment: comment,
                SubmittedByUserID: userid,
                JustOneTimeUser: Doritos.ContextUtil.GetJustOneTimeUserID()
            }

            Agility.UGC.API.SaveRecord(commentRecord, function(actSaveData) {
                if (actSaveData.ResponseType != Agility.UGC.API.ResponseType.OK) {
                    return;
                } else {

                    try {
                        Doritos.InvalidateCache.Remove("comment", SubmissionID);
                    }
                    catch (err) { }

                    Doritos.FacebookUtil.PublishCommentToWall(VideoTitle, BitlyLink, comment, null);

                    VideoDetails.LoadComments();
                }
            });

            $("#txtComment").val("");
        }
        else {
            Doritos.Controls.Login.OpenDialog();
            return;
        }


    }



    VideoDetails.GetPointImageString = function(totalPoints) {

        var pointsString = totalPoints.toString().replace(/^\s+|\s+$/g, "").toString();
        var imageString = "";


        for (var i = 0; i <= (7 - pointsString.length) - 1; i++) {

            imageString += "<img src=\"" + Agility.ResolveUrl("~/img/PointNumbers/large/0_off.png") + "\"/>";
        }

        for (var j = 0; j < pointsString.length; j++) {
            var value = pointsString.substring(j, j + 1);
            imageString += "<img src=\"" + Agility.ResolveUrl("~/img/PointNumbers/large/" + value + ".png") + "\"/>";


        }



        return imageString;
    }



})(Doritos.Modules.VideoDetails);





