function ajaxCommentAction(options){var _connectionError="Se ha producido un error, por favor vuelva a intentarlo en unos minutos.";if(typeof(options)!="undefined"){options.data=typeof(options.data)!="undefined"?options.data:{};options.url=options.data.url?options.data.url:"/modules/publisher/ajax_publisher.php";options.data.url=undefined;options.successCallBack=typeof(options.successCallBack)!="undefined"?options.successCallBack:function(){};options.errorCallBack=typeof(options.errorCallBack)!="undefined"?options.errorCallBack:function(){alert(_connectionError)};$.ajax({type:"POST",url:options.url,data:options.data,dataType:"json",error:function(XMLHttpRequest,textStatus,errorThrown){options.errorCallBack()},success:function(res){options.successCallBack(res)}})}return false}function deleteElementFunction($messageHtml,data){$messageHtml.hide();ajaxCommentAction({data:data,errorCallBack:function(){$messageHtml.show();alert("Se ha producido un error, por favor vuelva a intentarlo en unos minutos.")},successCallBack:function(response){if(response.error){$messageHtml.show();alert(response.msgError);return false}$messageHtml.remove()}})}(function($){$.fn.extend({comments:function(options){var defaults={usePrivacy:0,publicClass:"publicComment",privateClass:"privateComment",bindFocusBlur:true,idleClass:"formfield-quiet",focusClass:"formfield-current",dataClass:"formfield-filled",formTemplate:$("#repo_post_comment_form").html(),commentTemplate:$("#repo_post_comment_msg").html(),msgConnectionError:"Se ha producido un error, por favor vuelva a intentarlo en unos minutos."};var options=$.extend(defaults,options);return this.each(function(){var o=options;var $container=$(this);var postFormContainer={};function makeForm(){$container.append(o.formTemplate);postFormContainer.$form=$("form",$container);postFormContainer.$textarea=$container.find("textarea").eq(0);postFormContainer.$submit=$container.find("input").eq(0);postFormContainer.$elementContainer=$container.find("dl").eq(0);postFormContainer.$textarea.elastic().TextTip();if(o.bindFocusBlur){postFormContainer.$textarea.focus(function(){postFormContainer.$elementContainer.addClass("focus").removeClass("blur")});postFormContainer.$textarea.blur(function(){if(postFormContainer.$textarea.val()===""||postFormContainer.$textarea.val()===postFormContainer.$textarea.attr("title")){postFormContainer.$elementContainer.addClass("blur").removeClass("focus")}})}postFormContainer.$form.submit(function(){setFormStatus("sending");addComment();setFormStatus("normal");return false})}function addComment(){var commentBody=postFormContainer.$textarea.val();postFormContainer.$textarea.cleanTxt();if(commentBody==postFormContainer.$textarea.attr("title")){return false}var comment=o.commentTemplate.replace(/##commentBody##/g,commentBody.replace(/\n/g,"<br />"));postFormContainer.$form.before(comment);var $comment=$(".user-comment:last",$container);if(o.aditionalData.usePrivacy){$comment.addClass((_currentPrivacy==PROFILE_PRIVACY_PUBLIC)?o.publicClass:o.privateClass)}postComment($comment,commentBody)}function postComment($comment,commentBody){var sendData={elementId:o.elementId,u:o.userId,c:commentBody};if(o.aditionalData){if(o.aditionalData.usePrivacy){o.aditionalData.privacy=_currentPrivacy}sendData=$.extend(sendData,o.aditionalData)}ajaxCommentAction({data:sendData,errorCallBack:function(){alert(o.msgConnectionError);$comment.remove()},successCallBack:function(responseData){if(responseData.error){$comment.remove();alert(responseData.msgError);return false}if(responseData.response.commentId){$comment.find("a").eq(0).click(function(){delComment($comment,responseData.response.commentId)}).show()}}})}function delComment($comment,commentId){var sendData={elementId:o.elementId,commentId:commentId,u:o.userId};if(o.aditionalDeleteData){sendData=$.extend(sendData,o.aditionalDeleteData)}deleteElementFunction($comment,sendData)}function setFormStatus(status){if(status==="sending"){postFormContainer.$submit.attr("disabled",true);postFormContainer.$textarea.attr("disabled",true)}else{postFormContainer.$submit.removeAttr("disabled");postFormContainer.$textarea.removeAttr("disabled")}}makeForm()})}})})(jQuery);function createMessageBoard(options,message){var defaults={template:$("#repo_post_message_board").html(),msgConnectionError:"Se ha producido un error, por favor vuelva a intentarlo en unos minutos.",target:"#boardMessages",userId:""};var o=$.extend(defaults,options);var comment=o.template.replace(/##commentBody##/g,message.replace(/\n/g,"<br />"));var $container=$(o.target);$container.prepend(comment);var $message=$("li:first",$container);$message.show("slow");var sendData={u:o.userId,message:message};if(o.aditionalData){sendData=$.extend(sendData,o.aditionalData)}ajaxCommentAction({data:sendData,errorCallBack:function(){$message.remove();alert(o.msgConnectionError)},successCallBack:function(responseData){if(responseData.error){$message.remove();alert(responseData.msgError);return false}var oComment={elementId:responseData.response.elementId};if(o.commentOptions){oComment=$.extend(oComment,o.commentOptions)}$("div.newsfeed-commentsTarget:first",$message).comments(oComment);if(responseData.response.elementId){delMessage($message,responseData.response.elementId)}}});function delMessage($message,elementId){$("a.link-close:first",$message).click(function(){var deleteData={u:sendData.u,elementId:elementId};if(o.aditionalDeleteData){deleteData=$.extend(deleteData,o.aditionalDeleteData)}deleteElementFunction($message,deleteData)}).show()}};