// JavaScript Document
thepage="Percentages"
refnumber=8
//updated 12/02/02-netscape 7
tried=0
attempts=0
theanswer=0
answered=0
percent=0
which=0
all=0
part=0
totl=0
corrt=0
thedata=0
theanswer=""
needed=new Array()
needed[0]="part"
needed[1]="total"
needed[2]="per cent"
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]="part=(total*%)/100"
formula[1]="total=(part*100)/%"
formula[2]="%=(part/total)*100"
ansphrase=new parts("(I)%=(part/total)*100<br>Organize your data, identifying the givens and the unknown:","<br>Since you need to calculate<b> ","</b>, arrange equation(I):<br> ","<br>Substitute in the values and perform the calculation:")
function clear(){
	for(var j=0;j<3;j++)document.forms[0].elements[j].value="";
	document.forms[0].results.value=""
	tried=0
	attempts=0
	clearansspot()
	}
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	thedata=new Array()
	thedata[2]=0
	while(thedata[2]>95 || thedata[2]<5)thedata[2]=100*Math.random();
	thedata[1]=10*Math.random()
	thedata[0]=thedata[2]*thedata[1]/100
	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]+"/100="+thedata[0]
	if(which==1)thefinal="100*"+thedata[0]+"/"+thedata[2]+"="+thedata[1]
	if(which==2)thefinal="("+thedata[0]+"/"+thedata[1]+")*100="+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
		}
	}
}
