if(!window.MVD){MVD={}}if(!window.console){console={log:function(){}}}(function(C){MVD.Comments={};MVD.Comments.EC=function(G,F,E){this.system=G;this.cont=F;this.idExt=E};C.extend(MVD.Comments.EC.prototype,{getIdExt:function(){return this.idExt},setECId:function(E){this.ECId=E;return this},setMod:function(E){this.mod=E;return this},setBlocked:function(E){this.blocked=E;return this},getECId:function(){return this.ECId},setState:function(E){this.state=E;return this},_delCommentError:function(){MVD.errorPopup.showText("No se pudo borrar el comentario.<br>Por favor volvé a intentarlo luego de algunos minutos.")},_commentDeleted:function(E){this.viewer.deleteComment(E);this.pagination.commentDeleted()},delComment:function(F){var E=this;C.ajax({type:"POST",url:"acomdespublicar.aspx",data:{ComId:F},dataType:"json",success:function(G){if(G===1){E._commentDeleted(F)}else{E._delCommentError()}},error:E._delCommentError})},addComments:function(G,F,E){this.viewer.add(G,F,E);this.pagination.setInfo(F);return this},updateView:function(F,E){this.viewer.update(F,E);this.pagination.setInfo(F);return this},getLoggedOnUserInfo:function(){return this.system.getLoggedOnUserInfo()},loggedOnUserIs:function(E){return this.system.loggedOnUserIs(E)},loggedOnUserBlock:function(F,E){return this.system.loggedOnUserBlock(F,E)},userLoggedOn:function(){return this.system.userLoggedOn()},userIsMod:function(){return this.mod},userIsBlocked:function(E){return this.system.userIsBlocked(E)},loggedOnUserIsBlocked:function(){return this.blocked},init:function(E){var F=this;F.pagination=new MVD.Comments.Pagination(F,E.pagination);F.pagination.getElement().appendTo(F.cont);F.viewer=new MVD.Comments.Viewer(F,E.view);F.viewer.getElement().appendTo(F.cont).show();F.sendForm=new MVD.Comments.SendForm(F,E.form);if(F.sendForm.visible()){F.sendForm.getElement().appendTo(F.cont).show()}F.cont.addClass("comments-container").show();return F},dispose:function(){var E=this;E.cont.remove();delete E.pagination;delete E.viewer;delete E.sendForm;delete E.cont},refreshView:function(){if(this.ECId&&this.viewer){this.viewer.refresh()}},getLastId:function(){return this.viewer.getLastId()},getFirstId:function(){return this.viewer.getFirstId()},getLoaded:function(){return this.viewer.getCount()},previousPage:function(){var E=this;C.ajax({type:"POST",url:"acomentariosecpag.aspx",data:{ECId:E.ECId,page:1,from:E.getFirstId()},dataType:"json",success:function(F){E.addComments(true,F)},error:function(){MVD.errorPopup.showText("Momentaneamente no podemos cumplir con tu pedido.<br>Por favor volvé a intentarlo luego de algunos minutos.")}})}});var B=50;var A=18;MVD.Comments.SendForm=function(F,E){this.ec=F;if(this._userBlocked()){this._visible=false}else{this._visible=true;this.elem=E.clone();this.init()}};C.extend(MVD.Comments.SendForm.prototype,{init:function(){var E=this;E.input=C(".comment-text:first",E.elem);E.input.bind("keyup mouseup",function(){if(E._userLoggedOn()){E._onChangeText()}}).blur(function(){if(E.getText()==""){E._setOpen(false)}}).bind("paste",function(){return false});E.button=C(".comment-submit:first",E.elem);E.userinfo=C(".comment-userinfo:first",E.elem);E._setOpen(false)},visible:function(){return this._visible},getText:function(){return C.trim(this.input.val())},_setOpen:function(F){var E=this;E.open=F;if(F){E.input.height(B).val("").removeClass("empty").unbind("focus");E._enableButton(false);E._setUserInfo();E.userinfo.show();E.button.show()}else{E.input.height(A).val("Escribe aqui tu comentario...").addClass("empty").focus(function(){if(!E.open){if(E._userLoggedOn()){E._setOpen(true)}else{E.input.attr("enabled","0").blur();if(MVD.Comments.loginPopup){MVD.Comments.loginPopup.open()}else{alert("Debe iniciar sesión para enviar comentarios")}}}});E.userinfo.hide();E.button.hide()}},_setUserInfo:function(){var G=this.userinfo;var E=G.html();var F=this.ec.getLoggedOnUserInfo();E=E.replace(/@UsrRegId@/g,F.id);E=E.replace(/@UsrRegNick@/g,F.nick);E=E.replace(/@UsrRegMail@/g,F.email);G.html(E)},_enabled:function(E){var F=this;if(F.enabled!=E){F.enabled=E;if(E){F.input.removeAttr("disabled")}else{F.input.attr("disabled","disabled")}F._enableButton(E)}},_enableButton:function(E){var F=this;if(F.buttonEnabled!=E){F.buttonEnabled=E;if(E){F.button.removeClass("link-button-disabled").addClass("link-button-enabled").unbind("click").click(function(){return F._onSend()}).show()}else{F.button.removeClass("link-button-enabled").addClass("link-button-disabled").unbind("click").click(function(){return false}).show()}}},_onSend:function(){var E=this;var F=E.getText();if(F==""){delete E.buttonEnabled;E._enableButton(false);E.input.focus()}else{E._enabled(false);C.ajax({type:"POST",url:"acomguarda.aspx",data:{"text":F,"ECId":E.ec.getECId(),"last":E.ec.getLastId()},dataType:"json",success:function(G){E._commentSent(G)},error:function(){E._commentSentError()}})}return false},_commentSent:function(E){if(E&&E.code){this._enabled(true);this._setOpen(false);if(E.comments){this.ec.addComments(false,E.comments,E.ComId)}}else{this._commentSentError()}},_commentSentError:function(){MVD.errorPopup.showText("Hubo un error al intentar enviar el comentario.<br>Volvé a intentarlo más tarde.");this._enabled(true)},_onChangeText:function(){var E=this;E._enableButton(E.getText()!="")},getElement:function(){return this.elem},_userLoggedOn:function(){return this.ec.userLoggedOn()},_userBlocked:function(){return this.ec.loggedOnUserIsBlocked()}});MVD.Comments.User=function(E){this.state=0;this.blocked={};this.system=E};C.extend(MVD.Comments.User.prototype,{setState:function(E){this.state=E;return this},getState:function(){return state},setBlocked:function(F){var E={};C.each(F,function(G,H){E[H]=1});this.blocked=E},userIsBlocked:function(E){return !!(this.blocked[E])},setInfo:function(G,E,F){this.id=G;this.nick=E;this.email=F;return this},isLoggedOn:function(){return(this.state==1)},getInfo:function(){return{id:this.id,nick:this.nick,email:this.email}},is:function(E){return(this.id===E)},_blocked:function(G,E,F){if(E.result===1){if(F=="B"){this.blocked[G]=1}else{delete this.blocked[G]}this.system.refreshViews()}else{this._error()}},_error:function(){MVD.errorPopup.showText("No se pudo realizar la operación<br>Por favor volvé a intentarlo luego de algunos minutos.")},block:function(G,F){var E=this;C.ajax({type:"POST",url:"abloqueo.aspx",data:{accion:F,UsrRegId:G},dataType:"json",success:function(H){E._blocked(G,H,F)},error:function(){E._error()}})}});var D={nick:/@ComUsrRegNick@/g,date:/@ComFechaHora@/g,txt:/@ComTexto@/g,id:/@ComId@/g,usr:/@ComUsrRegId@/g};MVD.Comments.View=function(F,G,E){this._init(F,G,E)};C.extend(MVD.Comments.View.prototype,{_init:function(F,H,E){var G=this;G.elem=F.clone();G._replace(H);G.delbtn=C(".btnDelete",G.elem);G.blkbtn=C(".btnBlock",G.elem);G.info=H;if(E.userIsMod()){G.delbtn.click(function(){E.delComment(H.id);return false});G._configBlockBtn(E)}else{G.delbtn.hide();G.blkbtn.hide()}},_configBlockBtn:function(F){var G=this;var J=G.info.usr;if(F.loggedOnUserIs(J)){G.blkbtn.hide()}else{var H=F.userIsBlocked(J)?"D":"B";G.blkbtn.unbind("click").click(function(){F.loggedOnUserBlock(J,H);return false}).attr("title",(H=="B"?"Bloquear":"Desbloquear")+" a "+G.info.nick);var E=C("img",G.blkbtn);var I=E.attr("src");if(H=="B"){I=I.replace(/_on/g,"_off")}else{I=I.replace(/_off/g,"_on")}E.attr("src",I)}},_replace:function(F){var E=this.elem.html();C.each(D,function(H,G){E=E.replace(G,F[H])});this.elem.html(E);this.elem.attr("id","comment"+F.id)},getElement:function(){return this.elem},dispose:function(E){this.delbtn.unbind("click");if(E){var F=this.elem;F.slideUp("slow",function(){F.remove()})}else{this.elem.remove()}this.elem=null},refresh:function(E){if(E.userIsMod()){this._configBlockBtn(E)}}});MVD.Comments.Pagination=function(E,F){this.ec=E;this.elem=F.clone();this._init()};C.extend(MVD.Comments.Pagination.prototype,{getElement:function(){return this.elem},_init:function(){var E=this;E.previousBtn=C(".pagination-previous",E.elem).click(function(){E.ec.previousPage();return false})},_replace:function(F){var E=this;C.each(["number","page","pages"],function(G,H){C(".pagination-"+H,E.elem).text(F[H])})},_updateLoaded:function(){var F=this;var E=F.ec.getLoaded();C(".pagination-loaded",F.elem).text(E);F.previousBtn[(E>=F.info.number)?"hide":"show"]()},commentDeleted:function(){this.info.number--;this._updateLoaded();this._replace(this.info)},setInfo:function(F){var E=this;E.info=F;if(F&&(F.pages>1)){E._replace(F);E._updateLoaded();E.elem.show()}else{E.elem.hide()}}});MVD.Comments.Viewer=function(E,F){this.ec=E;this.templateView=F;this.cont=C("<div></div>");this.listCont=C("<div></div").appendTo(this.cont);this.views={}};C.extend(MVD.Comments.Viewer.prototype,{update:function(F,E){if(F&&F.comments){this._setComments(F.comments,E)}},add:function(F,G,E){if(G&&G.comments){this._addComments(F,G.comments,E)}},_delViews:function(){var F=this;F.listCont.empty();var E=F.views;if(E){C.each(E,function(G,H){E[G].dispose();delete E[G]})}F.views={};F.views_count=0},_setComments:function(F,E){var G=this;G._delViews();G._addComments(false,F,E)},_addComments:function(I,F,E){var H=this;var G=!I?H.listCont:C("<div></div>").addClass("pagina").hide().prependTo(H.listCont);C.each(F,function(L,J){var K=new MVD.Comments.View(H.templateView,J,H.ec);if(!H.views[J.id]){H.views_count++}H.views[J.id]=K;var M=K.getElement().appendTo(G);if(E&&(J.id===E)){M.slideDown("slow")}else{M.show()}});this._updateBounds(F);if(I){G.slideDown("slow")}},deleteComment:function(F){var E=this;if(E.views[F]){E.views[F].dispose(true);delete E.views[F];E.views_count--}},getElement:function(){return this.cont},getLastId:function(){return this.maxComId||0},getFirstId:function(){return this.minComId||0},getCount:function(){return this.views_count},_updateBounds:function(G){if(G.length){var E=G[G.length-1].id;this.maxComId=Math.max(this.maxComId||E,E);var F=G[0].id;this.minComId=Math.min(this.minComId||F,F)}},refresh:function(){var E=this.ec;C.each(this.views,function(F,G){G.refresh(E)})}});MVD.Comments.System=function(E){this.ecs={};this.templates=E;this.user=new MVD.Comments.User(this)};C.extend(MVD.Comments.System.prototype,{addEcs:function(E,F){this._getECsInfo(this._get_ecs_id_list(C(".comments-ecid",E)),F)},clear:function(){var E=this.ecs;C.each(E,function(G,F){F.dispose();delete E[G]})},_get_ecs_id_list:function(E){var H=this;var G=[];var F=/^[0-9A-Za-z]+\/.+$/;E.each(function(J,L){var K=C(L);var I=C.trim(K.text());if(I&&F.test(I)){if(!H.ecs[I]){H.ecs[I]=new MVD.Comments.EC(H,K,I)}G.push(I)}K.text("").removeClass("comments-ecid")});return G},_getECsInfo:function(G,F){if(G&&G.length){var E=this;C.ajax({type:"POST",url:"acomentariosecs.aspx",data:{"idExtList":G.join(","),"all":F?1:0},dataType:"json",success:function(H){E._updateUserInfo(H.user);E._updateBlockedInfo(H.blocked);E._updateECsInfo(H.ecs);if(E.onLoad){E.onLoad()}},error:function(){}})}},_updateECsInfo:function(F){var E=this;C.each(F,function(H,I){var G=E.ecs[I.idExt];if(I.state){G.setECId(I.EcId).setState(I.state).setMod(I.mod).setBlocked(I.block).init(E.templates).updateView(I.comments)}})},_updateUserInfo:function(E){this.user.setState(E.state);this.user.setInfo(E.id,E.nick,E.email)},_updateBlockedInfo:function(E){if(E){this.user.setBlocked(E)}},getLoggedOnUserInfo:function(){return this.user.getInfo()},loggedOnUserIs:function(E){return this.user.is(E)},loggedOnUserBlock:function(F,E){return this.user.block(F,E)},userLoggedOn:function(){return this.user.isLoggedOn()},userIsBlocked:function(E){return this.user.userIsBlocked(E)},refreshViews:function(){C.each(this.ecs,function(F,E){E.refreshView()})},refreshBlocked:function(){var E=this;C.ajax({type:"GET",url:"abloqueados.aspx?0",dataType:"json",success:function(F){E._updateBlockedInfo(F);E.refreshViews()},error:function(){}})}})})(jQuery)