//Conversions - Masses
//updated 11/14/00-added complete solution
thepage="Conversions - Masses"
//11/18/02-updated netscape 7
//global variables
//refnumber=31
attempts=0
which=0
theanswer=0
corrt=0
totl=0
function quads(name,factor,mp,mp2){
	this.name=name
	this.factor=factor
	this.mp=mp
	this.mp2=mp2
}
mass=new Array()
mass[1]=new quads("pounds",1)
mass[2]=new quads("ounces",16,"*1/16")
mass[3]=new quads("milligrams",4.54e5,"*1000","*1/1000")
mass[4]=new quads("grams",454,"","")
mass[5]=new quads("kilograms",.454,"*1/1000","*1000")
link=new Array(" pounds to grams "," grams to pounds ")
seqence=new Array()
function startit(){
	totl++
	document.forms[0].total.value=totl
	clear()
	startmass=0
	while(startmass<1)startmass=number(10*Math.random(),3,3);
	first=Math.ceil(2*Math.random())
	second=2+Math.ceil(3*Math.random())
	if(Math.random()>10){
		fmas=startmass*(mass[first].factor)
		fdim=mass[first].name
		smas=startmass*(mass[second].factor)
		sdim=mass[second].name
		key=1
	}
	else{
		smas=startmass*(mass[first].factor)
		sdim=mass[first].name
		fmas=startmass*(mass[second].factor)
		fdim=mass[second].name
		key=2
	}
	fmas=number(fmas,3,3)
	smas=number(smas,3,3)
	thequest="Convert "+fmas+fdim+" to "+sdim
	showquest(thequest)
	answerpath(key)
	buildanswer(key)
}
function answerpath(key){
	if(key==1){
		path=link[0]
		if(first==2)path=" ounces "+" to "+path;
		if(second!=4)path=path+" to "+mass[second].name
	}
	else{	
		path=link[1]
		if(second!=4)path=mass[second].name+" to "+path;
		if(first!=1)path=path+" to "+mass[first].name
	}		
	path="This problem can be solved by following conversion(s):<br><br>"+path+"<br><br>"
}
function buildanswer(key){
	theanswer=""
	if(key==1){
		theanswer=fmas
		if(first==2)theanswer=theanswer+"*16";
		theanswer=theanswer+"*454"+mass[second].mp
		}				
	else{
		theanswer=fmas+mass[second].mp2+"*1/454"
		if(first==2)theanswer=theanswer+"*1/16"
		}
	theanswer=theanswer+"="+smas
	theanswer=path+theanswer
}
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*smas & theans<1.05*smas){
		corrt++
		document.forms[0].results.value="Correct"
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}
	}
}
