﻿$(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;
    //    })
  });
  $("#btnSubmitSurvey").click(function () {
    if (SurveyCheck()) {
      $.post("response/post_survey.aspx", { chkSurveyGender_male: $('input[name=chkSurveyGender_male]:checked').val(),
        chkSurveyGender_female: $('input[name=chkSurveyGender_female]:checked').val(),
        chkSurveyAge_0_17: $('input[name=chkSurveyAge_0_17]:checked').val(),
        chkSurveyAge_18_24: $('input[name=chkSurveyAge_18_24]:checked').val(),
        chkSurveyAge_25_34: $('input[name=chkSurveyAge_25_34]:checked').val(),
        chkSurveyAge_35_44: $('input[name=chkSurveyAge_35_44]:checked').val(),
        chkSurveyAge_45_99: $('input[name=chkSurveyAge_45_99]:checked').val(),
        txtSurveyProgrammeID: $("#txtSurveyProgrammeID").val()
      },
      function (response) {
        $("#frmSurveyResponse").html(response).show();
        $("#frmSurveyForm").hide();
      });
    }
    return false;
  });
});
function SurveyCheck() {
  var ok = true;
  var chkSurveyGender_male = $('input[name=chkSurveyGender_male]:checked').val();
  var chkSurveyGender_female = $('input[name=chkSurveyGender_female]:checked').val();
  var chkSurveyAge_0_17 = $('input[name=chkSurveyAge_0_17]:checked').val();
  var chkSurveyAge_18_24 = $('input[name=chkSurveyAge_18_24]:checked').val();
  var chkSurveyAge_25_34 = $('input[name=chkSurveyAge_25_34]:checked').val();
  var chkSurveyAge_35_44 = $('input[name=chkSurveyAge_35_44]:checked').val();
  var chkSurveyAge_45_99 = $('input[name=chkSurveyAge_45_99]:checked').val();
  if ((chkSurveyGender_male != '1' && chkSurveyGender_female != '2') || (chkSurveyGender_male == '1' && chkSurveyGender_female == '2')) {
    alert('Select either Male or Female');
    ok = false;
  }
  else {
    var selectedCount = 0;
    if (chkSurveyAge_0_17 == "0_17") selectedCount++;
    if (chkSurveyAge_18_24 == "18_24") selectedCount++;
    if (chkSurveyAge_25_34 == "25_34") selectedCount++;
    if (chkSurveyAge_35_44 == "35_44") selectedCount++;
    if (chkSurveyAge_45_99 == "45_99") selectedCount++;
    if (selectedCount == 0) {
      alert('Select one of the age range');
      ok = false;
    }
    else if (selectedCount > 1) {
      alert('Select ONLY one of the age range');
      ok = false;
    }

  }
  return ok;
}
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) {
    var str_response = response;
    if (str_response == 'Security code is not correct') {
    }
    else {
      $("#txtNewComment_Comment").val('');
      $("#txtNewComment_Nickname").val('');
      $("#txtCaptcha").val('');
    }
    alert(response);
  });
  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() + "&vote3=" + $("#txtVoteValue3").val() + "&vote4=" + $("#txtVoteValue4").val() + "&vote5=" + $("#txtVoteValue5").val() + "&vote6=" + $("#txtVoteValue6").val() + "&vote7=" + $("#txtVoteValue7").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
  });
});
