var activeQuestionAnswerForm=0;var savingQuestion=false;var savingAnswer=false;var imageUploadContainerWasVisible=false;var imageUploadedContainerWasVisible=false;var checkEmail=false;var sendEmail=true;function submitQuestion(){var h=$j("#question").text();var g=false;var j=USER_ID;if(j==0){if(typeof loginWhileAnsweringEpisodeQuiz!="undefined"){loginWhileAnsweringEpisodeQuiz="false"}showLoginPopup()}else{if(checkEmail&&$j("#question-emailMe").attr("checked")){FB.Connect.showPermissionDialog("email",function(q){if(q){sendEmail=true}else{$j("#question-emailMe").attr("checked","")}});checkEmail=false}else{if(!savingQuestion){savingQuestion=true;$j("#counter-button-container img").css("cursor","default");h=$j.trim(h);var o=h;if(BrowserDetect.browser=="Explorer"){var p=new RegExp(String.fromCharCode(13)+String.fromCharCode(10),"gi");o=o.replace(p,"<br>")}o=stripHTML(o);o=get_ents(o);o=$j.trim(o);var a=false;if(h.length>QUESTION_SIZE_DB){savingQuestion=false;$j("#counter-button-container img").css("cursor","pointer");if(document.getElementById("unableToSubmit")){$j.facebox(document.getElementById("unableToSubmit").innerHTML);$j("#facebox .body").css({width:"335px"});$j("#facebox .footer").css({width:"335px"});$j("#facebox").css({left:($j(window).width()-$j("#facebox").width())/2})}return false}containsImgTagB=false;if(o.length==0){if(containsImgTag(h)){containsImgTagB=true}}var i=isEmpty(o);if((o.length>QUESTION_MAX_CHARACTER_COUNTER)||((o.length==0)&&!containsImgTagB)||(i&&!containsImgTagB)){if(o.length==0||i){var e=$j("#questionCounter");var l=$j("#questionCharactersText");var m=$j("#errorProfanityDescription");e.html("");l.html("Please submit a question");l.css({color:"#f00"});m.html("&nbsp;");m.css({display:"none"})}$j("#counter-button-container img").css("cursor","pointer");savingQuestion=false;return false}else{$j.blockUI({css:{border:"none",padding:"15px",backgroundColor:"#000","-webkit-border-radius":"10px","-moz-border-radius":"10px",opacity:0.5,color:"#fff"}});var c="/answers/mathhelpquestion";var k=$j("#categoryLevel2Id").val();var n="";if(sendEmail){n=$j("#question-emailMe").attr("checked")?"on":""}else{$j("#question-emailMe").attr("checked","")}var d=0;if(typeof current_epId=="undefined"){d=EPISODE_ID}else{d=current_epId}var b=a?"true":"false";$j("#auxDiv").html(h);$j("#auxDiv img").each(function(){var q=file_name_only(new String($j(this).attr("src")));if($j(this).attr("longdesc")!=""){$j(this).attr("src",$j(this).attr("longdesc"))}});h=$j("#auxDiv").html();$j("#auxDiv").html("");h=htmlNumbers(h);var f={question:h,userId:j,categoryLevel2Id:k,episodeId:d,emailMe:n,topicUrl:ONLY_TOPIC_URI,topicId:TOPIC_ID,isThereAFile:b};goAjax(c,f,afterSubmitQuestion);return false}}}}}function afterSubmitQuestion(e){var g=e;var f=g.search(/div/i);var a=null;if(f==-1){if(e!="imageError"){var d=$j("#errorProfanityDescription");d.html(e);$j("#errorProfanityDescription").show();var c=($j("#fileToUploadQuestion").val()=="")?false:true;if(!c){removeFile("Question")}}}else{a=$j(e).find("#question_id");var b=$j("#question").text();cleanQuestionForm();$j("#question-list").prepend(e);$j("#question-list #question-container-"+a.val()+" .question span a img").each(function(){$j(this).attr("onerror","loadAgainImage($j(this))")});$j("#question").text("");$j("#question").attr("value","");if(BrowserDetect.browser=="Firefox"){$j("#question_rte").contents().find("body").html('<br _moz_dirty=""/>')}else{$j("#question_rte").contents().find("body").html("")}}$j("#counter-button-container img").css("cursor","pointer");savingQuestion=false;$j.unblockUI({onUnblock:function(){if(e=="imageError"){if(document.getElementById("uploadFileError")){$j.facebox(document.getElementById("uploadFileError").innerHTML);$j("#facebox .body").css({width:"335px"});$j("#facebox .footer").css({width:"335px"});$j("#facebox").css({left:($j(window).width()-$j("#facebox").width())/2})}}else{if(f==1){var h=$j(e).find(".question_image img");var i=file_name_only(new String(h.attr("src")));a=a.val();if(i=="ajax-loader.gif"){window.setTimeout(function(){requestQuestionAnswerImageSource(a,"question")},15000)}}}}})}function requestQuestionAnswerImageSource(d,b){var a="/answers/getquestionanswerimage";var c={questionAnswerId:d,type:b};goAjax(a,c,function(e){afterRequestQuestionAnswerImageSource(e,d,b)})}function afterRequestQuestionAnswerImageSource(data,questionAnswerId,type){var response=eval("("+data+")");if(response.error=="false"){if(type=="question"){var questionAnswerContainer="#question-container-";var questionAnswerImage=".question_image";var questionAnswerImageWidth="330px"}else{var questionAnswerContainer="#answer-container-";var questionAnswerImage=".answer_image";var questionAnswerImageWidth="370px"}var img=$j(questionAnswerContainer+questionAnswerId+" "+questionAnswerImage+" img");$j(questionAnswerContainer+questionAnswerId+" "+questionAnswerImage+" img").fadeOut(function(){img.attr("src",response.imageSrc);$j(questionAnswerContainer+questionAnswerId+" "+questionAnswerImage+" img").load(function(){$j(questionAnswerContainer+questionAnswerId+" "+questionAnswerImage).css({"margin-left":"0px"});$j(questionAnswerContainer+questionAnswerId+" "+questionAnswerImage).css({width:questionAnswerImageWidth});var imageWidth=response.imageWidth+"px";img.css({width:imageWidth});$j(questionAnswerContainer+questionAnswerId+" "+questionAnswerImage+" img").fadeIn();var targetLink=$j(questionAnswerContainer+questionAnswerId+" "+questionAnswerImage+" a");targetLink.attr("href",response.imageSrc);targetLink.attr("target","_blank")})})}else{window.setTimeout(function(){requestQuestionAnswerImageSource(questionAnswerId,type)},15000)}}function loadQuestions(c){var a="/answers/mathhelpquestions";var b={episodeId:c};goAjax(a,b,afterLoadQuestions)}function afterLoadQuestions(a){$j("#question-list").html(a)}function showAnswers(a){var c=$j("#answer-list-"+a);var b=c.children().children().children(".answer-container");if((b.length>0)||($j("#answer-form-container-"+a).children().length>0)){$j("#answer-list-"+a).toggle()}}function showAnswerForm(a){var c=USER_ID;if(c==0){showLoginPopup()}else{var e=$j("#answer-form-container-"+a).html();e='<div style = "margin-top: 10px; float: left; width: 100%;"><div style = "float: left; width: 100%; padding-bottom: 5px;" id = "answer-label-container" name = "answer-label-container"><label id = "yourAnswer-label">Your Answer:</label><span>(</span><span id="answerCounter">'+ANSWER_MAX_CHARACTER_COUNTER+'</span><span id="answerCharactersText"> characters</span><span>)</span><span id="errorProfanityAnswer"></span></div><textarea id="answer" name="answer" class="jqrte_popup" rows="5" cols="5" maxlength = "'+ANSWER_MAX_CHARACTER_COUNTER+'"></textarea>'+$j("#answerContentEditor_rte").html()+'</div><div style = "margin-top: 5px; float: left; width: 100%;"><label id = "source-label">Source:</label><input id = "answer-source" name = "answer-source" type = "text" maxlength = "2000"></input></div><div style = "padding-top: 5px; padding-bottom: 8px; float: left; width: 100%; clear: both;">';e+='<div style = "float: right; display: inline; width: 120px;"><img id = "answer-question-img" name = "answer-question-img" onclick = "javascript:submitAnswer('+a+');" src = "/images/mathhelp/submitAnswerButton.png"></img></div>';e+='<div style = "float: left; width: 250px;"><input type="checkbox" id="emailMe" name="emailMe" '+(showUpEmail?"checked":"")+'><label class = "emailMe-label" for="emailMe">Email me when other answers come in</label></div>';e+="</div>";e+='<input type = "hidden" id = "answerFormQuestionId" name = "answerFormQuestionId" value = "'+a+'" >';$j("#answerFormRTE .jqrte_rte_div").html("");$j("#answer-form-container-"+activeQuestionAnswerForm).html("");var d=$j("#answer-list-"+activeQuestionAnswerForm);var b=d.children().children().children(".answer-container");if(!(b.length>0)){$j("#answer-list-"+activeQuestionAnswerForm).hide()}$j("#answer-form-container-"+a).html(e);$j("#question-container-"+activeQuestionAnswerForm+" #answer-question").fadeIn();activeQuestionAnswerForm=a;$j("#answer-list-"+a).show();addAfterFileUploadEvent("Answer");if(BrowserDetect.browser=="Firefox"){$j("#answer_rte").load(function(){$j("#answer_rte").jqrte_setIcon();$j("#answer_rte").jqrte_setContent();$j("#answer_rte").jqrte();try{setEventHandlerAnswerW3C()}catch(f){}})}else{$j("#answer_rte").ready(function(){$j("#answer_rte").jqrte_setIcon();$j("#answer_rte").jqrte_setContent();$j("#answer_rte").jqrte();try{if(BrowserDetect.browser=="Explorer"){document.getElementById("answer_rte").contentWindow.document.onclick=function(g){if(document.getElementById("answer_rte").contentWindow.document.body!=null){setEventHandlerAnswerIE()}};document.getElementById("answer_rte").contentWindow.document.oncontextmenu=function(g){if(document.getElementById("answer_rte").contentWindow.document.body!=null){setEventHandlerAnswerIE()}}}else{setEventHandlerAnswerW3C()}}catch(f){}})}$j("#question-container-"+activeQuestionAnswerForm+" #answer-question").fadeOut()}}function submitAnswer(b){var n=$j("#answer").text();var h=false;var j=USER_ID;if(j==0){showLoginPopup()}else{if(checkEmail&&$j("#emailMe").attr("checked")){FB.Connect.showPermissionDialog("email",function(p){if(p){sendEmail=true}else{$j("#emailMe").attr("checked","")}});checkEmail=false}else{if(!savingAnswer){savingAnswer=true;$j(".answer-form-container #answer-question-img").css("cursor","default");n=$j.trim(n);var i=n;if(BrowserDetect.browser=="Explorer"){var o=new RegExp(String.fromCharCode(13)+String.fromCharCode(10),"gi");i=i.replace(o,"<br>")}i=stripHTML(i);i=get_ents(i);i=$j.trim(i);var a=false;if(n.length>ANSWER_SIZE_DB){savingAnswer=false;$j(".answer-form-container #answer-question-img").css("cursor","pointer");if(document.getElementById("unableToSubmit")){$j.facebox(document.getElementById("unableToSubmit").innerHTML);$j("#facebox .body").css({width:"335px"});$j("#facebox .footer").css({width:"335px"});$j("#facebox").css({left:($j(window).width()-$j("#facebox").width())/2})}return false}containsImgTagB=false;if(i.length==0){if(containsImgTag(n)){containsImgTagB=true}}var g=isEmpty(i);if((i.length>ANSWER_MAX_CHARACTER_COUNTER)||((i.length==0)&&!containsImgTagB)||(g&&!containsImgTagB)){if(i.length==0||g){var e=$j("#answerCounter");var k=$j("#answerCharactersText");e.html("");k.html("Please submit an answer");k.css({color:"#f00"})}$j(".answer-form-container #answer-question-img").css("cursor","pointer");savingAnswer=false;return false}else{$j.blockUI({css:{border:"none",padding:"15px",backgroundColor:"#000","-webkit-border-radius":"10px","-moz-border-radius":"10px",opacity:0.5,color:"#fff"}});var d="/answers/mathhelpanswer";var m=$j("#answer-source").val();var l="";if(sendEmail){l=$j("#emailMe").attr("checked")?"on":""}else{$j("#emailMe").attr("checked","")}var c=a?"true":"false";$j("#auxDiv").html(n);$j("#auxDiv img").each(function(){var p=file_name_only(new String($j(this).attr("src")));if($j(this).attr("longdesc")!=""){$j(this).attr("src",$j(this).attr("longdesc"))}});n=$j("#auxDiv").html();$j("#auxDiv").html("");n=htmlNumbers(n);var f={answer:n,userId:j,questionId:b,source:m,emailMe:l,isThereAFile:c};goAjax(d,f,function(p){afterSubmitAnswer(p,b)});return false}}}}}function afterSubmitAnswer(e,a){var g=e;var f=g.search(/div/i);var d=null;if(f==-1){if(e!="imageError"){var c=$j("#errorProfanityAnswer");c.html(e);$j("#errorProfanityAnswer").show();var b=($j("#fileToUploadAnswer").val()=="")?false:true;if(!b){removeFile("Answer")}}}else{cleanAnswerForm();d=$j(e).find("#answer_id");$j("#answer-list-"+a).children().children().prepend(e);$j("#answer-container-"+d.val()+" .answer span img").each(function(){$j(this).attr("onerror","loadAgainImage($j(this))")});$j("#answer").text("");$j("#answer").attr("value","");if(BrowserDetect.browser=="Firefox"){$j("#answer_rte").contents().find("body").html('<br _moz_dirty=""/>')}else{$j("#answer_rte").contents().find("body").html("")}if((typeof(bunchballHandler)!="undefined")&&(bunchballHandler!=null)){bunchballHandler.showNotifications()}}$j(".answer-form-container #answer-question-img").css("cursor","pointer");savingAnswer=false;$j.unblockUI({onUnblock:function(){if(e=="imageError"){if(document.getElementById("uploadFileError")){$j.facebox(document.getElementById("uploadFileError").innerHTML);$j("#facebox .body").css({width:"335px"});$j("#facebox .footer").css({width:"335px"});$j("#facebox").css({left:($j(window).width()-$j("#facebox").width())/2})}}else{if(f==1){var h=$j(e).find(".answer_image img");var i=file_name_only(new String(h.attr("src")));d=d.val();if(i=="ajax-loader.gif"){window.setTimeout(function(){requestQuestionAnswerImageSource(d,"answer")},15000)}}}}})}function cleanQuestionForm(){var b=$j("#questionCounter");var a=$j("#questionCharactersText");var c=$j("#errorProfanityDescription");b.css({color:"#666"});a.css({color:"#666"});var d=$j("#question").attr("maxlength");b.html(d);a.html("&nbsp;characters");c.html("&nbsp;");c.css({display:"none"});$j("#question").attr("value","");$j("#question-emailMe").attr("checked",true);removeFile("Question")}function cleanAnswerForm(){var b=$j("#answerCounter");var a=$j("#answerCharactersText");var c=$j("errorProfanityAnswer");b.css({color:"#666"});a.css({color:"#666"});var d=$j(".answer-form-container #answer").attr("maxlength");b.html(d);a.html("&nbsp;characters");c.html("&nbsp;");c.css({display:"none"});$j(".answer-form-container #answer").attr("value","");$j("#answer-source").val("");$j(".answer-form-container #emailMe").attr("checked",true);removeFile("Answer")}function enablingQuestions(a){USER_ID=a;removeFile("Question");$j("#emailMe-container").fadeIn();enableRteAfterLogin("question",QUESTION_MAX_CHARACTER_COUNTER,true,true);$j("#question-label-container").append('<span id="errorProfanityDescription"></span>')}$j(document).ready(function(){addAfterFileUploadEvent("Question");$j("#question-list .question_image img").each(function(){var b=$j(this);var c=file_name_only(new String(b.attr("src")))});if(USER_ID==0){$j("#question_rte").jqrte_setIconNotLoggedIn()}else{$j("#question_rte").jqrte_setIcon();$j("#question_rte").jqrte_setContent();$j("#question_rte").jqrte();try{if(BrowserDetect.browser!="Explorer"){setEventHandlerQuestionW3C()}else{document.getElementById("question_rte").contentWindow.document.onclick=function(b){if(document.getElementById("question_rte").contentWindow.document.body!=null){setEventHandlerQuestionIE()}};document.getElementById("question_rte").contentWindow.document.oncontextmenu=function(b){if(document.getElementById("question_rte").contentWindow.document.body!=null){setEventHandlerQuestionIE()}}}}catch(a){}}if(USER_ID==0){$j(".jqrte_menu_div .jqrte_menu td").click(function(){showLoginPopup()})}});function addAfterFileUploadEvent(b){var a=document.getElementById("fileToUpload"+b);if(a!=null){a.onchange=a.onmouseout=function(){if(this.value!=""){$j("#image-upload-container"+b).hide();$j("#filename"+b).text("Uploaded!");$j("#removeFileLink"+b).show();$j("#image-uploaded-container"+b).show();if(b=="Question"){checkTextAreaLen(document.getElementById("question"))}else{if(b=="Answer"){checkTextAreaLen(document.getElementById("answer"))}}}else{$j("#filename").text("")}}}}function removeFile(a){$j("#fileToUpload"+a).remove();$j("#fileToUploadContainer"+a).append('<input id = "fileToUpload'+a+'" name = "fileToUpload'+a+'" style = "right: 125px;" type="file" class="file" />');addAfterFileUploadEvent(a);$j("#filename"+a).text("");$j("#removeFileLink"+a).hide();$j("#image-uploaded-container"+a).hide();$j("#image-upload-container"+a).show()}function ajaxFileUpload(){$j.ajaxFileUpload({url:"/image/uploadimageinsession",secureuri:false,fileElementId:"fileToUpload",dataType:"json",success:function(b,a){if(typeof(b.error)!="undefined"){if(b.error!=""){alert(b.error)}else{alert(b.msg)}}},error:function(b,a,c){alert(c)}});return false}function submitRichText(){var a=$j("#content").attr("value");alert(a);$j("#output").html(a)}function resetUploadImageInputTypeFile(){$j("#uploadimage_div_pc #uploadimage_div #uploadimage_error").html("");var a=$j("#uploadimage_div_pc #uploadimage_div #uploadimage_fileToUpload").parent();$j("#uploadimage_div_pc #uploadimage_div #uploadimage_fileToUpload").remove();a.append('<input type="file" name="fileToUpload" id="uploadimage_fileToUpload"/>')};