// Nomenclature - Simple Naming Script
thepage="Nomenclature - Simple Naming"
//updated 11/14/00-added complete solution
//11/20/02-updated netscape 7
refnumber=136
attempts=0
tried=0
totl=0
corrt=0
anpre=""
catpre=""
theformula=""
thesolution=""
newone=""
function atom(name,sym,charge){
	this.name=name
	this.sym=sym
	this.charge=charge
	}
ansphrase=new Array(" only one possible combination of these is possible, prefixes are unnecessary."," there is more than one possible combination, prefixes are needed.")
anion=new Array();
cation=new Array();
cation[0]=new atom("lithium","Li",1)
cation[1]=new atom("beryllium","Be",2)
cation[2]=new atom("potassium","K",1)
cation[3]=new atom("calcium","Ca",2)
cation[4]=new atom("sodium","Na",1)
cation[5]=new atom("magnesium","Mg",2)
cation[6]=new atom("cesium","Cs",1)
cation[7]=new atom("barium","Ba",2)
cation[8]=new atom("rubidium","Rb",1)
cation[9]=new atom("strontium","Sr",2)
cation[10]=new atom("aluminum","Al",3)
cation[11]=new atom("ammonium","NH<sub>4</sub>",1)
cation[12]=new atom("carbon","C",4)
cation[13]=new atom("silicon","Si",4)
cation[14]=new atom("phosphorus","P",3)
cation[15]=new atom("phosphorus","P",5)
cation[16]=new atom("boron","B",3)
cation[17]=new atom("sulfur","S",4)
cation[18]=new atom("sulfur","S",6)
cation[19]=new atom("nitrogen","N",3)
anion[0]=new atom("oxide","O",2)
anion[1]=new atom("fluoride","F",1)
anion[2]=new atom("sulfide","S",2)
anion[3]=new atom("chloride","Cl",1)
anion[4]=new atom("selenide","Se",2)
anion[5]=new atom("bromide","Br",1)
anion[6]=new atom("iodide","I",1)
anion[7]=new atom("carbonate","CO<sub>3</sub>",2)
anion[8]=new atom("hydroxide","OH",1)
anion[9]=new atom("nitrate","NO<sub>3</sub>",1)
anion[10]=new atom("nitrite","NO<sub>2</sub>",1)
anion[11]=new atom("sulfate","SO<sub>4</sub>",2)
anion[12]=new atom("sulfite","SO<sub>3</sub>",2)
anion[13]=new atom("cyanide","CN",1)
anion[14]=new atom("permanganate","MnO<sub>4</sub>",1)
anion[15]=new atom("dichromate","Cr<sub>2</sub>O<sub>7</sub>",2)
anion[16]=new atom("phosphate","PO<sub>4</sub>",3)
anion[17]=new atom("perchlorate","ClO<sub>4</sub>",1)
anion[18]=new atom("chlorite","ClO<sub>2</sub>",1)
anion[19]=new atom("hypochlorite","ClO",1)
anion[20]=new atom("chlorate","ClO<sub>3</sub>",1)
anion[21]=new atom("phosphite","PO<sub>3</sub>",3)
anion[22]=new atom("chromate","CrO<sub>4</sub>",2)
anion[23]=new atom("acetate","C<sub>2</sub>H<sub>3</sub>O<sub>2</sub>",1)
anion[24]=new atom("oxalate","C<sub>2</sub>O<sub>4</sub>",2)
anion[25]=new atom("silicate","SiO<sub>3</sub>",2)
anion[26]=new atom("borate","BO<sub>3</sub>",3)
thepres=new Array("","mono","di","tri","tetra","penta","hexa","hepta","octa","nona")
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	cat=Math.floor(cation.length*Math.random())
	if(cat>11) ani=Math.ceil(6*Math.random());
	else ani=Math.floor(anion.length*Math.random());
	if((cat==17 || cat==18)& ani==2){totl--;startit()}
	if((cat==13)& ani==25){totl--;startit()}
	else{
	x=cation[cat].charge
	y=anion[ani].charge
	if(x==y){
		csub=1
		asub=1
	}
	if(x>y){
	if(x%y==0){
		csub=1
		asub=Math.ceil(x/y)
	}
	else{
	 	csub=y
		asub=x
		}
	}
	else{
	if(y%x==0){
		csub=Math.ceil(y/x)
		asub=1	
	}
	else{
	 	csub=y
		asub=x
	    }
	}
	csub==1?catsub="":catsub="<sub>"+csub+"</sub>";
	asub==1? ansub="":ansub="<sub>"+asub+"</sub>";
	if(catsub=="")catsym=cation[cat].sym;
	else{
		if(cat==11)catsym="(" + cation[cat].sym + ")" +catsub;
		else catsym=cation[cat].sym+catsub;
	}
	if(ansub=="")ansym=anion[ani].sym;
	else{
		if(ani>6) ansym="("+ anion[ani].sym + ")"+ ansub;
		else ansym=anion[ani].sym+ ansub;
	}
	theformula=catsym + ansym
	anpre=catpre=""
	if(asub==1 && ani==0 && cat>11)anpre="mon";
	else if(asub>1 & cat>11)anpre=thepres[asub];
	if(cat>11 & csub>1)catpre=thepres[csub];
	thename=catpre+cation[cat].name+ "  " + anpre + anion[ani].name
	firstpart=catpre + cation[cat].name
	secpart=anpre + anion[ani].name
	showquest(theformula)
	buildanswer()
}}
function buildanswer(){
	theanswer="Since "
	cat<12?theanswer+=ansphrase[0]+"<br>":theanswer+=ansphrase[1]+"<br>";
	if(cat>12){
		csub<2?theanswer+=("No prefix is needed for the "+ cation[cat].name):theanswer+=("The prefix '"+catpre+"' is used before the "+cation[cat].name);
		theanswer+=("<br>The prefix "+anpre+" is used for the "+anion[ani].name+".")
	}
	theanswer+="<br>The proper name is, therefore <b>"+ thename
} 
function splitit(test){
	first=""
	two=""
	for(j=0;j<test.length;j++){
	if(test.charAt(j)!=" "){first=first+test.charAt(j)}
	else{if(first!=""){break}}
	}
	a=first
	for(h=j;h<test.length;h++){
	if(test.charAt(h)!=" "){two=two+test.charAt(h)}
	}
	b=two
	answer(a,b)    
}
function answer(a,b){
	if(tried==1)alert("You've already done this one. Get a new problem");
	else{
	if(tried==2){totl++;document.forms[0].total.value=totl}
	a=a.toLowerCase()
	b=b.toLowerCase()
	if ( a==firstpart & b==secpart){
	document.forms[0].results.value="both correct"
	corrt++
	document.forms[0].correct.value=corrt
	tried=1
	}
	else{ 
	if(a!=firstpart & b!=secpart){
		document.forms[0].results.value="both incorrect"
		}
	else{
		if(a!=firstpart){
		document.forms[0].results.value="first incorrect"
		}
		else{
			document.forms[0].results.value="second incorrect"
			}
          }
	tried=2
	}
	}
}
