<!--



var x,y;

var X,Y,p,xpos,ypos,imgj;



xL=285;

xR=435;

yT=80;

yB=385;

snaptoXani=353;

snaptoXcat=330;

boxXani=462;

boxYani=155;

boxXcat=220;

boxYcat=155;





function m(j,x,y){

  xpos = x;

  ypos = y;      

  j.pixelLeft=x;

  j.pixelTop=y;

}



function g(e){

    imgj = window.event.srcElement;

    p = imgj.parentElement.style;

    return;

}



function MM(e){

  if (p) {

      m(p,(window.event.clientX-X+document.body.scrollLeft-2),(window.event.clientY-Y+document.body.scrollTop-1));

      return false;

  }

}







function MD(e){

    g(e);

    if (p){

        X=window.event.offsetX;

        Y=window.event.offsetY;

    }

    return false;

}





function MU(){ 

  imgSrc=imgj.src;

  idx=imgSrc.indexOf(".gif");	

  ionTest=imgSrc.charAt(idx-5);

  if (ionTest=="n") {

    if (xpos>xL && xpos<xR && ypos>yT && ypos<yB) {    

        p.pixelLeft=snaptoXani;		    			   

    }

    else {

        p.pixelTop=boxYani;

        p.pixelLeft=boxXani;

    }

  }

  else {

    if (xpos>xL && xpos<xR && ypos>yT && ypos<yB) {    

        p.pixelLeft=snaptoXcat;

    }				    			   

    else {

        p.pixelTop=boxYcat;

        p.pixelLeft=boxXcat;

    }

  }

  p=null; 

}



document.onmousemove=MM;







theCation="";

theAnion="";

currQuestion=0;

totalQuestions=10;

defaultEmail=email;

catQuestion = new Array();

anQuestion = new Array();

compQuestion = new Array();

nameQuestion = new Array();

correct=0;

graded=false;

gameOver=false;

mailFlag=false;

score=0;

numScored=0;



Cation = new Array("Mg2+", "Fe3+", "Au1+", "Co2+", "K1+", "Ni2+", "Ra2+", "Ca2+", "Mn3+", "Cu2+", "Rb1+", "Cs1+", "Sr2+", "Cd2+", "Au3+", "Fe2+", "Cu1+", "Cr2+", "Pb2+", "Bi3+", "Mn2+", "Sc3+", "Li1+", "Hg[2]2+", "Co3+", "NH[4]1+", "Hg2+", "Ag1+", "Sn4+", "Cr3+", "Na1+", "Sn2+", "Al3+", "Be2+", "Ba2+", "Pb4+");

Anion = new Array("C[2]H[3]O[2]1-", "N3-", "PO[4]3-", "ClO[3]1-", "I1-", "HCO[3]1-", "NO[2]1-", "PO[3]3-", "SO[4]2-", "ClO[2]1-", "SO[3]2-", "CrO[4]2-", "CN1-", "AsO[4]3-", "IO[3]1-", "C[2]O[4]2-", "BrO[3]1-", "P3-", "HSO[4]1-", "ClO1-", "IO[4]1-", "F1-", "IO[2]1-", "O2-", "NO[3]1-", "CO[3]2-", "BrO[4]1-", "ClO[4]1-", "OH1-", "Cr[2]O[7]2-", "S2-", "H[2]PO[4]1-", "Br1-", "Cl1-", "SCN1-", "MnO[4]1-");



cat_old=0;

catColor_old="#00FFFF";

ani_old=0;

aniColor_old="#00FFFF";

blink=false;

simRunning=false;

simBlinking=false;

scored=true;





function startSim() {



	whichButton();

	if(gameOver) {



		alert("The game is over!");

		return;



	}

	if(simRunning) return;

	if(simBlinking) return;

	totalQuestions=document.frmChem.hdnQuestions.value;

	sim = setInterval("changeImage()",200);

	simRunning=true;

	graded=false;

	document.frmChem.numWrong.value=0;

	whichButton();



}



document.frmChem.cmdStart.focus();

document.frmChem.txtCompound.value="Compound";

	

function configGame() {



	if(simRunning) {

		whichButton();

		return;

	}

	config = open("configIt.htm", "configGame", "toolbar=no,resizable=no,width=370,height=150,left=100,top=100");

	return;



}



function gameHelp() {



	if(simRunning) {

		whichButton();

		return;

	}

	help = open("help.htm", "gameHelp", "toolbar=no,resizeable=no,scrollbars=yes,width=500,height=270,left=100,top=100");

	return;



}



function aboutGame() {



	if(simRunning) {

		whichButton();

		return;

	}

	about = open("splash.htm", "abtGame", "toolbar=no,resizable=no,width=350,height=270,left=100,top=100");

	return;



}





function whichButton() {



	if(simRunning) {

		document.frmChem.cmdEnd.focus();

		return;

	}

	if(gameOver) {

		document.frmChem.cmdSubmit.focus();

		return;

	}

	if(graded) {

		document.frmChem.cmdReset.focus();

		return;

	}

	if(simBlinking) {

		document.frmChem.cmdSeeChems.focus();

		return;

	}

	document.frmChem.cmdStart.focus();



}



function changeImage() {

	window["cat"+cat_old].bgColor=catColor_old;

	randNum_cat = Math.floor(36*Math.random());

	catColor_old = window["cat"+randNum_cat].bgColor;

	window["cat"+randNum_cat].bgColor="#FFFFFF";	

	theCation=Cation[randNum_cat];

	document.frmChem.txtCation.value=theCation;

	document.frmChem.hdnCation.value=theCation;

	cat_old = randNum_cat;



	

	window["ani"+ani_old].bgColor=aniColor_old;

	randNum_ani = Math.floor(36*Math.random());

	aniColor_old = window["ani"+randNum_ani].bgColor;

	window["ani"+randNum_ani].bgColor="#FFFFFF";

	theAnion=Anion[randNum_ani];

	document.frmChem.txtAnion.value=theAnion;

	document.frmChem.hdnAnion.value=theAnion;

	ani_old = randNum_ani;





}



function stopSim() {



	whichButton();

	if(!simRunning) return;

	if(simBlinking) return;

	if(document.frmChem.txtCation.value == "Hg[2]2+") {

		window["ani"+ani_old].bgColor=aniColor_old;

		randNum_ani = Math.floor(36*Math.random());

		while (randNum_ani==1 || randNum_ani==2 || randNum_ani==7 || randNum_ani==13 || randNum_ani==17 || randNum_ani==34) {

			randNum_ani = Math.floor(36*Math.random());

		}

		aniColor_old = window["ani"+randNum_ani].bgColor;

		window["ani"+randNum_ani].bgColor="#FFFFFF";	

		theAnion=Anion[randNum_ani];

		document.frmChem.txtAnion.value=theAnion;

		document.frmChem.hdnAnion.value=theAnion;

		ani_old = randNum_ani;

	}

	simRunning=false;

	clearInterval(sim);

	currQuestion++;

	document.frmChem.hdnBool.value="false";

	document.frmChem.txtCurProb.value=currQuestion;

	anQuestion[currQuestion] = Anion[randNum_ani];

	catQuestion[currQuestion] = Cation[randNum_cat];

	document.frmChem.txtTotProb.value=totalQuestions;

	document.frmChem.txtCompound.select();

	simBlinking=true;

	switchDraggables();

	scored=false;

	simAns = setInterval("blinkImage()",500);

	whichButton();



}



function blinkImage() {



	if(blink) {

	

		window["cat"+randNum_cat].bgColor=catColor_old;

		window["ani"+randNum_ani].bgColor=aniColor_old;

		blink = false;



	} else {



		window["cat"+randNum_cat].bgColor="#FFFFFF";

		window["ani"+randNum_ani].bgColor="#FFFFFF";		

		blink = true;



	}



}



function seeChems() {

	if (document.frmChem.numWrong.value >= document.frmChem.retries.value) alert("Please hit the 'Reset It' button to try another compound");	

	else {

	if(document.frmChem.txtCompound.value=="Compound") {



		document.frmChem.txtCompound.select();

		if(simBlinking) alert("Please enter the compound in the selected field \n at the bottom of the toolbar!");

		whichButton();

		return;



	}

	graded=true;

	whichButton();

	if(currQuestion>=totalQuestions) {

		document.frmChem.cmdSubmit.focus();

		gameOver=true;

	}

	compQuestion[currQuestion]=document.frmChem.txtCompound.value;

	check = open("chem1.htm", "abtGame", "toolbar=no,resizable=no,width=550,height=220,left=100,top=100");

	return;

	}



}



function resetIt() {

	scoreIt();

	if(gameOver) {

		if(!mailFlag) {

			alert("Please mail your work!");

			whichButton();

			return;

		}

	}

	whichButton();

	if(simRunning) return;

	if(!simBlinking) return;

	if(!graded) return;

	clearInterval(simAns);

	window["cat"+randNum_cat].bgColor=catColor_old;

	window["ani"+randNum_ani].bgColor=aniColor_old;

	document.frmChem.txtAnion.value="";

	document.frmChem.txtCation.value="";

	document.frmChem.txtCompound.value="Compound";

	theCation="";

	theAnion="";

	document.frmChem.hdnCation.value="";

	document.frmChem.hdnAnion.value="";

	simRunning=false;

	simBlinking=false;

	graded=false;

	document.frmChem.numWrong.value=0;

	document.frmChem.formulaCorrect.value=0;

	document.frmChem.nameCorrect.value=0;

	document.frmChem.nameQuestionTemp.value="";



    	for (i=1;i<=4;i++) {

      		c = frmChem["cat"+i].parentElement.style;

      		c.pixelTop=boxYcat;

      		c.pixelLeft=boxXcat;

	  	frmChem["cat"+i].src = "clearpixel.gif";

      		a = frmChem["ani"+i].parentElement.style;

      		a.pixelTop=boxYani;

      		a.pixelLeft=boxXani;

	  	frmChem["ani"+i].src = "clearpixel.gif";

	}



    

    	document.frmChem.cmdStart.focus();

	

	if (gameOver) {

		mailFlag=false;

		document.frmChem.txtCurProb.value="";

		document.frmChem.txtTotProb.value="";

		document.frmChem.txtScore.value="";

		document.frmChem.hdnBool.value="false";

		document.frmChem.hdnScore.value=0;

		for(i=0;i<totalQuestions;i++) {



			catQuestion[i]="";

			anQuestion[i]="";

			compQuestion[i]="";



		}

		gameOver=false;

		correct=0;

		currQuestion=0;

		score=0;

		numScored=0;

		gameType();

	}



}



function mailReset() {

	if(document.frmChem.hdnReset.value=="true") {

		document.frmChem.hdnReset.value="false";

		clearInterval(mReset);

		resetIt();

	}

}



function mailIt() {

	if(!gameOver) {

		alert("Please finish before mailing your score!");

		whichButton();

		return;

	}
	
	if (document.frmChem.test.value == "false") {

		alert("Emailing results is disabled in practice mode!");

		whichButton();

		return;
	
	}
	
	if (numScored != document.frmChem.txtTotProb.value) {

		scoreIt();

	}

	mailFlag=true;

	catTemp="";

	anTemp="";

	compTemp="";

	nameTemp="";

	for(i=1;i<=totalQuestions;i++) {

		catTemp = catTemp + catQuestion[i] + "|";

		anTemp = anTemp + anQuestion[i] + "|";

		compTemp = compTemp + compQuestion[i] + "|";

		nameTemp = nameTemp + nameQuestion[i] + "|";

	}

	document.frmChem.hdnCatArray.value=catTemp;

	document.frmChem.hdnAnArray.value=anTemp;

	document.frmChem.hdnCompArray.value=compTemp;

	document.frmChem.hdnNameArray.value=nameTemp;

	mReset = setInterval("mailReset()",250);

	mailit = open("mail.htm", "mailit", "toolbar=no,resizable=no,width=420,height=230,left=100,top=100");

	return;

}



function switchDraggables() {

  if (document.frmChem.test.value == "false") {

	chemA=theCation;

	chemB=theAnion;



	idx1=chemA.indexOf("+");

	idx2=chemA.indexOf("-");

	if(idx1==-1) { idx1=idx2; }



	idx2=chemB.indexOf("+");

	idx3=chemB.indexOf("-");

	if(idx2==-1) { idx2=idx3; }



	sub1=chemB.charAt(idx2-1);

	sub2=chemA.charAt(idx1-1);	



	for (i=1;i<=4;i++) {

	frmChem["ani"+i].src = "anion" +sub1+ ".gif";

	frmChem["cat"+i].src = "cation" +sub2+ ".gif";

    }

  }

}



function scoreIt() {

	if (scored) return;

	numScored++;

	if (document.frmChem.formulaCorrect.value==1)  score += 5;

	if (document.frmChem.nameCorrect.value==1)  score += 5;

	document.frmChem.txtScore.value = score;

	document.frmChem.hdnScore.value = score;

	nameQuestion[currQuestion]=document.frmChem.nameQuestionTemp.value;

	scored=true;

}



function gameType() {

     if (email != "") {

	open("gameType.htm", "typeWin", "toolbar=no,resizable=no,width=350,height=100,left=300,top=200");

	return;

     }

}





//-->



