//updated 11/14/00-added complete solution
thepage="Thermochemical Equations(64)"
refnumber=101
//global variables
corrt=0
tried=0
totl=0
which=0
opt=0
option=0
problem=""
thequest=""
thesolution=""
theanswr=0
theheat=0
qunit=""
qty=0
missing=0
mlabel=""
preamble="Given the following thermochemical equation:<br>"
question=new Array()
question[1]=new Array("What is the heat change in <b>KJ</b> accompanying the reaction of "," of ","?")
question[2]=new Array("What is the heat change in <b>KJ</b> accompanying the production of "," of ","?")
question[3]=new Array("If a reaction has a heat change of ","<B>KJ</b>, what quantity of "," in<b> ","</b> reacted?")
question[4]=new Array("If a reaction has a heat change of ","<b>KJ</b>, what quantity of "," in<b> ","</b> is produced?")
ansphrase=new Array("Heat can be treated like any other stoichiometric term in a balanced equation. In this case the relationship of the heat to<b> ","</b> is used to solve the question. You should recall that all stoichiometric relationships are direct. The solution follows the series of steps below.<Br>Since the missing quantity is ","<br>From the balanced equation it can be seen that:<br>","<br>As with other stoichiometry, the parenthetical terms are gotten from the balanced equation and, along with the given quantity, are substituted into the equation which is then solved:<br>")
//begin program
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	document.forms[0].results.value=""
	//the choose() function is part of reactionsets.js. It picks a reaction and builds arrays of formulas and masses
	choose()
	theheat=getheat()
	thequest=preamble+equation+"  <b> q= "+theheat+"</b>KJ<br>"
	buildquestion()
}
function getheat(){
	theheat=0
	while(theheat<50)theheat=number(5000*Math.random(),3,3)
	if(Math.random()>.5)theheat=-1*theheat
	return theheat
}
function buildquestion(which,opt){
	first=Math.floor(rxn[choice][0]*Math.random())
	second=first
	while(second<=(rxn[choice][0]-1))second=Math.floor(coeffs[choice].length*Math.random())
	if(Math.random()>.5){cpd=first;option=1}
	else{cpd=second;option=2};
	themass=number(100*Math.random(),3,3)
	cmpdmass=masses[cpd]/coeffs[choice][cpd]
	themoles=number(1*themass/cmpdmass,3,3)
	mlabel=new Array()
	if(Math.random()>.5){
		qunit="grams "
		qty=themass
		denom=masses[cpd]
		mlabel[1]=" grams of "+formula[cpd] 
		thisheat=theheat*qty/masses[cpd]
	}
	else{
		qunit="moles "
		qty=themoles
		denom=coeffs[choice][cpd]
		mlabel[1]=" moles of "+formula[cpd]
		thisheat=theheat*qty/coeffs[choice][cpd]
	}
	Math.random()>.5?missing=0:missing=2;
	if(missing==0){
		mlabel[0]=" q "
	      theanswr=thisheat
		thequest+="<br>"+question[option][0]+qty+qunit+question[option][1]+formula[cpd]+question[option][2]
	}
	else{
	theanswr=qty
	thequest+="<br>"+question[option+missing][0]+number(thisheat,3,3)+question[option+missing][1]+formula[cpd]+question[option+missing][2]+qunit+question[option+missing][3]
	}
	buildanswer(cpd)
	showquest(thequest)	
}
function buildanswer(cpd){
	theeqn=geteqns(cpd)
	theanswer=ansphrase[0]+qunit+" of "+formula[cpd]+ansphrase[1]+mlabel[1]+ansphrase[2]+theeqn[0]+ansphrase[3]+theeqn[1]
	//showanswer()
}
function geteqns(cpd){
	theeqn=new Array("","","")
	missing==0?theeqn[0]=("("+mlabel[0]+"/"+mlabel[1]+")*given "+qunit+"=?"):theeqn[0]=("("+mlabel[1]+"/q)*given q=?");
	missing==0?theeqn[1]=("("+theheat+"/"+denom+")*"+number(qty,3,3)+"="+number(thisheat,3,3)):theeqn[1]=("("+denom+"/"+theheat+")*"+number(thisheat,3,3)+"="+number(qty,3,3));
	return theeqn
}
function answer(val){
	if(tried==1)alert("You've done this one. Get a new problem.")
	else{
	attempts++
	test=1
	if(tried==1)alert("You've already done this problem. Get a new one!");
	else{
	if(tried==2){totl++;document.forms[0].total.value=totl};
	if(theanswr<0){
		if(val>1.05*theanswr & val<.95*theanswr)test=0;
	}
	else{
		if(val<1.05*theanswr & val>.95*theanswr)test=0;
	}
	if(test==0){
    		document.forms[0].results.value="correct"
    		corrt++
    		document.forms[0].correct.value=corrt
    		tried=1
	}
	else{
    		tried=2
    		document.forms[0].results.value="incorrect"}
	}	
}}
