(function () { "use strict"; function request(querytext, func, errorfunc) { var req = new XMLHttpRequest(); req.onreadystatechange = function() { if (req.readyState !== 4) { return; } if (req.status !== 200) { errorfunc(); return; } func(req.responseText); }; req.open("GET",querytext); req.send(); } gotonewpost.onclick = function(e) { window.location="/newpost.html"+window.location.search }; document.getElementById("posts").innerHTML='Loading posts...'; var postsarray=[]; var functionsarray=[]; var lastpost=-1; var toppost=-1; var postsperpage=5; function changepost(postnum,data) { var p=JSON.parse(data); var postdate=new Date(0); postdate.setUTCSeconds(parseInt(p.date)); var header=[]; var body=[]; var comments=[]; header.push('
'); header.push('

'); header.push(decodeURIComponent(p.title)); header.push('#'); header.push(postnum); header.push('

'); header.push('

Por '); header.push(p.author); header.push(' el '); header.push(postdate.toString()); header.push('

'); header.push('
') body.push('
'); body.push(decodeURIComponent(p.text)); body.push('
'); comments.push('
'); for(var i in p.comments) { var c=p.comments[i]; comments.push('
'); comments.push('

'); var commentdate=new Date(0); commentdate.setUTCSeconds(parseInt(c.date)); comments.push(decodeURIComponent(c.author)); comments.push(" "); comments.push(commentdate.toString()); comments.push('

'); comments.push(decodeURIComponent(c.text)); comments.push('

'); comments.push('
'); } comments.push('

'); comments.push(''); comments.push(''); comments.push('

'); postsarray[toppost-postnum]='
'+header.join("")+body.join("")+'
'+comments.join("") /*+JSON.stringify(p) */; functionsarray[toppost-postnum]=function() { var requri=[]; requri.push("/newcomment"); requri.push(window.location.search); requri.push("&n="+postnum); requri.push("&t="); requri.push(encodeURIComponent(document.getElementById("comment"+(toppost-postnum)).value)); request(requri.join(""),function(r) { refreshpost(postnum); },function() {}); } } function clearpost(postnum) { postsarray[toppost-postnum]=undefined; functionsarray[toppost-postnum]=undefined; } function displayposts() { var contents=[] for(var i=0;i