// JavaScript Document
//updated 11/14/00-added complete solution
thepage="Density"
//11/18/02-updated netscape 7
attempts=0
which=0
themass=0
thevolume=0
thedensity=0
whichphrase=0
thesolution=""
totl=0
corrt=0
thedata=0
needed=new Array()
needed[2]="density"
needed[1]="volume"
needed[0]="mass"
choices=new Array()
function parts(p1,p2,p3,p4,p5,p6,p7,p8){
	this.p1=p1
	this.p2=p2
	this.p3=p3
	this.p4=p4
	this.p5=p5
	this.p6=p6
	this.p7=p7
	this.p8=p8
}
formula=new Array()
formula[0]="m=d*V"
formula[1]="V=m/d"
formula[2]="d=m/V"
ansphrase=new parts("(I)d=m/V<br>Organize your data, identifying the givens and the unknown:","Since you need to calculate<b> ","</b>, arrange equation(I):<br> ","<br>Substitute in the values and perform the calculation:")
function clear(){
	clearansspot()
	document.forms[0].mass.value=""
	document.forms[0].volume.value=""
	document.forms[0].density.value=""
	attempts=0
	tried=0
}
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	thedata=new Array()
	thedata[0]=100*Math.random()
	thedata[1]=100*Math.random()
	thedata[2]=thedata[0]/thedata[1]
	if(thedata[2]>10 || thedata[2]<.1){totl--;startit()}
	else{
	for(var j=0;j<3;j++)thedata[j]=number(thedata[j],3,3)
	which=Math.floor(3*Math.random())
	for(var j=0;j<3;j++)if(j!=which)document.forms[0].elements[j].value=thedata[j];
	buildanswer()
	}
}
function buildanswer(){
	thetable=gettable()
	if(which==0)thefinal=thedata[2]+"*"+thedata[1]+"="+thedata[0]
	if(which==1)thefinal=thedata[0]+"/"+thedata[2]+"="+thedata[1]
	if(which==2)thefinal=thedata[0]+"/"+thedata[1]+"="+thedata[2]
	theanswer=ansphrase.p1+thetable+ansphrase.p2+needed[which]+ansphrase.p3+formula[which]+ansphrase.p4+thefinal
}
function gettable(){
	thetable="<br>"
	for(j=0;j<3;j++)j==which?thetable+=needed[j]+"="+"?"+"<br>":thetable+=needed[j]+"="+thedata[j]+"<br>";
	return thetable
}	
function answer(form){
	if(tried==1)alert("You've already done this one! Get a new Problem");
	else{
	if(tried==2){totl++;document.forms[0].total.value=totl}
	attempts++
		if (form.elements[which].value>.95*thedata[which] & form.elements[which].value<1.05*thedata[which])
 		{		
		document.forms[0].results.value="correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
		}
	else {
		document.forms[0].results.value="incorrect"
		tried=2
		}
	}
}
