﻿function GetThis(T, C, U, L)
{
  var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T)
    + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
  window.open(targetUrl);
}

function fbs_click() { u = location.href; t = document.title; window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436'); return false; }

function videoCommentListForm_OnBegin(e)
{
}

function videoCommentListForm_OnComplete(e)
{
}

function videoCommentListForm_OnFailure(e)
{
}

function videoCommentListForm_OnSuccess(e)
{
  videoCommentReport_BindEventHandlers();
}

function videoCommentList_SelectPage(index)
{
  var form = $('#videoCommentListForm')[0];
  $(form).find("input[name='pageNumber']")[0].value = index;
  $(form).find("input[name='videoCommentListFormSubmit']")[0].click();
}

function videoShareForm_OnBegin(e)
{
  // TODO: add client-side email validation (RegEx)
  var senderEmail = $(this).find("input[name='senderEmail']")[0];
  var recipients = $(this).find("input[name='recipients']")[0];

  if (senderEmail.value.trim() == '')
  {
    //<%-- TRANSLATE : sender email not provided --%>
    window.alert("Vous devez entrer une adresse courriel");
    senderEmail.focus();
    return false;
  }
  if (recipients.value.trim() == '')
  {
    //<%-- TRANSLATE : sender email not provided --%>
    window.alert("Vous devez entrer au moins une adresse courriel de destination (les adresses multiples doivent être séparées par une virgule)");
    recipients.focus();
    return false;
  }
}

function videoShareForm_OnComplete(e)
{
}

function videoShareForm_OnSuccess(e)
{
}

function videoShareForm_OnFailure(e)
{
}

function commentReportForm_OnBegin(e)
{
  var reason = $(this).find("input:checked[name='reportReason']");
  if (reason.length > 0)
  {
    var text = $(this).find("input[name='reportText']")[0];
    if (reason[0].value == 'Other')
    {
      if (text.value.trim() == '')
      {
        //<%-- TRANSLATE : no text entered for "Other" --%>
        window.alert("Vous devez entrer une raison");
        text.focus();
        return false;
      }
    }
    else
    {
      text.value = '';
    }
  }
  else
  {
    //<%-- TRANSLATE : no option selected --%>
    window.alert("Vous devez sélectionner une raison");
    return false;
  }
}

function commentReportForm_OnComplete(e)
{
}

function commentReportForm_OnFailure(e)
{
}

function commentReportForm_OnSuccess(e)
{
}

function videoCommentForm_OnBegin(e)
{
  var nameTextBox = $(this).find("input[name='name']")[0];
  var cityTextBox = $(this).find("input[name='city']")[0];
  var provTextBox = $(this).find("input[name='province']")[0];
  var textTextBox = $(this).find("textarea[name='text']")[0];

  if (textTextBox.value == '')
  {
    //<%-- TRANSLATE : comment text is empty --%>
    window.alert("Vous devez entrer un commentaire");
    textTextBox.focus();
    return false;
  }
}

function videoCommentForm_OnComplete(e)
{
}

function videoCommentForm_OnSuccess(e)
{
}

function videoCommentForm_OnFailure(e)
{
}

function videoRatingForm_OnBegin(e)
{
}

function videoRatingForm_OnComplete(e)
{

}

function videoRatingForm_OnSuccess(e)
{
  videoRating_BindEventHandlers();
}

function videoRatingForm_OnFailure(e)
{
}


$(document).ready(function()
{
  $(".accordionContent:not(:first)").hide();
  $("#videoAddComment").hide();
  $("#videoShareByEmailForm").hide();
  $('.reportForm').hide();

  videoRating_BindEventHandlers();
  videoCommentReport_BindEventHandlers();

  $(".accordionHeader").click(function()
  {
    var s = $(this);
    if (s.is(".active"))
    {
      s.toggleClass("active");
      s.children('.arrow').attr('src', $(document).data('AccordionHeaderInactiveImage'));
      s.next(".accordionContent").slideToggle();
    }
    else
    {
      $('.accordionHeader.active .arrow').attr('src', $(document).data('AccordionHeaderInactiveImage'));
      $(".accordionContent:visible").slideUp("fast");
      $(".accordionHeader.active").removeClass("active");
      s.toggleClass("active");
      s.children('.arrow').attr('src', $(document).data('AccordionHeaderActiveImage'));
      s.next(".accordionContent").slideToggle();
    }
    return false;
  });

  $("#videoAddCommentHeader").click(function()
  {
    var s = $(this);
    $("#videoAddComment").slideToggle(200);
    $('#videoAddCommentHeader .arrow').attr('src', $(document).data(s.is(".active") ? 'AccordionHeaderInactiveSmallImage' : 'AccordionHeaderActiveSmallImage'));
    s.toggleClass("active");
  });

  $("#videoShareByEmailHeader").click(function() {
        var s = $(this);
        $("#videoShareByEmailForm").slideToggle(200);
        $('#videoShareByEmailHeader .arrow').attr('src', $(document).data(s.is(".active") ? 'AccordionHeaderInactiveSmallImage' : 'AccordionHeaderActiveSmallImage'));
        s.toggleClass("active");
    });
/*
  $("#relatedVideoContainer > .content .header").hover(function()
  {
    $(this).toggleClass("active");
    $(this).next(".text").slideToggle();
    return false;
  }
    , function()
    {
      $(this).toggleClass("active");
      $(this).next(".text").slideToggle();
      return false;
    });
    */
});

function videoRating_BindEventHandlers()
{
  // submits the video rating form
  $('.ratingStar, .enabled').click(function(e)
  {
    // disable stars and reset to initial state, and clear message
    $('#videoRating > img').removeClass("enabled");
    var images = $('#videoRating img');
    for (var i = 0; i < 5; i++)
    {
      var img = images[i];
      img.src = $(document).data($(img).hasClass("highlight") ? "VideoRatingPostSrc" : "VideoRatingPreSrc");
    }

    // submit form
    var form = $('#videoRatingForm').get(0);
    var rating = $(e.target).get(0).alt;
    form['rating'].value = rating;
    form['videoRatingFormSubmit'].click();
  });

  // highlights the user's video rating selection and displays the associated message
  $('.ratingStar, .enabled').mouseover(function(e)
  {
    $(e.target).toggleClass('hover');
    var rating = parseInt(e.target.alt);
    var images = $('#videoRating img');
    for (var i = 0; i < 5; i++)
    {
      images[i].src = i < rating ? $(document).data("VideoRatingOverSrc") : $(document).data("VideoRatingPreSrc");
    }
    $('#videoRatingMessage').text($(document).data("VideoRatingMessages")[rating - 1]);
  });

  // restores the video rating stars to their initial state and clears the message
  $('.ratingStar, .enabled').mouseout(function(e)
  {
    $(e.target).toggleClass('hover');
    e.target.src = $(document).data($(e.target).hasClass("highlight") ? "VideoRatingPostSrc" : "VideoRatingPreSrc");
    var images = $('#videoRating img');
    for (var i = 0; i < 5; i++)
    {
      var img = images[i];
      img.src = $(document).data($(img).hasClass("highlight") ? "VideoRatingPostSrc" : "VideoRatingPreSrc");
    }
    $('#videoRatingMessage').text("");
  });
}

function videoCommentReport_BindEventHandlers()
{
  $('.reportForm input:radio').mouseup(function(e)
  {
    var container = $(e.target).parents('.videoCommentEntry');
    var textBox = container.find('input:text');

    if ($(e.target).hasClass('extender'))
    {
      textBox.show();
    }
    else
    {
      textBox.hide();
    }
  });

  $('.videoCommentEntry a.alert').click(function(e)
  {
    var link = $(e.target);
    var container = link.parents('.videoCommentEntry');
    link.hide();
    container.find('.text').hide();
    container.find('input:text').hide();
    container.find('.reportForm').show();
  });


  $('.reportForm input:reset').click(function(e)
  {
    var link = $(e.target);
    var container = link.parents('.videoCommentEntry');
    container.find('.reportForm').hide();
    container.find('.text').show();
    container.find('a.alert').show();
    container.find('input:text').hide();
    return false;
  });
}
