
CPN.LessonViewer=function(frame)
{this.lessonFrame=frame;this.window=frame.contentWindow;this.document=this.window.document;this.documentElement=$(this.window.document.documentElement);if(this.document.title)
{this.title=this.document.title;}
$('lessonTitle').innerHTML=this.title;this.view=this.INDEX_VIEW;this.currentLesson=null;this.currentPage=null;this.currentPageIndex=-1;this.breadcrumb={home:$('breadcrumb1'),category:$('breadcrumb2'),lesson:$('breadcrumb3')};if(this.title!='Lessons')
{this.breadcrumb.home.innerHTML='<a href="../learning/index.php" target="lessonContent">Lessons</a>';this.breadcrumb.category.show();this.breadcrumb.category.down('a').innerHTML=this.title;}
$('breadcrumbs').show();this.quizButton=$('quizButton');this.backButton=$('backButton');this.nextButton=$('nextButton');this.pageNumbers=$('pageNumbers');this.container=this.window.$('lessonContainer');this.currentModule=this.indexPage=this.window.$('index');this.lessons=[];this.parseLessons();this.showIndex();$('lessonFooter').down('table').show();$('lessonLoadingIcon').hide();this.lessonFrame.show();};CPN.LessonViewer.prototype={INDEX_VIEW:1,LESSON_VIEW:2,QUIZ_VIEW:3,FEEDBACK_URL:'../tools/feedback.php',lessonPrefix:'lesson_',parseLessons:function()
{var children=this.container.immediateDescendants();for(var i=0,count=children.length;i<count;i++)
{if(children[i].hasClassName('lesson'))
{var lesson=new CPN.Lesson(children[i],this);this.lessons[lesson.id]=lesson;}
children[i].hide();}},updateFooter:function(showBack,showNext,pageNum,numPages)
{setVisibility(this.backButton,showBack);setVisibility(this.nextButton,showNext);this.pageNumbers.innerHTML=(pageNum+1)+' of '+numPages;this.pageNumbers.show();},showIndex:function()
{this.hideCurrentLesson();this.currentModule=this.indexPage;this.indexPage.show();this.breadcrumb.lesson.hide();[this.quizButton,this.backButton,this.nextButton,this.pageNumbers].invoke('hide');},showLesson:function(lessonId)
{this.hideCurrentLesson();this.currentLesson=this.lessons[lessonId];if(this.currentLesson)
{this.breadcrumb.lesson.innerHTML='-&gt;&nbsp;'+this.currentLesson.title;this.breadcrumb.lesson.show();this.indexPage.hide();this.view=this.LESSON_VIEW;this.quizButton.show();this.setPage(0);this.currentLesson.show();}
else
{this.showIndex();}},hideCurrentLesson:function()
{if(this.currentLesson)
{this.currentLesson.hide();this.currentPage.hide();}},nextPage:function()
{this.setPage(this.currentPageIndex+1);},previousPage:function()
{this.setPage(this.currentPageIndex-1);},setPage:function(pageIndex)
{var result;if(this.view==this.LESSON_VIEW)
{result=this.currentLesson.setPage(pageIndex);}
else if(this.view==this.QUIZ_VIEW)
{result=this.currentLesson.quiz.setPage(pageIndex);}
else
{return;}
if(result)
{if(this.currentPage)
{this.currentPage.hide();}
this.currentPage=result;this.currentPageIndex=pageIndex;this.currentPage.show();}},showQuiz:function()
{if(this.view==this.QUIZ_VIEW||!this.currentLesson||!this.currentLesson.quiz)
{return;}
this.currentPage.hide();this.view=this.QUIZ_VIEW;this.currentLesson.quiz.show();this.setPage(0);},feedback:function()
{$('feedbackFrame').src=this.FEEDBACK_URL+'?s=lesson';$('feedbackDialog').show();this.feedbackDlg=new YAHOO.widget.Dialog
('feedbackDialog',{width:'330px',height:'315px',fixedcenter:true,visible:false,constraintoviewport:true,postmethod:'none',modal:true});this.feedbackDlg.render();this.feedbackDlg.show();}};CPN.Lesson=function(container,viewer)
{this.container=container;this.viewer=viewer;this.pages=[];this.quiz=null;this.id=container.id.substring(this.LESSON_PREFIX.length);this.parse();};CPN.Lesson.prototype={LESSON_PREFIX:'lesson_',show:function(){return this.container.show();},hide:function(){return this.container.hide();},parse:function()
{var lessonChildren=this.container.immediateDescendants();lessonChildren.invoke('hide');this.pages=lessonChildren.findAll(function(e){return e.hasClassName('page');});this.numPages=this.pages.length;this.title=lessonChildren.find(function(e){return e.hasClassName('title');}).innerHTML;var quizElement=this.viewer.window.$('quiz_'+this.id);if(quizElement)
{this.quiz=new CPN.Quiz(quizElement,this.viewer);}},setPage:function(pageNum)
{if(pageNum<0||this.numPages<=pageNum)
{return null;}
this.viewer.updateFooter(pageNum>0,(pageNum<this.numPages-1),pageNum,this.numPages);return this.pages[pageNum];}};CPN.Quiz=function(container,viewer)
{this.container=container;this.viewer=viewer;this.scores=[];this.parse();};CPN.Quiz.prototype={show:function(){return this.container.show();},hide:function(){return this.container.hide();},parse:function()
{var quizChildren=this.container.immediateDescendants();quizChildren.invoke('hide');this.questions=quizChildren.findAll(function(e){return e.hasClassName('question');});var answerKey=quizChildren.find(function(e){return e.hasClassName('answerKey');});this.answerKey=answerKey.innerHTML.toLowerCase().split(',');this.numQuestions=this.questions.length;this.container.select('.answer').invoke('hide');},setPage:function(questionNum)
{if(questionNum<0||this.numQuestions<questionNum)
{return null;}
if(questionNum==this.numQuestions)
{return this.showQuizResults(questionNum);}
var question=this.questions[questionNum];this.currentQuestionNum=questionNum;var questionAnswered;if(question.hasClassName('matching'))
{questionAnswered=this.matchingSetup(question);}
else
{questionAnswered=this.multipleChoiceSetup(question);}
var showBack=questionNum>0,showNext=(questionNum<this.numQuestions-1)&&questionAnswered;this.viewer.updateFooter(showBack,showNext,questionNum,this.numQuestions);return question;},multipleChoiceSetup:function(question)
{var questionAnswered=question.down('div.answer').visible();if(!questionAnswered)
{var answers=question.down('ol.answers').immediateDescendants();for(var i=0;i<answers.length;i++)
{YAHOO.util.Event.addListener(answers[i],'click',this.onAnswerClick,this,true);YAHOO.util.Event.addListener(answers[i],'mouseover',this.onAnswerMouseOver,this,true);YAHOO.util.Event.addListener(answers[i],'mouseout',this.onAnswerMouseOut,this,true);}}
return questionAnswered;},onAnswerClick:function(e)
{var li=Event.element(e),answers=li.parentNode.immediateDescendants(),usersAnswer=answers.indexOf(li),correctAnswer=this.getCorrectAnswer(),answerElement=this.questions[this.currentQuestionNum].down('div.answer');for(var i=0;i<answers.length;i++)
{YAHOO.util.Event.removeListener(answers[i],'click',this.onAnswerClick);YAHOO.util.Event.removeListener(answers[i],'mouseover',this.onAnswerMouseOver);YAHOO.util.Event.removeListener(answers[i],'mouseout',this.onAnswerMouseOut);}
li.addClassName('selected');this.scores[this.currentQuestionNum]=(usersAnswer==correctAnswer);if(usersAnswer==correctAnswer)
{new Insertion.Top(answerElement,'<b>Correct!</b><br/>');}
else
{answers[correctAnswer].addClassName('correctAnswer');new Insertion.Top(answerElement,'<b>Incorrect.</b><br/>');}
answerElement.show();this.viewer.nextButton.show();},onAnswerMouseOver:function(e)
{Event.element(e).addClassName('selected');},onAnswerMouseOut:function(e)
{Event.element(e).removeClassName('selected');},getCorrectAnswer:function()
{var possibleAnswers='abcdefg',correctAnswerLetter=this.answerKey[this.currentQuestionNum];return possibleAnswers.indexOf(correctAnswerLetter);},matchingSetup:function(question)
{if(question._setup!==true)
{var choices=question.select('.choices');choices=choices[0].immediateDescendants();var select=this.viewer.document.createElement('select');select.options.add(new Option('',''));for(var i=0;i<choices.length;i++)
{var letter=String.fromCharCode(i+65);select.options.add(new Option(letter,letter));}
for(var i=0;i<choices.length;i++)
{var html='<select>'+select.innerHTML+'</select>&nbsp;';new Insertion.Top(choices[i],html);}
var button=question.select('.checkAnswers');button=button[0];YAHOO.util.Event.addListener(button,'click',this.matchingCheckAnswers,this,true);question._setup=true;}},matchingCheckAnswers:function(e)
{var question=this.questions[this.currentQuestionNum],answerKey=question.down('.answerKey').innerHTML.toLowerCase().split(','),usersAnswers=question.select('.choices');usersAnswers=usersAnswers[0].immediateDescendants();var numWrong=0;for(var i=0;i<answerKey.length;i++)
{var li=usersAnswers[i],select=li.down('select'),answer=select.value;if(answer.toLowerCase()!=answerKey[i])
{li.style.backgroundColor='#FF8E8E';new Insertion.Bottom(li,' - Answer: '+answerKey[i].toUpperCase());numWrong++;}}
if(!this.matchingScore)
{this.matchingScore={correct:0,incorrect:0};}
this.matchingScore.incorrect+=numWrong;this.matchingScore.correct+=answerKey.length-numWrong;var button=question.select('.checkAnswers');button=button[0].hide();this.viewer.nextButton.show();},showQuizResults:function(pageIndex)
{var container=this.container.down('div.quizResults');if(!container)
{var numCorrect=this.scores.findAll(function(s){return s===true;}).length,numWrong=this.scores.findAll(function(s){return s===false;}).length;var html='<div class="quizResults">'+'<h2>Multiple Choice:</h2>'+'&nbsp;&nbsp;Correct: '+numCorrect+'<br>'+'&nbsp;&nbsp;Incorrect: '+numWrong+'<br>';if(this.matchingScore)
{html+='<h2>Matching:</h2>'+'&nbsp;&nbsp;Correct: '+this.matchingScore.correct+'<br>'+'&nbsp;&nbsp;Incorrect: '+this.matchingScore.incorrect+'<br>';}
html+='</div>';new Insertion.Bottom(this.container,html);container=this.container.down('div.quizResults');}
else
{ret=container;}
this.viewer.updateFooter(true,false,0,0);this.viewer.pageNumbers.hide();return container;}};function setVisibility(element,show)
{if(show)
{element.show();}
else
{element.hide();}}
function filterByClassName(elements,className)
{var f=function(e){e.hasClassName(className);};return elements.findAll(f);}
function showLesson(lessonId)
{window.parent.lessonViewer.showLesson(lessonId);}
function lessonSetLoad()
{var p=window.parent;p.$('lessonContent').hide();p.$('lessonLoadingIcon').show();}
var glossary=new Glossary('../');function g(element,entry)
{var name=entry?entry:element.innerHTML;var region=YAHOO.util.Dom.getRegion(element);glossary.show({'name':name},region.left,region.bottom+2,293);}
function frameCheck(redirectUrl)
{if(window.top==window)
{window.location=redirectUrl;}}