
var formcreator=$.inherit(Module,{__constructor:function(elem){this.__base(elem);this.type="formcreator";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.commentSubmitDefaultText="Submit";this.newQuestionCounter=100000001;this.showspams=false;},checkForm:function(){},setSpamEntry:function(obj,id,b){this.lyAjaxObj({id:id},(b?"mark":"unmark")+"EntryAsSpam");return false;},getForm:function(div){return $("."+div).find("form")[0];},toggleSpamEntry:function(obj,id){return this.setSpamEntry(obj,id,(obj.innerHTML=="mark"));},setShowSpams:function(b){this.showspams=b;},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();},getEntries:function(){this.lyAjaxObj({showspams:(this.showspams?"yes":"no")},"getEntries");return false;},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";}},setEntriesHTML:function(data){var cont=document.getElementById("commentList"+this.instId+"_"+this.subInstId);cont.innerHTML=data.commentsHTML;this.updateEntriesCount(data);},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;},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;},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');},toggleForm:function(display){},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();},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();},addAnswer:function(qid,grabFocus){var _this=this;var allQsDiv=document.getElementById("allQuestions_"+this.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;$('input',newDiv).each(function(){$(this).attr('name',"answers["+index+"]["+$(this).attr('name')+"]");$(this).siblings('a').click(function(){_this.removeAnswer(qid,index);});$(this).focus();});if(allQsDiv.scrollTop)
allQsDiv.scrollTop+=25;},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;}}},removeAnswer:function(qid,id){var div=document.getElementById("answerBlock"+this.instId+"_"+qid+"_"+id);div.parentNode.removeChild(div);},editQuestions:function(){this.lyAjaxObj({},"showEdit");},removeQuestion:function(qid){var row=document.getElementById("questionBlock"+this.instId+"_"+qid);row.parentNode.removeChild(row);this.alternateColors();},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);},onLightbox:function(evt){Lycos.ui.lightbox.show();Lycos.ui.lightbox.populate(evt.lyResponse.html);},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]);}}}},onRemoveQuestion:function(evt){this.removeQContainer(evt.lyResponse.qid);},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.resetForm();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.resetForm();this.toggleForm('none');}},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);}},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);}},onGetEntries:function(evt){this.setEntriesHTML(evt.lyResponse);},onDeleteEntry:function(evt){var data=evt.lyResponse;this.updateEntriesCount(data);x=document.getElementById("commentDeling"+data.id);x.parentNode.removeChild(x);},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);},resetForm:function(){$('input',$("div[id*='qContainer']",this.element)).val('');$('textarea',$("div[id*='qContainer']",this.element)).val('');$("input[id*='commentsSubmit']",this.element).val(this.commentSubmitDefaultText).attr('disabled',false);}});
