
Lycos.use("util/captcha");Lycos.use("ui");Lycos.webon.modules.guestbook=function(instId,subInstId){this.type="guestbook";this.lyModule=Lycos.webon.module;this.lyModule(instId,subInstId);this.jsObj="(Lycos.webon.getInstance('"+this.type+"', "+this.instId+", "+this.subInstId+"))"
var tmp=this;this.addEventListener("showEdit",function(e){tmp.onLightbox(e);});this.addEventListener("saveQuestions",function(e){tmp.onSaveQuestions(e);});this.addEventListener("removeQuestion",function(e){tmp.onRemoveQuestion(e);});this.addEventListener("comment",function(e){tmp.onComment(e);});this.addEventListener("markEntryAsSpam",function(e){tmp.onMarkEntryAsSpam(e);});this.addEventListener("unmarkEntryAsSpam",function(e){tmp.onUnmarkEntryAsSpam(e);});this.addEventListener("getEntries",function(e){tmp.onGetEntries(e);});this.addEventListener("deleteEntry",function(e){tmp.onDeleteEntry(e);});this.addEventListener("approveEntry",function(e){tmp.onApproveEntry(e);});this.commentSubmitting="Submitting...";this.commentSubmitted="Submit";this.newQuestionCounter=100000001;this.showspams=false;this.checkForm=function(){}
this.setSpamEntry=function(obj,id,b){this.lyAjaxObj({id:id},(b?"mark":"unmark")+"EntryAsSpam");return false;}
this.toggleSpamEntry=function(obj,id){return this.setSpamEntry(obj,id,(obj.innerHTML=="mark"));}
this.setShowSpams=function(b){this.showspams=b;}
this.toggleShowSpams=function(){this.showspams=!this.showspams;var el=document.getElementById("showSpamLink"+this.instId+"_"+this.subInstId);if(el)el.innerHTML=this.showspams?"hide":"show";this.getEntries();}
this.getEntries=function(){document.getElementById('commentList'+this.instId+'_'+this.subInstId).innerHTML='Getting comments...';this.lyAjaxObj({showspams:(this.showspams?"yes":"no")},"getEntries");return false;}
this.updateEntriesCount=function(data){if(data.action=="markEntryAsSpam"){numComm=document.getElementById("numComments"+this.instId+"_"+this.subInstId);numSpam=document.getElementById("numSpams"+this.instId+"_"+this.subInstId);numComm.innerHTML=parseInt(numComm.innerHTML)-1;numSpam.innerHTML=parseInt(numSpam.innerHTML)+1;}
else if(data.action=="unmarkEntryAsSpam"){numComm=document.getElementById("numComments"+this.instId+"_"+this.subInstId);numSpam=document.getElementById("numSpams"+this.instId+"_"+this.subInstId);numComm.innerHTML=parseInt(numComm.innerHTML)+1;numSpam.innerHTML=parseInt(numSpam.innerHTML)-1;}
else if(data.action=="deleteEntry"){numComm=document.getElementById("numComments"+this.instId+"_"+this.subInstId);numSpam=document.getElementById("numSpams"+this.instId+"_"+this.subInstId);if(data.isspam=="Y"&&numSpam){numSpam.innerHTML=parseInt(numSpam.innerHTML)-1;}
else{numComm.innerHTML=parseInt(numComm.innerHTML)-1;}}
else if(data.action=="approveEntry"){numComm=document.getElementById("numComments"+this.instId+"_"+this.subInstId);numSpam=document.getElementById("numSpams"+this.instId+"_"+this.subInstId);markLink=document.getElementById("markLink"+this.instId+"_"+data.id);s=(markLink&&markLink.innerHTML=="unmark"?numSpam:numComm);s.innerHTML=parseInt(s.innerHTML)+1;}
else if(data.action=="getEntries"||data.action=="comment"){document.getElementById("numComments"+this.instId+"_"+this.subInstId).innerHTML=data.commentCount;document.getElementById("numSpams"+this.instId+"_"+this.subInstId).innerHTML=data.spamCount;document.getElementById("viewSpam"+this.instId+"_"+this.subInstId).style.display=data.dispViewSpam;}
if(parseInt(document.getElementById("numComments"+this.instId+"_"+this.subInstId).innerHTML)>0){document.getElementById("viewCommentCount"+this.instId+"_"+this.subInstId).style.display="inline";document.getElementById("noComments"+this.instId+"_"+this.subInstId).style.display="none";}
else{document.getElementById("viewCommentCount"+this.instId+"_"+this.subInstId).style.display="none";document.getElementById("noComments"+this.instId+"_"+this.subInstId).style.display="inline";}
spamCount=parseInt(document.getElementById("numSpams"+this.instId+"_"+this.subInstId).innerHTML);if(!data.dispViewSpam){document.getElementById("viewSpam"+this.instId+"_"+this.subInstId).style.display=spamCount>0?"inline":"none";}}
this.setEntriesHTML=function(data){var cont=document.getElementById("commentList"+this.instId+"_"+this.subInstId);cont.innerHTML=data.commentsHTML;this.updateEntriesCount(data);}
this.delEntry=function(comment){resp=confirm("Are you sure you would like to delete this entry?");if(!resp)
return false;var cmAll=document.getElementById("commentAll"+this.instId+"_"+comment);var loading=cmAll.ownerDocument.createElement("div");var markLink=document.getElementById("markLink"+this.instId+"_"+comment);var isspam=(!markLink||markLink.innerHTML!="unmark"?"N":"Y");loading.id="commentDeling"+comment;loading.style.backgroundColor="white";loading.style.border="1px solid black";loading.style.color="black";loading.style.padding="10px";loading.innerHTML="<img src=\"/adm/media/ajax-loader.gif\" alt=\"Please Wait.\"> Deleting entry...";markLink=null;cmAll.parentNode.replaceChild(loading,cmAll);this.lyAjaxObj({id:comment,isspam:isspam},"deleteEntry");return false;}
this.approveEntry=function(alink,comment){var loading=alink.ownerDocument.createElement("span");loading.id="commentApproving"+comment;loading.style.backgroundColor="white";loading.style.border="1px solid black";loading.style.color="black";loading.innerHTML="Approving entry...";alink.parentNode.replaceChild(loading,alink);this.lyAjaxObj({id:comment},"approveEntry");return false;}
this.submitForm=function(frm){var btn=document.getElementById("commentsSubmit"+this.instId+"_"+this.subInstId);if(btn){btn.value=this.commentSubmitting;btn.disabled=true;}
var recaptcha_iframe=document.getElementById('recaptcha_iframe'+this.instId+'.'+this.subInstId);frm.recaptcha_challenge_field.value=recaptcha_iframe.contentWindow.document.getElementById('recaptcha_challenge_field').value;frm.recaptcha_response_field.value=recaptcha_iframe.contentWindow.document.getElementById('recaptcha_response_field').value;this.lyAjaxForm(frm,'comment');}
this.toggleForm=function(display){}
this.clearForm=function(form){var btn=document.getElementById("commentsSubmit"+this.instId+"_"+this.subInstId);if(btn){btn.value=this.commentSubmitted;btn.disabled=false;}
var f=document.getElementById("guestbook_form_"+this.instId);var e=f.elements;for(id in e){if(e[id]==null||e[id].type==null)
continue;if(e[id].type=="text"||e[id].type=="textarea"||e[id].type=="password")
e[id].value="";else if(e[id].type=="checkbox"||e[id].type=="radio")
e[id].checked=false;else if(e[id].type=="select-one"||e[id].type=="select-multiple"){e[id].selectedIndex=-1;}}}
this.addQuestion=function(){var newId=this.newQuestionCounter;this.newQuestionCounter+=1;var temp=document.getElementById("questionTemplate"+this.instId);var newRow=temp.ownerDocument.createElement('div');newRow.id="questionBlock"+this.instId+"_"+newId;newRow.className="questionHolder";newRow.innerHTML=temp.innerHTML.replace(/TEMPLATE/g,newId);temp.parentNode.appendChild(newRow);newRow.style.display="";this.addAnswer(newId,false);this.addAnswer(newId,false);var inputField=document.getElementById("qinput_"+newId);if(inputField)
inputField.focus();this.alternateColors();}
this.toggleAnswerAdd=function(qid){var idStr=this.instId+"_"+qid;var sel=document.getElementById("qtype"+idStr);var items=sel.value.split('_');var anset=document.getElementById("answerSet"+idStr);anset.style.display=(items[1]=='1'?"":"none");if(anset.scrollIntoView)
anset.scrollIntoView();}
this.addAnswer=function(qid,grabFocus){var allQsDiv=document.getElementById("allQuestions_"+instId);var idStr=this.instId+"_"+qid;var temp=document.getElementById("answerTemplate"+idStr);var newDiv=temp.cloneNode(true);var lnk=document.getElementById("answerLink"+idStr);lnk.parentNode.insertBefore(newDiv,lnk.previousSibling);newDiv.style.display="";var index=newDiv.parentNode.childNodes.length;newDiv.id="answerBlock"+idStr+"_"+index;for(var c=0;c<newDiv.childNodes.length;c++){if(newDiv.childNodes[c].tagName=="INPUT"){newDiv.childNodes[c].name="answers["+index+"]["+newDiv.childNodes[c].name+"]";if(grabFocus&&newDiv.childNodes[c].style.display!='none')
newDiv.childNodes[c].focus();var aTags=newDiv.getElementsByTagName("A");if(aTags.length>0)
aTags[0].href="javascript:"+this.jsObj+".removeAnswer("+qid+","+index+")";}}
if(allQsDiv.scrollTop)
allQsDiv.scrollTop+=25;}
this.alternateColors=function(){var ct=0;var parent=document.getElementById("questionTemplate"+this.instId).parentNode;var kids=parent.childNodes;for(i in kids){if(kids[i]&&kids[i].className&&kids[i].className.indexOf("questionHolder")>=0){kids[i].className="questionHolder"+(ct?" alternate":"");ct=(ct+1)%2;}}}
this.removeAnswer=function(qid,id){var div=document.getElementById("answerBlock"+this.instId+"_"+qid+"_"+id);div.parentNode.removeChild(div);}
this.editQuestions=function(){this.lyAjaxObj({},"showEdit");}
this.removeQuestion=function(qid){var row=document.getElementById("questionBlock"+this.instId+"_"+qid);row.parentNode.removeChild(row);this.alternateColors();}
this.removeQContainer=function(qid){var cont=document.getElementById("qContainer"+this.instId+"_"+qid);cont.parentNode.removeChild(cont);cont=document.getElementById("qContainer"+this.instId+"_"+qid+"_m");cont.parentNode.removeChild(cont);}
this.onLightbox=function(evt){Lycos.ui.lightbox.show();Lycos.ui.lightbox.populate(evt.lyResponse.html);}
this.onSaveQuestions=function(evt){var cont=document.getElementById("questions_block_"+this.instId);cont.innerHTML=evt.lyResponse.html;Lycos.ui.lightbox.hide();var frames=document.getElementsByTagName("iframe");for(var i=0;i<frames.length;i++){if(frames[i].id.indexOf('webon_edit_frame')!=-1){framedocument=frames[i].contentWindow.document;result=framedocument.getElementById("questions_block_"+this.instId);if(result!=null){Lycos.ui.regionCtrl.adjustHeight(frames[i]);Lycos.ui.regionCtrl.updateEditFrame(frames[i]);}}}}
this.onRemoveQuestion=function(evt){this.removeQContainer(evt.lyResponse.qid);}
this.onComment=function(evt){var data=evt.lyResponse;recaptcha_iframe=document.getElementById('recaptcha_iframe'+this.instId+'.'+this.subInstId);recaptcha_iframe.src=recaptcha_iframe.src;if(typeof(data.error)!="undefined"){if(data.lightbox&&data.lightbox=="cancel"){Lycos.ui.lightbox.hide();}
this.clearForm();alert(data.error);}
else{this.updateEntriesCount(data);if(data.id==0){var cont=document.getElementById("commentList"+this.instId+"_"+this.subInstId);cont.innerHTML=cont.innerHTML+data.html;}
this.clearForm();this.toggleForm('none');if(data&&data.newId){var aName="comment"+this.instId+"_"+data.newId;window.location.hash="#"+aName;Lycos.ui.dragdrop.scrollToAnchor(aName);}
else{window.location.hash="#";}}}
this.onMarkEntryAsSpam=function(evt){var data=evt.lyResponse;obj=document.getElementById("markLink"+this.instId+"_"+data.id);if(obj){obj.title="unmark entry as spam";obj.innerHTML="unmark";this.updateEntriesCount(data);}}
this.onUnmarkEntryAsSpam=function(evt){var data=evt.lyResponse;obj=document.getElementById("markLink"+this.instId+"_"+data.id);if(obj){obj.title="mark entry as spam";obj.innerHTML="mark";this.updateEntriesCount(data);}}
this.onGetEntries=function(evt){this.setEntriesHTML(evt.lyResponse);}
this.onDeleteEntry=function(evt){var data=evt.lyResponse;this.updateEntriesCount(data);x=document.getElementById("commentDeling"+data.id);x.parentNode.removeChild(x);}
this.onApproveEntry=function(evt){var data=evt.lyResponse;this.updateEntriesCount(data);var x=document.getElementById("commentApproving"+data.id);var y=document.getElementById("commentApprovalNotice"+this.instId+"_"+data.id);y.parentNode.removeChild(y);x.parentNode.removeChild(x);this.updateEntriesCount(data);}}
