// JavaScript Document
thepage="Comparisons"
//globals
//updated 10/31/00 added comp solution
//checked with NS47 and IE5
refnumber=11
//updated 12/02/02-netscape 7
qtype=0
ctype=0
first=0
second=0
look=0
totl=0
corrt=0
tried=0
firstline="<form><input type=radio name=which onClick=answer(1)>"
secondline="<input type=radio name=which onClick=answer(2)>"
firstelement=""
secondelement=""
qstring="";astring=""
samething=new Array(5)
samething[1]="equal masses"
samething[2]="equal volumes"
samething[3]="equal number of moles"
compare=new Array(5)
compare[1]="greater "
compare[2]="lesser "
lookfor=new Array(3)
lookfor[1]="mass"
lookfor[2]="volume"
lookfor[3]="number of moles"
constant=new Array(5)
constant[3]="gram atomic weight"
constant[2]="density"
constant[6]="molar volume"
inserts=new Array(5)
inserts[21]=". Mass and density, are directly related."
inserts[12]=". Volume and density are inversely related."
inserts[13]=". Moles and gaw are inversely related."
inserts[31]=". Mass and gaw are directly related."
inserts[32]=". Volume and molar volume are directly related."
inserts[23]=". Moles and molar volume are inversely related." 
function ask(p1,p2,p3,p4,p5){
	this.p1=p1
	this.p2=p2
	this.p3=p3
	this.p4=p4
	this.p5=p5
}
question=new ask("Samples of "," and "," have ",". <br />Which sample has the ","?<br />")
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;
	ctype=Math.ceil(2*Math.random())
	qtype=Math.ceil(3*Math.random())
	if(qtype==1){samemass(first,second)}
	if(qtype==2){samevolume(first,second)}
	if(qtype==3){samemoles(first,second)}
}
function samemass(){
	look=1
	while(look==1)look=Math.ceil(3*Math.random())
	astring=""+qtype+look
	qstring=""+qtype+ctype+look	
	buildquest()
	getresults()
}
function samemoles(){
	look=3
	while(look==3)look=Math.ceil(3*Math.random())
	qstring=""+qtype+ctype+look
	astring=""+qtype+look
	buildquest()
	getresults()
}
function samevolume(){
	look=2
	while(look==2)look=Math.ceil(3*Math.random())
	qstring=""+qtype+ctype+look
	astring=""+qtype+look
	buildquest()
	getresults()
}
function getresults(x){
	submitted=x
	choice=0
	qstring=1*qstring
	if(qstring==112){
		if(theatom[first].dens<theatom[second].dens)choice=1;
		else choice=2;
	}
	if(qstring==113){
		if(theatom[first].gaw<theatom[second].gaw)choice=1;
		else choice=2;
	}
	if(qstring==122){
		if(theatom[first].dens>theatom[second].dens)choice=1;
		else choice=2;
	}
	if(qstring==123){
		if(theatom[first].gaw<theatom[second].gaw)choice=2;
		else choice=1;
	}
	if(qstring==211){
		if(theatom[first].dens>theatom[second].dens)choice=1;
		else choice=2;
	}
	if(qstring==213){
		if(theatom[first].mv>theatom[second].mv)choice=2;
		else choice=1;
	}
	if(qstring==221){
		if(theatom[first].dens>theatom[second].dens)choice=2;
		else choice=1;
	}
	if(qstring==223){
		if(theatom[first].mv>theatom[second].mv)choice=1;
		else choice=2;
	}
	if(qstring==311){
		if(theatom[first].gaw>theatom[second].gaw)choice=1;
		else choice=2;
	}
	if(qstring==312){
		if(theatom[first].mv>theatom[second].mv)choice=1;
		else choice=2;
	}
	if(qstring==321){
		if(theatom[first].gaw>theatom[second].gaw)choice=2;
		else choice=1;
	}
	if(qstring==322){
		if(theatom[first].mv>theatom[second].mv)choice=2;
		else choice=1;
	}
	buildanswer(choice)
}
ansphrase=new ask("Since the samples have equal ",", the element with the "," will have the ")
function buildquest(){
thetable=gettable()
thequest=question.p1+firstelement+question.p2+secondelement+question.p3+samething[qtype]+question.p4+compare[ctype]+lookfor[look]+question.p5
thequest+=firstline+firstelement+secondline+secondelement+"<form>"+thetable
showquest(thequest)
}
function gettable(){
	thetable="<table><tr><td width=75></td><td width=75>"+theatom[first].nm+"</td><td width=75>"+theatom[second].nm+"</td></tr>";
	thetable+="<tr><td>g.a.w.</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
}
function answer(submitted){
	if(tried==1){
		alert("You've already done this one! Get a new problem.")
	}
	else{
	tried=1
	if(choice==submitted){
		corrt++
		document.forms[0].correct.value=corrt
		document.forms[0].results.value="correct"
	}
	else {
		document.forms[0].results.value="incorrect"
	}}
	showanswer()
}
function buildanswer(choice){
	if(ctype==1){
		if(astring==12 || astring==23 || astring==13)atype=2;
		else atype=1;
	} 
	if(ctype==2){
		if(astring==12 || astring==23 || astring==13)atype=1;
		else atype=2;
	}
theanswer=ansphrase.p1+lookfor[qtype]+ansphrase.p2+compare[atype]+constant[qtype*look]+ansphrase.p3+compare[ctype]+lookfor[look]+inserts[astring]
}
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();
}
