// Gas Laws - Dalton's Law Script
thepage="Gas Laws - Dalton's Law of Partial Pressures"
//11/20/02-updated netscape 7
//global variables
theanswer=""
which=0
cmpd=new Array("He","H<sub>2</sub>","Ar","C<sub>2</sub>H<sub>4</sub>","CH<sub>4</sub>","CO","CO<sub>2</sub>","C<sub>2</sub>H<sub>2</sub>","Xe","H<sub>2</sub>S")
syms=new Array("<B>n</B><sub>","<B>P</B><sub>","<B>&Chi;</B><sub>")
datalabels=new Array("moles","moles","moles","torr","torr","torr","","")
esub="</sub>"
symbols=option=0
dset=new Array()
qset=new Array()
dset[0]=new Array(0,1,3)
qset[0]=new Array(4,5)
dset[1]=new Array(0,1,5)
qset[1]=new Array(3,4)
dset[2]=new Array(0,3,5)
qset[2]=new Array(1,4,7)
dset[3]=new Array(0,3,6)
qset[3]=new Array(4,5)
dset[4]=new Array(5,6)
qset[4]=new Array(3,4)
dset[5]=new Array(3,5)
qset[5]=new Array(7,7)
dset[6]=new Array(3,6)
qset[6]=new Array(4,5)
dset[7]=new Array(0,2,3)
qset[7]=new Array(4,5)
dset[8]=new Array(0,2,5)
qset[8]=new Array(3,4)
solveset=new Array()
solveset[0]=new Array(2,0,"+",1)//nt=n1+n2
solveset[1]=new Array(6,0,"/",2)//x1=n2/nt
solveset[2]=new Array(7,1,"/",2)//x2=n2/nt
solveset[3]=new Array(6,99,"1-",7)//x1=1-x2
solveset[4]=new Array(7,99,"1-",6)//x2=1-x1
solveset[5]=new Array(3,6,"*",5)//p1=x1*pt
solveset[6]=new Array(4,7,"*",5)//p2=x2*pt
solveset[7]=new Array(5,3,"+",4)//pt=p1+p2
solveset[8]=new Array(6,3,"/",5)//x1=p1/pt
solveset[9]=new Array(7,4,"/",5)//x2=p2/pt
solveset[15]=new Array(0,"/",1,3,"/",4)//n1/n2=p1/p2
solveset[16]=new Array(0,"/",2,3,"/",5)//n1/nt=p1/pt
solveset[17]=new Array(1,"/",2,4,"/",5)//n2/nt=p2/pt
solveset[20]=new Array(3,0,"/",1,"*",4)//p1=(n1/n2)*p2
solveset[21]=new Array(4,1,"/",0,"*",3)//p2=(n2/n1)*p1
solvepath=new Array
solvepath[0]=new Array(0,4)
symbols=new Array()
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	first=Math.floor(cmpd.length*Math.random())
	second=first
	while(second==first)second=Math.floor(cmpd.length*Math.random())
	setsymbols(first,second)
	pt=nt=x1=0
	while(pt<100)pt=number((1000*Math.random()),2,3)
	while(nt<.01)nt=number(Math.random(),2,3)
	while(x1<.1 || x1>.8)x1=number(Math.random(),2,3)
	x2=number((1-x1),2,3)
	n1=number((nt*x1),2,3)
	n2=number((nt-n1),2,3)
	p1=number((pt*x1),2,3)
	p2=number((pt-p1),2,3)
	alldata=new Array(n1,n2,nt,p1,p2,pt,x1,x2)
	buildquestion(first,second)
	buildequat()
}
function buildequat(){
	wequat=Math.floor(10*Math.random())
	wequat=21
	if(wequat<10){
	thesolution=symbols[solveset[wequat][0]]+"="
	solveset[wequat][1]==99?thesolution+=solveset[wequat][2]+symbols[solveset[wequat][3]]:thesolution+=symbols[solveset[wequat][1]]+solveset[wequat][2]+symbols[solveset[wequat][3]];
	}
	else{
		if(wequat<20){
			thesolution=symbols[solveset[wequat][0]]+solveset[wequat][1]+symbols[solveset[wequat][2]]+"="+symbols[solveset[wequat][3]]+solveset[wequat][4]+symbols[solveset[wequat][5]]
	}
		else{
			thesolution=symbols[solveset[wequat][0]]+"="+symbols[solveset[wequat][1]]+solveset[wequat][2]+symbols[solveset[wequat][3]]+solveset[wequat][4]+symbols[solveset[wequat][5]]
			}
	}
}
function setsymbols(first,second){
	symbols[0]=syms[0]+cmpd[first]+esub
	symbols[1]=syms[0]+cmpd[second]+esub
	symbols[2]="<B>n</B><sub>T</sub>"
	symbols[3]=syms[1]+cmpd[first]+esub
	symbols[4]=syms[1]+cmpd[second]+esub
	symbols[5]="<B>P</B><sub>T</sub>"
	symbols[6]=syms[2]+cmpd[first]+esub
	symbols[7]=syms[2]+cmpd[second]+esub
}
function buildquestion(first,second){
	which=Math.floor(Math.random()*dset.length);
	thequest="A mixture of two gases, "+cmpd[first]+" and "+cmpd[second]+", has the properties listed below.<table border=0><tr>"
	for(j=0;j<dset[which].length;j++)thequest+="<td>"+symbols[dset[which][j]]+"="+alldata[dset[which][j]]+datalabels[dset[which][j]]+"<td></tr>";
	option=qset[which][Math.floor(Math.random()*qset[which].length)]
	thequest+="What is the "+symbols[option]+" for this mixture?"
	thequest+="</table>"
	theanswer=alldata[option]
	showquest(thequest)
}
function answer(theans){
	if(tried==1)alert("You've done this one! Get a new problem.");
	else{
	if(tried==2){totl++;document.forms[0].total.value=totl};
	attempts++
	if(theans>.95*alldata[option] && theans<1.05*alldata[option]){
		document.forms[0].results.value="Correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}
}}
