
var fSubmitting=false;var elEditForm=null;function validateGetFormData(){if(!fSubmitting){var username="";if(document.blogCommentForm.username){username=trim(document.blogCommentForm.username.value);}
var text=trim(document.blogCommentForm.text.value);var poststr="id="+document.blogCommentForm.id.value+"&pid="+document.blogCommentForm.pid.value+"&postcomment"+"&text="+ajaxEscape(text)+
(username?"&username="+ajaxEscape(username):"")+
(document.blogCommentForm.email?"&email="+ajaxEscape(document.blogCommentForm.email.value):"")+
(document.blogCommentForm.url?"&url="+ajaxEscape(document.blogCommentForm.url.value):"")+
(document.blogCommentForm.remember_me&&document.blogCommentForm.remember_me.checked?"&remember_me=true":"");return poststr;}
return null;}
function submitCommentForm(){var poststr=validateGetFormData();if(poststr){fSubmitting=true;setElementsByIdsDisplayInline("bcsubmitindicator");return new AJAXRequest("POST","/blogpostaddcomment.jspax",poststr,"http://www.vaxjopuls.se/blogg/",processAddComment);}}
function submitCommentFormForPreview(){var poststr=validateGetFormData();if(poststr){poststr="preview&"+poststr;fSubmitting=true;setElementsByIdsDisplayInline("bcsubmitindicator");return new AJAXRequest("POST","/blogpostaddcomment.jspax",poststr,"http://www.vaxjopuls.se/blogg/",processPreviewComment);}}
function processAddComment(myAJAX){if(myAJAX.readyState==4){fSubmitting=false;setElementsByIdsDisplayNone("bcsubmitindicator");if(document.blogCommentForm.username){document.blogCommentForm.username.className="inputfield";document.blogCommentForm.email.className="inputfield";document.blogCommentForm.url.className="inputfield";}
document.blogCommentForm.text.className="textareamessage";if(myAJAX.status==200){removeWriteCommentPreview();var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=="OK"){document.blogCommentForm.text.value="";getCommentsForced();return;}else if(status=="login"){return;}else{var fielderrors=xml.documentElement.getElementsByTagName("error");var errorsText="";var fFocused=false;for(var i=0;i<fielderrors.length;i++){var field=fielderrors[i].getAttributeNode("field").nodeValue;var el=document.blogCommentForm[field];if(el){el.className+=" error";if(!fFocused){el.focus();fFocused=true;}}}
return;}}}
alert("Misslyckades att posta...");}}
function removeWriteCommentPreview(){var el=document.getElementById('writecommentpreview');if(el){el.style.display="none";el.innerHTML="";}}
function removeEditCommentPreview(){var el=document.getElementById('editcommentpreview');if(el){el.style.display="none";el.innerHTML="";}}
function processPreviewComment(myAJAX){if(myAJAX.readyState==4){fSubmitting=false;setElementsByIdsDisplayNone("bcsubmitindicator");if(document.blogCommentForm.username){document.blogCommentForm.username.className="inputfield";document.blogCommentForm.email.className="inputfield";document.blogCommentForm.url.className="inputfield";}
document.blogCommentForm.text.className="textareamessage";if(myAJAX.status==200){var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=='OK'){var html=xml.documentElement.getElementsByTagName("html")[0].firstChild.nodeValue;var el=document.getElementById('writecommentpreview');el.style.display="block";el.innerHTML="Förhandsgranskning: <br />"+html;}else if(status=="login"){alert("Logga in först...");}else{var fielderrors=xml.documentElement.getElementsByTagName("error");var errorsText="";var fFocused=false;for(var i=0;i<fielderrors.length;i++){var field=fielderrors[i].getAttributeNode("field").nodeValue;var el=document.blogCommentForm[field];if(el){el.className+=" error";if(!fFocused){el.focus();fFocused=true;}}}
return;}}}}}
var refreshButton=null;var fUserRefresh=false;var cRefreshWaitSeconds;function refreshCommentsWithTimer(button){button.value="Laddar...";button.disabled=true;refreshButton=button;fUserRefresh=true;cRefreshWaitSeconds=15;getCommentsForced();}
function refreshCountdown(){cRefreshWaitSeconds--;if(cRefreshWaitSeconds){refreshButton.value="Vänta... "+cRefreshWaitSeconds;setTimeout(refreshCountdown,1000);}else{refreshButton.disabled=false;refreshButton.value="Ladda nya kommenterarer";}}
function getCommentsForced(){return new AJAXRequest("POST","/blogpostcomments.jspax","id="+document.blogCommentForm.id.value+"&pid="+document.blogCommentForm.pid.value,"http://www.vaxjopuls.se/blogg/",processGetComments);}
function processGetComments(myAJAX){if(myAJAX.readyState==4){if(myAJAX.status==200){var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=="OK"){var commentCount=xml.documentElement.getElementsByTagName("count")[0].firstChild.nodeValue;var el=document.getElementById("comments");el.innerHTML=xml.documentElement.getElementsByTagName("allcomments")[0].firstChild.nodeValue;if(fUserRefresh){fUserRefresh=false;setTimeout(refreshCountdown,1000);}}}}}}
function deleteComment(cid){if(confirm("Är du säker på att du vill ta bort den här kommentaren?")){return new AJAXRequest("POST","/blogpostdeletecomment.jspax","id="+document.blogCommentForm.id.value+"&pid="+document.blogCommentForm.pid.value+"&cid="+cid,"http://www.vaxjopuls.se/blogg/",processDeleteComment);}}
function processDeleteComment(myAJAX){if(myAJAX.readyState==4){if(myAJAX.status==200){var response=myAJAX.responseText;var index=response.indexOf("status=OK");if(index>=0){getCommentsForced();}else
alert("Misslyckades att ta bort kommentaren...");}}}
function hideCommentForm(){setElementsByIdsDisplayNone("writecomment");}
function removeCommentEditForm(fShowCommentForm){removeEditCommentPreview();if(elEditForm&&elEditForm.parentNode){elEditForm.parentNode.removeChild(elEditForm);}
if(fShowCommentForm)
setElementsByIdsDisplayBlock("writecomment");}
function editComment(cid){removeWriteCommentPreview();return new AJAXRequest("POST","/blogpostgetcomment.jspax","id="+document.blogCommentEditForm.id.value+"&pid="+document.blogCommentEditForm.pid.value+"&cid="+cid,"http://www.vaxjopuls.se/blogg/",processGetCommentForEditXML);}
function processGetCommentForEditXML(myAJAX){if(myAJAX.readyState==4){if(myAJAX.status==200){var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=="OK"){var cid=xml.documentElement.getElementsByTagName("id")[0].firstChild.nodeValue;var rawtext=xml.documentElement.getElementsByTagName("rawtext")[0].firstChild.nodeValue;if(!elEditForm)
elEditForm=document.getElementById("editcomment");var elDest=document.getElementById("c_"+cid);if(elEditForm&&elDest){hideCommentForm();removeCommentEditForm();elEditForm.style.display="block";elDest.appendChild(elEditForm);document.blogCommentEditForm.text.value=rawtext;document.blogCommentEditForm.cid.value=cid;}
return;}else if(status=="login"){openLoginForm(null,fMemberGallery?"mg":"regular",false,2);return;}}}}}
function submitCommentEditForm(){var poststr="id="+document.blogCommentEditForm.id.value+"&pid="+document.blogCommentEditForm.pid.value+"&cid="+document.blogCommentEditForm.cid.value+"&updatecomment"+"&text="+ajaxEscape(document.blogCommentEditForm.text.value);setElementsByIdsDisplayInline("bcesubmitindicator");return new AJAXRequest("POST","/blogpostupdatecomment.jspax",poststr,"http://www.vaxjopuls.se/photogallery.jsp",processUpdateCommentXML);}
function submitCommentEditForPreview(){var poststr="id="+document.blogCommentEditForm.id.value+"&pid="+document.blogCommentEditForm.pid.value+"&cid="+document.blogCommentEditForm.cid.value+"&updatecomment&preview"+"&text="+ajaxEscape(document.blogCommentEditForm.text.value);setElementsByIdsDisplayInline("bcesubmitindicator");return new AJAXRequest("POST","/blogpostupdatecomment.jspax",poststr,"http://www.vaxjopuls.se/photogallery.jsp",processUpdateCommentPreviewXML);}
function processUpdateCommentXML(myAJAX){if(myAJAX.readyState==4){setElementsByIdsDisplayNone("bcesubmitindicator");document.blogCommentEditForm.text.className="textareamessage";if(myAJAX.status==200){var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=="OK"){document.blogCommentEditForm.text.value="";removeCommentEditForm(true);getCommentsForced();return;}else if(status=="login"){alert("Logga in först...");return;}else{var fielderrors=xml.documentElement.getElementsByTagName("error");var errorsText="";var fFocused=false;for(var i=0;i<fielderrors.length;i++){var field=fielderrors[i].getAttributeNode("field").nodeValue;var el=document.blogCommentEditForm[field];if(el){el.className+=" error";if(!fFocused){el.focus();fFocused=true;}}}
return;}}}
alert("Misslyckades att uppdatera...");}}
function processUpdateCommentPreviewXML(myAJAX){if(myAJAX.readyState==4){setElementsByIdsDisplayNone("bcesubmitindicator");document.blogCommentEditForm.text.className="textareamessage";if(myAJAX.status==200){var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=="OK"){var html=xml.documentElement.getElementsByTagName("html")[0].firstChild.nodeValue;var el=document.getElementById('editcommentpreview');el.style.display="block";el.innerHTML="<br />Förhandsgranskning: <br />"+html;return;}else if(status=="login"){alert("Logga in först...");return;}else{var fielderrors=xml.documentElement.getElementsByTagName("error");var errorsText="";var fFocused=false;for(var i=0;i<fielderrors.length;i++){var field=fielderrors[i].getAttributeNode("field").nodeValue;var el=document.blogCommentEditForm[field];if(el){el.className+=" error";if(!fFocused){el.focus();fFocused=true;}}}
return;}}}
alert("Misslyckades att uppdatera...");}}
function submitBlogPostPoll(form){var poststr=voteFormToStr(form);if(!poststr){alert("Nu glömde du nog nåt? :p");}else{return new AJAXRequest("POST","/poll.jspax",poststr,"http://www.vaxjopuls.se/blogg",processSubmitVoteXML);}}
function showBlogPostPollResults(id){var poststr="action=show&id="+id;return new AJAXRequest("POST","/poll.jspax",poststr,"http://www.vaxjopuls.se/blogg",processSubmitVoteXML);}
function voteFormToStr(form){var poststr="action=vote&id="+form.id.value+"&";var cVotes=0;if(form.c_1.length){for(i=0;i<form.c_1.length;i++){if(form.c_1[i].checked==true){cVotes++;poststr+="c_"+cVotes+"="+form.c_1[i].value;break;}}}else{var i=1;var name="c_"+i;while(form[name]){if(form[name].checked){cVotes++;poststr+="c_"+i+"="+form[name].value;}
i++;name="c_"+i;}}
return cVotes>0?poststr:null;}
function processSubmitVoteXML(myAJAX){if(myAJAX.readyState==4){if(myAJAX.status==200){var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=="OK"){var id=xml.documentElement.getElementsByTagName("id")[0].firstChild.nodeValue;var html=xml.documentElement.getElementsByTagName("html")[0].firstChild.nodeValue;var el=document.getElementById("pollBox_"+id);if(el)
el.innerHTML=html;var resultsData=eval("("+xml.documentElement.getElementsByTagName("results")[0].firstChild.nodeValue+")");var effect=new PollAnimateEffect(resultsData,1.5);effect.startEffect();return;}}}
alert("Misslyckades med röstningen...");}}
function PollAnimateEffect(resultsData,secDuration){this.resultsData=resultsData;OpacityFadeEffect.base.constructor.call(this);this.effectDuration=secDuration;}
PollAnimateEffect.inherits(BaseEffect);PollAnimateEffect.prototype.renderEffect=function(pos,cFrame){for(data in this.resultsData){var percent=Math.round(pos*this.resultsData[data]);var el=document.getElementById("pollresult_"+data);if(el){el.innerHTML=percent+"%";}
el=document.getElementById("imgpollresult_"+data);if(el){el.width=percent;}}}
function animatePoll(resultsData,step){console.log("ok, got res");for(data in resultsData){if(resultsData[data]>=step){var el=document.getElementById("pollresult_"+data);if(el){el.innerHTML=step+"%";}
el=document.getElementById("imgpollresult_"+data);if(el){el.width=step;}}}
if(step<100)
setTimeout(function(){animatePoll(resultsData,step+2)},30);}
function loadYoutube(idElement,idMovie){var so=new SWFObject("http://www.youtube.com/v/"+idMovie,idElement,"441","357","7","#000000");so.addParam("wmode","transparent");so.write(idElement);}
