thepage="Base Solutions(81)"
//updated 11/18/02-netscape 7
//global variables
refnumber=114
theanswer=""
attempts=0
phans=0
corrt=0
totl=0
function parts(p1,p2,p3,p4,p5){
	this.p1=p1
	this.p2=p2
	this.p3=p3
	this.p4=p4
	this.p5=p5
}
function data(formula,name,K){
	this.formula=formula
	this.name=name
	this.K=K
}
hsym="[OH<sup>-</sup>]"
avalue="([C<sub>i</sub>*K<sub>b</sub>)<sup>1/2</sup>="+hsym
bases=new Array()
bases[0]=new data("C6H5NH2"," aniline ",4.3e-10)
bases[1]=new data("C5H5N","pyridine",1.8e-9)
bases[2]=new data("NH2OH","hydroxylamine",1.1e-8)
bases[3]=new data("C10H14N2","nicotine",1e-6)
bases[4]=new data("C17H19O3N","morphine",1.6e-6)
bases[5]=new data("NH2NH2","hydrazine",1.7e-6)
bases[6]=new data("NH3","ammonia",1.8e-5)
bases[7]=new data("(CH3)3N","trimethylamine",6.5e-5)
bases[8]=new data("CH3NH2","methylamine",3.6e-4)
bases[9]=new data("(C2H5)3N","triethylamine",1e-3)
function constants(){
var cont=window.open("","cont","scrollbars=yes,width=300,height=300")
cont.document.writeln ("<html>");
cont.document.writeln ("<head><title>Ionization Constants</title>");
cont.document.writeln ("</head>");
cont.document.writeln ("<body bgcolor = FFFFFF><b>Bases</b><table>");
for(k=0;k<=9;k++){
if(k==25){cont.document.writeln ("<tr><td><b>Bases</b><br></td></tr>")};
theK=bases[k].K
theK=number(theK,2,2)
cont.document.writeln("<tr><td>",bases[k]['name'],"</td><td>");
cont.document.writeln("<td>",showformula(k),"</td><td>");
cont.document.writeln("<td>",theK,"</td></tr>")};
cont.document.writeln("</table><form><input type=button value='Close Window' onClick='window.close()'></form>");
cont.document.writeln("<html>");
cont.document.close();
cont.focus();
}

checkstring="z0123456789"
ansphrase=new Array()
compare=new Array()
compare[0]=new Array(" <B>less</B> "," <B>valid</B>")
compare[1]=new Array(" <B>greater</B> "," <B>invalid</B> ")
ansphrase[1]=new parts("  has a K<sub>b</sub> of ",". First, calculate the value for the weak base approximation.<br>"," Since this is "," than 5% of the inital concentration ",",  the approximate value is ",".")
insphrase=new Array("<br> and the answer is pOH=","<br> and you must calculate the 'exact' answer using either successive approximations or the quadratic. This yields [OH<sup>-</sup>]=")
pathway=new Array()
pathway[0]=new Array(" less than "," valid ")
pathway[1]=new Array(" greater than "," invalid ") 
function startit(){
	clear()
	totl++
	document.forms[0].results.value=document.forms[0].theans.value=""
	document.forms[0].total.value=totl
	which=Math.floor(bases.length*Math.random())
	getconc()
}
function getconc(){
	first=0
	while(first<11)first=Math.ceil(100*Math.random());
	conc="0."+zero()+first
	getanswer(which,conc)
	buildquest(which,conc)
}
function zero(){
	added=""
	for(j=1;j<=Math.floor(3*Math.random());j++)added+="0";
	return added
}
function getanswer(which,conc){
	approx=Math.sqrt(conc*bases[which].K)
	check=.05*conc
	approx=number(approx,3,3)
	check=number(check,3,3)
	if(approx>check && Math.random()<.75){getconc()}
	else{
	if(approx<check){ans=approx;vkey=0;exans=approx}
	else{exans=(-bases[which].K+Math.sqrt(bases[which].K*bases[which].K+4*bases[which].K*conc))/2;vkey=1}
	phans=number((-Math.log(exans)/2.302),3,3)	
	buildanswer(which,conc,vkey,phans,exans,approx,check)
}}

function buildanswer(which,conc,vkey,phans,exans,approx,check){
	theanswer=""
	theanswer=bases[which].name+ansphrase[1].p1+number(bases[which].K,3,2)+ansphrase[1].p2+avalue+"<br>("+conc+"*"+number(bases[which].K,3,2)+")<sup>1/2</sup>="+number(approx,3,2)
	theanswer+=("<br>"+ansphrase[1].p3+compare[vkey][0]+ansphrase[1].p4+"("+number(check,3,2)+")"+ansphrase[1].p5+compare[vkey][1]+insphrase[vkey])
	if(vkey==0)theanswer+=phans;
	else theanswer=theanswer+number(exans,3,3)+" and pH="+phans;
}
function buildquest(){
	thequest="What is the pOH of a "+conc+"M solution of " 
	Math.random()>.5?thequest+=(bases[which].name+"?"):thequest+=(getformula()+"?")
	showquest(thequest)
}
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*phans & ans<1.05*phans){
		document.forms[0].results.value="Correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}}
}
function showformula(k){
	theformula=""
	teststring=bases[k].formula
	for(j=0;j<teststring.length;j++){
		checkstring.indexOf(teststring.charAt(j))>0?theformula+="<sub>"+teststring.charAt(j)+"</sub>":theformula+=teststring.charAt(j);
	}
	return theformula
}
function getformula(){
	theformula=""
	teststring=bases[which].formula
	for(j=0;j<teststring.length;j++){
		checkstring.indexOf(teststring.charAt(j))>0?theformula+="<sub>"+teststring.charAt(j)+"</sub>":theformula+=teststring.charAt(j);
	}
	return theformula
}
