pc_comments_p_hidden=pc_comments_div_hidden=true;pc_comments_form_hidden=false;pc_comments_count=0;
function formatItem(a,c){var b='<li class="new-user-msg" id="comment_'+a.mid+'"><dl class="f-wrap"><dt class="f-wrap"><span class="icon i-comment"></span><strong><a href="'+a.friendLink+'">'+a.friendName+"</a> "+i18n.Escribio+'</strong> <span class="datetime">- '+a.messageDate+'</span></dt><dd class="user-pic"><a class="thumb" href="'+a.friendLink+'"><img width="50" src="'+a.imgSrc+'" /></a></dd><dd class="user-msg">';if(a.canDelete){b+='<a href="javascript:void(0);" class="link-close" onclick="javascript:deleteComment(\''+
c+"', "+fpid+", "+a.aid+","+a.pid+","+a.mid+');"><span class="icon i-close">X</span></a>';if(a.uid)b+='<a href="#" class="link-close openwin" src="'+pages_url+"layers/pages_block_user.php?fpid="+fpid+"&uid="+a.uid+'"><span class="txt">'+i18n.Bloquear+"</span></a>"}b+="<p>"+a.messageText+"</p></dd></dl></li>";return b}
function addComment(a,c){if(a.error)window.alert(a.error);else{a=formatItem(a,c);$(c).append(a);if(pc_comments_div_hidden){$("#comments_container").show();pc_comments_div_hidden=false}pc_comments_count++;if(pc_comments_count>=pc_max_messages&&!pc_comments_form_hidden){$("#comments_form_div").hide();pc_comments_form_hidden=true}$("#board_cant_msgs").html(String(total_messages[photo_id].length+1));$("dd.user-msg .link-close .txt").css("visibility","hidden");$("dd.user-msg").hover(function(){$(this).find(".link-close .txt").css("visibility",
"visible")},function(){$(this).find(".link-close .txt").css("visibility","hidden")});$("#ex2").jqmAddTrigger("a.openwin")}}var photo_length_msg,photo_trim_msg;
function postComment(a,c,b,e,d,f){var g=$(e).get(0);if($.trim($("#new_comment").val())==""){photo_length_msg||alert(i18n["Por favor, ingresa un mensaje para enviar"]);return false}if($("#new_comment").val().length>5E3){photo_length_msg||alert(i18n["Por favor, ingresa un mensaje de menor tamanio."]);return false}$("#submit").attr("disabled",true);val=$("#submit").attr("value");$("#submit").attr("value",i18n.Enviando+"...");$.ajax({url:pages_url+"pages_album_add_photo_message.php",type:"POST",data:{u:a,
a:c,p:b,c:g.value,cu:f},dataType:"json",error:function(){alert(i18n["No se pudo agregar el comentario, por favor intente nuevamente en unos minutos."]);$("#submit").attr("disabled",false);$("#submit").attr("value",val)},success:function(h){addComment(h,d);g.value="";total_messages[b][total_messages[b].length]=h;$("#submit").attr("disabled",false);$("#submit").attr("value",val);pc_comments_count>=pc_max_messages&&$("#comments_full_p").show();total_comments++;$(".total_comments").html(total_comments)}})}
function loadComments(a,c,b,e){pc_comments_p_hidden=pc_comments_div_hidden=true;pc_comments_form_hidden=false;pc_comments_count=0;if(e!=null){$.each(e,function(d,f){addComment(f,b)});if(!pc_comments_form_hidden){$("#comments_form_div").show();$("#comments_full_p").hide()}e.length?$("#tit-comm").show():$("#tit-comm").hide()}else{$("#tit-comm").hide();$.ajax({url:pages_url+"pages_album_get_photo_messages.php",type:"POST",data:{a:a,p:c},dataType:"json",error:function(){},success:function(d){$.each(d,
function(f,g){addComment(false,g,b)})}})}}
function removeComment(a,c,b){if(a.result!="OK")window.alert(a.result);else{$("#comment_"+b).hide();pc_comments_count--;$("#board_cant_msgs").html(String(total_messages[photo_id].length-1));if(pc_comments_count==0){document.getElementById("comments_container").style.display="none";pc_comments_div_hidden=true}if(pc_comments_count<=pc_max_messages&&pc_comments_form_hidden){$("#comments_form_div").show();$("#comments_full_p").hide();pc_comments_form_hidden=false}}}
function deleteComment(a,c,b,e,d){window.confirm(i18n["Esta seguro?"])&&$.ajax({url:pages_url+"pages_album_delete_photo_message.php",type:"POST",data:{fpid:c,a:b,p:e,m:d},dataType:"json",error:function(){alert(i18n["No se pudo borrar el comentario, por favor intente nuevamente en unos minutos."])},success:function(f){removeComment(f,a,d);total_comments--;$(".total_comments").html(total_comments);for(i in total_messages[photo_id])total_messages[photo_id][i].mid==d&&delete total_messages[photo_id][i];
j=0;temp_messages=[];for(i in total_messages[photo_id]){temp_messages[j]=total_messages[photo_id][i];j++}total_messages[photo_id]=temp_messages}})};

