//Conversions - Temperature
thepage="Conversions - Temperature"
//11/18/02-updated netscape 7
//refnumber=20
attempts=0
KT=0
CT=0
FT=0
totl=0
corrt=0
theanswer=""
lines=new Array()
lines[1]=new parts("<sup>o</sup>C+273.15=K","","+273.15=<b>","K</b>")
lines[2]=new parts("5/9*(<sup>o</sup>F-32)=<sup>o</sup>C","5/9*(","-32)=<b>","<sup>o</sup>C</b>")
lines[3]=new parts("9/5*<sup>o</sup>C+32=<sup>o</sup>F","9/5*","+32=<b>","<sup>o</sup>F</b>")
lines[4]=new parts("K-273.15=<sup>o</sup>C","","-273.15=<b>","<sup>o</sup>C</b>")
pairs=new Array()
pairs[0]=new parts(4,3,1,2)
pairs[1]=new parts(1,3,0,2)
pairs[2]=new parts(2,1,1,0)
//This function clears all values in both tables on loading the page
//This function clears the first table
function clear(){
	document.forms[0].Ktemp.value=""
	document.forms[0].Ctemp.value=""
	document.forms[0].Ftemp.value=""
	document.forms[0].results.value=""
	attempts=0
	tried=0
	clearansspot()
}
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
}
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	KT=number((1000*Math.random()),4,3)
	CT=number((KT-273.15),4,3)
	FT=number((1.8*CT + 32),4,3)
	option=Math.floor(3*Math.random())
	if(option==0)document.forms[0].Ktemp.value=KT;
	if(option==1)document.forms[0].Ctemp.value=CT;
	if(option==2)document.forms[0].Ftemp.value=FT;
	temps=new Array(KT,CT,FT)
	buildanswer(option,temps)
}
function buildanswer(option,temps){
	line1=lines[pairs[option].p1].p1+"<br>"+lines[pairs[option].p1].p2+temps[option]+lines[pairs[option].p1].p3+temps[pairs[option].p3]+lines[pairs[option].p1].p4
	line2=lines[pairs[option].p2].p1+"<br>"+lines[pairs[option].p2].p2+temps[option]+lines[pairs[option].p2].p3+temps[pairs[option].p4]+lines[pairs[option].p2].p4
	theanswer=line1+"<br>"+line2
}
	
//This function checks for correctness by comparing the values. 
//The results are then posted to the second table. 
function answer(form){
	attempts++
	if(tried==1)alert("You've done this one! Get a new problem!");
	else{
	if(tried==2){totl++;document.forms[0].total.value=totl}
	cval=0
	if(option!=0){
		if(form.Ktemp.value<.95*KT || form.Ktemp.value>1.05*KT)cval++;
	}
	if(option!=1){
		if(FT<0){
			if(form.Ctemp.value>.95*CT || form.Ctemp.value<1.05*CT)cval++;
			}
		else{
			if(form.Ctemp.value<.95*Math.abs(CT) || form.Ctemp.value>1.05*Math.abs(CT))cval++;
		}
	}
	if(option!=2){
		if(CT<0){
			if(form.Ftemp.value>.95*FT || form.Ftemp.value<1.05*FT)cval++;
			}
		else{
			if(form.Ftemp.value<.95*Math.abs(FT) || form.Ftemp.value>1.05*Math.abs(FT))cval++;
			}
	}
	if(cval==0)	{	
		document.forms[0].results.value="correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
		}
	else {
		document.forms[0].results.value="incorrect"
		tried=2
		}
	}
}