﻿$(document).ready(function() {
  $("#btnSubmitVote").click(function() {
    $.post("response/post_vote.aspx", { radVoteValues: $('input[name=radVoteValues]:checked').val(),
      txtChannelID: $("#txtChannelID").val(),
      txtProgrammeID: $("#txtProgrammeID").val(),
      txtVideoID: $("#txtVideoID").val()
    },
    function(response) {
      $("#frmVoteResults").html(response).show();
      $("#frmVoteForm").hide();
    });
    return false;
  })
  $("#ddlRatings").change(function() {
    $.post("response/post_rating.aspx", { ddlRatings: $("#ddlRatings").val(), txtVideoID: $("#txtRatingVideoID").val()
    },
    function(response) {
      $("#divDDLRatings").html(response).show();
    });
    return false;
  })
  $("#btnSubmitEmail").click(function() {
    $.post("response/post_email_updates.aspx", { txtEmail: $("#txtEmail").val() },
    function(response) { $("#frmEmailSubscribe").html(response).show(); });
    return false;
  })
  $('#mycarousel').jcarousel();
  $("#carousel").css("visibility", "visible");
  $('input[type="text"]').livequery('focus', function() {
    //alert('clicked');
  });
  $('[class=btnReplySave]').livequery('click', function() {
    $('[class^=commentitem-commentlink]').hide();
    window.open("", "myNewWin", "width=500,height=300,toolbar=0");
  });
  $('div.commentrow').livequery(function() {
    $('[class^=commentitem-commentlink]').hide();
    //    $(".btnSubmitReply").click(function() {
    //      $.get("response/post_comment.aspx", { txtComment: $("#txtComment").val(),
    //        txtNickname: $("#txtNickname").val(),
    //        txtCommentID: $("#txtCommentID").val(),
    //        txtVideoID: $("#txtVideoID").val()
    //      },
    //      function(response) {
    //        alert(response);
    //      });
    //      return false;
    //    })
  });
});
function PostComment() {
  $.post("response/post_comment.aspx", { txtNewComment_Comment: $("#txtNewComment_Comment").val(),
    txtNickname: $("#txtNewComment_Nickname").val(),
    txtCaptcha: $("#txtCaptcha").val(),
    txtCommentID: $("#txtNewComment_CommentID").val(),
    txtVideoID: $("#txtNewComment_VideoID").val()
  },
  function(response) {
    alert(response);
  });
  $("#txtNewComment_Comment").val('');
  $("#txtNewComment_Nickname").val('');
  $("#txtCaptcha").val('')
  GetCommentsResult('1', $("#txtNewComment_VideoID").val(), '', ''); 
  return false;
}
function PostThumbUpDown(thispage, videoid, commentid, thumb) {
  var URL = "response/post_thumbupdown.aspx?c_id=" + commentid + "&thumb=" + thumb;
  $.get(URL, null, function(data) {
    GetCommentsResult(thispage, videoid, '', '');
  });
}
function PostThumbUpDownAllComments(thispage, videoid, commentid, thumb) {
  var URL = "response/post_thumbupdown.aspx?c_id=" + commentid + "&thumb=" + thumb;
  $.get(URL, null, function(data) {
  GetAllCommentsResult(thispage, videoid, '', '');
  });
}


function GetCommentsResult(page, search, ord, sor) {
  $("#CommentsContent").fadeTo("slow", 0.33, CommentsCallback(page, search, ord, sor));
}
function CommentsCallback(page, search, ord, sor) {
  var URL = "response/get_comments.aspx?page=" + page + "&v=" + search + "&ord=" + ord + "&sor=" + sor;
  $.get(URL, null, function(data) {
    $("#CommentsContent").html(data);
    $("#CommentsContent").fadeTo("slow", 1);
    window.location = "#top";
  });
}

function GetAllCommentsResult(page, search, ord, sor) {
  $("#CommentsContent").fadeTo("slow", 0.33, AllCommentsCallback(page, search, ord, sor));
}
function AllCommentsCallback(page, search, ord, sor) {
  var URL = "response/get_all_comments.aspx?page=" + page + "&v=" + search + "&ord=" + ord + "&sor=" + sor;
  $.get(URL, null, function(data) {
    $("#CommentsContent").html(data);
    $("#CommentsContent").fadeTo("slow", 1);
  });
}




function GetEpisodesResult(page, searchParameters, ord, sor) {
  $("#WatchEpisodes").fadeTo("slow", 0.33, EpisodesCallback(page, searchParameters, ord, sor));
}
function EpisodesCallback(page, searchParameters, ord, sor) {
  var URL = "response/get_episodes.aspx?page=" + page + "&ord=" + ord + "&sor=" + sor + "&" + searchParameters;
  $.get(URL, null, function(data) {
    $("#WatchEpisodes").html(data);
    $("#WatchEpisodes").fadeTo("fast", 1);
  });
}


function GetVoteResults() {
  var URL = "response/get_vote_results.aspx?p=" + $("#txtProgrammeID").val() + "&v=" + $("#txtVideoID").val() + "&vote1=" + $("#txtVoteValue1").val() + "&vote2=" + $("#txtVoteValue2").val();
  $.get(URL, null, function(data) {
    $("#frmVoteResults").html(data);
    $("#frmVoteResults").show();
    $("#frmVoteForm").hide();
  });
}
function ShowVoteForm() {
  $("#frmVoteResults").hide();
  $("#frmVoteForm").show();
}
function ShowHideComment(id) {
  $('.commentitem-commentlink' + id).slideToggle();
  $("#fieldComment").html("test 123");
}
function SendReply() {
  window.open("", "myNewWin", "width=500,height=300,toolbar=0");
}
function watch_mycarousel_itemLoadCallback(carousel, state) {
  if (state != 'init')
    return;
  jQuery.get('watch_carousel.aspx', function(data) {
    watch_mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
  });
};
function watch_mycarousel_itemAddCallback(carousel, first, last, data) {
  var items = data.split('|');
  for (i = 0; i < items.length; i++) {
    carousel.add(i + 1, items[i]);
  }
  carousel.size(items.length);
};
jQuery(document).ready(function() {
  jQuery('#watch_mycarousel').jcarousel({
    itemLoadCallback: watch_mycarousel_itemLoadCallback
  });
});