﻿var commenti={total:0,loaded:0,id:0,count:10,cmtid:0,loading:false,load:false,loadCount:function(){if($("#contacommenti").length>0){$.getJSON("/web/GetCommentsCount.aspx?idContent="+this.id+"&output=JSON&r="+Math.random(),function(data){$("#contacommenti").html(data.Table[0].t);commenti.total=data.Table[0].t;});}},loadList:function(reset){if(this.load&&!commenti.loading&&commenti.total>commenti.loaded){commenti.loading=true;$(".commenti-loading").show();$('#commenti-fine').hide();if($("#listacommenti").length>0){if(reset){$("#listacommenti").html('');this.cmtid=0;this.loaded=0;}
$.getJSON("/web/GetCommentsList.aspx?idContent="+this.id+"&count="+this.count+"&cmtId="+this.cmtid+"&output=JSON&r="+Math.random(),function(data){for(var i=0;i<data.Table.length;i++){$("#listacommenti").append("<li id=\"commento-"+data.Table[i].cmtId+"\"><h4>"+(commenti.total-commenti.loaded)+". "+data.Table[i].cmtTitle+"</h4><p>"+data.Table[i].cmtComment.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>')+"</p><p class=\"byline\"><cite>"+data.Table[i].cmtName+"</cite> - "+data.Table[i].cmtTS.substr(0,16).replace(".",":")+"</p></li>");if(i===data.Table.length-1){commenti.cmtid=data.Table[i].cmtId;}
commenti.loaded++;}
commenti.loading=false;$(".commenti-loading").hide();if(commenti.total>commenti.loaded){$('#commenti-missing').html(commenti.total-commenti.loaded);$('#commenti-fine').show();}});}}},loadForm:function(){$("#commenti-scrivi").load("/web/GetCommentsForm.aspx?r="+Math.random());},postComment:function(){var re=new RegExp(/<[^ ][^>]*>/);if(jQuery.trim($('#cmtTitle').val())===''&&jQuery.trim($('#cmtComment').val())===''){alert("Inserire Titolo e Testo.");}else if(re.test($('#cmtTitle').val())||re.test($('#cmtComment').val())){alert("Non Ã¨ possibile inserire HTML.");}else{$.ajax({type:"POST",url:$('#formcommento').attr("action")+"?idContent="+this.id,contentType:"application/x-www-form-urlencoded; charset=utf-8",data:$("#formcommento").serialize(),success:function(data){commenti.reset();$('#formcommento').fadeOut();$('#commento-grazie').fadeIn();},error:function(XMLHttpRequest,textStatus,errorThrown)
{}});}
return false;},reset:function(){$('#formcommento').each(function(){this.reset();});}};$(document).ready(function(){commenti.loadCount();});
