var gHost = location.protocol + '//' + location.host;

$(document).ready(function() {
  $("#show_comment_frm").show();
  $("#comment_frm").hide();

  $("#btn_show_comment_frm").bind("click", function() {
    $("#el_comment_name").attr("value", "");
    $("#el_comment_desc").attr("value", "");
    $("#show_comment_frm").hide();
    $("#comment_frm").show();
  });

  $("#btn_add_comment").bind("click", function() {
    $("#comment_frm").hide();
    $("#show_comment_frm").show();
  });

  $("#btn_add_comment").bind("click", function() {
    vPath = "/js/data/add_new_comment.php";
    vParams = {
      comment_name: $("#el_comment_name").attr("value"),
      comment_desc: $("#el_comment_desc").attr("value"),
      category: $("#el_category").attr("value"),
      id: $("#el_id").attr("value")
    };
    vResult = addNewComment(vPath, vParams, "POST", "html");
    $("#frm_answer").html(vResult.responseText);
    $("#frm_answer").css('font-weight', 'bold');
  });
});

function addNewComment(aPath, aParams, aType, aDataType) {
  var aDataObj = $.ajax({
    url: gHost + aPath,
    async: false,
    type: aType,
    dataType: aDataType,
    data: aParams/*,
    complete: function(aRes, status) {
      //if ( status == "sucess" || status == "notmodified" ) {
        aDataObj = aRes;
      //} else {
      //}
    }*/
  });
  return aDataObj;
}
