/*
 *Cand DOM este gata bindauim event-uri si ascundem element etc...
 */
$(document).ready(function(){
  $('#togglecom').hide();
  $('#togglerep').hide();
 /*
 *Hook the button
 */
  $('#showrep').click(function() {
    $("#togglerep").animate({
      "height": "toggle",
      "opacity": "toggle"
    }, {
      duration: 600
    });
  });
  $('#showcomm').click(function() {
    $("#togglecom").animate({
      "height": "toggle",
      "opacity": "toggle"
    }, {
      duration: 600
    });
  });
});

/*
 * Ajax report post
 */
$(function() {

  $("#rep").click(function() {
    // validate and process form
    // first hide any error messages

    var email = $("input#email").val();
    if (email == "") {
      $("input#email").focus();
      return false;
    }
    var reports = $("textarea#problema").val();
    if (reports == "") {
      $("textarea#problema").focus();
      return false;
    }

    var fileid = $("input#fileid").val();
    var nume = $('div.midbar > strong').html();
    var dataString = 'email=' + email + '&comment=' + reports ;

    $.ajax({
      type: "POST",
      url: "/file.php?action=report&id="+ fileid + "&nume=" + nume,
      data: dataString,
      success: function() {
        $('#reports').html("<div id='message'></div>");
        $('#message').html("<h2>Raportul a fost adaugat!</h2>")
        .append("<p>Problema va fi rezolvata curand.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='/templates/barbie/images/check.png' />");
        });
      }
    });
    return false;
  });
});
/*
 * Ajax comments post
 */
$(function() {

  $("#addcomm").click(function() {
    // validate and process form
    // first hide any error messages

    var name = $("input#name").val();
    if (name == "") {
      $("input#name").focus();
      return false;
    }
    var comment = $("textarea#comment").val();
    if (comment == "") {
      $("textarea#comment").focus();
      return false;
    }

    var fileid = $("input#fileid").val();
    var dataString = 'nume=' + name + '&message=' + comment ;

    $.ajax({
      type: "POST",
      url: "/file.php?action=addcomment&id="+ fileid,
      data: dataString,
      success: function() {
        $('#comments').html("<div style=\"height: 60px;\" id='message'></div>");
        $('#message').html("<h2>Comentariu a fost adaugat!</h2>")
        .append("<p>Va dorim distractie placuta in continuare!.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='/templates/barbie/images/check.png' />");
        });
      }
    });
    return false;
  });
});