thepage="Heatxfer-water WP(62)"
//11/20/02-updated netscape 7
refnumber=88
//global variables
attempts=0
which=0
theanswer=0
corrt=0
totl=0
option=0
ans=""
alldata=0
solved=0
function parts(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10){
	this.p1=p1
	this.p2=p2
	this.p3=p3
	this.p4=p4
	this.p5=p5
	this.p6=p6
	this.p7=p7
	this.p8=p8
	this.p9=p9
	this.p10=p10
}
//0=Tf1,1=Ti1,2=mass1,3=Tf2,4=Ti2,5=mass2
rowlabels=new Array("Sample 1","Sample 2")
datalabels=new Array("mass<sub>1</sub>","Ti<sub>1</sub>","mass<sub>2</sub>","Ti<sub>2</sub>","T<sub>f</sub>","mass<sub>total</sub>","dT<sub>1</sub>","dT<sub>2</sub>")
collabels=new Array("Mass","T<sub>i</sub>","T<sub>f</sub>")
dataunit=new Array("<sup>o</sup>C","<sup>o</sup>C","grams","<sup>o</sup>C","<sup>o</sup>C","grams")
question=new Array()
question[0]=new Array("A sample of water of unknown mass with a temperature of ","<sup>o</sup>C is combined with a sample of water with a mass of ","grams and a temperature of ","<sup>o</sup>C. The resultant mixture is found to have a final temperature of ","<sup>o</sup>C. What was the mass of the first sample?")
question[1]=new Array("A sample of water of unknown temperature with a mass of ","grams is combined with a sample of water with a mass of "," and a temperature of ","<sup>o</sup>C. The resultant mixture is found to have a final temperature of ","<sup>o</sup>C. What was the initial temperature of the first sample?")
question[2]=new Array("A sample of water with a mass of ","grams and a temperature of ","<sup>o</sup>C is combined with a sample of water with a temperature of ","<sup>o</sup>C and an unknown  mass. The resultant mixture is found to have a final temperature of  ","<sup>o</sup>C. What was the mass of the second sample?")
question[3]=new Array("A sample of water with a mass of ","grams and a temperature of ","<sup>o</sup>C is combined with a sample of water with a mass of ","grams and an unknown  temperature. The resultant mixture is found to have a final temperature of ","<sup>o</sup>C. What was the initial temperature of the second sample?")
question[4]=new Array("A sample of water with a mass of ","grams and a temperature of ","<sup>o</sup>C is combined with a sample of water with a mass of ","grams and a temperture of ","<sup>o</sup>C. What will be the temperature of the resultant mixture?")
seqs=new Array()
seqs[0]=new Array(1,2,3,4,8)
seqs[1]=new Array(0,2,3,4,8)
seqs[2]=new Array(0,1,3,4,8)
seqs[3]=new Array(0,1,2,4,8)
seqs[4]=new Array(0,1,2,3,8)
answerintro="To help with the presentation, the information in the question can be organized into the following table.<br>"
equation=new Array()
equation[0]=new Array("The basic equation for mixing samples of water with different initial temperatures is<br>",datalabels[0]+"*("+datalabels[4]+"-"+datalabels[1]+")+"+datalabels[2]+"*("+datalabels[4]+"-"+datalabels[3]+")=0")
equation[1]=new Array("Solving for mass<sub>1</sub> yields:<br>","-"+datalabels[2]+"*("+datalabels[4]+"-"+datalabels[3]+")/"+"("+datalabels[4]+"-"+datalabels[1]+")="+datalabels[0])
equation[2]=new Array("Evaluate the term for the first sample:<br>",datalabels[0]+"*("+datalabels[4]+"-"+datalabels[1]+")")
equation[3]=new Array("Evaluate the term for the second sample:<br>",datalabels[2]+"*("+datalabels[4]+"-"+datalabels[3]+")")
equation[4]=new Array("Solving for mass<sub>2</sub> yields:<br>","-"+datalabels[0]+"*("+datalabels[4]+"-"+datalabels[1]+")/"+"("+datalabels[4]+"-"+datalabels[3]+")="+datalabels[2])
equation[5]=new Array("Solving for Ti<sub>1</sub> yields:<br>",datalabels[2]+"*("+datalabels[4]+"-"+datalabels[3]+")/"+datalabels[0]+"+"+datalabels[4]+"="+datalabels[1])
equation[6]=new Array("Solving for Ti<sub>2</sub> yields:<br>",datalabels[0]+"*("+datalabels[4]+"-"+datalabels[1]+")/"+datalabels[2]+"+"+datalabels[4]+"="+datalabels[3])
equation[7]=new Array("Solving for T<sub>f</sub> yields:<br>","("+datalabels[0]+"*"+datalabels[1]+"+"+datalabels[2]+"*"+datalabels[3]+")/("+datalabels[0]+"+"+datalabels[2]+")="+datalabels[4])
eqnsets=new Array()
eqnsets[0]=new Array(0,1)

eqnsets[1]=new Array(0,5)
eqnsets[2]=new Array(0,4)
eqnsets[3]=new Array(0,6)
eqnsets[4]=new Array(0,7)
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	ti1=100*Math.random()
	ti2=ti1
	while(Math.abs(ti1-ti2)<10)ti2=100*Math.random();
	ti1=number(ti1,3,3)
	ti2=number(ti2,3,3)
	mass1=number(50*Math.random(),3,3)
	mass2=number(50*Math.random(),3,3)
	masst=number(1*mass1+1*mass2,3,3)
	tf=(mass1*ti1+mass2*ti2)/(1*mass1 + 1*mass2)
	dt1=number((tf-1*ti1),3,3)
	dt2=number((tf-1*ti2),3,3)
	tf=number(tf,3,3)
	alldata=new Array(mass1,ti1,mass2,ti2,tf,masst,dt1,dt2,"")
	option=Math.floor(5*Math.random())
	buildquest(option)
	buildanswer(option)
}
function buildquest(){
	thequest=""
	for(var j=0;j<5;j++)thequest+=question[option][j]+alldata[seqs[option][j]]
	showquest(thequest)
}

function buildanswer(option){
	thetable=gettable(option)
	getsolved()
	theanswer=answerintro+thetable
	for(var j=0;j<eqnsets[option].length;j++)theanswer+=(equation[eqnsets[option][j]][0]+equation[eqnsets[option][j]][1]+" =><br> "+solved[eqnsets[option][j]]+"<br>");
}
function getsolved(){
	solved=new Array()
	solved[0]=""
	solved[99]=alldata[0]+"*("+alldata[4]+"-"+alldata[1]+")+"+alldata[2]+"*("+alldata[4]+"-"+alldata[3]+")=0"
	solved[1]="-"+alldata[2]+"*("+alldata[4]+"-"+alldata[3]+")/"+"("+alldata[4]+"-"+alldata[1]+")="+alldata[0]
	solved[2]=alldata[2]+"*("+alldata[4]+"-"+alldata[3]
	solved[3]=alldata[2]+"*("+alldata[4]+"-"+alldata[3]
	solved[4]="-"+alldata[0]+"*("+alldata[4]+"-"+alldata[1]+")/"+"("+alldata[4]+"-"+alldata[3]+")="+alldata[2]
	solved[5]=alldata[2]+"*("+alldata[4]+"-"+alldata[3]+")/"+alldata[0]+"+"+alldata[4]+"="+alldata[1]
	solved[6]=alldata[0]+"*("+alldata[4]+"-"+alldata[1]+")/"+alldata[2]+"+"+alldata[4]+"="+alldata[3]
	solved[7]="("+alldata[0]+"*"+alldata[1]+"+"+alldata[2]+"*"+alldata[3]+")/("+alldata[0]+"+"+alldata[2]+")="+alldata[4]
}

function gettable(option){
	thetable="<table><tr><td></td>"
	for(j=0;j<3;j++)thetable+=("<td>"+collabels[j]+"</td>");	
	for(k=0;k<2;k++){
		thetable+=("<tr><td>"+rowlabels[k]+"</td>")
	for(l=0;l<3;l++){
			if(l<2)(2*k+l==option)?thetable+="<td>?</td>":thetable+="<td>"+alldata[2*k+l]+"</td>";
			else option==4?thetable+="<td>?</td>":thetable+="<td>"+alldata[4]+"</td>";
}
		thetable+="</tr>"
		}
	thetable+="</table>"
	return thetable
}		
function answer(ans){
	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(ans>.95*alldata[option] & ans<1.05*alldata[option]){
		document.forms[0].results.value="correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		tried=2
		document.forms[0].results.value="incorrect"
	}
}}
