﻿
function CopyToClipboard()
{
    document.aspnetForm.ctl00_MainBodyPlaceHolder_videoEmbedTextField.focus();
    document.aspnetForm.ctl00_MainBodyPlaceHolder_videoEmbedTextField.select();
}

function expandDescription( boolExpand )
{
    var videoDescriptionSpan = document.getElementById("videoDescriptionSpan");

    if (boolExpand == true)
    {
        videoDescriptionSpan.innerHTML = HtmlDecode(encodedDescriptionLong);
        //Create the new <a>
        var anAnchor = document.createElement('a');
        anAnchor.href="javascript:expandDescription(false)";
        //Create a text node to hold the text of the <a>
        var anAnchorTextNode = document.createTextNode(" (less)");
        //Append the <a> text node to the <a> element
        anAnchor.appendChild(anAnchorTextNode);
        anAnchor.className = "smallText eLink";
        //Append the new link to the existing <div>
        videoDescriptionSpan.appendChild(anAnchor);
    }
    else 
    {
        videoDescriptionSpan.innerHTML = HtmlDecode(encodedDescriptionShort);
        var anAnchor = document.createElement('a');
        anAnchor.href = "javascript:expandDescription(true)";
        //Create a text node to hold the text of the <a>
        var anAnchorTextNode = document.createTextNode("...(more)");
        //Append the <a> text node to the <a> element
        anAnchor.appendChild(anAnchorTextNode);
        anAnchor.className = "smallText eLink";
        //Append the new link to the existing <div>
        videoDescriptionSpan.appendChild(anAnchor);
    }
    
    show_div("CategoriesAndTagsSection");
}


 /*******************************************************************************
 '
 ' Name        : changeCommentPager()
 '
 ' Description : Changes selected the comment pager button CSS class to "page_current"
 '               and changes the previously selected pager button css class to nothing
 '
 ' Arguments   : elementID  - the elementID of the pager button whose CSS class we want to change
 '     
 ' Returns     : Nothing     
 ' 
 '*******************************************************************************/
var currentSelectedCommentButtonTop = "ctl00_MainBodyPlaceHolder_top_lnkButton1";
var currentSelectedCommentButtonBottom = "ctl00_MainBodyPlaceHolder_bottom_lnkButton1";
 
function changeCommentPager(elementID)
{
    document.getElementById(currentSelectedCommentButtonTop).className = "";
    document.getElementById(currentSelectedCommentButtonBottom).className = "";

    elementID = elementID.replace(/bottom/,"top");
    document.getElementById(elementID).className = "page_current";
    currentSelectedCommentButtonTop = elementID;

    elementID = elementID.replace(/top/,"bottom");
    document.getElementById(elementID).className = "page_current";
    currentSelectedCommentButtonBottom = elementID;
}


// This remove function is not yet in use keeping it there just in case
function removeElement() 
{
    var d = document.getElementById("ctl00_MainBodyPlaceHolder_UpdatePanel1");
    var olddiv = document.getElementById("commentsDiv");
    d.removeChild(olddiv);
}


function show_div(div_id)
{
    if (document.getElementById(div_id).className == "collapsed-content")
    {
        document.getElementById(div_id).className = "expanded";
    }
    else
    {
        document.getElementById(div_id).className = "collapsed-content";
    }
}


/*----------------------------------
     Video Player Methods
----------------------------------*/


var originalPlayerDiv  = "";
  
function addVideoPlayer()
{
    // Collapse the player Placeholder
    document.getElementById("PlayerFullScreenPlaceHolder").className = "collapsed-content";
    // Get the VideoPlayer DIV
    var videoPlayerContainer = document.getElementById("videoPlayerContainer");
    // Append the previously removed player into it
    videoPlayerContainer.appendChild(originalPlayerDiv);
}

function removeVideoPlayer() 
{
    var videoPlayerContainer = document.getElementById("videoPlayerContainer");
    var videoPlayerElement = document.getElementById("videoPlayer");
    // Make a copy of the videoPlayer so it can be inserted later if
    // the user wants it.
    originalPlayerDiv = videoPlayerElement;
    videoPlayerContainer.removeChild(videoPlayerElement);
    document.getElementById("PlayerFullScreenPlaceHolder").className = "videoPlaceHolder";
}


/*----------------------------------
     Video Commments Methods
----------------------------------*/

var currentCommentPage = 0;

function GetComments(pageNumber)
{
    if (pageNumber == null)
    {
        pageNumber = 1;
    }

    // If the current page number is selected there no need to call web service
  //  if (currentCommentPage != pageNumber || pageNumber == -1)
  //  {
  
  isLoggedIn = false;
  
  if(loggedInYouTube == true && videoType == "yt")
  {
    isLoggedIn = true;
  }
  
 // if(loggedInVeoh == true  && videoType == "vo" )
  //{
  //  isLoggedIn = true;
 // }
  
        // Show the comments AJAX loader
        document.getElementById("commentsLoaderGIF").className = "expanded";
        CommentsService.GetComments(videoID, pageNumber, videoType, videoAuthor, isLoggedIn, commentsSuccess, commentsFail); 
  //  }

    currentCommentPage = pageNumber;
}


function commentsSuccess(result, eventArgs) 
{
    // The comment results webservice returns an array of up to 4 seperate result enities
    // result[0] = Number of video comments
    // result[1] = Comment Results / No Comments / Error Message
    // result[2] = Error Code
    
    // Hide the comments AJAX loader
    document.getElementById("commentsLoaderGIF").className = "collapsed-content";
    
    // Get a comments AJAX placeholder reference
    var commentsPlaceHolderElement = document.getElementById("commentsPlaceHolder");
    // Get a reference to the number of comments label
    var lblNoOfComments = document.getElementById(lblNoOfCommentsID);

    // Switch on error code
    // Default option is means no error, display comments
    switch (result[2]) 
    {
        case "youTubeNoVideoCommentsFound":
            commentsPlaceHolderElement.innerHTML = result[1];

            document.getElementById("ctl00_MainBodyPlaceHolder_noCommentsAd").style.display = "";

            switch (videoType) 
            {
                case "yt":
                    
                    if (loggedInYouTube == true)
                    {
                        document.getElementById("commentsContainer").style.height = "170px";
                    }
                    else 
                    {
                        document.getElementById("commentsContainer").style.height = "100px";
                    }
                    break;
                case "vo":
                    document.getElementById("commentsContainer").style.height = "90px";
                    break;
            }

            break;
        case "youTubeVideoCommentsDisabled":
        case "veohVideoCommentsDisabled":

            // Display the disabled comments message in the placeholder.
            commentsPlaceHolderElement.innerHTML = result[1];
            // Display the hidden top right advert.
            document.getElementById("ctl00_MainBodyPlaceHolder_noCommentsAd").style.display = "";

            switch (videoType) 
            {
                case "yt":
                
                    if (loggedInYouTube == false) 
                    {
                        document.getElementById("logOnToCommentDiv").className = "collapsed-content";
                    }
                    else 
                    {
                        document.getElementById(mainCommentDivID).className = "collapsed-content";
                    }
                    break;
                    
                case "vo":
                    document.getElementById("commentsMessage").style.display = "none";
                    break;
            }
           
            document.getElementById("commentsContainer").style.height = "45px";
            break;
        default:
            lblNoOfComments.innerHTML = "(" + result[0] + ")";
            // Display the result of the comments webservice in the placeholder.
            commentsPlaceHolderElement.innerHTML = result[1];
        break;
    
    }
}


function commentsFail(error) {

    document.getElementById("commentsLoaderGIF").className = "collapsed-content";

    // Display the error.    
    var commentsPlaceHolderElement =    document.getElementById("commentsPlaceHolder");
    commentsPlaceHolderElement.innerHTML = "";
    
}




/*----------------------------------
     Related Videos Methods
----------------------------------*/

var currentRelatedVideosPage = 0;
var currentRelatedVideosOrderBy = "relevance";

function GetRelatedVideos(pageNumber, orderBy)
{

    if (currentRelatedVideosOrderBy != orderBy)
    {
        // The user has just changed the orderBy of relatedVideos
       // ManageOrderByLinks("Related", orderBy);
        //currentRelatedVideosOrderBy = orderBy;
    }


    if (pageNumber == null)
    {
        pageNumber = 1;
    }

    if (orderBy == null)
    {
        orderBy = "relevance";
    }


    if (currentRelatedVideosPage != pageNumber || pageNumber == 1)
    {
        // Show the comments AJAX loader
        document.getElementById("relatedLoaderGIFTop").className = "expanded";
        document.getElementById("relatedLoaderGIFBottom").className = "expanded";

        RelatedVideosService.GetRelatedVideos(videoID, pageNumber, videoType, videoGridSize, orderBy, familyFilterOn, videoDisplayModeRelatedVideos, GetRelatedVideosSuccess, GetRelatedVideosFail);
    }
    currentRelatedVideosPage = pageNumber;
}


function GetRelatedVideosSuccess(result, eventArgs)
{ 

    // Hide the comments AJAX loader
    document.getElementById("relatedLoaderGIFTop").className = "collapsed-content";
    document.getElementById("relatedLoaderGIFBottom").className = "collapsed-content";
    
    // Display the result of the comments webservice in the placeholder.
    var RelatedVideosPlaceHolder = document.getElementById("RelatedVideosPlaceHolder");
    RelatedVideosPlaceHolder.innerHTML = result;
}


function GetRelatedVideosFail(error)
{
    // Hide the comments AJAX loader
    document.getElementById("relatedLoaderGIFTop").className = "collapsed-content";
    document.getElementById("relatedLoaderGIFBottom").className = "collapsed-content";
    
    // Display the error.    
    var commentsPlaceHolderElement = document.getElementById("RelatedVideosPlaceHolder");
    commentsPlaceHolderElement.innerHTML =  "Service Error: " + error.get_message();
}

/*----------------------------------
     User Videos Methods
----------------------------------*/

var currentUserVideoPageNo = 0;
var currentUserVideoOrderBy = "relevance";
//var videoUserVideoOrderByChanged = false;
var hasUserVideoRunOnce = false;

function GetUserVideos(pageNumber, orderBy, fromProxy)
{
    if (hasUserVideoRunOnce  == false && fromProxy == true || fromProxy == null)
    {
        if (currentUserVideoOrderBy != orderBy)
        {
            // The user has just changed the orderBy of videoResponses
            //ManageOrderByLinks("User", orderBy);
          //  currentUserVideoOrderBy = orderBy;
           // videoResponsesOrderByChanged = true;
        }

        //switch (videoType) 
      //  {
          //  case "yt":
                ManageOrderByLinks("User", orderBy);
            //    break;
          //  case "vo":
            //    ManageOrderByLinks("VeohUser", orderBy);
             //   break;
        
       // }


        if (pageNumber == null  && currentUserVideoPageNo == 0)
        {
            pageNumber = 1;
        }


        // If the current page number is selected there no need to call web service
        //if ((currentUserVideoPageNo != pageNumber && pageNumber != null ) || videoResponsesOrderByChanged == true)
       // {
            // Show the comments AJAX loader
        document.getElementById("userLoaderGIFTop").className = "expanded";
        document.getElementById("userLoaderGIFBottom").className = "expanded";

            // Make the AJAX call to the webservice to retrieve any user videos
            UserVideosService.GetUserVideos(videoAuthor, videoType, pageNumber, videoGridSize, orderBy, familyFilterOn, videoDisplayModeUserVideos, getUserVideosSuccess, getUserVideosFail);

            videoResponsesOrderByChanged = false;
            hasUserVideoRunOnce = true;
       // }

        currentUserVideoPageNo = pageNumber;
    }
}

function getUserVideosFail(error)
{
    alert("User Videos Method Fail!");
    // Hide the comments AJAX loader
    document.getElementById("userLoaderGIFTop").className = "collapsed-content";
    document.getElementById("userLoaderGIFBottom").className = "collapsed-content";

    // Display the error.    
    //  var commentsPlaceHolderElement = document.getElementById("RelatedVideosPlaceHolder");
    //  commentsPlaceHolderElement.innerHTML =  "Service Error: " + error.get_message();
    //  "Service Error: " + error.get_message();
}

function getUserVideosSuccess(result, eventArgs)
{
    //  alert("User Videos Method Success!");

    // Hide the comments AJAX loader
    document.getElementById("userLoaderGIFTop").className = "collapsed-content";
    document.getElementById("userLoaderGIFBottom").className = "collapsed-content";

    // Display the result of the comments webservice in the placeholder.
    var RelatedVideosPlaceHolder = document.getElementById("userVideosPlaceHolder");
    RelatedVideosPlaceHolder.innerHTML = result;
}

// Got to use a proxy function call to GetUserVideos from the tab clicked event
// as the function signatures are different.
function userVideosClicked(sender, e) 
{
    GetUserVideos(1, "relevance", true);
}



/*------------------------------------
           Comments
------------------------------------ */

function showCommentReplyField()
{
    if(!CheckYouTubeLogin() || !CheckVeohLogin())
    {
        alert("Please login to your " + videoTypeName + " account to post a comment.");
    }

    return false;
}



function updateCharCount(charCount_id, label_id, textArea) 
{
    var msg = new Object();
    msg["exceeded"] = "No of characters over the limit: ";
    msg["remaining"] = "Remaining character count: ";
    updateCharCount_js(charCount_id, label_id, textArea, 500, msg);
}



function updateCharCount_js(charCount_id,label_id,textArea,maxChars,messages)
{
    if(textArea.value.length>maxChars)
    {
        if(document.getElementById(label_id).innerHTML != messages["exceeded"])
        {
            document.getElementById(label_id).innerHTML = messages["exceeded"];
        }

        document.getElementById(charCount_id).value = textArea.value.length-maxChars;
        document.getElementById(charCount_id).style.background =  "red";
    }
    else
    {
        if(document.getElementById(label_id).innerHTML != messages["remaining"])
        {
            document.getElementById(label_id).innerHTML = messages["remaining"];
        }

        document.getElementById(charCount_id).value = maxChars-textArea.value.length;
        document.getElementById(charCount_id).style.background = "#fafafa";
    }
}


function postThreadedComment(comment_form_id) 
{
    var msg = new Object();
    msg["add"] = "Adding comment...";
    postThreadedComment_js(comment_form_id, msg);
}


function postThreadedComment_js(comment_form_id , messages)
{
    var form = document.getElementById(comment_form_id);

    if(ThreadedCommentHandler(form,comment_form_id))
    {
        //  var add_button = form.add_comment_button;
        // add_button.value = messages["add"];
        //  form.comment.disabled = true;
        //  add_button.disabled = true;
    }  
}

function ThreadedCommentHandler(comment_form, comment_form_id) 
{
    var msg = new Object();
    msg["empty"] = "You must enter a comment!";
    msg["toolong"] = "Your comment must be shorter than 500 characters!";
    ThreadedCommentHandler_js(comment_form, comment_form_id, msg);
}
	
	
var comment_button; 
	
function ThreadedCommentHandler_js(comment_form, comment_form_id, messages)
{
    var comment = document.getElementById("comment_"  + comment_form_id);
    comment_button = document.getElementById("add_comment_button_"  + comment_form_id);

    if(comment.value.length == 0 || comment.value == null)
    {
        alert(messages["empty"]);
        comment.disabled = false;
        comment.focus();
        return false;
    }

    if(comment.value.length > 500)
    {
        alert(messages["toolong"]);
        comment.disabled = false;
        comment.focus();
        return false;
    }

    postComment(comment , "something");
}




function postComment(comment, replyCommentID)
{
    comment_button.value = "Comment posting...";
    PostCommentService.PostComment(videoID, null, videoTypeName, comment.value, youTubeSessionToken, postCommentSuccess, postCommentFail);
}

function postCommentFail(error)
{
    // alert("Post Comments Videos Method Fail!");
    var errorMessage = error.get_message();
    // alert(message);
    var errorMessageFeild = document.getElementById("messagePostError");

    var message = "<div class=\"userMessage\" style=\"width:100%\">";
    message += errorMessage;
    message += "</div>";

    // pageHolder.Controls.Add(new LiteralControl("<div class=\"userMessage\" style=\"width:95%\">"));
    // pageHolder.Controls.Add(new LiteralControl("No Comments"));
    //    pageHolder.Controls.Add(new LiteralControl("</div>"));

    errorMessageFeild.innerHTML = message;

    comment_button.value = "Comment Rejected!";
    comment_button.disabled = true;
}

function postCommentSuccess(result, eventArgs)
{
    // alert("Post Comment Success!");
    comment_button.value = "Comment Posted!";

    comment_button.disabled = true;
    
    
    setTimeout("GetComments()",1000);
}


/*----------------------------------
     User Videos Methods
----------------------------------*/

var currentVideoResponsesPageNo = 0;
var currentVideoResponsesOrderBy = "relevance";
var videoResponsesOrderByChanged = false;
var hasVideoResponsesRunOnce = false;

function GetVideoResponses(pageNumber, orderBy, fromProxy)
{
    if (hasVideoResponsesRunOnce == false && fromProxy == true || fromProxy == null)
    {
        if (currentVideoResponsesOrderBy != orderBy)
        {
            // The user has just changed the orderBy of videoResponses
            ManageOrderByLinks("Responses", orderBy);
            currentVideoResponsesOrderBy = orderBy;
            videoResponsesOrderByChanged = true;
        }

        if (pageNumber == null  && currentVideoResponsesPageNo == 0)
        {
            pageNumber = 1;
        }

        // If the current page number is selected there no need to call web service
        if ( (currentVideoResponsesPageNo != pageNumber && pageNumber != null) || ( videoResponsesOrderByChanged == true) || (hasVideoResponsesRunOnce == false))
        {
            // Show the comments AJAX loader
            document.getElementById("videoResponsesLoaderGIFTop").className = "expanded";
            document.getElementById("videoResponsesLoaderGIFBottom").className = "expanded";

            // Make the AJAX call to the webservice to retrieve any user videos
            VideoResponsesService.GetVideoResponses(videoID, pageNumber, videoType, orderBy, familyFilterOn, videoDisplayModeVideosResponses, GetVideoResponsesSuccess, GetVideoResponsesFail);

            videoResponsesOrderByChanged = false;
            hasVideoResponsesRunOnce = true;
        }
        
        currentVideoResponsesPageNo = pageNumber;
    }
}


function GetVideoResponsesFail(error)
{
    // Hide the comments AJAX loader
    document.getElementById("videoResponsesLoaderGIFTop").className = "collapsed-content";
    document.getElementById("videoResponsesLoaderGIFBottom").className = "collapsed-content";

    // Display the error.    
    var message =   "Service Error: " + error.get_message();

    var videosResponsesPlaceHolder = document.getElementById("videosResponsesPlaceHolder");
    videosResponsesPlaceHolder.innerHTML = message;
}

function GetVideoResponsesSuccess(result, eventArgs)
{
    // Hide the comments AJAX loader
    document.getElementById("videoResponsesLoaderGIFTop").className = "collapsed-content";
    document.getElementById("videoResponsesLoaderGIFBottom").className = "collapsed-content";

    // Display the result of the comments webservice in the placeholder.
    var videosResponsesPlaceHolder = document.getElementById("videosResponsesPlaceHolder");
    videosResponsesPlaceHolder.innerHTML = result;
}

// Got to use a proxy function call to GetUserVideos from the tab clicked event
// as the function signatures are different.
function GetVideoResponsesClicked(sender, e) 
{
    GetVideoResponses(1, "relevance", true);
}



/*----------------------------------
     Rating Methods
----------------------------------*/


function onMouseOver(source, args) 
{    
    var label =  document.getElementById(ratingLabelID);

    if(CheckYouTubeLogin() == true || CheckVeohLogin() == true)
    {
        switch(args.get_Rating())
        {   
            case 1:
                label.innerHTML = "Poor";
                break;    
            case 2:
                label.innerHTML = "Nothing Special";
                break;
            case 3:
                label.innerHTML = "Worth Watching";
                break; 
            case 4:
                label.innerHTML = "Petty Cool";
                break; 
            case 5:
                label.innerHTML = "Excellent";
                break; 
            default:
                label.innerHTML = "";
        }
    }

    
        if(videoType == "yt" && CheckYouTubeLogin() == false )
        {
            label.innerHTML = "Please log in to Rate";
        }
        else if (videoType == "vo")
        {
            label.innerHTML = "<b>Unable to rate<br/> Veoh Videos</b>";
            
        }
    
}
    
function onMouseDown(source, args) 
{ 
    if ((loggedInYouTube == true && videoType == "yt"))
    {
        disableRating();

        var label =  document.getElementById(ratingLabelID);
        label.innerHTML = "Posting rating...";
        var rating = args.get_Rating();
        RatingsService.PostRating(videoID, rating, videoTypeName, youTubeSessionToken, postRatingSuccess, postRatingFail);
    } 
    
    
}
    
function postRatingFail(error)
{
    alert("Sorry we could not post your rating, please try again later.");
    var label =  document.getElementById(ratingLabelID);
    
     if (videoType == "vo")
     {
     label.innerHTML = "Unable to rate Veoh Videos";
     }
     else if (videoType == "yt")
     {
        label.innerHTML = "Sorry, please try again.";
    }
}


function postRatingSuccess(result, eventArgs)
{
    var label =  document.getElementById(ratingLabelID);
    label.innerHTML = "Thanks for Rating";
}

    
function onMouseOut(source, args) 
{    
    var label =  document.getElementById(ratingLabelID);
    label.innerHTML = noOfRatingMessage;
}
    
    
function disableRating()
{
    var elt = $find('RatingBehavior1').get_element();
    $find("RatingBehavior1").set_ReadOnly(true);
}





function AddFavourtite()
{
    if (loggedInYouTube == true && videoType == "yt")
    {
        FavoritesService.AddFavourite(videoID, youTubeSessionToken, AddFavourtiteSuccess, AddFavourtiteFail);
    }
    else if (loggedInYouTube == false && videoType == "yt")
    {
        var actionMessageField = document.getElementById("actionMessage");
        var message = "<div class=\"userMessage\" style=\"width:95%; margin-left:6px; margin-top:6px; background:#d1f0b3\">";
        message += "<b>Want to add to Favorites? Sign in to your <a href=\"" + youTubeLogInUrl +  "\" style=\"text-decoration:none\">YouTube</a> account.</b>";
        message += "</div>";
        actionMessageField.innerHTML = message;
    }
    else if (videoType == "vo")
    {
        alert("Sorry your unable to favorite Veoh Videos.")
    }

}

function AddFavourtiteSuccess(result, eventArgs)
{
    var actionMessageField = document.getElementById("actionMessage");
    var message = "<div class=\"userMessage\" style=\"width:95%; margin-left:6px; margin-top:6px; background:#d1f0b3\">";
    message += "<b>This video has been added to your favorites</b>";
    message += "</div>";
    actionMessageField.innerHTML = message;
    setTimeout("removeMessage(actionMessage)",6000);
}

function removeMessage(fieldToRemove)
{
    var actionMessageField = document.getElementById("actionMessage");
    actionMessageField.innerHTML = "";
}


function AddFavourtiteFail(error)
{
    var actionMessageField = document.getElementById("actionMessage");
    var message = "<div class=\"userMessage\" style=\"width:95%; margin-left:6px; margin-top:6px; background:#d1f0b3\">";
    message += "<b>Opps, sorry there was an error and we were unable to add this to your favorites.  The error has been logged of us. <br />Please try again later.</b>";
    message += "</div>";
    actionMessageField.innerHTML = message;
}


/*----------------------------------
        Rating Methods
----------------------------------*/

// Got to use a proxy function call to GetUserVideos from the tab clicked event
// as the function signatures are different.
function GetVideoFavoritesClicked(sender, e) {
   // alert("here");
    GetFavoritiedVideo(1, "relevance", true);
}


var currentUserVideoPageNo = 0;
var currentVideoFavoritesOrderBy = "relevance";
//var videoUserVideoOrderByChanged = false;
var hasGetFavoritedRunOnce = false;

function GetFavoritiedVideo(pageNumber, orderBy, fromProxy) 
{
  //  alert("here1");
    if (hasGetFavoritedRunOnce == false && fromProxy == true || fromProxy == null)
    {
        hasGetFavoritedRunOnce = true;
    
    
        //if (currentUserVideoOrderBy != orderBy)
        // {
        if (videoType == "yt")
        {

            ManageOrderByLinks("Favorites", orderBy);
        }
       

        if (pageNumber == null && currentUserVideoPageNo == 0)
        {
            pageNumber = 1;
        }

      //  alert("here2")
        // Show the comments AJAX loader
        document.getElementById("favoriteLoaderGIFTop").className = "expanded";
        document.getElementById("favoriteLoaderGIFBottom").className = "expanded";

        // alert(familyFilterOn);
        // Make the AJAX call to the webservice to retrieve any user videos
        FavoritesVideoService.GetFavoriteVideos(videoAuthor, pageNumber, videoType, videoGridSize, orderBy, familyFilterOn, videoDisplayModeVideosFavorites, getVideoFavoritesSuccess, getVideoFavoritesFail);
       // alert("here3")
      //  videoResponsesOrderByChanged = false;
       // hasUserVideoRunOnce = true;
        // }

        //currentUserVideoPageNo = pageNumber;

        currentVideoFavoritesOrderBy = orderBy
    }
}

function getVideoFavoritesSuccess(result, eventArgs) {
     // alert("Favourited Videos Method Success!");

    // Hide the comments AJAX loader
      document.getElementById("favoriteLoaderGIFTop").className = "collapsed-content";
      document.getElementById("favoriteLoaderGIFBottom").className = "collapsed-content";
    

    // Display the result of the comments webservice in the placeholder.
      var RelatedVideosPlaceHolder = document.getElementById("videoFavoritesPlaceHolder");
    RelatedVideosPlaceHolder.innerHTML = result;
}

// Got to use a proxy function call to GetUserVideos from the tab clicked event
// as the function signatures are different.
function getVideoFavoritesFail(result, eventArgs) {
      alert("Video Favorites Method Fail!");

    // Hide the comments AJAX loader
      document.getElementById("favoriteLoaderGIFTop").className = "collapsed-content";
      document.getElementById("favoriteLoaderGIFBottom").className = "collapsed-content";

    // Display the result of the comments webservice in the placeholder.
  //  var RelatedVideosPlaceHolder = document.getElementById("userVideosPlaceHolder");
   // RelatedVideosPlaceHolder.innerHTML = result;
  }





  /*----------------------------------
  Recommended Videos Methods
  ----------------------------------*/

  // Got to use a proxy function call to GetRecommendedVideos from the tab clicked event
  // as the function signatures are different.
  function recommendedVideosClickedProxy(sender, e) 
  {
      GetRecommendedVideos(1, true);
  }


  //var currentUserVideoPageNo = 0;
  //var currentUserVideoOrderBy = "relevance";
  ///var videoUserVideoOrderByChanged = false;
   var hasRecommendedVideoRunOnce = false;

   function GetRecommendedVideos(pageNumber, fromProxy) {

    
      if (hasRecommendedVideoRunOnce == false && fromProxy == true || fromProxy == null) 
      {
          if (pageNumber == null) 
          {
              pageNumber = 1;
          }


          // If the current page number is selected there no need to call web service
          //if ((currentUserVideoPageNo != pageNumber && pageNumber != null ) || videoResponsesOrderByChanged == true)
          // {
          // Show the comments AJAX loader
          document.getElementById("recommendedLoaderGIFTop").className = "expanded";
          document.getElementById("recommendedLoaderGIFBottom").className = "expanded";

          // Make the AJAX call to the webservice to retrieve recommended videos
          RecommendedVideosService.GetRecommendedVideos(pageNumber, veohSessionToken, videoGridSize, videoDisplayModeUserVideos, getRecommendedVideosSuccess, getRecommendedVideosFail);

         // videoResponsesOrderByChanged = false;
         hasRecommendedVideoRunOnce = true;
          // }

          currentUserVideoPageNo = pageNumber;
      }
  }

  function getRecommendedVideosSuccess(result, eventArgs) {
        //alert("Recommended Videos Method Success!");

      // Hide the comments AJAX loader
        document.getElementById("recommendedLoaderGIFTop").className = "collapsed-content";
        document.getElementById("recommendedLoaderGIFBottom").className = "collapsed-content";

      // Display the result of the recommended webservice in the placeholder.
        var recommendedVideosPlaceHolder = document.getElementById("RecommendedVideosPlaceHolder");
      recommendedVideosPlaceHolder.innerHTML = result;
  }

  function getRecommendedVideosFail(error) {
      alert("User Videos Method Fail!");
      // Hide the comments AJAX loader
      document.getElementById("recommendedLoaderGIFTop").className = "collapsed-content";
      document.getElementById("recommendedLoaderGIFBottom").className = "collapsed-content";

      // Display the error.    
      //  var commentsPlaceHolderElement = document.getElementById("RelatedVideosPlaceHolder");
      //  commentsPlaceHolderElement.innerHTML =  "Service Error: " + error.get_message();
      //  "Service Error: " + error.get_message();
  }




