//updated 11/14/00-added complete solution
thepage="Molarity - Solve for missing variables"
//11/20/02-updated netscape 7
//global variables
//refnumber=71
corrt=0
tried=0
totl=0
theanswer=""
alldata=0
solved=0
equation=new Array()
datalabels=new Array("<u>M</u>","moles","volume(L)")
equation[0]=datalabels[1]+"/"+datalabels[2]+"="+datalabels[0]//n/V=M
equation[1]=datalabels[0]+"*"+datalabels[2]+"="+datalabels[1]//M*V=n
equation[2]=datalabels[1]+"/"+datalabels[0]+"="+datalabels[2]//n/M=V
eqnsets=new Array()
function cleanse(){
	clear()
	totl=corrt=0
	document.forms[0].total.value=0
	document.forms[0].correct.value=0
}
function clear(){
	attempts=0
	tried=0
	clearansspot()
	document.forms[0].results.value=""
}
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	n=0
	while(n<.01)n=Math.random()
	v=0
	while(v<.1 || v>5)v=10*Math.random()
	M=n/v
	n=number(n,3,3)
	v=number(v,3,3)
	M=number(M,3,3)
	alldata=new Array(M,n,v)
	getsolved()
	setproblem()
	}
function getsolved(){
	solved=new Array()
	solved[0]=alldata[1]+"/"+alldata[2]+"="+alldata[0]//n/V=M
	solved[1]=alldata[0]+"*"+alldata[2]+"="+alldata[1]//M*V=n
	solved[2]=alldata[1]+"/"+alldata[0]+"="+alldata[2]//n/M=V
}
function setproblem(){
	empty=Math.floor(3*Math.random())
	for(var j=0;j<3;j++){
		j==empty?document.forms[0].elements[j].value="":document.forms[0].elements[j].value=alldata[j];
	}
	buildanswer(empty)
}
function buildanswer(empty){
	shown=new Array()
	for(j=0;j<3;j++){
		if(j!=empty)shown[shown.length]=j
	}
	theanswer="Given "+datalabels[shown[0]]+" and "+datalabels[shown[1]]+",  "+datalabels[empty]+" is calculated as shown below:<br><br>"+equation[empty]+"<br><br>"+solved[empty]
}
function answer(form){
	if(tried==1)alert("You've already done this one. Get a new problem.")
	else{
		attempts++
		if(tried==2){totl++;document.forms[0].total.value=totl};
	if(form.elements[empty].value>.95*alldata[empty] & form.elements[empty].value<1.05*alldata[empty]){
		form.results.value="correct"
		corrt++
		form.correct.value=corrt
		tried=1
	}
	else{
		form.results.value="incorrect"
		tried=2
	}
	}
}
