//Conversions - Length
//updated 11/14/00-added complete solution
//11/18/02-updated netscape 7
thepage="Conversions - Length"
var ie4 = (document.all) ? true : false;
//global variables
//refnumber=32
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
}
lengths=new Array()
lengths[1]=new quads("miles",.0000158,"*5280*12*2.54","*1/12*1/5280")
lengths[2]=new quads("yards",.0278,"*36*2.54","*1/36")
lengths[3]=new quads("feet",.08333,"*12*2.54","*1/12")
lengths[4]=new quads("inches",1,"*2.54","")
lengths[5]=new quads("millimeters",25.4,"*10","*1/10")
lengths[6]=new quads("centimeters",2.54,"","")
lengths[7]=new quads("meters",.0254,"*1/100","*100")
lengths[8]=new quads("kilometers",.0000254,"*1/1000","*10<sup>5</sup>")
seqence=new Array()
link=new Array(" inches to centimeter "," centimeters to inches ")
function startit(){
	totl++
	document.forms[0].total.value=totl
	clear()
	startlen=0
	while(startlen<1)startlen=Math.round(1000*Math.random())/10;
	first=Math.ceil(4*Math.random())
	second=4+Math.ceil(4*Math.random())
	if(Math.random()<.5){
		flen=startlen*(lengths[first].factor)
		fdim=lengths[first].name
		slen=startlen*(lengths[second].factor)
		sdim=lengths[second].name
		key=1
	}
	else{
		slen=startlen*(lengths[first].factor)
		sdim=lengths[first].name
		flen=startlen*(lengths[second].factor)
		fdim=lengths[second].name
		key=2
	}
	flen=number(flen,3,3)
	slen=number(slen,3,3)
	thequest="Convert "+flen+fdim+" to "+sdim
	showquest(thequest)
	answerpath(key)
	buildanswer(key)
}
function answerpath(key){
	if(key==1){
		path=link[0]
		if(first==1)path="miles to feet"+" to "+path;
		else if(first!=4)path=lengths[first].name+" to "+path;
		if(second==5)path=path+" to millmeters.";
		else{
			for(var j=7;j<=second;j++)path=path+" to "+lengths[j].name		
		}
	}
	else{	
		path=link[1]
		if(second==6)path=path;
		else{ if(second==5)path="millimeters to "+ path;
			else path=lengths[second].name+" to "+path;}
		if(first!=4)path=path+" to "+lengths[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=flen+lengths[first].mp
		if(second==5)theanswer=theanswer+"*10";
		else for(j=7;j<=second;j++)theanswer=theanswer+lengths[j].mp
	}			
	else{
		theanswer=flen+lengths[second].mp2+"*1/2.54"
		if(first<4)theanswer=theanswer+lengths[first].mp2
		}
	theanswer=theanswer+"="+slen
	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*slen & theans<1.05*slen){
		corrt++
		document.forms[0].results.value="Correct"
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}
	}
}
