﻿
		/*
 * Copyright (C) 2007 Trivantis Corporation
 */

	
function saveVariable(A,B,C,D,E) {var F=getTitleMgrHandle();var G="";if (C) {var H=new Date();H.setTime(H.getTime()+(C*24*60*60*1000));G="; expires="+H.toGMTString();};var I=UniEscape(B);var J=(C?'LectoraPermCookie':'LectoraTempCookie');if(D){J+='_'+D;};var K='|'+A+"=";var L=document.cookie.split(';');var i,j;var M=0;var N=n;var O=-1;for(i=0;i<L.length;i++){var c=L[i];for(j=0;j<c.length;j++){if(c.charAt(j)!=' '){break;}};c=c.substring(j);if(c.indexOf(J)===0){var P=c.indexOf('=');M=parseInt(c.substring(J.length,P),10);var Q=c.indexOf(K);if(Q>=0){var R=c.substring(P+1,Q);var S=c.substring(Q+K.length);var T=S.indexOf('|');S=S.substring(T);N=R+S;O=M;break;}else{N=c.substring(P+1);}}};trivLogMsg('saveVariable for '+A+' to ['+B+']',2);if(F){F.setVariable(A,I,C);if((!C||E)&&!document.titleMgr&&!window.jTitleManager){return;}};var U=K+I+"|";var W=n;if(N!==n&&(N.length+U.length<4000)){if(N){N=N.substring(0,N.length-1);};if(C<0){U=n;};W=J+M;document.cookie=W+"="+N+U+G+"; path=/";}else{if(N!==n&&O!=-1) {var X=J+O;document.cookie=X+"="+N+G+"; path=/";};W=J+(M+1);document.cookie=W+"="+U+G+"; path=/";}};function readVariable(A,B,C,D) {var E=getTitleMgrHandle();if(E===n||E.findVariable(A)<0){var F=(C?'LectoraPermCookie':'LectoraTempCookie');if(D){F+='_'+D;};var G='|'+A+"=";var H=document.cookie.split(';');var i,j;for(i=0;i<H.length;i++){var c=H[i];for(j=0;j<c.length;j++){if(c.charAt(j)!=' '){break;}};c=c.substring(j);if(c.indexOf(F)===0){var I=c.indexOf(G);if(I>=0){var J=c.substring(I+G.length);var K=J.indexOf('|');J=J.substring(0,K);var L=UniUnescape(J);if(E){E.setVariable(A,J,C);};trivLogMsg('readVariable for '+A+' = ['+L+']',1);return L;}}}};if(E) {var M=new String(E.getVariable(A,B,C));B=UniUnescape(M);};trivLogMsg('readVariable for '+A+' = ['+B+']');return B;};function cleanupTitle(A) {if(window.name.indexOf('Trivantis_')==-1) {var B=new Date();B.setTime(B.getTime()+(-1*24*60*60*1000));var C="; expires="+B.toGMTString();var D='LectoraTempCookie';if(A){D+='_'+A;};for(var i=1;i<21;i++){var E=D+i;if(readCookie(E,'')!==''){document.cookie=E+"="+C+"; path=/";}else{break;}};if (A!=A.toLowerCase()) cleanupTitle(A.toLowerCase());return 1;}else{return 0;}};function Variable(A,B,f,C,D,E,F) {var G=this;G.origAICC=f;G.bSCORM=f;G.of=f;G.f=f;G.eTS=n;G.tV=n;G.aiccframe=D;G.aiccgroup=n;G.aicccore=f;G.exp=E;G.defVal=(B===n||typeof B=='undefined'?n:B.toString());G.cm=0;G.title=F;G.lastUT=n;if(C) {G.cm=-1*C;if(A=='CM_Course_ID')G.name='TrivantisCourse';else if(A=='CM_Course_Name')G.name='TrivantisCourseName';else if(A=='CM_Student_ID')G.name='TrivantisLogin';else if(A=='CM_Student_Name')G.name='TrivantisLoginName';else {G.name=A;G.cm=C;}}else if(D) {var H=A.indexOf('AICC_');if(H===0) {G.origAICC=t;G.name=A.substring(5);var I=n;if(D=='scorm') {G.bSCORM=t;G.aiccgroup='cmi';G.name=G.name.toLowerCase();I=G.name.substring(0,5);if(I=='core_') {G.name=G.name.substring(5);};if(G.name=='lesson') {G.name='cmi.suspend_data';}else if(G.name=='vendor') {G.name='cmi.launch_data';}else if(G.name=='time') {G.name='cmi.core.total_time';}else if(G.name=='score') {G.name='cmi.core.score.raw';}else {G.name='cmi.core.'+G.name;}}else if(D=='scorm2004') {G.bSCORM=t;G.aiccgroup='cmi';G.name=G.name.toLowerCase();I=G.name.substring(0,5);if(I=='core_') {G.name=G.name.substring(5);};if(G.name=='lesson') {G.name='cmi.suspend_data';}else if(G.name=='vendor') {G.name='cmi.launch_data';}else if(G.name=='time') {G.name='cmi.total_time';}else if(G.name=='score') {G.name='cmi.score.raw';}else if(G.name=='course_id'){G.name='cmi.evaluation.course_id';}else if(G.name=='lesson_id'){G.name='cmi.core.lesson_id';}else if(G.name=='student_id'){G.name='cmi.learner_id';}else if(G.name=='student_name'){G.name='cmi.learner_name';}else if(G.name=='lesson_location'){G.name='cmi.location';}else if(G.name=='lesson_status'){G.name='cmi.success_status';}else {G.name='cmi.'+G.name;}}else if(G.name=='Core_Lesson') {G.aiccgroup='[CORE_LESSON]';}else if(G.name=='Core_Vendor') {G.aiccgroup='[CORE_VENDOR]';}else if(G.name=='Course_ID') {G.aiccgroup='[EVALUATION]';}else {G.aiccgroup='[CORE]';G.aicccore=t;};if(!G.bSCORM) {G.update();}}else {if(D=='scorm'||D=='scorm2004') {G.bSCORM=t;};if(A.indexOf('CMI_Core')===0) {G.origAICC=t;G.aiccgroup='cmi';if(A=='CMI_Core_Entry') {G.name='cmi.core.entry';G.update();}else {G.name='cmi.core.exit';G.value=G.defVal;}}else if (A=='CMI_Completion_Status') {if(D=='scorm2004') {G.bSCORM=t;};G.origAICC=t;G.aiccgroup='cmi';G.name='cmi.completion_status';G.update();}else {G.name=A;}}}else {G.name=A;};if(G.f==4) {G.uDT();}};var p=Variable.prototype;p.save=function() {var A=this;var B=n;if(A.cm) {B=getTitleMgrHandle();if(B) {B.setVariable(A.name,UniEscape(A.value),A.exp);}}else if(A.aiccframe){B=getTitleMgrHandle();if(A.bSCORM) {var C=A.value;if(C=='~~~null~~~'){C=n;};if(A.name=='cmi.core.total_time'||A.name=='cmi.total_time') {if(A.aiccframe=='scorm') {LMSSetValue('cmi.core.session_time',C);if(B) {B.setVariable('cmi.core.session_time',UniEscape(A.value),A.exp);}}else {LMSSetValue('cmi.session_time',C);if(B) {B.setVariable('cmi.session_time',UniEscape(A.value),A.exp);}}}else {if(B) {B.setVariable(A.name,UniEscape(A.value),A.exp);};if(A.aiccgroup) {LMSSetValue(A.name,C);if(A.name=='cmi.score.raw'){var D=A.value/100;LMSSetValue('cmi.score.scaled',D);LMSCommit("");}else if(this.name=='cmi.core.score.raw'||this.name=='cmi.core.lesson_status'||this.name=='cmi.success_status'){LMSCommit("");}}else {var E=A.name+"=";var F=E+UniEscape(A.value)+';';var G=f;var H=new String(LMSGetValue('cmi.suspend_data'));if(H!='') {var I=H.split(';');for(var i=0;i<I.length;i++) {var c=I[i];if (c!=''&&c.indexOf(E)!=0) {F=F+c+';';}}};LMSSetValue('cmi.suspend_data',F);var J=new String(LMSGetValue('cmi.suspend_data'));if(UniUnescape(J).length<UniUnescape(F).length) {G=t;};if(G) {var K='Some of the persistent data was not able to be stored';trivLogMsg(K,2);alert(K);}}}}else{if(A.aicccore) putParam(A.aiccgroup,A.name+'='+A.value,A.aiccframe);else if(A.aiccgroup) putParam(A.aiccgroup,A.value,A.aiccframe);else{if(B) B.setVariable(A.name,UniEscape(A.value),A.exp);saveVariable(A.name,A.value,A.exp,A.title,A.aiccframe);}}}else{if(A.f!==0&&A.tV>=0) {if(A.f==4) {saveVariable(A.name,"~~f=4~~"+A.tV+'#'+A.value,A.exp,A.title,A.aiccframe);}else if (A.f==2) {saveVariable(A.name,"~~f=2~~"+A.tV+'#'+A.value,A.exp,A.title,A.aiccframe);}else if (A.f==1) {saveVariable(A.name,"~~f=1~~"+A.tV+'#'+A.value,A.exp,A.title,A.aiccframe);}};A.value=EncodeNull(A.value);saveVariable(A.name,A.value,A.exp,A.title,A.aiccframe);}};p.set=function(A) {var B=this;B.value=EncodeNull(A);B.f=0;B.eTS=n;B.tV=n;B.save();};p.add=function(A) {var B=this;this.update();if (B.f>0&&!isNaN(A)) {B.tV+=CalcTD(B.f,A);B.uDTV();}else if(B.value=="~~~null~~~") {B.f=0;if(A!==n&&A!=='') {B.value=A;}}else {B.f=0;if(A!=n&&A!='') {if(!isNaN(B.value)&&!isNaN(A)&&!isNaN(parseFloat(A))&&!isNaN(parseFloat(B.value))) {var C=parseFloat(B.value)+parseFloat(A);var D=B.value.toString();if(A.indexOf(".")!=-1&&D.indexOf(".")!=-1){C=(parseInt(C*100000000,10))/100000000;};B.value=C.toString();}else if (A!="~~~null~~~") { B.value+=A;}}};B.save();};p.sub=function(A) {var B=this;B.update();var C=n;if (B.f>0&&!isNaN(A)) {B.tV-=CalcTD(B.f,A);B.uDTV();}else if(B.value=="~~~null~~~") {B.f=0;if(!isNaN(A)&&!isNaN(parseFloat(A))) {B.value=parseFloat("-"+A).toString();}}else {B.f=0;if(A!==n&&A!=="") {if(!isNaN(B.value)&&!isNaN(A)&&!isNaN(parseFloat(A))&&!isNaN(parseFloat(B.value))) {C=parseFloat(B.value)-parseFloat(A);var D=B.value.toString();A=A.toString();if(A.indexOf(".")!=-1&&D.indexOf(".")!=-1){C=(parseInt(C*100000000,10))/100000000;};B.value=C.toString();}else if(B.value.length>=A.length&&B.value.substr(B.value.length-A.length)==A) {B.value=B.value.substr(0,B.value.length-A.length);}}};B.save();};p.mult=function(A) {var B=this;B.update();if(B.value!="~~~null~~~") {if(!isNaN(B.value)&&!isNaN(A)&&!isNaN(parseFloat(A))&&!isNaN(parseFloat(B.value))) {var C=parseFloat(B.value)*parseFloat(A);if(A.indexOf(".")!=-1&&B.value.toString().indexOf(".")!=-1){C=(parseInt(C*100000000,10))/100000000;};B.value=C.toString();};B.save();}};p.div=function(A) {var B=this;B.update();if(B.value!="~~~null~~~") {if(!isNaN(B.value)&&!isNaN(A)&&!isNaN(parseFloat(A))&&!isNaN(parseFloat(B.value))) {if(parseFloat(A)!==0) {var C=parseFloat(B.value)/parseFloat(A);C=parseInt(C*100,10);C=parseFloat(C/100);if(A.indexOf(".")!=-1&&B.value.toString().indexOf(".")!=-1){C=(parseInt(C*100000000,10))/100000000;};B.value=C.toString();}};B.save();}};p.setByVar=function(A) {var B=this;if(A.f>0) {A.uDT();}else {A.update();};B.value=A.value;B.f=A.f;B.eTS=A.eTS;B.tV=A.tV;B.save();};p.addByVar=function VarAddVar(A) {var B=this;if(A.f>0) {A.uDT();if(B.f>0) {B.tV+=A.tV;if(A.f==1) {B.f=1;};B.uDTV();}else {B.add(A.value);}}else {A.update();B.add(A.value);}};p.subByVar=function(A) {var B=this;if(A.f>0) {A.uDT();if(B.f>0) {B.tV-=A.tV;if(A.f==1) {B.f=1;};B.uDTV();}else {B.sub(A.value);}}else {A.update();B.sub(A.value);}};p.contains=function(A) {this.update();var B=this.value;if(B=="~~~null~~~"||(B==""&&B!=0)) {return 0;};return (new String(B)).indexOf(A)>=0;};p.equals=function(A) {this.update();return (this.value==A);};p.lessThan=function(A) {this.update();var B=this.value;if(B=="~~~null~~~"||(B==""&&B!=0)) {if(A=="~~~null~~~"||A==="") {return 0;}else {return 1;}};if(isNaN(B)||isNaN(A)){return B<A;}else {return parseFloat(B)<parseFloat(A);}};p.greaterThan=function(A) {this.update();var B=this.value;if(B=="~~~null~~~"||(B==""&&B!=0)) {if(A=="~~~null~~~"||A==="") {return 1;}else {return 0;}};if(isNaN(B)||isNaN(A)) {return B>A;}else {return parseFloat(B)>parseFloat(A);}};p.uDT=function() {var A=this;var B=new Date();if(A.f==1) {A.tV=B.getTime();A.value=FormatDS(B);}else if(A.f==2) {A.tV=B.getTime();A.value=FormatTS(B);}else if(A.of==4) {var C=0;if(A.eTS===n) {var D=readVariable(A.name,"",A.exp,A.title);if(D) {var E=parseInt(D,10);var F=D.indexOf(':');D=D.substring(F+1);var G=parseInt(D,10);F=D.indexOf(':');D=D.substring(F+1);var H=parseInt(D,10);C=(((E*60)+G)*60+H)*1000;};A.eTS=B.getTime()-C;};A.tV=B.getTime()-A.eTS;A.value=FormatETS(A.tV);};A.save();};p.uDTV=function() {var A=this;if(A.f==1) {A.value=FormatDS(new Date(A.tV));}else if(A.f==2) {A.value=FormatTS(new Date(A.tV));}else if(A.f==4) {A.value=FormatETS(A.tV);};A.save();};p.update=function() {var A=this;var B=new Date().getTime();if(A.lastUT>=B-500) {return;}else {A.lastUT=B;};var C=n;if(A.cm) {if(A.cm<0) {A.defVal=readCookie(A.name,A.defVal);A.cm*=-1;};C=getTitleMgrHandle();if(C) {var D=new String(C.getVariable(A.name,UniEscape(A.defVal),A.exp));A.value=UniUnescape(D);}else A.value=A.defVal;}else if(A.aiccframe) {C=getTitleMgrHandle();if(A.origAICC) {if(A.bSCORM) {if(A.name=='cmi.evaluation.course_id') {A.value=A.defVal;}else if(A.name=='cmi.core.lesson_id') {A.value=A.defVal;}else if(A.name!='cmi.core.exit'&&A.name!='cmi.exit') A.value=new String(LMSGetValue(A.name));if(C) {C.setVariable(A.name,UniEscape(A.value),A.exp);if(A.name=='cmi.learner_id') {C.setVariable('cmi.core.student_id',UniEscape(A.value),A.exp);};if(A.name=='cmi.learner_name') {C.setVariable('cmi.core.student_name',UniEscape(A.value),A.exp);};if(A.name=='cmi.core.total_time'||A.name=='cmi.total_time') {A.value=UpdateSCORMTotalTime(A.value);}}}else if(A.name=='Core_Lesson') {A.value=getParam(A.aiccgroup);}else if(A.name=='Core_Vendor') {A.value=getParam(A.aiccgroup);}else if(A.name=='Course_ID') {A.value=getParam(A.name);}else {A.value=getParam(A.name);}}else {if(A.bSCORM) {A.value=A.defVal;if(C&&C.findVariable(A.name)!=-1){var D=new String(C.getVariable(A.name,UniEscape(A.defVal),A.exp));A.value=UniUnescape(D);} else {var F=new String(LMSGetValue('cmi.suspend_data'));if(F==='') {if(C) {C.setVariable(A.name,UniEscape(A.value),A.exp);}}else {var G=F.split(';');for(var i=0;i<G.length;i++) {var c=G[i];if(c.indexOf('=')>=0) {ce=c.split('=');if(A.name==ce[0]) {A.value=UniUnescape(ce[1]);};if(C) {C.setVariable(ce[0],ce[1],A.exp);}}}}}}else {if(C) {var D=new String(C.getVariable(A.name,UniEscape(A.defVal),A.exp));A.value=UniUnescape(D);}else {A.value=A.defVal;}}}}else if(A.f>0) {A.uDT();}else {var I=readVariable(A.name,A.defVal,A.exp,A.title);var J=I?I.substr(0,7):n;if(J=="~~f=1~~") {A.tV=parseInt(I.substr(7,I.length-7),10);A.f=1;A.uDTV();}else if(J=="~~f=2~~") {A.tV=parseInt(I.substr(7,I.length-7),10);A.f=2;A.uDTV();}else if(J=="~~f=4~~") {B=new Date();A.tV=parseInt(I.substr(7,I.length-7),10);A.eTS=B.getTime()-A.tV;A.f=4;A.uDTV();}else {A.value=I;}};A.value=EncodeNull(A.value);};p.getValue=function(){this.update();return this.value;};p.mailTo=function() {this.update();ObjLayerActionGoTo('mailto:'+this.value);};p.isCorr=function(A) {this.update();return (this.value.toString()==A)?t:f;};p.isCorrSub=function(A,B) {this.update();var C=A.split(",");return (this.value.toString().indexOf(C[B?B:0])>=0)?t:f;};p.isAnsSub=function(A) {this.update();var B=','+(A+1)+'-';var C=','+this.value;return (C.indexOf(B)>=0)?t:f;};p.isCorrFIB=function(A) {this.update();var B=A.split("~;~");for(var i=0;i<B.length;i++) {if(this.value.toString()==B[i]) return t;};return f;};function saveTestScore(A,B,C,D){saveVariable(A,B,n,C,D);};var titleMgrHandle=n;var getFn=n;function getTitleMgrHandle(){if(!theApp.is.ieMac){if (titleMgrHandle===n){try {titleMgrHandle=getTitleMgr(window,0);} catch(error){ titleMgrHandle=n;}}};return titleMgrHandle;};function getTitleMgr(A,B){if(!A) return null;if(A.jTitleManager) return A.jTitleManager;else if(A.document.titleMgr) return A.document.titleMgr;else{var C;if(this.frameElement&&this.frameElement.id&&this.frameElement.id.indexOf('DLG_content')==0&&parent.parent) C=eval("parent.parent.titlemgrframe");else C=eval("parent.titlemgrframe");try {if(!C) C=A.parent.titlemgrframe;} catch (e) {};if(C) {if(C.jTitleManager) return C.jTitleManager;else return C.document.TitleMgr;} else {if(A.name.indexOf('Trivantis_Dlg_')==0) return getTitleMgr(A.parent,B+1);else {if(A.name.indexOf('Trivantis_')==0) return getTitleMgr(A.opener,B+1);else if(B<2) return getTitleMgr(A.parent,B+1);}}};return null;};function readCookie(A,B) {var C=A+"=";var D=document.cookie.split(';');for(var i=0;i<D.length;i++) {var c=D[i];while (c.charAt(0)==' ') {c=c.substring(1);};if (c.indexOf(C)===0) {return c.substring(C.length);}};return B;};function afterProcessTest(A,B) {};function UpdateSCORMTotalTime(A) {var B=readVariable('TrivantisSCORMTimer',0);if (B===0) {return A;};var C=new Date().getTime();var D=C-B;var E=parseInt(A,10);var F=A.indexOf(':');A=A.substring(F+1);var G=parseInt(A,10);F=A.indexOf(':');A=A.substring(F+1);var H=parseInt(A,10);F=A.indexOf('.');A=A.substring(F+1);var I=parseInt(A,10)*100;var J=(((E*60)+G)*60+H)*1000+I;return convertTotalMills(J+D);};function EncodeNull(A) {return (A==null)?"~~~null~~~":((String(A)=="0")?0:((A=="")?"~~~null~~~":A));};

