// (c) Link-Systems International, Inc. (1999)
function n20()
{
this.ntemplates=0;
this.template_files=new Array();
this.templates=new Array();
}

var template_list=new n20();

function Test()
{
this.questions=new Array();
this.title="";
this.type="";
}

var test=new Test();


function n25(nv,va,qu,so,hi,wo,rf,cc,chap,sec)
{
var ty='S';
this.type=ty;
this.nvars=nv;
this.vars=va;
this.question=qu;
this.solution=so;
this.hint=hi;
this.worked=wo;
this.ref=rf;
this.concept=cc;
this.chapter=chap;
this.section=sec;
}


function n61(nv,va,qu,so,hi,wo,rf,cc,nch,ch,chap,sec)
{
var ty='M';
this.type=ty;
this.nvars=nv;
this.vars=va;
this.question=qu;
this.solution=so;
this.hint=hi;
this.worked=wo;
this.ref=rf;
this.concept=cc;
this.nchoices=nch;
this.choices=ch;
this.chapter=chap;
this.section=sec;
}


function n150(nv,va,qu,so,hi,wo,rf,cc,nqs,ins,or,qw,qh,aw,ah,chap,sec)
{
var ty='A';
this.type=ty;
this.nvars=nv;
this.vars=va;
this.question=qu;
this.solution=so;
this.hint=hi;
this.worked=wo;
this.ref=rf;
this.concept=cc;
this.nquestions=nqs;
this.instructions=ins;
this.orientation=or;
this.qwidth=qw;
this.qheight=qh;
this.awidth=aw;
this.aheight=ah;
this.chapter=chap;
this.section=sec;
}


function n108(nv,va,qu,so,hi,wo,rf,cc,nqa,ins,or,qw,qh,aw,ah,chap,sec)
{
var ty='D';
this.type=ty;
this.nvars=nv;
this.vars=va;
this.question=qu;
this.solution=so;
this.hint=hi;
this.worked=wo;
this.ref=rf;
this.concept=cc;
this.nquestions=nqs;
this.instructions=ins;
this.orientation=or;
this.qwidth=qw;
this.qheight=qh;
this.awidth=aw;
this.chapter=chap;
this.section=sec;
}


function n26(template_index,varvals,solution)
{
this.template_index=template_index;
this.varvals=varvals;
this.solution=solution;
this.correct=false;
this.done=false;
this.bookmarked=false;
this.seen_solution=false;
this.response="";
this.retries=0;
this.problemnumber=0;
this.next=null;
this.prev=null;
}


function n62(template_index,varvals,solution,ichoices)
{
this.template_index=template_index;
this.varvals=varvals;
this.solution=solution;
this.correct=false;
this.done=false;
this.bookmarked=false;
this.seen_solution=false;
this.response=-1;
this.ichoices=ichoices;
this.retries=0;
this.problemnumber=0;
this.next=null;
this.prev=null;
}


function n151(template_index,varvals,solution,iquests,ichoices)
{
this.template_index=template_index;
this.varvals=varvals;
this.solution=solution;
this.correct=false;
this.done=false;
this.bookmarked=false;
this.seen_solution=false;
this.response="";
this.iquests=iquests;
this.ichoices=ichoices;
this.retries=0;
this.problemnumber=0;
this.next=null;
this.prev=null;
}


function n109(template_index,varvals,solution,iquests,ichoices)
{
this.template_index=template_index;
this.varvals=varvals;
this.solution=solution;
this.correct=false;
this.done=false;
this.bookmarked=false;
this.seen_solution=false;
this.response="";
this.iquests=iquests;
this.ichoices=ichoices;
this.retries=0;
this.problemnumber=0;
this.next=null;
this.prev=null;
}



function n8(ty,sp)
{
this.type=ty;
this.spec=sp;
}



function Value(ty,va)
{
this.type=ty;
this.val=va;
}



function n88(pgref){

var chap,sec,pglink,refline,lpgref;

if(pgref)
{
chap=(curr_chap);
chap=chap==NCHAPTERS&&CHAP0?0:chap;
sec=(curr_sec);
pglink="pg"+parseInt(pgref);
refline=new String(MOREINFO);
if(pgref.indexOf('-')>0)
lpgref="pages "+pgref;
else
lpgref="page "+pgref;
refline=refline.replace(/<<P>>/g,lpgref);
refline=refline.replace(/<<R>>/g,pglink);
refline=refline.replace(/<<C>>/g,chap);
refline=refline.replace(/<<S>>/g,sec);
refline="<P>"+refline;
}else{
refline="";
}
return refline;
}



function n6(instring,ncvals,cvals)
{
var ostring=new String(instring);
var tvar,temp,tcut,tend,tvarlen,tval,ch,i=0,j,k=0;

for(i=ncvals;i>=0;i--)
{
tvar="V."+i;
tvarlen=tvar.length;
while(ostring.indexOf(tvar)>=0)
{
tcut=ostring.indexOf(tvar);
tend=ostring.length;


if(Number(cvals[i])<0)
{
ch=" ";
for(j=tcut-1,k=0;j>=0&&ch==" ";j--)
{
ch=ostring.substring(j,j+1);
k++;
}

if(ch=="+")
tval=" - "+(cvals[i]*-1);
else if(ch=="-")
tval=" + "+(cvals[i]*-1);
else if(ch=="*"||ch=="/")
tval=ch+"("+cvals[i]+")";
else
{
k=0;
tval=cvals[i];
}
}
else
{
k=0;
tval=cvals[i];
}

temp=ostring.substring(0,tcut-k)+tval+
ostring.substring(tcut+tvarlen,tend);
ostring=temp;
}
}
return ostring;
}



function evaluate(tval,ncvals,cvals)
{
var tindx,temp,tspec0,tspec1,tspec2,tspval0,tspval1,tspval2,size,choices;
var range_chk=0,max_tries=0,n=0;
var whole,num,den,len,spacer,tstring,indx;
var result;
var ttype=new String(tval.type);


if(ttype.substring(0,1)=='G')
{
choices=tval.type.split(".");

result="<img src=\""+tval.spec[0]+"\" border=0 width="+choices[1]+
" height="+choices[2]+" align=absmiddle>";

}


if(ttype.substring(0,1)=='I')
{
if(isNaN(parseInt(Math.round(eval(""+n6(tval.spec[1],ncvals,cvals))))))
result=Math.round(eval(""+n6(tval.spec[0],ncvals,cvals)));

else
{
tspec0=n6(tval.spec[0],ncvals,cvals);
tspec1=n6(tval.spec[1],ncvals,cvals);
tspec2=n6(tval.spec[2],ncvals,cvals);
tspval0=Number(eval(""+tspec0));
tspval1=Number(eval(""+tspec1));


if(tspec2!=NA)
{
tspval2=tspec2.split(",");

while(!range_chk&&max_tries<20)
{
temp=Math.random()*(tspval1-tspval0);
result=Math.round(temp+tspval0);

for(n=0;n<tspval2.length;n++)
if(eval(tspval2[n])!=result)range_chk++;

if(range_chk!=tspval2.length)range_chk=0;

max_tries++;
}

if(max_tries==20&&range_chk==0)result=null;
}
else
{
temp=Math.random()*(tspval1-tspval0);
result=Math.round(temp+tspval0);
}
}
if(result==null)result=999999999;

}


if(ttype.substring(0,1)=='L')
{
size=parseInt(ttype.substring(2,ttype.length));

tstring=new String(tval.spec[0]);
if((indx=tstring.indexOf(':'))>-1)
{
tindx=eval(""+n6(tstring.substring(0,indx),ncvals,cvals))-1;
tstring=tstring.substring(indx+1,tstring.length);
if(tindx<0)
tindx=0;
if(tindx>=size)
tindx=size-1;
}
else
tindx=Math.floor(Math.random()* size);

if(size<=0)result=99999999;
else
{
choices=tstring.split(',');
result=n6(choices[tindx],ncvals,cvals);
}

}


if(ttype.substring(0,1)=='R')
{

if(isNaN(parseInt(Math.round(eval(""+n6(tval.spec[1],ncvals,cvals))))))
{
temp=eval(""+n6(tval.spec[0],ncvals,cvals));
result=n93(temp,ttype);
}


else
{
tspec0=n6(tval.spec[0],ncvals,cvals);
tspec1=n6(tval.spec[1],ncvals,cvals);
tspec2=n6(tval.spec[2],ncvals,cvals);
tspval0=Number(eval(""+tspec0));
tspval1=Number(eval(""+tspec1));
if(tspec2!=NA)
{
tspval2=tspec2.split(",");

while(!range_chk&&max_tries<20)
{
temp=Math.random()*(tspval1-tspval0)+tspval0;
result=n93(temp,ttype);

for(n=0;n<tspval2.length;n++)
if((n93(eval(tspval2[n]),ttype))!=result)range_chk++;

if(range_chk!=tspval2.length)range_chk=0;

max_tries++;
}

if(max_tries==20&&range_chk==0)result=999999999;
}
else
{
temp=Math.random()*(tspval1-tspval0)+tspval0;
result=n93(temp,ttype);
}
}
}


if(ttype.substring(0,1)=='S')
{
temp=n6(tval.spec[0],ncvals,cvals);
if(temp==null)temp='Undefined';

if(ttype.substring(1,2)=='E')
{
result=eval(""+temp);
}
else
result=temp;
}

return result;
}


function n93(val,type)
{
var size,temp,result;
var ndigl=Math.floor(Math.log(Math.abs(val))*Math.LOG10E);

size=parseInt(type.substring(eval(type.indexOf('.')+1),type.length));
if(size<0)
temp=val;


else
{
var mult=1.0;
temp=val;
if(val<0)
{
mult=-1.0
temp=Math.abs(val);
}


if(Math.abs(val)<.1)
temp=0.1+temp;


if(ndigl<0&&size>12)
{
size=12;
}
else if(ndigl>=0&&ndigl+size>12)
{
size=12 -ndigl;

}


temp=""+temp;


var decpos=temp.indexOf('.');
if(decpos<0)
decpos=temp.length;

var pos=Number(decpos)+size+1;


if(pos<=temp.length-1)
{
if(temp.charAt(pos)=='5')
temp=temp.substring(0,pos)+'9';
else if(temp.charAt(pos)=='4'&&temp.length>=15)
{
count=0;
while(temp.charAt(pos+count+1)=='9'&&pos+count+1<temp.length)
count++;
if((1.0*count)/(temp.length-pos-1)>=.8)
temp=temp.substring(0,pos)+'9';
}
}


if(Math.abs(val)<.1)
temp=Number(temp)-0.1;

temp=mult*(Math.round(Math.pow(10,size)*temp))/ Math.pow(10.0,size);
}


if(temp==null)temp=999999999;


result=""+temp;
if(result.indexOf(".")==0)
result="0"+result;
else
if(result.indexOf("-")==0&&result.indexOf(".")==1)
result="-0"+result.substring(1,result.length);


if(type.substring(1,2)=='*'&&size>=0)
{
if(result.indexOf(".")<0)
result=result+".";
temp=result.substring(result.indexOf("."),result.length)
for(i=temp.length;i<=size;i++)
result=result+"0";
}
return result;
}




function n11(vals,nvals)
{
var i,j,ival,jval;
var uniq=true;


for(i=0;i<nvals;i++)
{
ival=vals[i].type.substring(0,1)=="R"||
vals[i].type.substring(0,1)=="I"||
vals[i].type.substring(0,2)=="SE"?
eval(""+vals[i].val): vals[i].val;
for(j=i-1;j>=0;j--)
{
jval=vals[j].type.substring(0,1)=="R"||
vals[j].type.substring(0,1)=="I"||
vals[j].type.substring(0,2)=="SE"?
eval(""+vals[j].val): vals[j].val;
if(ival==jval)
uniq=false;
}
}


return uniq;
}

function mkchapmenu(init)
{
question.document.open();
question.document.write("<html><head><title>Main Menu</title>"+nl+
"<SCRIPT language='Javascript'>"+nl+
"function go2chap(chapter_n)"+nl+
"{"+nl+
"if(chapter_n!=100)"+nl+
"{"+nl+
"parent.curr_chap=chapter_n;"+nl+
"parent.curr_sec=0;"+nl+
"parent.Sec_disp();"+nl+
"} else {"+nl+
"parent.mktest(0,0,'T-FIN')"+nl+
"if (parent.template_list.ntemplates > 0)"+nl+
"  parent.n71(parent.template_list.template_files[0],null);"+nl+
"} }"+nl+
"<\/SCRIPT>"+nl);
question.document.write("<LINK rel=stylesheet href='cd_styles.css' type='text/css'>"+nl);
question.document.write("</head>"+nl);
question.document.write("<body class='question' bgcolor='white'>"+nl);
question.document.write("<center>"+nl+
"<P><b><font size=+1>"+
"<i>Welcome to the Understanding Basic Statistics Site!</i></font>"+
"<p>Please select the chapter you wish to practice.</b><P>"+
"<table border=2 cellpadding=20 bgcolor='white'>"+nl+"<tr><td>"+nl);
for(i=1;i<=NCHAPTERS;i++)
{
question.document.write("<a href='javascript:go2chap("+i+")'><b>"+
CHAPTITLES[i]+"<\/b><\/a><br>"+"\n");
}


question.document.write("<br><a href='javascript:go2chap(100)'><b>"+
"FINAL EXAM<\/b><\/a><br>"+"\n");

question.document.write("<\/td><\/tr><\/table><\/center><\/body><\/html>");
question.document.close();


if(!init)
{
subtitle.document.location='subtitle.html';
if(chap_buttons.indexOf("|")>=0)
{
var buttarr=new Array();
buttarr=chap_buttons.split("|");
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(buttarr[1],"Chapters","horizontal","separate"));
buttons.document.close();
extras.document.open("text/html","replace");
extras.document.write(display_buttons(buttarr[0],"Chapters","vertical","separate"));
extras.document.close();
}
else
{
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(chap_buttons,"Chapters","horizontal","separate"));
buttons.document.close();
}
}
}



function Sec_disp()
{
var chapn=curr_chap;
var qindx=SECTITLES[chapn].length -1;


subtitle.document.open("text/html","replace");
var sub_title="<html><head>"+nl;
subtitle.document.write(sub_title);
sub_title="<link rel=stylesheet href='cd_styles.css' type='text/css'>"+nl;
subtitle.document.write(sub_title);
sub_title="<\/head>"+nl+"<body bgcolor=white>"+nl+
"<table width=100% height=40 cellspacing=0 cellpadding=0 "+
" border=0><tr>"+
"<td width=5 height=38 bgcolor='#ffffff'>"+
"<img src='gifs/blank.gif' border=0 width=5 height=2><\/td>"+
"<td height=38><font color="+tfcolor+"><b>"+TITLE+
"<br><font size=+1 color="+tfcolor+">"+
"CHAPTER "+curr_chap+
"<\/font><\/b><\/font>"+
"<\/td><\/tr><tr>"+
"<td width=5 height=2 bgcolor='#ffffff'>"+
"<img src='gifs/blank.gif' border=0 width=5 height=2><\/td>"+
"<td height=2 bgcolor='#ff9900' width=100%>"+
"<img src='gifs/blank.gif' border=0 width=100% height=2>"+
"<\/td><\/tr>"+
"<\/table><\/body><\/html>";
subtitle.document.write(sub_title);
subtitle.document.close();

question.document.open();
question.document.write("<html><head>"+nl+
"<BASE HREF=\'"+topURL+"\'>"+nl+
"<script>"+nl+
"function checksec(secn,type)"+nl+"{"+nl+
"var chapn =  parent.curr_chap;"+nl+
" parent.curr_sec = secn;"+nl+
"parent.mktest(chapn,secn,type);"+nl+
"if (parent.template_list.ntemplates > 0)"+nl+
"  parent.n71(parent.template_list.template_files[0],null);"+nl+
"}"+nl+
"<\/script>"+nl);

question.document.write("<link rel=stylesheet href='cd_styles.css' type='text/css'>"+nl);
question.document.write("<\/head>"+nl);
question.document.write("<body class='question'>"+nl);



question.document.write(
"<p><center>"+nl+"<b>"+nl+
"Please select the section you wish to practice."+nl+
"<\/b></center><P>"+nl+"<center><table cellpadding=20 bgcolor=white border=2><tr><td>"+nl);

if((typeof pretest!="undefined")&&pretest&&chapn>1)
question.document.write("<a href='javascript:void(checksec(0,\"T-PRE\"));'>"+
"<b>Chapter "+chapn+" "+pretestname+"<\/b><\/a><br>"+nl);

for(i=1;i<=qindx;i++)
{
question.document.write(
"<a href='javascript:"+
"void(checksec("+i+",\"S-SEC\"));'>"+
"<b>"+SECTITLES[chapn][i]+"<\/b><\/a><br>"+nl);
}

if((typeof posttest!="undefined")&&posttest)
question.document.write("<a href='javascript:void(checksec(0,\"T-POST\"));'>"+
"<b>Chapter "+chapn+" "+posttestname+"<\/b><\/a><br>"+nl);

if((typeof cumtest!="undefined")&&cumtest)
question.document.write("<a href='javascript:void(checksec(0,\"T-CUM\"));'>"+
"<b>Chapter "+chapn+" "+cumtestname+"<\/b><\/a><br>"+nl);

question.document.write("<\/td><\/tr><\/table><\/center>"+nl);
question.document.write("<\/body><\/html>");
question.document.close();


if(sec_buttons.indexOf("|")>=0)
{
var buttarr=new Array();
buttarr=sec_buttons.split("|");
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(buttarr[1],"Sections","horizontal","separate"));
buttons.document.close();
extras.document.open("text/html","replace");
extras.document.write(display_buttons(buttarr[0],"Sections","vertical","separate"));
extras.document.close();
}
else
{
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(sec_buttons,"Sections","horizontal","separate"));
buttons.document.close();
}

}



function mktest(chapn,secn,type)
{
curr_template=0;
curr_instance=0;
template_list.ntemplates=0;
template_list.template_files.length=0;
template_list.templates.length=0;
test.questions.length=0;
template_list.template_files=new Array();
template_list.templates=new Array();
test.questions=new Array();
var now=new Date();
testtime=now.getTime();

switch(type){

case"S-SEC":
curr_chap=chapn;
curr_sec=secn;
test.type="S-SEC";
test.title=sectestname;
template_list.ntemplates=SECTEMPLATES[chapn][secn];
for(i=0,prob=1;i<template_list.ntemplates;i++,prob++)
{
template_list.template_files[i]="chap"+chapn+"/sect"+secn+
"/prob"+prob+"/prob.html";

}
nquests=i;
break;

case"T-PRE":
if(chapn==STCHAP)
{
pname=pretestname.toLowerCase();
if(!standalone)
alert("There is no "+pname+" for this chapter.");
return;
}
else
{
test.type="T-PRE";
test.title=pretestname;
mkrandomtest(STCHAP,chapn-1,pretest_size);
}
break;

case"T-POST":
test.type="T-POST";
test.title=posttestname;
mkrandomtest(chapn,chapn,posttest_size);
break;

case"T-CUM":
test.type="T-CUM";
test.title=cumtestname;
mkrandomtest(STCHAP,chapn,cumtest_size);
break;

case"T-FIN":
test.type="T-FIN";
test.title=finaltestname;
mkrandomtest(STCHAP,NCHAPTERS,cumtest_size);
break;

DEFAULT:
test.type="T-FIN";
mkrandomtest(STCHAP,NCHAPTERS,cumtest_size);
}
}



function mkrandomtest(stchap,enchap,testsize)
{
var nchaps=enchap-stchap+1;
var count=0,pcount=0;


if(testsize<=nchaps)
{
for(c=stchap+nchaps-testsize;c<=enchap;c++)
{
s=NSECTIONS[c];
if(SECTEMPLATES[c][s]>0)
{
prob=Math.floor(SECTEMPLATES[c][s]*Math.random())+1;
template_list.template_files[count]="chap"+c+"/sect"+s+
"/prob"+prob+"/prob.html";
count++
}
}
}



else
{
nqperchap=Math.floor(testsize/nchaps);
echapqs=testsize -nchaps*nqperchap;
for(c=stchap;c<=enchap;c++)
{
if(c<=enchap-echapqs)
nq=nqperchap;
else
nq=nqperchap+1;


if(nq<NSECTIONS[c])
{
for(s=NSECTIONS[c]-nq+1;s<=NSECTIONS[c];s++)
{
if(SECTEMPLATES[c][s]>0)
{
prob=Math.floor(SECTEMPLATES[c][s]*Math.random())+1;
template_list.template_files[count]="chap"+c+"/sect"+s+
"/prob"+prob+"/prob.html";
count++
}
}
}


else
{
nqpersec=Math.floor(nq/NSECTIONS[c]);
esecqs=nq -NSECTIONS[c]*nqpersec;
for(s=1;s<=NSECTIONS[c];s++)
{
if(s<=NSECTIONS[c]-esecqs)
nsq=nqpersec;
else
nsq=nqpersec+1;

prob=0;
for(p=1;p<=nsq;p++)
{
if(SECTEMPLATES[c][s]>0)
{
prob=prob+Math.floor(SECTEMPLATES[c][s]/nsq*Math.random())+1;
if(prob>SECTEMPLATES[c][s])
prob=SECTEMPLATES[c][s];
template_list.template_files[count]="chap"+c+"/sect"+s+
"/prob"+prob+"/prob.html";
count++
}
}
}
}
}
}


if(count>0){
template_list.ntemplates=testsize;
nquests=testsize;
}else{
template_list.ntemplates=0;
nquests=0;
}
}




var nexttm;
function n71(dbfile,ipar)
{
if(!(dbld&&exld)){
nexttm=setTimeout("n71('"+dbfile+"',"+ipar+")",50);
}
else
{
clearTimeout(nexttm);
mkdb=false;
db.document.location.href=dbfile;
go_makedb(ipar);
}
}

function go_makedb(ipar)
{
if(!(mkdb))
nexttm=setTimeout("go_makedb("+ipar+")",50);
else{
var pnum=ipar==null?0:test.questions[ipar].problemnumber+1;
clearTimeout(nexttm);
n76(curr_template,curr_instance);
test.questions[curr_instance].prev=ipar;
test.questions[curr_instance].problemnumber=pnum;

n44();
}
}



function n76(tindex,iindex)
{
var varvals=new Array();
var tsolution,tprob,tvar,indx1,indx2,tspec,ttype,tvalue,temp,i;
var uniquech=false;
var uniquepr=false;
var non_unique_ctr=-1;
var tchoices=new Array();
var nchoices;
var tmix=new Array();

var probt=template_list.templates[tindex];

nchoices=Math.min(MAXCHOICES-1,probt.nchoices);

while((uniquech==false||uniquepr==false)&&non_unique_ctr<100)
{
for(i=0;i<probt.nvars;i++)
varvals[i]=evaluate(probt.vars[i],i-1,varvals);

uniquepr=true;
for(i=0;i<iindex;i++)
{
if(test.questions[i].varvals.length==probt.nvars)
{
uniquepr=false;
for(j=0;j<probt.nvars;j++)
{
if(test.questions[i].varvals[j]!=varvals[j])
{
uniquepr=true;
break;
}
}
}
if(!uniquepr)
break;
}
if(!uniquepr)
{
non_unique_ctr++;
continue;
}


tvalue=""+evaluate(probt.solution,probt.nvars,varvals);
tvalue=tvalue.replace(/<box>/gi,"");
tvalue=tvalue.replace(/<\/box>/gi,"");

ttype=new String(probt.solution.type);
if(ttype=="SE")
ttype="S";
tchoices[0]=new Value(ttype,tvalue);
solindx=0;

if(ttype.substring(0,1)=="G")
tsolution=probt.solution.spec[0];

else
tsolution=tvalue;


if(probt.type=="M")
{
for(i=0;i<probt.nchoices;i++)
tmix[i]=i;
for(i=0;i<probt.nchoices;i++)
{
indx1=Math.floor(Math.random()*probt.nchoices);
indx2=Math.floor(Math.random()*probt.nchoices);
if(indx1!=indx2)
{
temp=tmix[indx1];
tmix[indx1]=tmix[indx2];
tmix[indx2]=temp;
}
}

for(i=0;i<Math.min(MAXCHOICES-1,probt.nchoices);i++)
{
indx1=tmix[i];
indx2=i+1;
ttype=new String(probt.choices[indx1].type);
tvalue=""+evaluate(probt.choices[indx1],probt.nvars,varvals);
tvalue=tvalue.replace(/<box>/gi,"");
tvalue=tvalue.replace(/<\/box>/gi,"");
if(ttype=="SE")
ttype="S";
tchoices[indx2]=new Value(ttype,tvalue);
}

uniquech=n11(tchoices,Math.min(MAXCHOICES,parseInt(probt.nchoices)));

if(uniquech)
{
if(probt.nchoices>2)
{
last=Math.min(MAXCHOICES-1,probt.nchoices);
indx1=Math.floor(Math.random()*last);
temp=tchoices[0];
tchoices[0]=tchoices[indx1];
tchoices[indx1]=temp;
tsolution=indx1;
tchoices[probt.nchoices]=new n8();
tchoices[probt.nchoices].val='none of these';
tchoices[probt.nchoices].type='S';
}
else
{
indx1=Math.floor(Math.random()*probt.nchoices+.5);
temp=tchoices[0];
tchoices[0]=tchoices[indx1];
tchoices[indx1]=temp;
tsolution=indx1;
}
}

}

else
uniquech=true;

non_unique_ctr++;
}
if(probt.type=="S"){
test.questions[iindex]=new n26(tindex,varvals,tsolution);
}else if(probt.type=="M"){
test.questions[iindex]=new n62(tindex,varvals,tsolution,tchoices);
}
}



function n44()
{
var buttonslist;
var buttonshtml;
var questionhtml;
var ques_state=-1;
subtitle.document.open("text/html","replace");
var sec_title="<html><head>"+nl;
subtitle.document.write(sec_title);
sec_title="<link rel=stylesheet href='cd_styles.css' type='text/css'>"+nl;
subtitle.document.write(sec_title);
sec_title="<\/head><body bgcolor='white'>"+
"<table width=100% height=80 cellspacing=0 cellpadding=0 "+
" border=0><tr>"+
"<td width=5 height=38 bgcolor='#ffffff'>"+
"<img src='gifs/blank.gif' border=0 width=5 height=38><\/td>"+
"<td height=38>";


if(bookmarkview)
test.questions[curr_instance].bookmarked=true;


probi=test.questions[curr_instance];
probt=template_list.templates[curr_template];

changed_since_checked=true;

with(probi)
{
if(done&&correct)
ques_state=0;
else if(done&&!correct&&seen_solution)
ques_state=1;
else if(!done&&!correct&&!seen_solution)
ques_state=2;
else if(!done&&!correct&&seen_solution)
ques_state=3;
}

if(test.type.charAt(0)=="S")
{
buttonslist=practice_buttons;
if(bookmarkview)
buttonslist=bookmark_practice_buttons;
}
else
{
buttonslist=test_buttons;
if(bookmarkview)
buttonslist=bookmark_test_buttons;
}
buttonslist=buttonslist.toLowerCase();

switch(test.type){
case"S-SEC":
sec_title+="<font color="+tfcolor+"><b>"+TITLE+
"<br><font size=+1 color="+tfcolor+">"+
"CHAPTER "+curr_chap+": SECTION "+curr_sec+
"<\/font><\/b><\/font>";
break;
case"T-PRE":
sec_title+="<font color="+tfcolor+"><b>"+TITLE+
"<br><font size=+1 color="+tfcolor+">"+
"CHAPTER "+curr_chap+": "+pretestname+
"<\/font><\/b><\/font>";
break;
case"T-POST":
sec_title+="<font color="+tfcolor+"><b>"+TITLE+
"<br><font size=+1 color="+tfcolor+">"+
"CHAPTER "+curr_chap+": "+posttestname+
"<\/font><\/b><\/font>";
break;
case"T-CUM":
sec_title+="<font color="+tfcolor+"><b>"+TITLE+
"<br><font size=+1 color="+tfcolor+">"+
"CHAPTER "+curr_chap+": "+cumtestname+
"<\/font><\/b><\/font>";
break;
case"T-FIN":
sec_title+="<font color="+tfcolor+"><b>"+TITLE+
"<br><font size=+1 color="+tfcolor+">"+
finaltestname+"<\/font><\/b><\/font>";
buttonslist=buttonslist.replace(/section/,"");
break;
case"S-SELF":
ti=test.questions[curr_instance].template_index;
pc=template_list.templates[ti].chapter;
ps=template_list.templates[ti].section;
sec_title+="<font color="+tfcolor+"><b>"+TITLE+"<br>"+
"<font size=+1>"+selftestname+"<\/font><\/b>"+"<br>"+
"<font size=-1>(Current Problem From Section "+
pc+"."+ps+")<\/font><\/font>";
break;
default:
sec_title="";
}
sec_title+="<\/td><\/tr><tr>"+
"<td width=5 bgcolor='#ffffff'>"+
"   <img src='gifs/blank.gif' border=0 width=5 height=2><\/td>"+
"<td height=2 bgcolor='#ff9900' width=100%>"+
"   <img src='gifs/blank.gif' border=0 width=100% height=2><\/td><\/tr>"+
"<tr><td colspan=2 align=right>"+n10()+"<\/td><\/tr>"+
"<\/table><\/body><\/html>";

subtitle.document.write(sec_title);
subtitle.document.close();

switch(probt.type)
{
case"S": questionhtml=n112(probi,ques_state);
break;
case"M": questionhtml=n113(probi,ques_state);
break;
case"A": questionhtml=n117(probi,ques_state);
break;
case"D": questionhtml=n118(probi,ques_state);
break;
default: alert("Unknown problem type");
}

question.document.open("text/html","replace");
question.document.write(questionhtml);
question.document.close();


if(buttonslist.indexOf("|")>=0)
{
var buttarr=new Array();
buttarr=buttonslist.split("|");
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(buttarr[1],"Problem","horizontal","separate"));
buttons.document.close();
extras.document.open("text/html","replace");
extras.document.write(display_buttons(buttarr[0],"Problem","vertical","separate"));
extras.document.close();
}
else
{
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(buttonslist,"Problem","horizontal","separate"));
buttons.document.close();
}
}


function n112(prob,ques_state)
{
var tspec,tvar,tresponse,tsolution,tmpques_string;
var nvars=template_list.templates[prob.template_index].nvars;
var html_string="";
var ques_string=template_list.templates[prob.template_index].question;


if(nvars>0)
{
tspec=new Array(ques_string,"");
tvar=new n8("S",tspec);
ques_string=evaluate(tvar,nvars,prob.varvals);
}
else
{
ques_string=template_list.templates[prob.template_index].question;
}

tmpquest_string=ques_string.toLowerCase();
if(tmpquest_string.indexOf("<table")>=0||tmpquest_string.indexOf("<innertable")>=0)
{
ques_string=n116(ques_string,true,true);
}
ques_string="<table cellpadding=0 cellspacing=0 border=0><tr>"+
"<td width=100>&nbsp;</td>"+
"<td><b>"+ques_string+"</b></td>"+
"<td width=100 align=right>&nbsp;</td>"+
"</tr></table>";

tresponse="document.forms[0].resp.value";
tsolution=prob.solution;

html_string="<html>"+nl+"<head>"+nl+
"<script language='JavaScript'>"+nl+
"window.onerror = parent.handle_error;"+nl+
"var answer = null;"+nl+
"var choice = 'none';"+nl+
"parent.curr_instance="+curr_instance+";"+nl+
"parent.curr_template = parent.test.questions[parent.curr_instance].template_index;"+nl+
"var instance = parent.test.questions[parent.curr_instance]"+nl+
"// handlefocus()"+nl+
"function handlefocus()"+nl+
"{"+nl+
"  var oktofocus = true;"+nl+
"  if (typeof parent.gcfl=='undefined')"+nl+
"    parent.gcfl = false;"+nl+
"  for (winname in parent.window_list)"+nl+
"  {"+nl+
"    if (!(!parent.gcfl && winname=='calculator'))"+nl+
"    {"+nl+
"      var windownm = parent.window_list[winname];"+nl+
"      if (!windownm.closed)"+nl+
"      {"+nl+
"        oktofocus = false;"+nl+
"        break;"+nl+
"      }"+nl+
"    }"+nl+
"  }"+nl+
"  if (oktofocus)"+nl+
"    document.studresp.resp.focus();"+nl+
"}"+nl+
"<\/script>"+nl+
"<link rel=stylesheet href='cd_styles.css' type='text/css'>"+nl+
"<\/head>"+nl+nl+
"<body bgcolor=white onload='handlefocus();'>"+nl+
"<form name=studresp onSubmit='return false;'>"+nl+
"<center>"+nl+
"<table cellpadding=5><tr>"+nl+
"<td align=center>"+ques_string+"</td>"+nl+"</tr></table>"+nl+
"<br>&nbsp;<br><b>Your Answer:</b>&nbsp;"+
"<input type=text name=resp value=\""+unescape(prob.response)+"\">&nbsp;"+nl;

if(!(test.type.charAt(0)=='T')&&show_check)
{
switch(ques_state)
{
case 0,1:
html_string+="<img name=checkB src=\"gifs/buttons/empty.gif\" border=0 alt='' align=absmiddle>";
break;
case 2:
curr_check_on.src=check_on.src;
curr_check_off.src=check_off.src;
html_string+="<a href='JavaScript:void(parent.close_popups(false));"+
"if(parent.checker(\"check\")) void(parent.next()); '"+
"onMouseover='window.status=\"Check Your Answer\";"+
"document.checkB.src=parent.curr_check_on.src;return true;' "+
"onMouseout='window.status=\"\";"+
"document.checkB.src=parent.curr_check_off.src;return true;' "+
"title='Check Your Answer'>"+
"<img name=checkB src=\"gifs/buttons/check1.gif\" border=0 "+
"alt='Check Your Answer' align=absmiddle></a>";
break;
case 3:
curr_check_on.src=tryanother_on.src;
curr_check_off.src=tryanother_off.src;
html_string+="<a href='JavaScript:void(parent.close_popups(false));"+
"void(parent.n12()) '"+
"onMouseover='window.status=\"Try Another Problem of the Same Type\";"+
"document.checkB.src=parent.curr_check_on.src;return true;' "+
"onMouseout='window.status=\"\";"+
"document.checkB.src=parent.curr_check_off.src;return true;' "+
"title='Try Another Problem'>"+
"<img name=checkB src=\"gifs/buttons/tryanother1.gif\" border=0 "+
"alt='Try Another Problem' align=absmiddle></a>";
break;
default:
html_string+="<img name=checkB src=\"gifs/buttons/empty.gif\" border=0 alt='' align=absmiddle>";
break;
}
}
html_string+="<p>"+nl+"<i>";
if(test.type.charAt(0)=="S"){
switch(ques_state)
{
case 0:
html_string+="You have answered this question correctly.";
break;
case 1:
html_string+="You have tried another problem of the same type.";
break;
case 2:
if(prob.next!=null||prob.retries>0)
html_string+="This question has not yet been answered correctly.";
break;
case 3:
html_string+="You have seen the solution to this problem, please try another.";
break;
default:
html_string+="";
break;
}
}
html_string+="</i>"+"</center>"+nl+
"</form>"+nl+"</body>"+nl+"</html>";

return html_string;
}

function n113(prob,ques_state)
{
var tspec,tvar,tmpques_string;
var chlen,chlen2,rows,cols,temp,nopts;
var tc,ts,tcresp,tcsol;
var instance=template_list.templates[prob.template_index];
var nvars=instance.nvars;
var html_string="";
var ques_string=instance.question;
var massaged_choices=new Array();


if(nvars>0)
{
tspec=new Array(ques_string,"");
tvar=new n8("S",tspec);
ques_string=evaluate(tvar,nvars,prob.varvals);
}

tmpquest_string=ques_string.toLowerCase();
if(tmpquest_string.indexOf("<table")>=0||tmpquest_string.indexOf("<innertable")>=0)
{
ques_string=n116(ques_string,true,true);
}
ques_string="<table cellpadding=0 cellspacing=0 border=0><tr>"+
"<td width=100>&nbsp;</td>"+
"<td><b>"+ques_string+"</b></td>"+
"<td width=100 align=right>&nbsp;</td>"+
"</tr></table>";

nopts=prob.ichoices.length;

chlen=5;
chlen2=chlen;
rows=Math.min(MAXCHOICES,nopts)/2;
cols=2;
for(i=0;i<Math.min(MAXCHOICES,nopts);i++)
{
temp=new String(prob.ichoices[i].val);
temp=temp.toLowerCase();
temp=temp.replace(/<img[^>]*chars[^>]*>/gi,":");
temp=temp.replace(/<img[^>]*dot\.gif[^>]*>/gi,":");
temp=temp.replace(/<img[^>]*blank\.gif[^>]*>/gi,":");
temp=temp.replace(/<img[^>]*spacer\.gif[^>]*>/gi,":");
temp=temp.replace(/<img[^>]*space\.gif[^>]*>/gi,":");
temp=temp.replace(/<img[^>]*>/gi,"12345678901234567890");
temp=temp.replace(/<\/*table[^>]*>/gi,"");
temp=temp.replace(/<\/*innertable[^>]*>/gi,"");
temp=temp.replace(/<\/*.>/gi,"");
temp2=temp.split(/<tr/gi);
temp=temp.replace(/<\/*td[^>]*>/gi,"");
temp=temp.replace(/<\/*tr[^>]*>/gi,"");
temp=temp.replace(/<\/*sup[^>]*>/gi,"");
temp=temp.replace(/<\/*sub[^>]*>/gi,"");
temp=temp.replace(/<\/*font[^>]*>/gi,"");
temp=temp.replace(/\&nbsp;/gi," ");
if(temp.length>20)
{
rows=Math.min(MAXCHOICES,nopts);
cols=1;
break;
}
}



for(i=0;i<Math.min(MAXCHOICES,nopts);i++)
{
tc=new String(prob.ichoices[i].val);
ts=tc.toLowerCase();
if((ts.indexOf("<table")>=0)||(ts.indexOf("<innertable")>=0))
{
tc=n116(tc,false,false);
massaged_choices[i]=tc;
}
else
{
massaged_choices[i]="<table cellspacing=0 cellpadding=0 border=0>"+
"<tr><td nowrap>"+tc+"<\/td><\/tr><\/table>";
}
}

html_string="<html>"+nl+"<head>"+nl+
"<script language='JavaScript'>"+nl+
"window.onerror = parent.handle_error;"+nl+
"var answer = null;"+nl+
"var choice = 'none';"+nl+
"var instance = parent.test.questions[parent.curr_instance]"+nl+
"<\/script>"+nl+
"<link rel=stylesheet href='cd_styles.css' type='text/css'>"+nl+
"<\/head>"+nl+nl+
"<body bgcolor=white>"+nl+
"<form onSubmit='return false;'>"+nl+
"<center>"+nl+
"<table cellpadding=5><tr>"+nl+
"<td align=center>"+ques_string+"</td>"+nl+"</tr></table>"+nl;

html_string+="<table cellpadding=0 cellspacing=4 border=0>"+nl;
for(var j=0;j<rows;j++)
{
html_string+="<tr>"+nl;
for(var k=0;k<cols;k++)
{
var selected_string="";
if(parseInt(prob.response)==(j*cols+k))
selected_string="checked ";

html_string+="<td><input type=radio name=a "+selected_string+
"onClick='if(!parent.test.questions[parent.curr_instance].done && !parent.test.questions[parent.curr_instance].seen_solution){parent.test.questions[parent.curr_instance].response="+(j*cols+k)+";parent.changed_since_checked=true;}'></td>"+
"<td nowrap>"+massaged_choices[j*cols+k]+"</td>"+
"<td height=1><img src='gifs/spacer.gif' border=0></td>"+nl;
}
if(j==0)
{
if(!(test.type.charAt(0)=='T')&&show_check)
{
switch(ques_state)
{
case 0,1:
html_string+="<td valign=middle rowspan="+rows+">"+
"<img name=checkB src=\"gifs/buttons/empty.gif\" border=0 alt='' align=absmiddle></td>"+nl;
break;
case 2:
curr_check_on.src=check_on.src;
curr_check_off.src=check_off.src;
html_string+="<td valign=middle rowspan="+rows+"><a href='JavaScript:void(parent.close_popups(false));"+
"if(parent.checker(\"check\")) void(parent.next()); '"+
"onMouseover='window.status=\"Check Your Answer\";"+
"document.checkB.src=parent.curr_check_on.src;return true;' "+
"onMouseout='window.status=\"\";"+
"document.checkB.src=parent.curr_check_off.src;return true;' "+
"title='Check Your Answer'>"+
"<img name=checkB src=\"gifs/buttons/check1.gif\" border=0 "+
"alt='Check Your Answer' align=absmiddle></a></td>"+nl;
break;
case 3:
curr_check_on.src=tryanother_on.src;
curr_check_off.src=tryanother_off.src;
html_string+="<td valign=middle rowspan="+rows+"><a href='JavaScript:void(parent.close_popups(false));"+
"void(parent.n12()); '"+
"onMouseover='window.status=\"Try Another Problem of the Same Type\";"+
"document.checkB.src=parent.curr_check_on.src;return true;' "+
"onMouseout='window.status=\"\";"+
"document.checkB.src=parent.curr_check_off.src;return true;' "+
"title='Try Another Problem'>"+
"<img name=checkB src=\"gifs/buttons/tryanother1.gif\" border=0 "+
"alt='Try Another Problem' align=absmiddle></a></td>"+nl;
break;
default:
html_string+="<td valign=middle rowspan="+rows+">"+
"<img name=checkB src=\"gifs/buttons/empty.gif\" border=0 alt='' align=absmiddle></td>"+nl;
break;
}
html_string+="</tr>"+nl+nl;
}
else
html_string+="<td>&nbsp;</td>"+nl+"</tr>"+nl+nl;
}

if(j==(rows-1))
{
var thecolspan=cols==1? 4: 7;
html_string+="<tr><td colspan="+thecolspan+" align=center><br><i>";
if(test.type.charAt(0)=="S"){
switch(ques_state)
{
case 0:
html_string+="You have answered this question correctly.";
break;
case 1:
html_string+="You have tried another problem of the same type.";
break;
case 2:
if(prob.next!=null||prob.retries>0)
html_string+="This question has not yet been answered correctly.";
break;
case 3:
html_string+="You have seen the solution to this problem, please try another.";
break;
default:
html_string+="";
break;
}
}
html_string+="</i></td></tr>"+nl+nl;
}
else
html_string+="</tr>"+nl;
}
html_string+="</table></td></tr></table>"+nl+"</center>";
html_string+=nl+"</form>"+nl+"</body>"+nl+"</html>";
return html_string;
}

function n117(prob,ques_state)
{
return"display Matching";
}

function n118(prob,ques_state)
{
return"display Drag N Drop";
}



function n116(instring,boldfl,wrapfl)
{
var bds,bde,wrap,outstring;

if(boldfl)
{
bds="<B>";
bde="<\/B>";
}
else
{
bds="";
bde="";
}
if(wrapfl)
wrap="";
else
wrap="";

outstring=new String(instring);
outstring=outstring.replace(/(<td[^>]*>)/ig,"$1"+bds);
outstring=outstring.replace(/<\/td>/ig,bde+"<\/td>");
outstring=outstring.replace(/(<table[^>]*>)/ig,
bde+"<\/td><td align=left valign=center "+wrap+">"+"$1");
outstring=outstring.replace(/<\/table>/ig,
"<\/table><\/td><td align=left valign=center "+wrap+">"+bds);
outstring=outstring.replace(/<p>/ig,
bde+"<\/td><\/tr><\/table><p><table cellpadding=0 cellspacing=0 border=0>"+
"<tr><td align=left valign=center "+wrap+">"+bds);
outstring=outstring.replace(/<br>/ig,
bde+"<\/td><\/tr><\/table><table cellpadding=0 cellspacing=0 border=0>"+
"<tr><td align=left valign=center "+wrap+">"+bds);
outstring=outstring.replace(/\s*<b>\s*<b>\s*/ig,"<b>");
outstring=outstring.replace(/\s*<\/b>\s*<\/b>\s*/ig,"<\/b>");
outstring=outstring.replace(/<td[^>]*>\s*<\/td>/ig,"");
outstring=outstring.replace(/<td[^>]*>\s*<b>\s*<\/b>\s*<\/td>/ig,"");
outstring=outstring.replace(/innertable/ig,"table");
outstring="<table cellspacing=0 cellpadding=0 border=0 nowrap>"+
"<tr><td align=left valign=center "+wrap+">"+bds+
outstring+bde+"<\/td><\/tr><\/table>";
return outstring;
}

function n10(rawscore,totalques)
{
var btyp=navigator.userAgent.toLowerCase();
var prefixText=bookmarkview?"":"";
var status_html="";
var bmimage="trans.gif";
if(curr_instance>=0)
bmimage=test.questions[curr_instance].bookmarked?"paperclip.gif":"trans.gif";
var pretable_html='<table cellspacing=0 cellpadding=0>'+
'<tr><td background=\"\" valign=middle><font face="'+ffamily+'" color="'+tfcolor+'"><b>';
var posttable_html='</b></font>&nbsp;</td><td width=23 background=\"\">'+
'<img name=\"paperclip\" src=\"gifs/header/'+bmimage+'\"></td></tr></table>';

if(typeof rawscore!="undefined"&&typeof totalques!="undefined")
{
status_html+=pretable_html+prefixText+"<b>Your Score:&nbsp  "+rawscore+
'/'+totalques+" questions were answered correctly.</b>"+posttable_html;
}
else
{
switch(test.type)
{
case"S-SEC":
status_html+='<form name=counters onSubmit="parent.n9(document.counters.nq.value);return false;">'+
pretable_html+prefixText+'Problem '+(test.questions[curr_instance].problemnumber+1)+' of &nbsp; '+
'<input type=text name="nq" value='+nquests+' size=3 '+
'onChange="parent.n9(document.counters.nq.value)">'+posttable_html+"</form>";
break;
case"T-PRE":
status_html+=pretable_html+prefixText+'Problem '+(test.questions[curr_instance].problemnumber+1)+
' of &nbsp;'+pretest_size+posttable_html;
break;
case"T-POST":
status_html+=pretable_html+prefixText+'Problem '+(test.questions[curr_instance].problemnumber+1)+
' of &nbsp;'+posttest_size+posttable_html;
break;
case"T-CUM":
status_html+=pretable_html+prefixText+'Problem '+(test.questions[curr_instance].problemnumber+1)+
' of &nbsp;'+cumtest_size+posttable_html;
break;
case"T-FIN":
status_html+=pretable_html+prefixText+'Problem '+(test.questions[curr_instance].problemnumber+1)+
' of &nbsp;'+cumtest_size+posttable_html;
break;
case"S-SELF":
status_html+=pretable_html+prefixText+self_test_score+
' Correct / '+
(test.questions.length)+
' Attempted'+posttable_html;
break;
default:
}
}
return(status_html);
}

function n9(nv)
{
var minq;
var defq=Math.max(test.questions.length,template_list.ntemplates);
nv=isNaN(parseInt(nv))?0:parseInt(nv);
if(test.type.charAt(0)=='T')
minq=Math.max(MINTQ,test.questions.length);
else
minq=Math.max(MINSQ,test.questions.length);
if(nv<minq)
{
alert("Invalid Number of Problems Specified;"+"\n"+
"you must specify a value no less than "+minq+".\n"+
"Resetting to the default.");
nquests=minq;
subtitle.document.counters.nq.value=nquests;
}
else
{
nquests=nv;
}
}

function n80(wintitle)
{
var header="<html><head>"+nl+
"<title>"+wintitle+"</title>"+nl+
"<\/head>"+nl+
"<body bgcolor=white>"+nl+
"<center><h2>"+wintitle+"<\/h2><\/center>"+nl;
return header;
}


function n79()
{
var trailer="<form Onsubmit='return false'>"+nl+
"<center>"+
"<input type=button onClick=\""+prtcmd+"\" value=' Print '> "+
"<\/center>"+nl+
"<\/form>"+nl+
"<script language='JavaScript'>"+nl+
"if(typeof(parent.opener.pgld)!=\"undefined\")"+nl+
"parent.opener.pgld=true;"+nl+
"<\/script>"+nl+
"<\/body><\/html>";
return trailer;
}


function yesnoresp(flag)
{
var winname="correctwin";
var soundflag=sound?"on":"off";
if(flag)
{
if(NS4||NS6||isMac)
{
var options='width=105,height=105,menubar=0,location=0,toolbar=0,'+
'status=0,resizable=0,scrollbars=0,alwaysRaised=1';
if(window_list[winname]&&!window_list[winname].closed)
window_list[winname].close();
window_list[winname]=window.open('messages/correct_'+soundflag+'.htm',winname,options);
window_list[winname].focus();
}
else
{
var diagwth=135;
var diaght=135;
var options='dialogWidth:'+diagwth+'px; dialogHeight:'+diaght+'px; center:yes; status:no; scroll:no';
window.showModalDialog("messages/correct_"+soundflag+".htm",null,options);
}
}
else
alert("That is incorrect.");
}

function get_report()
{
var result_loc;
var rawscore=0;
var totalques=0;
var report_html="";

report_html="<head>"+"\n"+
"<style type='text/css'>"+"\n"+
"  H1 {font-family: Arial, Helvetica}"+"\n"+
"  P {font-family: Arial, Helvetica}"+"\n"+
"  H2 {color:#004778;font-family: Arial, Helvetica}"+"\n"+
"  H3 {color:#004778;font-family: Arial, Helvetica}"+"\n"+
"  BODY {font-family: Arial, Helvetica}"+"\n"+
"  TABLE {font-family: Arial, Helvetica}"+"\n"+
"  TD {font-family: Arial, Helvetica}"+"\n"+
"  A {text-decoration:none;font-family: Arial, Helvetica}"+"\n"+
"</style>"+"\n";
"<SCRIPT language='JavaScript'>"+"\n"+
"window.onerror = parent.handle_error;"+nl+
"<\/SCRIPT>"+"\n"+
"</head>";

report_html+="<html><body bgcolor='#ffffff'>"+"\n"+"<center>";
report_html+="<font size=+1><b>"+"Your Test"+" Results<\/b><\/font>"+
"<\/center><p>";

if(test.questions.length>0)
{
var pnum=0;
for(var i=0;i!=null;i=test.questions[i].next)
{
pnum++;
var ques=test.questions[i];
var tidx=ques.template_index;
var theresponse="";
var thesolution="";
report_html+="<table cellspacing=5 border=0><tr>"+
"<td valign=top align=left nowrap>";
report_html+="<b>Problem "+pnum+":<\/b></td><td align=left>"+
n89(i)+"</td></tr>";

if(template_list.templates[tidx].type.charAt(0)=="M")
{
theresponse=ques.response>=0? new String(ques.ichoices[ques.response].val): new String("None Given");
thesolution=new String(ques.ichoices[ques.solution].val);
var tr=theresponse.toLowerCase();
var ts=thesolution.toLowerCase();
if((tr.indexOf("<table")>=0)||(tr.indexOf("<innertable")>=0))
theresponse=n116(theresponse,false,false);
if((ts.indexOf("<table")>=0)||(ts.indexOf("<innertable")>=0))
thesolution=n116(thesolution,false,false);

report_html+="<tr><td>&nbsp;</td><td align=left>"+
"<b>Your choices:<\/b><br>"+n91(i)+"</td></tr>";
}
else if(template_list.templates[tidx].type.charAt(0)=="S")
{
theresponse=ques.response!=""? unescape(ques.response):"None Given";
thesolution=unescape(ques.solution);
}

var correct_msg="";
if(ques.correct)
{
correct_msg="<font color='#007700'>"+"<b>Your Answer is Correct</b></font>"+"<p>";
rawscore++;
}
else
correct_msg="<font color='#770000'><b>Your Answer is Not Correct</b></font><br>"+
"<tr><td>&nbsp;</td><td align=left>"+
"<table cellpadding=0 cellspacing=0 border=0>"+
"<tr>"+
"<td align=left>The Solution Is: &nbsp;</td>"+
"<td align=left>"+thesolution+"</td>"+
"</tr>"+
"</table></td></tr>";

report_html+="<tr><td>&nbsp;</td><td align=left>"+
"<table cellpadding=0 cellspacing=0 border=0>"+
"<tr><td>&nbsp;</td>"+
"<td align=left><b>Your Answer:<\/b>&nbsp;</td>"+
"<td align=left>"+theresponse+"</td>"+
"</tr></table></td></tr>";

report_html+="<tr><td>&nbsp;</td><td>"+
"<table cellpadding=0 cellspacing=0 border=0>"+
"<tr><td>&nbsp;</td>"+
"<td align=left>"+correct_msg+"</td>"+
"</tr></table></td></tr>";

report_html+="<tr><td colspan=2><p><hr><p></td></tr>";
report_html+="</table>";
totalques++;
}
}
else
report_html+="<font face=arial>"+
"<center>"+
"<h3>No questions have been answered in this test yet</h3><br>"+
"</center>"+
"</font>";



report_html+="<p> Your score is: "+rawscore+" / "+totalques+".";
report_html+="<script language='JavaScript'>"+nl+
"if(typeof(parent.pgld)!=\"undefined\")"+nl+
"parent.pgld=true;"+nl+
"<\/script>"+nl;
report_html+="</body></html>";

var sub_title="<html><head>"+nl+
"<link rel=stylesheet href='cd_styles.css' type='text/css'>"+nl+
"<\/head>"+nl+"<body bgcolor=white>"+nl+
"<table width=100% height=80 cellspacing=0 cellpadding=0 "+
" border=0><tr>"+
"<td width=5 height=38 bgcolor='#ffffff'>"+
"<img src='gifs/blank.gif' border=0 width=5 height=2><\/td>"+
"<td height=38><font color="+tfcolor+"><b>"+TITLE+
"<br><font size=+1 color="+tfcolor+">"+
test.title+
"<\/font><\/b><\/font>"+
"<\/td><\/tr><tr>"+
"<td width=5 height=2 bgcolor='#ffffff'>"+
"<img src='gifs/blank.gif' border=0 width=5 height=2><\/td>"+
"<td height=2 bgcolor='#ff9900' width=100%>"+
"<img src='gifs/blank.gif' border=0 width=100% height=2>"+
"<\/td><\/tr>"+
"<tr><td colspan=2 valign=top, align=right>"+
" <font color="+tfcolor+"><b>Your Score is: "+rawscore+" / "+
totalques+".<\/font><\/td><\/tr>"+
"<\/table><\/body><\/html>";
subtitle.document.open("text/html","replace");
subtitle.document.write(sub_title);
subtitle.document.close();

question.document.open();
question.document.write(report_html);
question.document.close();

var cur_buttons=report_buttons;
if(test.type!="S-SEC")
cur_buttons=cur_buttons.replace(/section/,"");

if(cur_buttons.indexOf("|")>=0)
{
var buttarr=new Array();
buttarr=cur_buttons.split("|");
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(buttarr[1],"Sections","horizontal","separate"));
buttons.document.close();
extras.document.open("text/html","replace");
extras.document.write(display_buttons(buttarr[0],"Sections","vertical","separate"));
extras.document.close();
}
else
{
buttons.document.open("text/html","replace");
buttons.document.write(display_buttons(cur_buttons,"Sections","horizontal","separate"));
buttons.document.close();
}
test.questions.length=0;
}


function handle_error(msg,url,line)
{
if(debug_mode)
alert("An error has occured"+"\n\n"+"Error Message: "+msg+"\n"+"URL: "+url+"\n"+"Line #: "+line);
top.location="index.html";
return true;
}




dbld=true;



