oTQ.oQ=function(){var d={qid:$D.generateId(null,"qid"),qtags:"",qtype:"single",qbody:"",qtext:"",explanation:"",difflevel:5,aAnswers:[]};var b=["single","multi","blank"];var c={setQtype:function(e){d.qtype=e},getType:function(){return d.qtype},setBody:function(e){d.qbody=e},setTags:function(e){d.qtags=e},getBody:function(){return d.qbody},setExplanation:function(e){d.explanation=e},getExplanation:function(){return d.explanation},addAnswer:function(f,j,g,l,h,e){var k={};k.body=g;k.iscorrect=l;k.aid=f;k.letter=j;k.explanation=(h)?h:"";k.matchcase=(e)?e:"";d.aAnswers.push(k)},getAnswers:function(){return d.aAnswers},getQ:function(){return d}};return c};oTQ.qMaker=function(){var h,n,k,g,f,m,o,d,c,l,j,e,b=["A","B","C","D","E","F","G","H","I","J","K","L","M","O","P","Q"];if(!oTQVARS){throw new TQException("oQTVARS not found on page. It must be present in HTML code somewhere")}if(oTQVARS.maxAnswers){j=oTQVARS.maxAnswers}$("qbtext").focus();that={setAnswerLetters:function(p){b=p},renderButtons:function(){var q,p=$C("tt",null,$("main"));g=new $W.Button("addanswer");g.on("click",this.addAnswer,this,true);f=new $W.Button("explain");f.on("click",this.addExplanation,f);m=new $W.Button("preview");m.on("click",this.preview,this,true);d=new $W.Button("endpreview");d.on("click",this.send,this,true);q=new $W.Button("edit");q.on("click",this.edit,this,true);o=new $W.Button("sendout");o.on("click",this.send,this,true);k=new $W.Tooltip("oTooltip",{context:p,effect:{effect:$W.ContainerEffect.FADE,duration:0.2,autodismissdelay:3000}})},addAnswer:function(){var t,p,s,q,r=this.getAnswerTrs();t=this.getCountAnswers();p=r[0];q=p.cloneNode(true);q.id=$D.generateId(null,"ans");this.toggleCheckBox(q,false);$D.removeClass(q,"glow");$D.removeClass($C("delete","div",q),"hidden");s=q.getElementsByTagName("textarea")[0];$D.addClass(q.getElementsByTagName("em")[0],"hidden");this.getChoicesTbody().appendChild(q);s.focus();this.setQnumbers();t++;if(t>=j){g.set("disabled",true)}},toggleCheckBox:function(p,r){var q=p.getElementsByTagName("input");if(q&&q[0]){q[0].checked=r}},getChoicesTbody:function(){if(!l){var q=$("choices");var p=q.getElementsByTagName("tbody");l=p[0]}return l},toggleAsCorrect:function(s){var q,r,p=$D.getAncestorByTagName(s,"tr");r=p.getElementsByTagName("em")[0];if($D.hasClass(p,"glow")){$D.removeClass(p,"glow");this.toggleCheckBox(p,false);$D.addClass(r,"hidden")}else{$D.addClass(p,"glow");this.toggleCheckBox(p,true);$D.removeClass(r,"hidden")}this.setQnumbers()},addExplanation:function(r){var q=$E.getTarget(r);var p=$("explanation");$D.removeClass(p,"hidden")},removeExplanation:function(){var p=$("explanation");p.getElementsByTagName("textarea")[0].value="";$D.addClass(p,"hidden");f.set("disabled",false)},setQnumbers:function(){var p,q=0,t,s,r=this.getAnswerTrs();n="single";for(i=0;i<r.length;i+=1){p=r[i];t=b[i];p.getElementsByTagName("textarea")[0].tabIndex=i+2;s=$C("order","td",p)[0];s.innerHTML=t;if($D.hasClass(r[i],"glow")){q++}}if(q>1){n="multi"}},getCountAnswers:function(){var p,q;p=this.getAnswerTrs();q=p.length;return q},getAnswerTrs:function(){a=this.getChoicesTbody().getElementsByTagName("tr");return a},getQuestionBody:function(){var p="",q=$("qbody").getElementsByTagName("textarea");if(!q){throw new TQException("Unable to find textarea element")}p=q[0].value;return p},getTags:function(){var p=$("qtags");var q=p.value;return q},getExplanation:function(){var q,p="";q=$("explanation").getElementsByTagName("textarea");if(!q){throw new TQException('Unable to find element "textarea" under the "explanation" div')}p=q[0].value;return p},deleteAnswer:function(q){var p=$D.getAncestorByTagName(q,"tr");p.parentNode.removeChild(p);this.setQnumbers();g.set("disabled",false)},getAnswerBody:function(p){var q=p.getElementsByTagName("textarea");if(!q){throw new TQException("Unable to find textarea of the answer")}return q[0].value},makeQuestion:function(){var p,q,s,r=this.getAnswerTrs();c=oTQ.oQ();c.setBody(this.getQuestionBody());c.setTags(this.getTags());c.setQtype(n);c.setExplanation(this.getExplanation());for(i=0;i<r.length;i+=1){p=r[i];q=this.getAnswerBody(p);sAnsLetter=$C("order","td",p)[0].innerHTML;s=($D.hasClass(p,"glow"));c.addAnswer(p.id,sAnsLetter,q,s)}return this},validate:function(){var q=0,r,p,s;if(""===this.getQuestionBody()){alert("Question body cannot be empty. Please enter a text of the question");s=$("qbody").getElementsByTagName("textarea")[0];return s}r=this.getAnswerTrs();for(i=0;i<r.length;i+=1){p=r[i];s=p.getElementsByTagName("textarea")[0];if(""===s.value){alert("Answer choice cannot be left blank. Either enter some text for this answer choice or delete it");return s}if($D.hasClass(r[i],"glow")){q++}}if(0===q){alert('Please designate at least one answer choice as "correct answer"');return false}return true},showEndPreview:function(){if($D.hasClass($("endPreview"),"hidden")){$D.removeClass($("endPreview"),"hidden")}},hideEndPreview:function(){if(!$D.hasClass($("endPreview"),"hidden")){$D.addClass($("endPreview"),"hidden")}},preview:function(){var r,p,q=this.validate();if(true!==q){if(q){q.focus()}return false}this.makeQuestion();r=c.getQ();e=oTQ.qRenderer(r);p=e.getRendered();k.hide();h=$("main").replaceChild(p,$("question"));this.showEndPreview()},edit:function(){if(!h){throw new TQException("Cannot switch back to edit mode because eEditorDiv element not found")}k.hide();if(e){e.destroySubmitButton()}var p=$("main").replaceChild(h,$("qdiv"));p=null;this.hideEndPreview()},getQuestion:function(){var p=c.getQ();return p},send:function(r){var q=$E.getTarget(r);if(!$("qdiv")){var p=this.validate();if(true!==p){if(p){p.focus()}return false}this.makeQuestion()}oTQ.formElements.disable(o);oTQ.formElements.disable(d);oTQ.formElements.addLoaderClass(q);oTQ.authAndPost(oTQ.sendNewQuestion)},toString:function(){return"object qMaker"}};return that};oTQ.sendNewQuestion=function(){if(!oTQ.oQmaker){alert("Cannot send question because object oTQ.oQmaker not found");return false}var c=oTQ.getToken(),d=oTQ.oQmaker.getQuestion();var b=$J.stringify(d);$CONN.asyncRequest("POST","/index.php",oTQ.oCallback,"a=sendq&q="+b+"&token="+c);return"oTQ.sendNewQuestion ok"};$E.onDOMReady(function(){oTQ.oQmaker=oTQ.qMaker();oTQ.oQmaker.renderButtons();oTQ.oQmaker.setQnumbers()});
