// JavaScript Document
thepage="Which is it?"
//updated 10/31/00 added comp solution
//checked with ns47 and IE5
refnumber=13
//updated 12/02/02-netscape 7
//globals
theanswer=""
qtype=0
ctype=0
first=0
second=0
look=0
totl=0
corrt=0
tried=0
choice=0
moles=new Array(5)
mass=new Array(5)
volume=new Array(5)
firstelement=""
secondelement=""
qstring="";fstring="";sstring=""
firstdot="<form><input type=radio name=which onClick=answer(1)>"
seconddot="<input type=radio name=which onClick=answer(2)>"
samething=new Array(5)
compare=new Array(5)
compare[1]="greater "
compare[2]="lesser "
lookfor=new Array(3)
lookfor[1]="number of moles"
lookfor[2]="mass"
lookfor[3]="volume"
function parts(p1,p2,p3,p4,p5,p6){
	this.p1=p1
	this.p2=p2
	this.p3=p3
	this.p4=p4
	this.p5=p5
	this.p6=p6
}
question=new parts("Which will have a <b>", ":</b><br> A "," sample of "," or a "," sample of ",".")
function clear(){
	tried=0
	clearansspot()
	document.forms[0].results.value=""
}
function startit(){
	totl++
	clear()
	document.forms[0].total.value=totl
	first=Math.floor(theatom.length*Math.random())
	second=first
	while(second==first){second=Math.floor(theatom.length*Math.random())}
	if(Math.random()>.5)firstelement=theatom[first].nm;
		else firstelement=theatom[first].sym;
	if(Math.random()>.5)secondelement=theatom[second].sym;
		else secondelement=theatom[second].nm;
	properties(1,first)
	properties(2,second)
	setvalues()
	qtype=Math.ceil(3*Math.random())
	ctype=Math.ceil(2*Math.random())
	qstring=""+ctype+qtype
	buildquest()
	getresults()
}
function properties(order,which){
	moles[order]=Math.ceil(100*Math.random())/10
	mass[order]=Math.ceil(100*moles[order]*theatom[which].gaw)/100
	volume[order]=Math.ceil(100*mass[order]/theatom[which].dens)/100
}
function setvalues(){
	forfirst=Math.ceil(3*Math.random())
	forsecond=forfirst
	while(forsecond==forfirst)forsecond=Math.ceil(3*Math.random())
	if(forfirst==1)fstring=moles[1] + " mole"
	if(forfirst==2)fstring=mass[1] + "gram"
	if(forfirst==3)fstring=volume[1] + "cm<sup>3</sup>"
	if(forsecond==1)sstring=moles[2] + " mole"
	if(forsecond==2)sstring=mass[2] + "gram"
	if(forsecond==3)sstring=volume[2] + "cm<sup>3</sup>"
}
ansphrase=new parts("First, convert both samples into the comparison dimension. You should try approximating that first and only do the exact calculation if the approx values don't give a clear result.<br>"," Since the question asks for the element with the "," you should be able to see that the proper response is ",".")
function getresults(x){
	submitted=x
	choice=0
	qstring=1*qstring
	if(qstring==11){
		if(moles[1]>moles[2])choice=1;
		else choice=2;
	}
	if(qstring==12){
		if(mass[1]>mass[2])choice=1;
		else choice=2;
	}
	if(qstring==13){
		if(volume[1]>volume[2])choice=1;
		else choice=2;
	}
	if(qstring==21){
		if(moles[1]<moles[2])choice=1;
		else choice=2;
	}
	if(qstring==22){
		if(mass[1]<mass[2])choice=1;
		else choice=2;
	}
	if(qstring==23){
		if(volume[1]<volume[2])choice=1;
		else choice=2;
	}
	buildanswer(choice)
}
function buildquest(){
thetable=gettable()
thequest=question.p1+compare[ctype]+lookfor[qtype]+question.p2+fstring+question.p3+firstelement+question.p4+sstring+question.p5+secondelement+question.p6
thequest+=firstdot+firstelement+seconddot+secondelement+"<form>"+thetable
showquest(thequest)
}
function buildanswer(choice){
if(qtype==1){
		fsolstring="=>"+moles[1]+"moles<br>"
		ssolstring="=>"+moles[2]+"moles<br>"
	}
	if(qtype==2){
		fsolstring="=>"+mass[1]+"grams<br>"
		ssolstring="=>"+mass[2]+"grams<br>"
	}
	if(qtype==3){
		fsolstring="=>"+volume[1]+"cm<sup>3</sup><br>"
		ssolstring="=>"+volume[2]+"cm<sup>3</sup><br>"
	}
	if(choice==1)finish=firstelement;
	else finish=secondelement;
theanswer=ansphrase.p1+firstelement+fsolstring+secondelement+ssolstring+ansphrase.p2+compare[ctype]+lookfor[qtype]+ansphrase.p3+finish
}
function answer(submitted){
	if(tried==1){
		alert("You've already done this one! Get a new problem.")
	}
	else{
	if(choice==submitted){
		corrt++
		document.forms[0].correct.value=corrt
		document.forms[0].results.value="correct"
		tried=1
	}
	else {
		document.forms[0].results.value="incorrect"
	}}
	showanswer()
}
function constants(){
var cont=window.open("","cont","scrollbars=yes,width=320,height=300")
cont.document.writeln ("<html>");
cont.document.writeln ("<head><title>The Elements</title>");
cont.document.writeln ("</head><body>");
cont.document.writeln ("Properties of Selected Elements<br><table border=1>");
cont.document.writeln("<tr><td>Name</td><td>Symbol</td><td>GAW</td><td>Density</td><td>Molar Vol</td></tr>");
for(k=0;k<theatom.length;k++){
cont.document.writeln("<tr><td>",theatom[k].nm,"</td><td>",theatom[k].sym,"</td><td>",number(theatom[k].gaw,4,3),"</td><td>",theatom[k].dens,"</td><td>",theatom[k].mv,"</td></tr>");
}
cont.document.writeln("</table><form><input type=button value='Close Window' onClick='window.close()'></form>");
cont.document.writeln("</body></html>");
cont.document.close();
cont.focus();
}
function gettable(){
	thetable="<table border=1><tr><td></td><td>"+theatom[first].nm+"</td><td>"+theatom[second].nm+"</td></tr>";
	thetable+="<tr><td>gaw</td><td>"+theatom[first].gaw+"</td><td>"+theatom[second].gaw+"</td></tr>"
	thetable+="<tr><td>density</td><td>"+theatom[first].dens+"</td><td>"+theatom[second].dens+"</td></tr>"
	thetable+="<tr><td>molar vol</td><td>"+theatom[first].mv+"</td><td>"+theatom[second].mv+"</td></tr>"
	thetable+="</table>"
 	return thetable
}
