// JavaScript Document
thepage="Dealing with Three Variables"
a=0;b=0;c=0
variable=new Array()
relates=new Array("direct","inverse")
letters=new Array("A","B","C")
pairs=new Array("A and B:","A and C:","B and C:")
couples=new Array()
couples[0]=new Array(0,0,1)
couples[1]=new Array(0,1,0)
couples[2]=new Array(1,0,0)
couples[3]=new Array(1,1,1)
known=new Array()
known[0]=new Array(1,2)
known[1]=new Array(0,2)
known[2]=new Array(0,1)
keys=new Array()
keys[0]=new Array(0,1,2,3)
keys[1]=new Array(1,0,2,3)
keys[2]=new Array(1,2,0,3)
missing=0
option=0
first=second=0
cell=new Array()
cell[0]="<input type=radio name=theone onClick='answer(0)'>"
cell[1]="<input type=radio name=theone onClick='answer(1)'>"
cell[2]="<input type=radio name=theone onClick='answer(2)'>"
cell[3]="<input type=radio name=theone onClick='answer(3)'>"
solseq=new Array()
solseq[0]=new Array()
solseq[1]=new Array()
solseq[2]=new Array()
solseq[3]=new Array()
solseq[0][0]=new Array(1,"*",2)
solseq[0][1]=new Array(0,"http://proton.csudh.edu/",2)
solseq[0][2]=new Array(0,"http://proton.csudh.edu/",1)
solseq[1][0]=new Array(1,"http://proton.csudh.edu/",2)
solseq[1][1]=new Array(0,"*",2)
solseq[1][2]=new Array(1,"http://proton.csudh.edu/",0)
solseq[2][0]=new Array(2,"http://proton.csudh.edu/",1)
solseq[2][1]=new Array(2,"http://proton.csudh.edu/",0)
solseq[2][2]=new Array(0,"*",1)
solseq[3][0]=new Array(0,"*",2)
solseq[3][1]=new Array(0,"*",2)
solseq[3][2]=new Array(0,"*",2)

choices=new Array()
phrase=new Array("For a system fully defined by three variables,A,B and C, if the relations between the variables are as shown below, what will the value of "," be if the values of "," and ", " are "," and "," respectively?")
function cleanse(){
	timer(0)
	totl=0
	corrt=0
	document.forms[0].correct.value=""
	document.forms[0].total.value=""
	clear()
}
function clear(){
	document.forms[0].results.value=""
	tried=0
	clearansspot()
}

function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	for(j=0;j<3;j++){
		variable[j]=0
		while(variable[j]<1)variable[j]=10*Math.random();
	}
	option=Math.floor(4*Math.random())
	missing=Math.floor(3*Math.random())
	geta(variable,missing)
	for(k=0;k<3;k++)variable[k]=number(variable[k],3,3);
	buildquest(variable,missing,option)
}
function geta(variable,option){
	b=variable[known[missing][0]]
	c=variable[known[missing][1]]
	choices[0]=number((b*c),3,3)
	choices[1]=number((b/c),3,3)
	choices[2]=number((c/b),3,3)
	choices[3]=number((1/(b*c)),3,3)
}
function buildquest(variable,missing,option){
	thequest=phrase[0]+letters[missing]+phrase[1]+letters[known[missing][0]]+phrase[2]+letters[known[missing][1]]+phrase[3]+variable[known[missing][0]]+phrase[4]+variable[known[missing][1]]+phrase[5]+"<br>"
	j=0
	first=second=Math.floor(3*Math.random())
	while(first==second)second=Math.floor(3*Math.random())
	thequest+=(pairs[first]+relates[couples[option][first]])+"<br>"
	thequest+=(pairs[second]+relates[couples[option][second]])+"<br>"
	/*
	for(j=0;j<2;j++){
		thequest+=(pairs[j]+relates[couples[option][j]])+"<br>"
	}*/
	thequest+="<form>"
	j=0
	for(j=0;j<4;j++){
		thequest+=(cell[j]+choices[j])
	}
	thequest+="</form>"
	showquest(thequest)
	buildanswer()	
}
function buildanswer(){
	//buildequation()
	theanswer="From the relationships shown above, you should be able to construct the following equation:<br>"
	option==3?theanswer+=(letters[missing]+"=1/"):theanswer+=(letters[missing]+"=");
	theanswer+=(letters[solseq[option][missing][0]]+solseq[option][missing][1]+letters[solseq[option][missing][2]])
	theanswer+=("<br>Substituting in the values and solving yields:<Br>")
	if(option==3)theanswer+="1/index.html"
	theanswer+=(variable[solseq[option][missing][0]]+solseq[option][missing][1]+variable[solseq[option][missing][2]]+"="+choices[keys[missing][option]])
	//showanswer()
}

function answer(ans){
if(tried==1){
		alert("Sorry, you've already submitted this problem! We'll get you a new one!")
		startit()}
else{
 	if(tried==2){totl++;document.forms[0].total.value=totl}
	if (ans==keys[missing][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"
	}
}}
function update(){
	document.forms[0].total.value=totl
	document.forms[0].correct.value=corrt
	document.forms[0].time.value=howlong
	document.forms[0].page.value=thepage
	document.forms[0].verify.value=Math.round(10000*Math.random())
}
